Skip to content

Instantly share code, notes, and snippets.

@mattradford
Created June 11, 2018 09:30
Show Gist options
  • Save mattradford/6756d401709b28249fab70bbb72cf0fc to your computer and use it in GitHub Desktop.
Save mattradford/6756d401709b28249fab70bbb72cf0fc to your computer and use it in GitHub Desktop.
Restrict ACF menu visibility based on the user's email domain
/**
* Restrict ACF Custom Fields menu to example.com domains only
*/
function td_acf_hide_admin() {
$current_user = wp_get_current_user();
$domain = substr(
strrchr(
$current_user->user_email,
"@"
), 1
); //Get Domain
$allowed_domains = array( 'example.com' );
if( !in_array( $domain, $allowed_domains ) ){
remove_menu_page( 'edit.php?post_type=acf-field-group' );
}
}
add_action( 'admin_init', 'td_acf_hide_admin' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment