admin管理员组

文章数量:1201788

I am trying to add a Menu in WordPress Admin Panel. I am using below code.

This code is working.

add_submenu_page('weather_info', 'Weather Information', 'Weathers', 'manage_options', 'weathers', [$this, 'weathers']);

But below code is not working. I am facing error Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'edit.php?post_type=weather' not found or invalid function name .

add_submenu_page('weather_info', 'Weather Information', 'Weathers', 'manage_options', 'weathers', 'edit.php?post_type=weather');

I am trying to add a Menu in WordPress Admin Panel. I am using below code.

This code is working.

add_submenu_page('weather_info', 'Weather Information', 'Weathers', 'manage_options', 'weathers', [$this, 'weathers']);

But below code is not working. I am facing error Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'edit.php?post_type=weather' not found or invalid function name .

add_submenu_page('weather_info', 'Weather Information', 'Weathers', 'manage_options', 'weathers', 'edit.php?post_type=weather');
Share Improve this question asked May 31, 2022 at 2:04 FoysalFoysal 4451 gold badge5 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

edit.php?post_type=weather isn't a valid PHP function name.

If you're trying to set the menu up as a submenu of your custom post screens, I think edit.php?post_type=weather—the $parent_slug—should be the first parameter, not the last. ie,

add_submenu_page(
  'edit.php?post_type=weather',
  'Weather Information',
  'Weathers',
  'manage_options',
  'weathers',
  [$this, 'weathers']
);

References

  • add_submenu_page()

本文标签: wp adminaddsubmenupage() issue