Home › Forums › Feature Requests › Read-Only Field › Reply To: Read-Only Field
The following code will add a checkbox in text fields and if you check read-only, it will become read-only for all users.
The same login will apply to Disabled.
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' => 'true_false',
'name' => 'readonly',
));
acf_render_field_setting( $field, array(
'label' => __('Disabled?','acf'),
'instructions' => '',
'type' => 'true_false',
'name' => 'disabled',
));
}
add_filter('acf/prepare_field', 'filter_acf_prepare_field');
function filter_acf_prepare_field( $field ) {
if( !empty($field['readonly']) ){
$field['readonly'] = 1;
}
if( !empty($field['disabled']) ){
$field['disabled'] = 1;
}
return $field;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.