[wp-trac] [WordPress Trac] #58403: Running remove_menu_page in the theme will cause admin-ajax.php 500 errors

WordPress Trac noreply at wordpress.org
Thu May 25 13:10:25 UTC 2023


#58403: Running remove_menu_page in the theme will cause admin-ajax.php 500 errors
--------------------------+------------------------------
 Reporter:  niau          |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Menus         |     Version:  6.2.2
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by petitphp):

 * component:  Plugins => Menus
 * severity:  blocker => normal


Comment:

 Hello @niau and welcome to trac.

 Looking at your example, you are calling the function `remove_menu_page`
 during the `admin_init` action.
 According to
 [https://developer.wordpress.org/reference/functions/remove_menu_page
 /#more-information the documentation for this function], you should be
 using the `admin_menu` action instead to avoid the error.
 The `admin_init` action is too early, and the menu is not ready to be
 manipulated at this point.

 Can you try to change the hook and see if you still have the issue ?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58403#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list