[wp-trac] [WordPress Trac] #51254: includes/plugin.php remove_menu_page should check if $menu is array

WordPress Trac noreply at wordpress.org
Sat Sep 5 17:05:13 UTC 2020


#51254: includes/plugin.php remove_menu_page should check if $menu is array
----------------------------+-----------------------
 Reporter:  kernelzechs     |       Owner:  (none)
     Type:  defect (bug)    |      Status:  reopened
 Priority:  normal          |   Milestone:
Component:  Administration  |     Version:
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:
----------------------------+-----------------------
Changes (by kernelzechs):

 * status:  closed => reopened
 * resolution:  duplicate =>


Comment:

 Thanks for getting back to me so quickly!

 However we saw a case related to admin_init hook where on a normal admin
 page (front-end) works as defined here:
 https://developer.wordpress.org/reference/functions/remove_menu_page/
 (also recommended in the comments depending on how quickly you needed
 something removed, in our case early)

 However when admin-ajax.php would be called it would try and run the
 admin_init hook and thus would fail since the menu isn't loaded. At the
 very least some sort of context detection would be optimal here if not a
 fix for detecting the object type prior to running. We have worked around
 the issue code wise on our end, but I would rather see it handled
 gracefully.

 Replying to [comment:1 SergeyBiryukov]:
 > Hi there, welcome to WordPress Trac! Thanks for the report.
 >
 > Just noting this was discussed a few times before, specifically in
 #23767 and #19937.
 >
 > Adding an `is_array()` or `! empty()` check would remove the warning,
 but would also just hide the fact that calling the function the function
 too early or on an incorrect hook still doesn't work as expected.
 >
 > comment:1:ticket:23767 outlines a few scenarios where this warning can
 occur. All of them are developer errors, so the developer should see that
 something is wrong. Hiding the warning would just make debugging harder.

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


More information about the wp-trac mailing list