Custom Tag Not Found
-
Hello,
I’m trying to track down a strange issue across multiple plugins…
TL;DR Is there any reason why a new instance of
WPCF7_Validation()
wouldn’t recognize a custom tag?In ReCaptcha v2 for Contact Form 7 I am creating a custom tag via
wpcf7_init
function iqfix_wpcf7_add_recaptcha_tag() { wpcf7_add_form_tag( 'recaptcha', 'iqfix_wpcf7_recaptcha_form_tag_handler', array( 'display-block' => true ) ); } add_action( 'wpcf7_init', 'iqfix_wpcf7_add_recaptcha_tag', 20 );
The creation code works great and as expected.
Except whenever another plugin Conditional Fields for Contact Form 7 does the following:
function skip_validation_for_hidden_fields($result, $tags) { $invalid_fields = $result->get_invalid_fields(); $return_result = new WPCF7_Validation(); foreach ($invalid_fields as $invalid_field_key => $invalid_field_data) { $return_result->invalidate($invalid_field_key, $invalid_field_data['reason']); } } add_filter( 'wpcf7_validate', 'skip_validation_for_hidden_fields', 2, 2 );
Some code is removed for simplicity purposes to encapsulate the question better.
If I error log
$invalid_fields
, I see that an error exists on submission as it should if the user does not check the ReCaptcha box. Whenever I error logWPCF7_Validation::invalidate()
for the$return_result
variable though, it doesn’t recognize the ‘recaptcha’ as a tag. In any other case, it does recognize the tag. What happens is thatWPCF7_Validation::invalidate()
returns early here:includes\validation.php LN 27
if ( empty( $name ) or ! wpcf7_is_name( $name ) ) { return; }
With the creation of the new instance, it can’t seem to get
new WPCF7_FormTag( 'recapthca' )
at this point.Is there any reason creating a new instance of
WPCF7_Validation()
during thewpcf7_validate
hook would not recognize custom-created tags?
- The topic ‘Custom Tag Not Found’ is closed to new replies.