0

I have added some custom tables to a wordpress and trying to add wp-admin section to manage them. By using following code I have successfully added a menu item in wp-admin but I'm unable to call the php page that resides into my theme folder

add_menu_page('Private Messages', 'Private Messages', 'manage_options',
              'message_admin', 'message-admin.php',
               get_bloginfo('stylesheet_directory').'/style/images/message.png');

in error_log it gives me this error

PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'message-admin.php' not found or invalid function name in /var/www/idon.dev/wp-includes/plugin.php on line 470, referer: http://idon.dev/wp-admin/admin.php?page=message_admin

Update:

The wordpress says

$function

(string) (optional) The function that displays the page content for the menu page. Default: None. Technically, the function parameter is optional, but if it is not supplied, then WordPress will assume that including the PHP file will generate the administration screen, without calling a function. Most plugin authors choose to put the page-generating code in a function within their main plugin file. In the event that the function parameter is specified, it is possible to use any string for the file parameter. This allows usage of pages such as ?page=my_super_plugin_page instead of ?page=my-super-plugin/admin-options.php.

I know what does it mean

PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function

but what I'm trying to achieve is to call a page rather of function. what is according to wordpress is possible, or guide me if I'm wrong.

Please note that I don't want to include page in functions, I will rather be happy to add my code into function.

2

The error tells you what the problem is...

PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ...

Your "callback" isn't a function. It is a file. It doesn't work that way. You will need a helper function to include a file. Something like:

add_menu_page(
  'Private Messages', 
  'Private Messages', 
  'manage_options',
  'message_admin', 
  'include_message_admin',
  get_bloginfo('stylesheet_directory').'/style/images/message.png'
);

function include_message_admin() {
  // include('/path/to/message-admin.php');
  // something like
  include(get_template_directory().'/message-admin.php');
  // or 
  include(get_stylesheet_directory().'/message-admin.php');
}
  • please check the update in the question – riksof-zeeshan May 8 '14 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.