Skip to content

Instantly share code, notes, and snippets.

@jo-snips
Forked from brasofilo/authorized-acf-access.php
Created December 9, 2012 01:22
Show Gist options
  • Select an option

  • Save jo-snips/4242890 to your computer and use it in GitHub Desktop.

Select an option

Save jo-snips/4242890 to your computer and use it in GitHub Desktop.
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( $current_user->user_login != 'admin' )
{
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment