HMVC framework for WordPress plugin development Download

Hello World

WordPress Plugin using WordPress Fuel


Below is the code for writing a simple Hello world plugin. This plugin displays user friendly message within WordPress admin.

/* 
Plugin Name: Hello World HMVC - Admin
Description: Sample Hello World Plugin using WordPress Fuel
Version: 1.0 
*/
require_once "mvc/init.php";
        
class WPFuel_HelloWorld_Plugin extends absMVC_Plugin
{
    protected $_plugin_slug = 'helloworld';

    protected function _init()
    {
        //nothing to init
    }
  
    public function registerAdminMenu()
    {
        $role = 'administrator';
        add_menu_page('Hello World', 'Hello World',$role, __FILE__); 
        
        add_submenu_page(__FILE__, 'Welcome', 'Welcome',$role, 
            $this->_getAdminPageSlug('home'), array($this , 'handleAdminMenu')
        ); 
        //output: http://yourdomain.com/wp-admin/admin.php?page=helloworld_home
    }
}

new WPFuel_HelloWorld_Plugin(__FILE__);

  • Line 8: WPFuel_HelloWorld_Plugin class inherits abstract absMVC_Plugin class.
  • Line 10: $_plugin_slug must be unique and one word that best defines your plugin. Mainly used for various namespacing reated features.
  • Line 12: _init() method's body is intentionally empty as there's no need for initialization.
  • Line 17: 'registerAdminMenu' method is used to generate admin menu for the plugin. handleAdminMenu is passed as a callback method to process the menu request. 'handleAdminMenu' is a generic method to process all the admin requests. It uses 'page' query parameter to dispatch the request to particular admin controller. helloworld_home is the controller.
  • Line 29: 'WPFuel_HelloWorld_Plugin' class is instiantiated.

Screenshot


As you can see the admin menu Hello world and the user friendly message.