diff --git a/.tests/php/integration/CF7/CF7Test.php b/.tests/php/integration/CF7/CF7Test.php index 0f16c81e..210e896e 100644 --- a/.tests/php/integration/CF7/CF7Test.php +++ b/.tests/php/integration/CF7/CF7Test.php @@ -679,9 +679,11 @@ public function test_has_field(): void { $field_type = 'hcaptcha'; $field->type = $field_type; $form_fields = [ $field ]; + $form_html = 'some cf7 html'; $submission->shouldReceive( 'get_contact_form' )->andReturn( $contact_form ); $contact_form->shouldReceive( 'scan_form_tags' )->andReturn( $form_fields ); + $contact_form->shouldReceive( 'form_html' )->andReturn( $form_html ); $subject = Mockery::mock( CF7::class )->makePartial(); diff --git a/readme.txt b/readme.txt index 71d284c1..db8e2c42 100644 --- a/readme.txt +++ b/readme.txt @@ -638,6 +638,7 @@ Instructions for popular native integrations are below: * Fixed ASC ordering by date on the Events page. * Fixed selection of a time interval on the Events page when site local time was not GMT. * Fixed losing options during plugin update in rare cases. +* Fixed shortcode processing in the Contact Form 7 form when Auto-Add was off. = 4.10.0 = * Added support for wp_login_form() function and LoginOut block. diff --git a/src/php/CF7/CF7.php b/src/php/CF7/CF7.php index 234e0ac4..b58f12c7 100644 --- a/src/php/CF7/CF7.php +++ b/src/php/CF7/CF7.php @@ -34,6 +34,11 @@ class CF7 extends Base { */ private const DATA_NAME = 'hcap-cf7'; + /** + * Field type. + */ + private const FIELD_TYPE = 'hcaptcha'; + /** * Init hooks. * @@ -202,7 +207,7 @@ public function verify_hcaptcha( $result, $tag ) { if ( ! $this->mode_auto && - ! ( $this->mode_embed && $this->has_field( $submission, 'hcaptcha' ) ) + ! ( $this->mode_embed && $this->has_field( $submission, self::FIELD_TYPE ) ) ) { return $result; } @@ -227,7 +232,13 @@ public function verify_hcaptcha( $result, $tag ) { * @return bool */ protected function has_field( WPCF7_Submission $submission, string $type ): bool { - $form_fields = $submission->get_contact_form()->scan_form_tags(); + $contact_form = $submission->get_contact_form(); + + if ( self::FIELD_TYPE === $type && has_shortcode( $contact_form->form_html(), 'cf7-hcaptcha' ) ) { + return true; + } + + $form_fields = $contact_form->scan_form_tags(); foreach ( $form_fields as $form_field ) { if ( $type === $form_field->type ) { @@ -254,7 +265,7 @@ private function get_invalidated_result( $result, $captcha_result = '' ) { $result->invalidate( [ - 'type' => 'hcaptcha', + 'type' => self::FIELD_TYPE, 'name' => self::DATA_NAME, ], $captcha_result