diff --git a/src/php/CF7/Admin.php b/src/php/CF7/Admin.php
index 79c95163..7e8c69bb 100644
--- a/src/php/CF7/Admin.php
+++ b/src/php/CF7/Admin.php
@@ -108,13 +108,23 @@ private function insert_live_form( string $output ): string {
}
$form_shortcode = htmlspecialchars_decode( $m[1] );
+ $live_form = do_shortcode( $form_shortcode );
+ $stripe_message = '';
+
+ if ( $this->has_stripe_element( $live_form ) ) {
+ $stripe_message =
+ '
' .
'
' .
- '
Live Form
' .
- do_shortcode( $form_shortcode ) .
+ '' . __( 'Live Form', 'hcaptcha-for-forms-and-more' ) . '
' .
+ $stripe_message .
+ $live_form .
'' .
'
' .
"\n";
diff --git a/src/php/CF7/Base.php b/src/php/CF7/Base.php
index 25eb0a18..a25685de 100644
--- a/src/php/CF7/Base.php
+++ b/src/php/CF7/Base.php
@@ -42,4 +42,15 @@ public function init_hooks(): void {
$this->mode_auto = hcaptcha()->settings()->is( 'cf7_status', 'form' );
$this->mode_embed = hcaptcha()->settings()->is( 'cf7_status', 'embed' );
}
+
+ /**
+ * Whether the form contains a Stripe element.
+ *
+ * @param string $output Output.
+ *
+ * @return bool
+ */
+ protected function has_stripe_element( string $output ): bool {
+ return false !== strpos( $output, '' );
+ }
}
diff --git a/src/php/CF7/CF7.php b/src/php/CF7/CF7.php
index 321df359..7c3978b8 100644
--- a/src/php/CF7/CF7.php
+++ b/src/php/CF7/CF7.php
@@ -58,23 +58,24 @@ public function init_hooks(): void {
* @param array|string $attr Shortcode attributes array or empty string.
* @param array $m Regular expression match array.
*
- * @return string|mixed
+ * @return string
* @noinspection PhpUnusedParameterInspection
*/
- public function wpcf7_shortcode( $output, string $tag, $attr, array $m ) {
+ public function wpcf7_shortcode( $output, string $tag, $attr, array $m ): string {
+ $output = (string) $output;
+
if ( 'contact-form-7' !== $tag ) {
return $output;
}
- if ( false !== strpos( $output, '
' ) ) {
+ if ( $this->has_stripe_element( $output ) ) {
/**
* Do not show hCaptcha in the CF7 form having Stripe field.
* Stripe payment form has its own hidden hCaptcha field.
*/
- return $output;
+ return preg_replace( '/\[cf7-hcaptcha.*?]/', '', $output );
}
- $output = (string) $output;
$form_id = isset( $attr['id'] ) ? (int) $attr['id'] : 0;
$cf7_hcap_shortcode = $this->get_cf7_hcap_shortcode( $output );