• Hi Guys,

    I am trying to create a class for my plugin but everytime I try to execute it I get errors. Code below followed by error message:

    class MyCourses
    {
    	function printNewCoursePage() {
    		echo "sheep";
    	}
    
    	function addNewCourse() {
    		add_menu_page(
    			'Courses',
    			'Manage Courses',
    			'administrator',
    			'newcourse',
    			'printNewCoursePage'
    		);
    	}
    }
    
    $abCourses = new MyCourses();
    add_action('admin_menu', array(&$abCourses, 'addNewCourse'));

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'printNewCoursePage' not found or invalid function name in C:\wamp\www\wordpress\wp-includes\plugin.php on line 339

    The problem is with the following line of code:
    add_action('admin_menu', array(&$abCourses, 'addNewCourse'));

Viewing 1 replies (of 1 total)
  • Try:

    add_menu_page(
    			'Courses',
    			'Manage Courses',
    			'administrator',
    			'newcourse',
    			array($this,'printNewCoursePage')
    		);

    If that doesn’t work– never tried exactly what you are trying– move your add_action into a constructor inside the class file.

Viewing 1 replies (of 1 total)

The topic ‘Plugin Class error message’ is closed to new replies.