How to Write a Wordpress Plugin – Sample Code
I wanted to write a plugin and came across an excellent site by Ronald Huereca that gives you good start on wordpress plugin. He gives a pdf down loadable file for wordpress plugn too.
How to Write a Wordpress Plugin, written by Ronald Huereca is an extensive, twelve entry series on the process of creating your own Wordpress plugin. Every step is covered, from “Seven Steps for Writing a Wordpress Plugin” all the way down to adding ajax to your plugin and releasing it. This is an excellent article series for anyone interested in the process behind creating your very first Wordpress plugin. With code examples to help assist you, you will be on your way to future releases of your own plugins for the Wordpress community.
The devlounge site by Ronald Huereca:
http://www.devlounge.net/extras/how-to-write-a-wordpress-plugin
There is one more site by lorelle :
http://lorelle.wordpress.com/2006/03/02/how-to-write-a-simple-wordpress-plugin/
The wordpress codex page gives complete introduction:http://codex.wordpress.org/Writing_a_Plugin
I tried a few sample plugins and reproduced below:
| What is a wordpress plugin? |
|---|
| The codex gives “A WordPress Plugin is a program, or a set of one or more functions, written in the PHP scripting language, that adds a specific set of features or services to the WordPress weblog, which can be seamlessly integrated with the weblog using access points and methods provided by the WordPress Plugin Application Program Interface (API).” |
/*
Plugin Name: Jiltin Simple Plugin
Plugin URI: http://www.notesbit.com
Description: This is just a test plugin
Author: Jiltin
Version: 1.0
Author URI: http://www.notesbit.com
*/
add_action(‘admin_menu’, ‘my_plugin_menu’);
function my_plugin_menu() {
add_options_page(‘My Plugin Options’, ‘My Plugin’, 8, ‘your-unique-identifier’, ‘my_plugin_options’);
}
function my_plugin_options() {
echo ‘<div class="wrap">’;
echo ‘<p>Here is where the form would go if I actually had options.</p>’;
echo ‘</div>’;
}
?>
Here is the little more complex plugin that adds few menu in your admin menu.
/*
Plugin Name: Jiltin Plugin Menuadd
Plugin URI: http://www.notesbit.com
Description: Jiltin Plugin Menuadd
Author: Jay
Author URI: http://www.notesbit.com
*/
// Hook for adding admin menus
add_action(‘admin_menu’, ‘mt_add_pages’);
// action function for above hook
function mt_add_pages() {
// Add a new submenu under Options:
add_options_page(‘Test Page title Options’, ‘Test menu title Options’, 8, ‘test_file_options’, ‘mt_options_page’);
// Add a new submenu under Manage:
add_management_page(‘Test Manage’, ‘Test Manage’, 8, ‘testmanage’, ‘mt_manage_page’);
// Add a new top-level menu (ill-advised):
add_menu_page(‘Test Toplevel’, ‘Test Toplevel’, 8, __FILE__, ‘mt_toplevel_page’);
// Add a new top-level menu (ill-advised):
// add_menu_page(’Test Toplevel2′, ‘Test Toplevel2′, 8, __FILE__, ‘mt_toplevel_page’);
// Add a submenu to the custom top-level menu:
add_submenu_page(__FILE__, ‘Test Sublevel’, ‘Test Sublevel’, 8, ’sub-page’, ‘mt_sublevel_page’);
// Add a second submenu to the custom top-level menu:
add_submenu_page(__FILE__, ‘Test Sublevel 2′, ‘Test Sublevel 2′, 8, ’sub-page2′, ‘mt_sublevel_page2′);
}
// mt_options_page() displays the page content for the Test Options submenu
function mt_options_page() {
echo "<h2>Test Options</h2>";
}
// mt_manage_page() displays the page content for the Test Manage submenu
function mt_manage_page() {
echo "<h2>Test Manage</h2>";
}
// mt_toplevel_page() displays the page content for the custom Test Toplevel menu
function mt_toplevel_page() {
echo "<h2>Test Toplevel</h2>";
}
// mt_sublevel_page() displays the page content for the first submenu
// of the custom Test Toplevel menu
function mt_sublevel_page() {
echo "<h2>Test Sublevel</h2>";
}
// mt_sublevel_page2() displays the page content for the second submenu
// of the custom Test Toplevel menu
function mt_sublevel_page2() {
echo "<h2>Test Sublevel 2</h2>";
}
?>

Very interesting post!
Thank you very much for such amazing ideas!!! I’ll be your follower, lots of interesting stuff here.
Admins, hello! here are having problems with your site. malware warning Write me. icq 674465674567
Всем хорошего времени суток! Кто знает где находится село дебесы?.
That was an excellently written essay, thank you so much.
Yes, really.
Umm, are you raelly just giving this info out for nothing?
Это мне напомнило одну фразу из известного фильма: