Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
thanks splashingpixels, appreciate your help just used the __('Contact'). –  DextrousDave Sep 2 '13 at 15:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.