Hiding Meta Box Plugin from WordPress Dashboard Menu for Non-Admins

Support General Hiding Meta Box Plugin from WordPress Dashboard Menu for Non-AdminsResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27373
    omarthegeekomarthegeek
    Participant

    The Meta Box plugin is currently visible as an item on the WordPress Dashboard Menu to Administrators as well as non Administrators users ex: Editor User.

    While those non Administrators get a message saying "Sorry, you are not allowed to access this page.", I would very much prefer the plugin was fully hidden from them instead of showing them something they shouldn't have access to.

    I know there are plugins out there for customizing the menu and such, but I would rather prefer a simple script to add to functions.php to hide it from all users except Administrators.

    Thanks!

    #27382
    Long NguyenLong Nguyen
    Moderator

    Hi Omar,

    Please try to use this code to remove the Meta Box menu from the dashboard if the user is not an administrator.

    add_action( 'admin_init', 'remove_menu_metabox' );
    
    function remove_menu_metabox() {
        if ( !current_user_can( 'administrator' ) ) { //change role or capability here
            remove_menu_page( 'meta-box' );
        }
    }
    #27398
    omarthegeekomarthegeek
    Participant

    Worked beautifully, Thanks!

    #45642
    Keith CrossKeith Cross
    Participant

    Could this be an administrator setting in the plugin? It's very likely a common need.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.