• Hi everybody

    I’m trying to create a plugin. But i wanna do it in OOP and i encounter an ‘undefined’ problem when i try to use wordpress’s functions in my class. My question is this: How can i use wordpress’s functions like ‘add_menu_page()’, ‘add_plugins_page()’, ‘add_action()’, …?

    Thanks for your help.

Viewing 1 replies (of 1 total)
  • You need to pass $this before adding/mentioning the functions. If you are developing plugin with OOP concept, you need to add/use $this else your functions won’t come into action.

    
    class My_Class_Name
    {
    
    	function __construct() 
    	{
    		if (is_admin()) {
    			add_action('admin_menu',array(&$this,'my_class_admin_settings'));
    		}
    	}
    
    	public function my_class_admin_settings()
    	{
    		add_menu_page('Page Title','Menu Title','manage_options','my_menu_page',array($this,'my_func_menu_page'),'dashicons-welcome-widgets-menus', 6);
    	}
    
    	public function my_func_menu_page()
    	{
    		// Your functionality goes here
    	}	
    } // end class
    
    For the callback name, use this: array($this,'<function name>')
    
Viewing 1 replies (of 1 total)

The topic ‘Plugin Development’ is closed to new replies.