Skip to content

Instantly share code, notes, and snippets.

@santanup789
Created July 28, 2022 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santanup789/0b54a69093278dba072cb32a182646b0 to your computer and use it in GitHub Desktop.
Save santanup789/0b54a69093278dba072cb32a182646b0 to your computer and use it in GitHub Desktop.
Render Read only and Disable option for any ACF
//Just repeat this add_action hook available for the ACF plugin
//add_action('acf/render_field_settings/type=text', 'add_readonly_and_disabled_to_text_field');
//for the other types of fields be just changing the value of the type in the hook "/type=text".
//e.g. add_action('acf/render_field_settings/type=textarea', 'add_readonly_and_disabled_to_text_field');
//It will add 2 radio option read-only and disable the field for the textarea field.
<?php
add_action('acf/render_field_settings/type=textarea', 'add_readonly_and_disabled_to_text_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?','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'readonly',
'choices' => array(
1 => __("Yes",'acf'),
0 => __("No",'acf'),
),
'layout' => 'horizontal',
));
acf_render_field_setting( $field, array(
'label' => __('Disabled?','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'disabled',
'choices' => array(
1 => __("Yes",'acf'),
0 => __("No",'acf'),
),
'layout' => 'horizontal',
));
}
?>
@santanup789
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment