25% off ProSNIPC25OFF

ACF: Hide a Field Group from Non-Admins

Hides every field belonging to a specific ACF field group from users who do not have the manage_options capability by returning false from acf/prepare_field.

PHPby SnipCraft
php
<?php
// Replace "group_XXXXXXXXXXXXXXXX" with your actual ACF field group key.
// The key is shown in the ACF field group list (e.g. group_5f3b2a1c4d8e9).
define( 'SCSEED_RESTRICTED_GROUP_KEY', 'group_XXXXXXXXXXXXXXXX' );

add_filter( 'acf/prepare_field', function( $field ) {
    if ( ! is_array( $field ) ) {
        return $field;
    }

    // Only process fields whose direct parent matches the restricted group key.
    $parent = isset( $field['parent'] ) ? $field['parent'] : '';
    if ( $parent !== SCSEED_RESTRICTED_GROUP_KEY ) {
        return $field;
    }

    // Show the field to admins; hide it from everyone else.
    if ( current_user_can( 'manage_options' ) ) {
        return $field;
    }

    return false;
} );
#acf#admin#field-group#permissions#roles