Created
May 11, 2020 09:54
-
-
Save raftaar1191/565014438cd15a0480f8fb76fea861e3 to your computer and use it in GitHub Desktop.
ACF custom required field message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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