Removing WordPress Plugin Menu Item for a specific user

I want to remove certain dashboard menu times for a specific user. Now this menu consist of plugin menu items as well. One particular plugin I want to hide from the user is Contact Form 7.

Here is the code added to the functions.php file to hide the menu items:

Read More
function remove_menus()
{
    global $menu;
    global $current_user;
    get_currentuserinfo();
    if($current_user->user_login == 'brian')
    {
        $restricted = array(__('Media'),
                            __('Links'),
                            __('Pages'),
                            __('Comments'),
                            __('Appearance'),
                            __('Plugins'),
                            __('Users'),
                            __('Tools'),
                            __('Settings'),
                    __('WPCF7')  //this does not work
        );
        end ($menu);
        while (prev($menu)){
            $value = explode(' ',$menu[key($menu)][0]);
            if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
        }// end while
    }// end if
}
add_action('admin_menu', 'remove_menus'); 

Now everything listed in the code above here is hidden, except for the Contact Form 7 Plugin menu. How do I call the correct plugin name?

Thanks

Related posts

1 comment

  1. Here is the code you need:

    global $current_user;
    get_currentuserinfo();
    
    if ( $current_user->user_login === 'brian' )
         remove_action( 'admin_menu', 'wpcf7_admin_menu', 9 );
    

    Or if you want to retain your own code, use this:

    function remove_menus()
    {
        global $menu;
        global $current_user;
        get_currentuserinfo();
        if($current_user->user_login == 'brian')
        {
            $restricted = array(__('Media'),
                                __('Links'),
                                __('Pages'),
                                __('Comments'),
                                __('Appearance'),
                                __('Plugins'),
                                __('Users'),
                                __('Tools'),
                                __('Settings'),
                        __('Contact')  //this does not work
            );
            end ($menu);
            while (prev($menu)){
                $value = explode(' ',$menu[key($menu)][0]);
                if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
            }// end while
        }// end if
    }
    add_action('admin_menu', 'remove_menus'); 
    

    I changed WPCF7 to Contact in the array.

Comments are closed.