Skip to content

Instantly share code, notes, and snippets.

@vovadocent
Last active April 26, 2024 21:52
Show Gist options
  • Save vovadocent/107954847a288729c6eada52c0439f08 to your computer and use it in GitHub Desktop.
Save vovadocent/107954847a288729c6eada52c0439f08 to your computer and use it in GitHub Desktop.
Readonly and disabled to ACF text field
<?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',
));
}
@aaronsummers
Copy link

aaronsummers commented Nov 22, 2022

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);
	
}

@classikd
Copy link

The parameter 'value' => 0 must be removed else it doesn't save current state.

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