I am loading my php file by putting this into my theme's functions.php:
require get_stylesheet_directory() . '/inc/manage-menus.php';
alter_menu('my-user', 'plugins.php', false);
The code in manage-menus.php looks like this:
function alter_item ($user, $items, $action) {
global $current_user, $menu;
get_currentuserinfo();
switch ($action) {
case false:
if ($current_user->user_login == $user) {
remove_menu_page ($items);
}
break;
case true:
if ($current_user->user_login == $user) {
//Do something else
}
break;
}
}
function alter_menu($user, $items, $action) {
add_action( 'admin_menu', 'alter_item' );
alter_item( $user, $items, $action );
}
I though when I use the admin_menu hook I should be on the safe side... but it tells me that:
Call to undefined function remove_menu_page() in ....
Any ideas?
PS I tried an OOP approach, which gave me the same result:
manage-menus.php:
abstract class admin_menu_alterations {
function hook_alter_menu(){
echo 'executing hook';
add_action( 'admin_menu',array( $this, 'alter_menu' ) );
}
public abstract function alter_menu($user, $items);
}
class hide_admin_menu_items extends admin_menu_alterations {
public function alter_menu($user, $items) {
$this->hook_alter_mennu();
global $current_user;
get_currentuserinfo();
echo $current_user->user_login;
if ($current_user->user_login == $user) {
remove_menu_page ($items_to_be_removed);
}
}
}
functions.php:
$hide_menu_items = new hide_admin_menu_items();
$hide_menu_items->alter_menu("my-user", "plugins.php");