Support » Plugins » Adding Menu Pages

  • I am trying to create a plugin for myself, and I am having errors creating the menus. I have read the documentation and searched up and down for an answer.

    I am using add_menu_page() and add_submenu_page() to create my menus. The menu options are created on the sidebar, but the functions which should be run to display the page throw errors.

    The error is:

    Warning: call_user_func_array() []: First argument is expected to be a valid callback, 'hg_menu_main' was given in /home/mydir/public_html/mysite/wp-includes/plugin.php on line 339

    My function which is called to build the menus:

    function hg_buildAdmin() {
    	//required files
    	require(WP_PLUGIN_URL . '/my_plugin/menu_main.php');
    	require(WP_PLUGIN_URL . '/my_plugin/menu_add.php');
    	add_menu_page('MyMenu', 'MyMenu', 10, 'menu_main', 'hg_menu_main');
    	add_submenu_page('menu_main', 'Sub1', 'Sub1', 10, 'menu_main', 'hg_menu_main');
    	add_submenu_page('menu_main', 'Sub2', 'Sub2', 10, 'menu_add', 'hg_menu_add');

    I am guessing it has something to do with the fact that my functions for creating pages are in seperate files, because if I add the functions directly to the main plugin file, it seems to work fine. I do not want this though. Please help me.

    [moderated–bump removed. Please refrain from bumping as per Forum Rules]

Viewing 1 replies (of 1 total)
  • Hi,

    Are you including those pages before making the call? Maybe you could try including them inside the function, something like:

    function hg_menu_main(){

    It’s not a clean way, but it worth the shot I think 😛

Viewing 1 replies (of 1 total)
  • The topic ‘Adding Menu Pages’ is closed to new replies.