Skip to content

Commit

Permalink
Add compatibility with Contact Form 7 Stripe integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 21, 2024
1 parent a34be2e commit 42be7c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ Instructions for popular native integrations are below:

= 4.4.0 =
* Added integration with WPS Hide Login plugin.
* Added compatibility with Contact Form 7 Stripe integration.
* Fixed conflict with Ninja Forms Upload field.
* Fixed Ninja Forms Ajax processing.
* Fixed error in cron with Matomo Analytics.
Expand Down
45 changes: 33 additions & 12 deletions src/php/CF7/CF7.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public function wpcf7_shortcode( $output, string $tag, $attr, array $m ) {
return $output;
}

if ( false !== strpos( $output, '<div class="wpcf7-stripe">' ) ) {
// Stripe payment form already contains hCaptcha.
return $output;
}

$output = (string) $output;
$form_id = isset( $attr['id'] ) ? (int) $attr['id'] : 0;
$cf7_hcap_shortcode = $this->get_cf7_hcap_shortcode( $output );
Expand Down Expand Up @@ -183,6 +188,10 @@ public function verify_hcaptcha( $result, $tag ) {
return $this->get_invalidated_result( $result );
}

if ( $this->has_stripe_field( $submission ) ) {
return $result;
}

if (
! $this->mode_auto &&
! ( $this->mode_embed && $this->has_hcaptcha_field( $submission ) )
Expand All @@ -202,14 +211,23 @@ public function verify_hcaptcha( $result, $tag ) {
}

/**
* Whether the field is hCaptcha field.
* Whether form has a field of given type.
*
* @param WPCF7_FormTag $field Field.
* @param WPCF7_Submission $submission Submission.
* @param string $type Field type.
*
* @return bool
*/
private function is_hcaptcha_field( WPCF7_FormTag $field ): bool {
return ( 'hcaptcha' === $field->type );
private function has_field( WPCF7_Submission $submission, string $type ): bool {
$form_fields = $submission->get_contact_form()->scan_form_tags();

foreach ( $form_fields as $form_field ) {
if ( $type === $form_field->type ) {
return true;
}
}

return false;
}

/**
Expand All @@ -220,15 +238,18 @@ private function is_hcaptcha_field( WPCF7_FormTag $field ): bool {
* @return bool
*/
protected function has_hcaptcha_field( WPCF7_Submission $submission ): bool {
$form_fields = $submission->get_contact_form()->scan_form_tags();

foreach ( $form_fields as $form_field ) {
if ( $this->is_hcaptcha_field( $form_field ) ) {
return true;
}
}
return $this->has_field( $submission, 'hcaptcha' );
}

return false;
/**
* Whether form has its own Stripe field.
*
* @param WPCF7_Submission $submission Submission.
*
* @return bool
*/
protected function has_stripe_field( WPCF7_Submission $submission ): bool {
return $this->has_field( $submission, 'stripe' );
}

/**
Expand Down

0 comments on commit 42be7c4

Please sign in to comment.