Support

Account

Home Forums ACF PRO Disable / Hide field for multiple users (names)

Solving

Disable / Hide field for multiple users (names)

    • Precies

    • September 3, 2019 at 1:23 am

    Hello,

    Using advanced custom field for a while now but never tried something that is in my head right now and I dont know if it is possible and if yes, how.

    I want to create a field that is only visible for users I say can see the field. So for example I have a field (FIELD 1) that normaly is visible for everyone I only want user_name_1, user_name_2 and user_name_3 to see this field when they are logged in.

    Is something like this possible and if yes, how.

    Any help would be very welcome

    Kind regards.

    Joep

    • Precies

    • September 4, 2019 at 7:59 pm

    I managed to get it to work this far:

    function my_acf_prepare_field_wordpress( $field ) {
    	$current_user = wp_get_current_user();
    	
    	if( $current_user->user_login == "Username" ) {
    		if( $field['value'] ) {
    			$field['disabled'] = true;
    		}
    	}
    	return $field;
    }
    
    add_filter('acf/prepare_field/name=pakket-of-dienst', 'my_acf_prepare_field_wordpress');

    The whole field is disabled with this function but I only need to disable a specific option of this select field.

    Is this possible, if yes, could anybody point me in the right direction?

    • Precies

    • September 5, 2019 at 12:06 am

    Fixed it with this function:

    function my_acf_prepare_field_wordpress( $field ) {
    	$current_user = wp_get_current_user();
    	if( $current_user->user_login != "User1" && $current_user->user_login != "User2") {
    		$choices = $field['choices'];
    		unset($field['choices']['your-field-option']);
    	}
    	return $field;
    }
    
    add_filter('acf/prepare_field/name=pakket-of-dienst', 'my_acf_prepare_field_wordpress');
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.