Title: Plugin Class error message
Last modified: August 19, 2016

---

# Plugin Class error message

 *  [shadd](https://wordpress.org/support/users/shadd/)
 * (@shadd)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/plugin-class-error-message/)
 * 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)

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/plugin-class-error-message/#post-1285507)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/plugin-class-error-message/#post-1285507)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
