Code: Select all
<?php
/*
Plugin Name: My First Plugin
Plugin URI: http://jim.killanet.net/blog/
Version: 0.1
Description: This is the first plugin that I have made for WordPress
Author: Jim Anderson
Author URI: http://jim.killanet.net/blog/
*/The next part is a comment block required by WordPress to let WordPress know what your plugin is and to create that nifty activate/deactivate row in the plugin management table. The only "required" field is the plugin name, however, these are the most basic fields and placing all of them in the comment block is helpful to other people. If not to yourself at a later date when you wonder what a plugin does or give it to someone else and they need to contact you.
Code: Select all
function add_plugin_page()
{
add_menu_page('My First Plugin', 'Plugin', '8', __FILE__, 'plugin_content');
}"function add_plugin_page()" is a function who's sole purpose is to call the "add_menu_page" function. The first field in the "add_menu_page()" function is the text that WordPress will append to the title in the title bar. Next is the text that will appear in the actual menu on the admin page; that you click to view your plugin. The third field is the user level which is able to use your plugin, with "0" being the lowest and "10" being the WordPress Blog Admins. Fourth is the file name which contains the function which WordPress should run when it initiates the script, in this case we use PHP's "__FILE__" to signify that the current file should be use. Lastly we have the name of the function that WordPress needs to call in order to display the content of your plugin. This last field is not necessary and if you do not include it, WordPress simply assumes that by including the file, the content will be either echoed or printed out.
Code: Select all
function plugin_content() {
print "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque quam.";
}Code: Select all
add_action('admin_menu', 'add_plugin_page');As promised, here is the full, uncommented code (minus of course, the WordPress required comments. that you can use as a skeleton or for anything you wish.
Code: Select all
<?php
/*
Plugin Name: My First Plugin
Plugin URI: http://jim.killanet.net/blog/
Version: 0.1
Description: This is the first plugin that I have made for WordPress
Author: Jim Anderson
Author URI: http://jim.killanet.net/blog/
*/
function add_plugin_page()
{
add_menu_page('My First Plugin', 'Plugin', '8', __FILE__, 'plugin_content');
}
function plugin_content() {
print "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque quam.";
}
add_action('admin_menu', 'add_plugin_page');
?>Code: Select all
<?php
/*
Plugin Name: My First Plugin
Plugin URI: http://jim.killanet.net/blog/
Version: 0.1
Description: This is the first plugin that I have made for WordPress
Author: Jim Anderson
Author URI: http://jim.killanet.net/blog/
*/
/*
Function for adding a new page to the menu.
*/
function add_plugin_page()
{
add_menu_page('My First Plugin', 'Plugin', '8', __FILE__, 'plugin_content');
}
/*
Function that displays any and all of the content that is to be displayed in our plugin.
*/
function plugin_content() {
print "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque quam.";
}
/*
Function for adding the "add_plugin_page" sink to the admin menu hook
*/
add_action('admin_menu', 'add_plugin_page');
?>

