Oterox
7/14/2019 - 10:28 AM

WordPress Hide admin menu based on user role

WordPress Hide admin menu based on user role

<?php
/* check if user is administrator - only show downloads menu if is admin */
add_action( 'admin_init', 'ox_remove_menu_pages' );
function ox_remove_menu_pages() {
    global $user_ID;
    //if the user is NOT an administrator remove the menu for downloads
    if ( !current_user_can( 'administrator' ) ) { //change role or capability here
        remove_menu_page( 'edit.php?post_type=wpdmpro' ); //change menu item here
    }
}
?>