How to Write a Wordpress Plugin – Sample Code

Posted by Jay     25 August, 2009    12,751 views   

fruit_plugin.jpgI 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).”
<?php
/*
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.

physical_electrical_plugin.jpg

<?php
/*
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>";
}

?>

Following Google Searches Lead To This Post: writing a wordpress plugin + examples
add_menu_page submenu
sample wordpress plugin
create plugin sample example wordpress
wp add_menu_page
èíòåðüåð
how to write the server code in wordpress
write form plugin in wordpress
add_menu_page examples
write plugin in wordpress with mysql database
wordpress add_menu_page adds extra page
wordpress plugin mysql editor
add_menu_page()+example
wordpress plugin sample
how to create a wordpress plugin for database operations
linux wordpress writing
write your own wordpress menu
wordpress add_menu_page current class on link
wordpress create plugin write to database
wordpress plugin add_menu_page tutorial
ôîêóñ
plugins wordpress submenu
wordpress +plugin +sample
add_menu_page wordpress example
add_options_page example
add_options_page wordpress
wordpress add_menu_page example
how write code in post wordpress
// Add a new submenu under Options: in wordpress
wordpress submenu plugin
wordpress add_menu_page editor and administrator
add submenu page wordpress plugin
add_action(’admin_menu’, ‘mt_add_pages’);
wordpress plugin write ajax
creating a wordpress plugin add_options_page
wordpress add_menu_page
wordpress plugin samples
create a plugin for wordpress add_menu_page
add_menu_page wordpress
wordpress submenus example
how to write applications for wordpress
wordpress plugin add_submenu_page handle
wordpress plugin admin page menu
mt_add_pages
add_menu_page example wordpress
wordpress write plugin sample
wordpress sample program
wordpress plugin writing example
Writing a WordPress Plugin database
wordpress plugin add_menu_page
write linux plugin
wordpress sample plugin create with example
write plugins example
sample code for adding menus in wordpress through php
wordpress option page add_menu_page
wordpress option page add_menu_page editor
how to write a wordpress plugin
free wordpress themes fruit
Categories : Plugins, Web & Scripts, wordpress Tags : ,

Comments
May 15, 2011

Very interesting post! :)

Posted by flashuac
May 29, 2011

Thank you very much for such amazing ideas!!! I’ll be your follower, lots of interesting stuff here.

Posted by eve isk
June 4, 2011

Admins, hello! here are having problems with your site. malware warning Write me. icq 674465674567

Posted by triliaDap
June 10, 2011

Всем хорошего времени суток! Кто знает где находится село дебесы?.

Posted by kapustmaks
June 16, 2011
Posted by rpv5t4n8
July 4, 2011

That was an excellently written essay, thank you so much.

Posted by grandresume
July 24, 2011

Yes, really.

Posted by berrygergyVof
July 30, 2011

Umm, are you raelly just giving this info out for nothing?

Posted by Allayna
September 1, 2011

Это мне напомнило одну фразу из известного фильма:

Posted by Cigonceidgego
Leave a comment

(required)

(required)