WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#17585 closed defect (bug) (invalid)

Function remove_menu_page() makes an error message

Reported by: Surbma Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1.3
Component: Plugins Keywords: has-patch
Focuses: Cc:

Description

If I use the function remove_menu_page() an error message appears every time when I'd like to quick edit a post or page and also when I'm editing a post or page and it autosaves itself or if I make a change in the permalink of the post or page.

The error message is this:
Warning: Invalid argument supplied for foreach() in /storage1/home/premiumw/public_html/wp-admin/includes/plugin.php on line 1264

Warning: Invalid argument supplied for foreach() in /storage1/home/premiumw/public_html/wp-admin/includes/plugin.php on line 1264

Warning: Cannot modify header information - headers already sent by (output started at /storage1/home/premiumw/public_html/wp-admin/includes/plugin.php:1264) in /storage1/home/premiumw/public_html/wp-includes/class-wp-ajax-response.php on line 129

When I disable the plugin, the error is not appearing. This error message was not there in the 3.1.2 version.

Attachments (3)

Screen_shot_1.jpg (113.8 KB) - added by Surbma 10 years ago.
After autosave
Screen_shot_2.jpg (46.2 KB) - added by Surbma 10 years ago.
Permalink editing
Screen_shot_3.jpg (50.5 KB) - added by Surbma 10 years ago.
After quickedit

Download all attachments as: .zip

Change History (7)

@Surbma
10 years ago

After autosave

@Surbma
10 years ago

Permalink editing

@Surbma
10 years ago

After quickedit

#1 @nacin
10 years ago

  • Keywords reporter-feedback added

I don't think this is an issue with 3.1.3 vs 3.1.2. Rather, you're calling remove_menu_page() before $menu is actually set up, or it seems in cases when $menu is never set up. You need to wait for the admin_menu hook to actually call remove_menu_page(). If you're doing it on admin_init, then you're using the wrong hook, and that's why it's borking on AJAX requests.

We *could* do some poka-yoke there, by returning false if $menu isn't set. But I'd rather it fail that way plugins know they're doing something wrong.

#2 @Surbma
10 years ago

  • Keywords has-patch added
  • Type changed from defect (bug) to task (blessed)

This is the official reference: http://codex.wordpress.org/Function_Reference/remove_menu_page

It suggests to hook on admin_init. If this is not the right hook, than the reference should be changed. I used this hook in 3.1.2 and before without any error.

I've changed the hook to admin_menu and it is now working without the error message. :) So I see, this is not a bug, but a wrong instruction in the codex.

#3 @Surbma
10 years ago

  • Keywords reporter-feedback removed

#4 @nacin
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Type changed from task (blessed) to defect (bug)

This isn't a task... Anyway, I'm closing this and I'll modify the Codex. (Keep in mind it's a wiki, so anyone can edit.)

Thanks.

Note: See TracTickets for help on using tickets.