[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 09:55:14 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:  Plugins       |    Version:  6.2.2
 Severity:  blocker       |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 {{{#!php
 <?php
   add_action('admin_init', function () {
     current_user_can('administrator') || remove_menu_page('tools.php');
   });
 }}}

 When I log in with administrator, everything is fine, but when I switch to
 another user, I can't get into Media Manager.

 Check the source code and find that '/wp-admin/includes/plugin.php' of
 'remove_menu_page' does not check if '$menu' is empty.

 {{{#!php
 <?php
   function remove_menu_page( $menu_slug ) {
     global $menu;

     if (!empty($menu)) {
       foreach ( $menu as $i => $item ) {
         if ( $menu_slug === $item[2] ) {
           unset( $menu[ $i ] );
           return $item;
         }
       }
     }


     return false;
   }
 }}}

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


More information about the wp-trac mailing list