Allow menu items by users

With this snippet you can hide menu items from all users and only allow selected admins access.

This snippet is custom for ACF – add to functions.


function remove_acf_menu()
{

// provide a list of usernames who can edit custom field definitions here

$admins = array( 
        'Lee Rickler'
    );
 
    // get the current user
    $current_user = wp_get_current_user();
 
    // match and remove if needed
    if( !in_array( $current_user->user_login, $admins ) )
    {
        remove_menu_page('edit.php?post_type=acf');
        remove_menu_page('acf-options');
    }
 
}
add_action( 'admin_menu', 'remove_acf_menu', 999 );