Support » Plugins and Hacks » Jetpack Only for Admins » conflict with AJAX due to PHP warning
3 years ago
This could be the source of other bugs reported here.
We are getting a debug warning that breaks AJAX responses, even though WP_DEBUG is off. Here is a fix:
* Updated to use the fix suggested here: http://wordpress.org/support/topic/warning-while-using-wp-cli *
Version: 1.1, file jp-rm-jpmenu.php, line 36:
add_action( 'admin_init', 'jp_rm_menu' );
add_action( 'admin_menu', 'jp_rm_menu' );
The error we are seeing is in remove_menu_page():
<b>Warning</b>: Invalid argument supplied for foreach() in <b>.../wp-admin/includes/plugin.php</b> on line <b>1375</b><br />
I have not encountered this bug on my WP site. However using ‘admin_init’ correctly hides the Jetpack menu items, but ‘admin_menu’ does NOT.
2 years, 11 months ago
Well, I believe my other fix was something like if (defined('DOING_AJAX') && DOING_AJAX) return;. You don’t need to add menus in admin_init when doing AJAX.
if (defined('DOING_AJAX') && DOING_AJAX) return;
But the correct way is probably ‘admin_menu’. Maybe change the priority so it works with JetPack?
2 years, 9 months ago
I am experiencing the same issue where if I change ‘admin_init’ to ‘admin_menu’ then it resolves the errors, but no longer hides the Jetpack menu item.
Could you elaborate on how exactly to implement one of your other fixes?
2 years, 6 months ago
add_action( 'admin_menu', 'jp_rm_menu', 2000 );
// Note Jetpack 3.0.2 uses 'admin_menu' priority 998 and 999