Skip to content

Instantly share code, notes, and snippets.

@raftaar1191
Created May 11, 2020 09:54
Show Gist options
  • Save raftaar1191/565014438cd15a0480f8fb76fea861e3 to your computer and use it in GitHub Desktop.
Save raftaar1191/565014438cd15a0480f8fb76fea861e3 to your computer and use it in GitHub Desktop.
ACF custom required field message
function bbdfy_acf_require_custom_message( $field ) {
acf_render_field_setting(
$field,
array(
'label' => __( 'Custom Error Message', 'acf' ),
'instructions' => __( 'Error Message to display when feidls is require and not submitted.', 'acf' ),
'type' => 'textarea',
'name' => 'custom_error_message',
'rows' => 5,
),
true
);
}
add_action( 'acf/render_field_settings', 'bbdfy_acf_require_custom_message', 100, 1 );
function bbdfy_acf_require_custom_message_display( $valid, $value, $field, $input ) {
if ( ! empty( $field['required'] ) && ! empty( $field['custom_error_message'] ) && empty( $valid ) ) {
$valid = $field['custom_error_message'];
}
return $valid;
}
add_action( 'acf/validate_value', 'bbdfy_acf_require_custom_message_display', 100, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment