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 am using User Role Editor to specify customized user roles. I am also using Advanced Custom Fields plugin.

I would like to be able to hide Advanced Custom Fields from showing up for certain users; however, the only way to do this in User Role Editor is to uncheck "Manage Options" box. The problem with doing this is it removes other plugins from showing up which I in fact would like to show up for those users.

Is there a bit of manual code I can place in my functions.php that will remove only Advanced Custom Fields for certain user roles? Just this plugin.

share|improve this question

1 Answer 1

The admin_menu action will hide the ACF menu, in this example for not-admins.

And admin_head will block the access if the URL is accessed directly.
E.g.: http://example.com/wp-admin/edit.php?post_type=acf and http://example.com/wp-admin/edit.php?post_type=acf&page=acf-settings

add_action( 'admin_menu', 'wpse_59032_remove_acf_menu', 9999 );
add_action( 'admin_head-edit.php', 'wpse_59032_block_acf_screens' );
add_action( 'admin_head-custom-fields_page_acf-settings', 'wpse_59032_block_acf_screens' );

function wpse_59032_remove_acf_menu() 
{
    /* if not our allowed users, hide menu */
    if ( !current_user_can('delete_plugins') ) {
        remove_menu_page('edit.php?post_type=acf');
    }
}

function wpse_59032_block_acf_screens()
{   
    global $current_screen;

    /* not our screen, do nothing */
    if( 'edit-acf' != $current_screen->id && 'custom-fields_page_acf-settings' != $current_screen->id )
        return;

    /* if not our allowed users, block access */
    if ( !current_user_can('delete_plugins') ) {
        wp_die('message');
    }

}
share|improve this answer

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.