PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.8
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.8
2.12.8 2.12.7 2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 All 98 releases
← All changes | inc/fields/inlinebutton-markup.php +78 -54 0.0.11 → 2.12.8 View file →
@@ -7,8 +7,9 @@
7 7 */
8 8
9 9 namespace SRFM\Inc\Fields;
10 10
11 +use SRFM\Inc\Generate_Form_Markup;
11 12 use SRFM\Inc\Helper;
12 13
13 14 if ( ! defined( 'ABSPATH' ) ) {
14 15 exit; // Exit if accessed directly.
@@ -19,9 +20,8 @@
19 20 *
20 21 * @since 0.0.2
21 22 */
22 23 class Inlinebutton_Markup extends Base {
23 -
24 24 /**
25 25 * Text displayed on the button.
26 26 *
27 27 * @var string
@@ -117,13 +117,13 @@
117 117 */
118 118 public function __construct( $attributes ) {
119 119 $this->set_properties( $attributes );
120 120 $this->slug = 'inline-button';
121 - $this->button_text = isset( $attributes['buttonText'] ) ? $attributes['buttonText'] : '';
121 + $this->button_text = $attributes['buttonText'] ?? '';
122 122 $this->btn_from_theme = Helper::get_meta_value( $this->form_id, '_srfm_inherit_theme_button' );
123 - $page_break_settings = defined( 'SRFM_PRO_VER' ) ? get_post_meta( (int) $this->form_id, '_srfm_page_break_settings', true ) : [];
123 + $page_break_settings = Helper::has_pro() ? get_post_meta( (int) $this->form_id, '_srfm_page_break_settings', true ) : [];
124 124 $page_break_settings = is_array( $page_break_settings ) ? $page_break_settings : [];
125 - $this->is_page_break = isset( $page_break_settings['is_page_break'] ) ? $page_break_settings['is_page_break'] : false;
125 + $this->is_page_break = $page_break_settings['is_page_break'] ?? false;
126 126 $this->captcha_security_type = Helper::get_meta_value( $this->form_id, '_srfm_captcha_security_type' );
127 127 $this->recaptcha_version = Helper::get_meta_value( $this->form_id, '_srfm_form_recaptcha' );
128 128 $this->google_captcha_site_key = '';
129 129 $this->global_setting_options = [];
@@ -133,25 +133,25 @@
133 133
134 134 if ( is_array( $this->global_setting_options ) ) {
135 135 switch ( $this->recaptcha_version ) {
136 136 case 'v2-checkbox':
137 - $this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v2_checkbox_site_key'] ) ? $this->global_setting_options['srfm_v2_checkbox_site_key'] : '';
137 + $this->google_captcha_site_key = $this->global_setting_options['srfm_v2_checkbox_site_key'] ?? '';
138 138 break;
139 139 case 'v2-invisible':
140 - $this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v2_invisible_site_key'] ) ? $this->global_setting_options['srfm_v2_invisible_site_key'] : '';
140 + $this->google_captcha_site_key = $this->global_setting_options['srfm_v2_invisible_site_key'] ?? '';
141 141 break;
142 142 case 'v3-reCAPTCHA':
143 - $this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v3_site_key'] ) ? $this->global_setting_options['srfm_v3_site_key'] : '';
143 + $this->google_captcha_site_key = $this->global_setting_options['srfm_v3_site_key'] ?? '';
144 144 break;
145 145 default:
146 146 break;
147 147 }
148 148 if ( 'cf-turnstile' === $this->captcha_security_type ) {
149 - $this->cf_turnstile_site_key = isset( $this->global_setting_options['srfm_cf_turnstile_site_key'] ) ? $this->global_setting_options['srfm_cf_turnstile_site_key'] : '';
150 - $this->cf_appearance_mode = isset( $this->global_setting_options['srfm_cf_appearance_mode'] ) ? $this->global_setting_options['srfm_cf_appearance_mode'] : 'auto';
149 + $this->cf_turnstile_site_key = $this->global_setting_options['srfm_cf_turnstile_site_key'] ?? '';
150 + $this->cf_appearance_mode = $this->global_setting_options['srfm_cf_appearance_mode'] ?? 'auto';
151 151 }
152 152 if ( 'hcaptcha' === $this->captcha_security_type ) {
153 - $this->hcaptcha_site_key = isset( $this->global_setting_options['srfm_hcaptcha_site_key'] ) ? $this->global_setting_options['srfm_hcaptcha_site_key'] : '';
153 + $this->hcaptcha_site_key = $this->global_setting_options['srfm_hcaptcha_site_key'] ?? '';
154 154 }
155 155 }
156 156 $theme_name = wp_get_theme()->get( 'Name' );
157 157 $this->add_button_padding = true;
@@ -163,61 +163,85 @@
163 163 /**
164 164 * Render inline button markup
165 165 *
166 166 * @since 0.0.2
167 - * @return string|boolean|void
167 + * @return string|bool|void
168 168 */
169 169 public function markup() {
170 + $container_hidden_class = 'g-recaptcha' === $this->captcha_security_type && ( 'v3-reCAPTCHA' === $this->recaptcha_version || 'v2-invisible' === $this->recaptcha_version ) ? 'srfm-display-none' : '';
170 171 ob_start(); ?>
171 - <?php if ( ! $this->is_page_break ) : ?>
172 - <?php if ( $this->captcha_security_type && 'none' !== $this->captcha_security_type ) : ?>
173 - <div class="srfm-captcha-container">
174 - <?php if ( 'g-recaptcha' === $this->captcha_security_type && 'v2-checkbox' === $this->recaptcha_version ) : ?>
175 - <?php echo "<div class='g-recaptcha' data-callback='onSuccess' recaptcha-type='" . esc_attr( $this->recaptcha_version ) . "' data-sitekey='" . esc_attr( strval( $this->google_captcha_site_key ) ) . "'></div>"; ?>
176 - <?php endif; ?>
177 - <?php if ( 'cf-turnstile' === $this->captcha_security_type && $this->cf_turnstile_site_key ) : ?>
178 - <?php echo "<div id='srfm-cf-sitekey' class='cf-turnstile' data-callback='onSuccess' data-theme='" . esc_attr( strval( $this->cf_appearance_mode ) ) . "' data-sitekey='" . esc_attr( strval( $this->cf_turnstile_site_key ) ) . "'></div>"; ?>
179 - <?php endif; ?>
180 - <?php if ( 'hcaptcha' === $this->captcha_security_type && $this->hcaptcha_site_key ) : ?>
181 - <?php echo "<div id='srfm-hcaptcha-sitekey' data-callback='onSuccess' class='h-captcha' data-sitekey='" . esc_attr( strval( $this->hcaptcha_site_key ) ) . "'></div>"; ?>
182 - <?php endif; ?>
183 - <div class="srfm-validation-error" id="captcha-error" style="display: none;"><?php echo esc_attr__( 'Please verify that you are not a robot.', 'sureforms' ); ?></div>
172 + <?php if ( ! $this->is_page_break ) { ?>
173 + <?php if ( $this->captcha_security_type && 'none' !== $this->captcha_security_type ) { ?>
174 + <div class="srfm-captcha-container <?php echo esc_attr( $container_hidden_class ); ?>">
175 + <?php if ( 'g-recaptcha' === $this->captcha_security_type && 'v2-checkbox' === $this->recaptcha_version ) { ?>
176 + <div class='g-recaptcha' data-callback='onSuccess' data-error-callback='onGCaptchaV2CheckBoxError' recaptcha-type='<?php echo esc_attr( $this->recaptcha_version ); ?>' data-sitekey='<?php echo esc_attr( strval( $this->google_captcha_site_key ) ); ?>'></div>
177 + <?php } ?>
178 + <?php if ( 'cf-turnstile' === $this->captcha_security_type && $this->cf_turnstile_site_key ) { ?>
179 + <div id='srfm-cf-sitekey' class='cf-turnstile' data-callback='onSuccess' data-error-callback='onTurnstileError' data-theme='<?php echo esc_attr( strval( $this->cf_appearance_mode ) ); ?>' data-sitekey='<?php echo esc_attr( strval( $this->cf_turnstile_site_key ) ); ?>'></div>
180 + <?php } ?>
181 + <?php if ( 'hcaptcha' === $this->captcha_security_type && $this->hcaptcha_site_key ) { ?>
182 + <div id='srfm-hcaptcha-sitekey' data-callback='onSuccess' data-error-callback='onHCaptchaError' class='h-captcha' data-sitekey='<?php echo esc_attr( strval( $this->hcaptcha_site_key ) ); ?>'></div>
183 + <?php } ?>
184 + <div class="srfm-validation-error" id="captcha-error" style="display: none;"><?php echo esc_html__( 'Please verify that you are not a robot.', 'sureforms' ); ?></div>
184 185 </div>
185 - <?php endif; ?>
186 + <?php } ?>
186 187 <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="<?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?> srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?> srfm-block srfm-custom-button-ctn <?php echo esc_attr( '1' === $this->btn_from_theme ? 'wp-block-button' : '' ); ?>">
187 188 <?php
188 - if ( 'g-recaptcha' === $this->captcha_security_type ) :
189 - if ( 'v3-reCAPTCHA' === $this->recaptcha_version ) :
190 - wp_enqueue_script( 'srfm-google-recaptchaV3', 'https://www.google.com/recaptcha/api.js?render=' . esc_js( $this->google_captcha_site_key ), [], SRFM_VER, true );
191 - endif;
189 + if ( 'g-recaptcha' === $this->captcha_security_type ) {
192 190
193 - if ( 'v2-checkbox' === $this->recaptcha_version ) :
194 - wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js', [], SRFM_VER, true );
195 - endif;
191 + if ( empty( $this->google_captcha_site_key ) ) {
192 + Helper::render_missing_sitekey_error( 'Google reCAPTCHA' );
193 + } else {
194 + if ( 'v3-reCAPTCHA' === $this->recaptcha_version ) {
195 + wp_enqueue_script( 'srfm-google-recaptchaV3', 'https://www.google.com/recaptcha/api.js?render=' . $this->google_captcha_site_key, [], null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- This is a third-party script, and specifying a version may lead to caching issues. Using null ensures the latest version is always loaded.
196 + }
196 197
197 - if ( 'v2-invisible' === $this->recaptcha_version ) :
198 - wp_enqueue_script( 'google-recaptcha-invisible', 'https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit', [ SRFM_SLUG . '-form-submit' ], SRFM_VER, true );
199 - endif;
200 - endif;
198 + if ( 'v2-checkbox' === $this->recaptcha_version ) {
199 + wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js', [], SRFM_VER, true );
200 + }
201 201
202 - if ( 'cf-turnstile' === $this->captcha_security_type ) :
203 - // Cloudflare Turnstile script.
204 - wp_enqueue_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
205 - SRFM_SLUG . '-cf-turnstile',
206 - 'https://challenges.cloudflare.com/turnstile/v0/api.js',
207 - [],
208 - null,
209 - [
210 - false,
211 - 'defer' => true,
212 - ]
213 - );
214 - endif;
215 - if ( 'hcaptcha' === $this->captcha_security_type ) :
216 - wp_enqueue_script( 'hcaptcha', 'https://js.hcaptcha.com/1/api.js', [], null, [ 'strategy' => 'defer' ] ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
217 - endif;
202 + if ( 'v2-invisible' === $this->recaptcha_version ) {
203 + wp_enqueue_script( 'google-recaptcha-invisible', 'https://www.google.com/recaptcha/api.js?onload=recaptchaCallback&render=explicit', [ SRFM_SLUG . '-form-submit' ], SRFM_VER, true );
204 + }
205 + }
206 + }
207 +
208 + if ( 'cf-turnstile' === $this->captcha_security_type ) {
209 + if ( ! empty( $this->cf_turnstile_site_key ) ) {
210 + // Cloudflare Turnstile script.
211 + // phpcs:disable WordPress.WP.EnqueuedResourceParameters.MissingVersion, PluginCheck.CodeAnalysis.EnqueuedResourceOffloading.OffloadedContent -- Cloudflare Turnstile must be loaded from Cloudflare's servers for token verification; the version is controlled by Cloudflare.
212 + wp_enqueue_script(
213 + SRFM_SLUG . '-cf-turnstile',
214 + 'https://challenges.cloudflare.com/turnstile/v0/api.js',
215 + [],
216 + null,
217 + [
218 + 'strategy' => 'defer',
219 + ]
220 + );
221 + // phpcs:enable WordPress.WP.EnqueuedResourceParameters.MissingVersion, PluginCheck.CodeAnalysis.EnqueuedResourceOffloading.OffloadedContent
222 + } else {
223 + Helper::render_missing_sitekey_error( 'Cloudflare Turnstile' );
224 + }
225 + }
226 + if ( 'hcaptcha' === $this->captcha_security_type ) {
227 + if ( ! empty( $this->hcaptcha_site_key ) ) {
228 + wp_enqueue_script( 'hcaptcha', 'https://js.hcaptcha.com/1/api.js', [], null, [ 'strategy' => 'defer' ] ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion, PluginCheck.CodeAnalysis.EnqueuedResourceOffloading.OffloadedContent -- hCaptcha must be loaded from hCaptcha's servers for token verification; the version is controlled by hCaptcha.
229 + } else {
230 + Helper::render_missing_sitekey_error( 'HCaptcha' );
231 + }
232 + }
233 + $srfm_custom_button_classes = apply_filters( 'srfm_add_button_classes', [ 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ? 'g-recaptcha ' : '', '1' === $this->btn_from_theme ? 'wp-block-button__link' : 'srfm-button srfm-submit-button srfm-btn-frontend srfm-custom-button' ], $this->form_id, Generate_Form_Markup::get_current_block_attrs() );
234 +
235 + $button_style = $this->btn_from_theme ? '' : ' font-family: inherit; font-weight: var(--wp--custom--font-weight--medium); line-height: normal;';
236 + $button_style .= 'width:100%;';
237 +
238 + $button_attributes = '';
239 + if ( 'g-recaptcha' === $this->captcha_security_type && ( 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ) ) {
240 + $button_attributes = 'recaptcha-type="' . esc_attr( $this->recaptcha_version ) . '" data-sitekey="' . esc_attr( $this->google_captcha_site_key ) . '" data-callback="recaptchaCallback"';
241 + }
218 242 ?>
219 - <button style="<?php echo $this->btn_from_theme ? '' : ' font-family: inherit; font-weight: var(--wp--custom--font-weight--medium); line-height: normal;'; ?>width:100%;" id="srfm-submit-btn" class="<?php echo esc_attr( 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ? 'g-recaptcha ' : '' ); ?> <?php echo esc_attr( '1' === $this->btn_from_theme ? 'wp-block-button__link' : 'srfm-button srfm-submit-button srfm-btn-frontend srfm-custom-button' ); ?> " <?php echo 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ? esc_attr( 'recaptcha-type=' . $this->recaptcha_version . ' data-sitekey=' . $this->google_captcha_site_key ) : ''; ?>>
243 + <button style="<?php echo esc_attr( $button_style ); ?>" id="srfm-submit-btn" class="<?php echo esc_attr( Helper::join_strings( $srfm_custom_button_classes ) ); ?>" <?php echo $button_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Individual attribute values are escaped with esc_attr() at build time above. ?>>
220 244 <div class="srfm-submit-wrap">
221 245 <?php echo esc_html( $this->button_text ); ?>
222 246 <div class="srfm-loader"></div>
223 247 </div>
@@ -224,9 +248,9 @@
224 248 </button>
225 249 <div class="srfm-error-wrap"></div>
226 250 </div>
227 251 <?php
228 - endif;
252 + }
229 253 return ob_get_clean();
230 254 }
231 255
232 256 }