A Minimal Plugin for WordPress
I recently found a need to access data held in a WordPress database. Although I could have written code that accessed the database directly, I decided to write a plugin so that I could use the in-built WordPress functions.
Writing a WordPress plugin is fairly straightforward and I would recommend reading information provided at wordpress.org for writing plugins
http://codex.wordpress.org/Writing_a_Plugin
http://codex.wordpress.org/Function_Reference
However, if it’s of any interest, here are my efforts at creating a minimal plugin. A minimal plugin is presented which can be re-used, essentially as a starting point, for creating various different plugins, and is the minimum structure required when creating a plugin for WordPress.
I created a file, called minimal_plugin.php, containing the following code and placed it in my wordpress plugins directory. (wordpress/wp-content/plugins). The plugin, called Minimal Plugin is then available in the list of plugins:

When this plugin is activated, a menu item Minimal Plugin is added to the WordPress Dashboard:

The code consists of 2 functions
function minimal_addMenu() is used to add a menu item and is called by
-
add_action(‘admin_menu’, ‘minimal_addMenu’);
which adds the menu item to the dashboard admin page.
function minimal_adminMenu() defines what is displayed on the page under the Minimal Plugin tab. This can also used to call available internal WordPress functions that allow you to access details available in the database.
In addition, information is used from the comments section
-
/*
-
Plugin Name: Minimal Plugin
-
Plugin URI: http://somewhere/
-
Description: Minimal Plugin
-
Author: Minimal
-
Version: 0.0.1
-
Author URI: http://somewhere/
-
*/
Here is the complete code listing
-
<?php
-
/*
-
Plugin Name: Minimal Plugin
-
Plugin URI: http://somewhere/
-
Description: Minimal Plugin
-
Author: Minimal
-
Version: 0.0.1
-
Author URI: http://somewhere/
-
-
Last update: 09/20/07 (09/20/07)
-
-
Functions:
-
minimal_adminMenu: where all the work is done
-
-
Copyright 2006-2007 Minimal
-
-
This program is free software; you can redistribute it and/or modify
-
it under the terms of the GNU General Public License as published by
-
the Free Software Foundation; either version 2 of the License, or
-
(at your option) any later version.
-
-
This program is distributed in the hope that it will be useful,
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
GNU General Public License for more details.
-
-
You should have received a copy of the GNU General Public License
-
along with this program; if not, write to the Free Software
-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
*/
-
$minimal_version = ‘v0.0.1′; // the current version
-
-
// more details at …
-
// http://codex.wordpress.org/Writing_a_Plugin
-
// http://codex.wordpress.org/Function_Reference
-
-
-
function minimal_addMenu()
-
{
-
{
-
add_submenu_page(‘index.php’, ‘Minimal Plugin Template’, ‘Minimal Plugin’, 1, basename(__FILE__),‘minimal_adminMenu’);
-
}
-
}
-
-
function minimal_adminMenu()
-
{
-
global $minimal_version;
-
echo(‘<div class="wrap">’);
-
echo("<h2>Minimal Plugin – version $minimal_version</h2><br /><br />");
-
echo(‘</div>’);
-
}
-
-
add_action(‘admin_menu’, ‘minimal_addMenu’);
-
-
?>
Nice article. thanks