Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hide ACF Menu from Clients
/**
* A method to really block access to ACF menu
* http://www.advancedcustomfields.com/docs/tutorials/hide-acf-menu-from-clients/
*/
/**
* Remove ACF menu item from the admin menu
*/
add_action( 'admin_menu', 'acf_remove_menu_page', 15 );
function acf_remove_menu_page()
{
global $current_user;
get_currentuserinfo();
if( 'admin' != $current_user->user_login )
{
remove_menu_page( 'edit.php?post_type=acf' );
}
}
/**
* Prevent unauthorized access to ACF menus
*/
add_action( 'admin_head', 'acf_prevent_url_access' );
function acf_prevent_url_access()
{
global $current_screen, $current_user;
// Not our pages, exit earlier
if( 'edit-acf' != $current_screen->id && 'custom-fields_page_acf-settings' != $current_screen->id )
return;
// Authorized user, exit earlier
if( $current_user->user_login == 'admin' )
return;
// User not authorized to access page, redirect to dashboard
wp_redirect( admin_url() );
exit;
}
@augustoms

This comment has been minimized.

Copy link

commented Dec 27, 2012

In the "acf_prevent_url_access" function, we got an error with the wp_redirect( admin_url() ) - header information can’t be modified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.