-
-
Save vovadocent/107954847a288729c6eada52c0439f08 to your computer and use it in GitHub Desktop.
<?php | |
add_action('acf/render_field_settings/type=text', 'add_readonly_and_disabled_to_text_field'); | |
function add_readonly_and_disabled_to_text_field($field) { | |
acf_render_field_setting( $field, array( | |
'label' => __('Read Only?','acf'), | |
'instructions' => '', | |
'type' => 'radio', | |
'name' => 'readonly', | |
'choices' => array( | |
1 => __("Yes",'acf'), | |
0 => __("No",'acf'), | |
), | |
'value' => 0, | |
'layout' => 'horizontal', | |
)); | |
acf_render_field_setting( $field, array( | |
'label' => __('Disabled?','acf'), | |
'instructions' => '', | |
'type' => 'radio', | |
'name' => 'disabled', | |
'choices' => array( | |
1 => __("Yes",'acf'), | |
0 => __("No",'acf'), | |
), | |
'value' => 0, | |
'layout' => 'horizontal', | |
)); | |
} |
Hello, is the code to save and apply HTML to the field not done yet?
Hi. In fact, this is a simply extension of the field configuration, after which you will have the opportunity to set attributes ("disabled" or "readonly") for simple ACF text fields from the admin area
Hi, yes but it seems that it indeed add the "disabled" checkbox to the admin ACF field configurator. But the field itself (on the post page let's say for example) seems not disabled.
I believe it misses the acf/prepare_field
hook part to update the field config and disable it.
I ended disabling the entire group from the acf/prepare_field
hook, and it would be easy to update to match your new field.
Hi, yes but it seems that it indeed add the "disabled" checkbox to the admin ACF field configurator. But the field itself (on the post page let's say for example) seems not disabled. I believe it misses the
acf/prepare_field
hook part to update the field config and disable it.I ended disabling the entire group from the
acf/prepare_field
hook, and it would be easy to update to match your new field.
Usually, I didn't need to apply these attributes somewhere on the front, and that's why I have noted this solution, which is focused exclusively for the admin area use.
To be honest, this note is pretty old and I'm not even sure it still works. And that's why I don't mind you supplementing this solution yourself ;)
If you would like to use ACF's standard style that it uses for choices when creating fields. i.e. true/false field:
add_action('acf/render_field_settings/type=text', 'add_readonly_and_disabled_to_text_field');
function add_readonly_and_disabled_to_text_field($field)
{
acf_render_field_setting( $field, array(
'label' => __('Read Only?'),
'instructions' => '',
'name' => 'readonly',
'type' => 'true_false',
'ui' => 1,
), true);
}
The parameter 'value' => 0
must be removed else it doesn't save current state.
Hello, is the code to save and apply HTML to the field not done yet?