Skip to content

Instantly share code, notes, and snippets.

@brasofilo
Created December 8, 2012 18:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brasofilo/4241339 to your computer and use it in GitHub Desktop.
Save brasofilo/4241339 to your computer and use it in GitHub Desktop.
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
Copy link

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