WordPress Starter Plugin

Everything you need to write your own plugin. This is the starter solution. It shows how to plugin with your own class to wordpress, already set up custom functions. This is version 1 of this empty plugin. The admin menu (with a submenu), a settings page, another settings page. You can do just about anything your heart desires with wordpress, and plugging into it is pretty easy. Check this out:

/////////////////////////////////////////////////////////////////
/*
Plugin Name: Steve's Starter Plugin
Plugin URI: http://stevesplugin.StevenKohlmeyer.com/
Version: v1.00
Author: Steven Kohlmeyer
Description: A starter Plugin to write any plugins from.
Copyright 2010  Steven Kohlmeyer  (email : StevenKohlmeyer [a t ] g m ail DOT com)
*/

/*  Copyright 2010
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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

if( !class_exists('MY_Plugin') )
{
	class MY_Plugin
	{
		var $thispluginurl = '';
		var $thispluginpath = '';
		var $adminOptionsName = "MY_Options";  

		function MY_Plugin()
		{
			//constructor
		}
		function init()
        {
            $this->getAdminOptions();
        }
		function getAdminOptions()
        {
			$MYPluginOptions = array(
                'abc' => '',
                'def' => '',
                'ghi' => '',
				'jkl' => '',
				'mno' => '',
				'pqr' => '',
				'stu' => '');
			$MYOptions = get_option($this->adminOptionsName);
			if (!empty($MYOptions))
            {
                foreach ($MYOptions as $key => $option)
                {
                    $MYPluginOptions[$key] = $option;
                }
            }
            update_option($this->adminOptionsName, $MYPluginOptions);
            return $MYPluginOptions;
		}
		function printAdminPage()
		{
			global $wpdb;
			$MYOptions = $this->getAdminOptions();

			//Print Admin Settings Page Here

			echo "Admin Page Settings. . . . . . . .
n";
		}
		function printImportPage()
		{
			global $wpdb;
			$MYOptions = $this->getAdminOptions();

			//Print Admin Settings Page Here

			echo "Import Page . . . . . . . .
n";
		}

	}
}

if (class_exists("MY_Plugin"))
{
    $MY = new MY_Plugin();
}
if (!function_exists("MY_admin"))
{
    function MY_admin_menu()
	{
		global $MY;
		if (!isset($MY))
        {
            return;
        }
		if (function_exists('add_menu_page'))
        {
			//add_menu_page('Page title', 'Top-level menu title', 'manage_options', 'my-top-level-handle', 'my_magic_function');
            add_menu_page( 'MY Settings', 'MY', 'install_plugins', basename(__FILE__), array(&$MY, 'printAdminPage'), 'icon.jpg', 1 );
			//add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );

		}
		if (function_exists('add_submenu_page'))
		{
			add_submenu_page( basename(__FILE__), 'MY Settings', 'Settings', 'install_plugins', basename(__FILE__), array(&$MY, 'printAdminPage'));
			add_submenu_page( basename(__FILE__), 'MY Import', 'Import', 'install_plugins', 'MY_import.php', array(&$MY, 'printImportPage'));
			//add_submenu_page( 'my-top-level-handle', 'Page title', 'Sub-menu title', 'manage_options', 'my-submenu-handle', 'my_magic_function');

		}

	}
}

if (isset($MY))
{
	//Actions here
	add_action('admin_menu', 'MY_admin_menu');

	//Filters here

}
This entry was posted in Internet, PHP, techblog, Web Development & Administration, Wordpress. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted October 9, 2011 at 1:04 pm | Permalink

    How can i provide update functionality in my plugin. do i need to add any hook or action for it.?
    thanks

    • SteveK
      Posted November 10, 2011 at 4:10 am | Permalink

      Upload it to wordpress.org?

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>