I have a snippet of code I've written in the functions.php file which is simply to remove menu pages if the user cannot activate plugins. It works as intended; however it is showing a PHP error in the admin area only if the logged in user is an administrator.
Here's the code snippet:
<?php
/************ Remove admin menu items from anyone who isn't an admin ************/
if (!current_user_can('activate_plugins') ) {
function my_remove_menu_pages() {
remove_menu_page('link-manager.php');
remove_menu_page('tools.php');
remove_menu_page('edit-comments.php');
}
};
add_action( 'admin_menu', 'my_remove_menu_pages' );
?>
Here's the error:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'my_remove_menu_pages' not found or invalid function name in /var/www/vhosts/mydomain.com/httpdocs/wp-includes/plugin.php on line 406
I've tried rewriting the snippet a couple different ways, and each time it basically does the same thing. Works as intended, removing admin menu pages for less than admins, but gives the same error in the WP backend when logged in as admin. Any suggestions or thoughts on this?
add_actionline inside theif (!current_user_can('activate_plugins') ) {? – Mike Madern Feb 27 at 14:47