Support

Account

Home Forums Backend Issues (wp-admin) Filter acf/load_field to Disable Fields not working in User Profile Reply To: Filter acf/load_field to Disable Fields not working in User Profile

  • Ensuring that the filter priority was more than 10 didn’t fix the problem. Here is the full code for the filter:

    
    /**
     * Modify fields on load based on our advanced settings
     */
    function tgmembership_modify_acf_field_on_load( $field ) {
    	// get plugin settings
    	$options = get_option( 'tgmembership_options' );
    	// get names of fields that should be read-only
    	$readonly_fields = array_map('trim', explode(",", $options["acf_readonly"]));
    	
    	// loop each readonly slug and set the disabled flag on those fields
    	foreach ($readonly_fields as $name) {
    		if ($field["name"] == $name) {
    			$field['disabled'] = 1;
    		}
    	}
    	
    	// return the field
    	return $field;
    }
    add_filter('acf/load_field', 'tgmembership_modify_acf_field_on_load', 16);
    

    I really think that ACF just isn’t respecting the disabled flag when adding fields to the User Profile. If that is the case then maybe I just can’t use ACF for the fields I want read-only (there are a few others I need to do manually anyway as they’re more complex, so that wouldn’t be a real problem). But I’d consider that a bug in ACF.