Hide ACF Fields From Non-Administrators
Hides the ACF fields you choose in the editor for everyone except administrators, such as internal notes or technical settings.
Opens WPIDE on
Code
// Field names only administrators see.
$wpide_acf_admin_fields = array( 'internal_notes', 'tracking_code' );
foreach ( $wpide_acf_admin_fields as $wpide_acf_admin_field ) {
add_filter( 'acf/prepare_field/name=' . $wpide_acf_admin_field, function ( $field ) {
return current_user_can( 'manage_options' ) ? $field : false;
} );
}
Notes
Hidden fields keep their saved values. Change manage_options to target another role.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.