PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.86
reCaptcha by BestWebSoft v1.86
1.79 1.80 1.82 1.83 1.84 1.85 1.86 1.87 trunk 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.35 1.36 1.37 1.38 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.57 1.58 1.59 1.60 1.61 1.62 1.63 1.64 1.65 1.66 1.67 1.68 1.70 1.71 1.72 1.73 1.74 1.75 1.78
google-captcha / includes / forms.php
google-captcha / includes Last commit date
allowlist.php 4 months ago captcha-for-formidable.php 4 months ago class-gglcptch-settings-tabs.php 4 months ago forms.php 4 months ago pro_banners.php 4 months ago
forms.php
667 lines
1 <?php
2 /**
3 * Contains the extending functionality
4 *
5 * @since 1.32
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) exit;
9
10 if ( ! function_exists( 'gglcptch_get_forms' ) ) {
11 /**
12 * All forms for reCaptcha
13 *
14 * @return array $gglcptch_forms Forms for reCaptcha.
15 */
16 function gglcptch_get_forms() {
17 global $gglcptch_forms;
18
19 $default_forms = array(
20 'login_form' => array( 'form_name' => __( 'Login form', 'google-captcha' ) ),
21 'registration_form' => array( 'form_name' => __( 'Registration form', 'google-captcha' ) ),
22 'reset_pwd_form' => array( 'form_name' => __( 'Reset password form', 'google-captcha' ) ),
23 'password_form' => array( 'form_name' => __( 'Protected post password form', 'google-captcha' ) ),
24 'comments_form' => array( 'form_name' => __( 'Comments form', 'google-captcha' ) ),
25 'contact_form' => array( 'form_name' => 'Contact Form' ),
26 'testimonials' => array( 'form_name' => __( 'Testimonials', 'google-captcha' ) ),
27 'frm_contact_form' => array( 'form_name' => __( 'Formidable Contact Form', 'google-captcha' ) ),
28 'bws_login_form' => array( 'form_name' => __( 'BWS Login form', 'google-captcha' ) ),
29 'bws_register_form' => array( 'form_name' => __( 'BWS Register form', 'google-captcha' ) ),
30 'bws_forgot_pass_form' => array( 'form_name' => __( 'BWS Forgot Password form', 'google-captcha' ) ),
31 );
32
33 $custom_forms = apply_filters( 'gglcptch_add_custom_form', array() );
34 $gglcptch_forms = array_merge( $default_forms, $custom_forms );
35
36 foreach ( $gglcptch_forms as $form_slug => $form_data ) {
37 $gglcptch_forms[ $form_slug ]['form_notice'] = gglcptch_get_form_notice( $form_slug );
38 }
39
40 $gglcptch_forms = apply_filters( 'gglcptch_forms', $gglcptch_forms );
41
42 return $gglcptch_forms;
43 }
44 }
45
46 if ( ! function_exists( 'gglcptch_get_sections' ) ) {
47 /**
48 * Google captcha sections for dashboard setting page
49 *
50 * @return array $gglcptch_sections Google captcha sections.
51 */
52 function gglcptch_get_sections() {
53 global $gglcptch_sections;
54
55 $default_sections = array(
56 'standard' => array(
57 'name' => __( 'WordPress default', 'google-captcha' ),
58 'forms' => array(
59 'login_form',
60 'registration_form',
61 'reset_pwd_form',
62 'password_form',
63 'comments_form',
64 ),
65 ),
66 'external' => array(
67 'name' => __( 'External Plugins', 'google-captcha' ),
68 'forms' => array(
69 'contact_form',
70 'testimonials',
71 'frm_contact_form'
72 ),
73 ),
74 'bws_login_register' => array(
75 'name' => 'BWS Login Register',
76 'forms' => array(
77 'bws_login_form',
78 'bws_register_form',
79 'bws_forgot_pass_form'
80 ),
81 ),
82 );
83
84 $custom_forms = apply_filters( 'gglcptch_add_custom_form', array() );
85
86 $custom_sections = ( empty( $custom_forms ) ) ? array() : array(
87 'custom' => array(
88 'name' => __( 'Custom Forms', 'google-captcha' ),
89 'forms' => array_keys( $custom_forms ),
90 ),
91 );
92 $gglcptch_sections = array_merge( $default_sections, $custom_sections );
93
94 foreach ( $gglcptch_sections as $section_slug => $section_data ) {
95 $gglcptch_sections[ $section_slug ]['section_notice'] = gglcptch_get_section_notice( $section_slug );
96 }
97
98 $gglcptch_sections = apply_filters( 'gglcptch_sections', $gglcptch_sections );
99
100 return $gglcptch_sections;
101 }
102 }
103
104 if ( ! function_exists( 'gglcptch_add_lmtttmpts_forms' ) ) {
105 /**
106 * Add reCaptcha forms to the Limit Attempts plugin
107 *
108 * @param array $forms (Optional) Forms array.
109 * @return array $forms Forms array.
110 */
111 function gglcptch_add_lmtttmpts_forms( $forms = array() ) {
112 if ( ! is_array( $forms ) ) {
113 $forms = array();
114 }
115
116 $forms['gglcptch'] = array(
117 'name' => __( 'reCaptcha Plugin', 'google-captcha' ),
118 'forms' => array(),
119 );
120
121 $recaptcha_forms = gglcptch_get_forms();
122
123 foreach ( $recaptcha_forms as $form_slug => $form_data ) {
124 $forms['gglcptch']['forms'][ "{$form_slug}_captcha_check" ] = $form_data;
125 if ( empty( $form_data['form_notice'] ) ) {
126 $forms['gglcptch']['forms'][ "{$form_slug}_captcha_check" ]['form_notice'] = gglcptch_get_section_notice( $form_slug );
127 }
128 }
129
130 return $forms;
131 }
132 }
133
134 if ( ! function_exists( 'gglcptch_get_section_notice' ) ) {
135 /**
136 * Display section notice
137 *
138 * @access public
139 * @param string $section_slug Section slug for notice.
140 * @return array The action results.
141 */
142 function gglcptch_get_section_notice( $section_slug = '' ) {
143 $section_notice = '';
144
145 $plugins = array(
146 'bws_login_register' => 'bws-login-register/bws-login-register.php'
147 );
148
149 $plugins = apply_filters( 'gglcptch_custom_plugin_section_notice', $plugins );
150
151 $is_network_admin = is_network_admin();
152
153 if ( isset( $plugins[ $section_slug ] ) ) {
154 $slug = explode( '/', $plugins[ $section_slug ] );
155 $slug = $slug[0];
156 $plugin_info = gglcptch_plugin_status( $plugins[ $section_slug ], get_plugins(), $is_network_admin );
157 if ( 'deactivated' === $plugin_info['status'] ) {
158 $section_notice = '<a href="' . self_admin_url( 'plugins.php' ) . '">' . __( 'Activate', 'google-captcha' ) . '</a>';
159 } elseif ( 'not_installed' === $plugin_info['status'] ) {
160 $section_notice = sprintf( '<a href="http://wordpress.org/plugins/%s/" target="_blank">%s</a>', $slug, __( 'Install Now', 'google-captcha' ) );
161 }
162 }
163
164 return apply_filters( 'gglcptch_section_notice', $section_notice, $section_slug );
165 }
166 }
167
168 if ( ! function_exists( 'gglcptch_get_form_notice' ) ) {
169 /**
170 * Add Settings and Support links
171 *
172 * @param string $form_slug Form slug.
173 * @return string apply_filters result.
174 */
175 function gglcptch_get_form_notice( $form_slug = '' ) {
176 global $wp_version, $gglcptch_plugin_info;
177 $form_notice = '';
178
179 $plugins = array(
180 'contact_form' => array( 'contact-form-plugin/contact_form.php', 'contact-form-pro/contact_form_pro.php', 'contact-form-plus/contact-form-plus.php' ),
181 'testimonials' => array( 'bws-testimonials/bws-testimonials.php', 'bws-testimonials-pro/bws-testimonials-pro.php' ),
182 'frm_contact_form' => array( 'formidable/formidable.php', 'formidable-pro/formidable-pro.php' ),
183 );
184
185 if ( isset( $plugins[ $form_slug ] ) ) {
186 $plugin_info = gglcptch_plugin_status( $plugins[ $form_slug ], get_plugins(), is_network_admin() );
187
188 if ( 'deactivated' === $plugin_info['status'] ) {
189 $form_notice = '<a href="' . self_admin_url( 'plugins.php' ) . '">' . __( 'Activate', 'google-captcha' ) . '</a>';
190 } elseif ( 'not_installed' === $plugin_info['status'] ) {
191 if ( 'contact_form' === $form_slug ) {
192 $form_notice = '<a href="https://bestwebsoft.com/products/wordpress/plugins/contact-form/?k=fa26df3911ebcd90c3e85117d6dd0ce0&pn=281&v=' . $gglcptch_plugin_info['Version'] . '&wp_v=' . $wp_version . '" target="_blank">' . __( 'Install Now', 'google-captcha' ) . '</a>';
193 } else {
194 $form_notice = '<a href="https://bestwebsoft.com/products/wordpress/plugins/bws-testimonials/?k=451513a59dcd9844db90b567473022ce&pn=281&v=' . $gglcptch_plugin_info['Version'] . '&wp_v=' . $wp_version . '" target="_blank">' . __( 'Install Now', 'google-captcha' ) . '</a>';
195 }
196 }
197 }
198 return apply_filters( 'gglcptch_form_notice', $form_notice, $form_slug );
199 }
200 }
201
202 if ( ! function_exists( 'gglcptch_add_actions' ) ) {
203 /**
204 * Add Settings and Support links
205 */
206 function gglcptch_add_actions() {
207 global $gglcptch_options;
208
209 $is_user_logged_in = is_user_logged_in();
210
211 if ( ! empty( $gglcptch_options['login_form'] ) || ! empty( $gglcptch_options['reset_pwd_form'] ) || ! empty( $gglcptch_options['registration_form'] ) ) {
212
213 if ( gglcptch_is_recaptcha_required( 'login_form', $is_user_logged_in ) ) {
214 add_action( 'login_form', 'gglcptch_login_display' );
215 add_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
216 }
217
218 if ( gglcptch_is_recaptcha_required( 'registration_form', $is_user_logged_in ) ) {
219 if ( ! is_multisite() ) {
220 add_action( 'register_form', 'gglcptch_login_display', 99 );
221 add_action( 'registration_errors', 'gglcptch_register_check', 10, 1 );
222 } else {
223 add_action( 'signup_extra_fields', 'gglcptch_signup_display' );
224 add_action( 'signup_blogform', 'gglcptch_signup_display' );
225 add_filter( 'wpmu_validate_user_signup', 'gglcptch_signup_check', 10, 3 );
226 }
227 }
228
229 if ( gglcptch_is_recaptcha_required( 'reset_pwd_form', $is_user_logged_in ) ) {
230 add_action( 'lostpassword_form', 'gglcptch_login_display' );
231 add_action( 'allow_password_reset', 'gglcptch_lostpassword_check' );
232 }
233 }
234
235 /* Add Google Captcha to Protected post password */
236 if ( gglcptch_is_recaptcha_required( 'password_form', $is_user_logged_in ) ) {
237 add_filter( 'the_password_form', 'gglcptch_password_form_display', 10, 2 );
238 add_filter( 'post_password_expires', 'gglcptch_password_form_cookie' );
239 add_filter( 'post_password_required', 'gglcptch_password_form_check', 10, 2 );
240 }
241
242 /* Add Google Captcha to WP comments */
243 if ( gglcptch_is_recaptcha_required( 'comments_form', $is_user_logged_in ) ) {
244 add_action( 'comment_form_after_fields', 'gglcptch_commentform_display' );
245 add_action( 'comment_form_logged_in_after', 'gglcptch_commentform_display' );
246 add_action( 'pre_comment_on_post', 'gglcptch_commentform_check' );
247 }
248
249 /* Add Google Captcha to Contact Form by BestWebSoft */
250 if ( gglcptch_is_recaptcha_required( 'contact_form', $is_user_logged_in ) ) {
251 add_filter( 'cntctfrm_display_captcha', 'gglcptch_display', 10, 1 );
252 add_filter( 'cntctfrm_check_form', 'gglcptch_contact_form_check' );
253 }
254
255 /* Add Google Captcha to Testimonials by BestWebSoft */
256 if ( gglcptch_is_recaptcha_required( 'testimonials', $is_user_logged_in ) ) {
257 add_filter( 'tstmnls_display_recaptcha', 'gglcptch_display', 10, 0 );
258 }
259
260 /* Add Google Captcha to BWS Login Register */
261 if ( gglcptch_is_recaptcha_required( 'bws_login_form', $is_user_logged_in ) || gglcptch_is_recaptcha_required( 'bws_register_form', $is_user_logged_in ) || gglcptch_is_recaptcha_required( 'bws_forgot_pass_form', $is_user_logged_in ) ) {
262 add_filter( 'lgnrgstrfrm_add_field', 'gglcptch_add_login_register_forms', 10, 2 );
263 add_filter( 'lgnrgstrfrm_check_field', 'gglcptch_check_login_register_forms', 10 );
264 }
265
266 /* Add Force Strong Passwords to login/register forms */
267 add_action( 'validate_password_reset', 'gglcptch_validate_password_reset_form', 10, 2 );
268 /*add_action( 'bp_before_account_details_fields', 'gglcptch_display_bp_errors', 10, 0 );
269 add_action( 'bp_signup_pre_validate', 'gglcptch_validate_bp_signup_form', 10, 0 );
270 add_action( 'bp_template_content', 'gglcptch_display_bp_template_errors', 10, 0 );
271 add_action( 'bp_core_general_settings_after_save', 'gglcptch_bp_add_error', 10, 0 );*/
272
273 do_action( 'gglcptch_add_plus_actions', $is_user_logged_in );
274 }
275 }
276
277 if ( ! function_exists( 'gglcptch_echo_recaptcha' ) ) {
278 /**
279 * Echo google captcha
280 *
281 * @param string $content Content without captcha.
282 */
283 function gglcptch_echo_recaptcha( $content = '' ) {
284 echo gglcptch_display( $content );
285 }
286 }
287
288 if ( ! function_exists( 'gglcptch_login_display' ) ) {
289 /**
290 * Add google captcha to the login form
291 *
292 * @return bool true
293 */
294 function gglcptch_login_display() {
295
296 global $gglcptch_options;
297
298 if ( isset( $gglcptch_options['recaptcha_version'] ) ) {
299 if ( 'v2' === $gglcptch_options['recaptcha_version'] ) {
300 $from_width = 302; ?>
301 <style type="text/css" media="screen">
302 .login-action-login #loginform,
303 .login-action-lostpassword #lostpasswordform,
304 .login-action-register #registerform {
305 width: <?php echo esc_attr( $from_width ); ?>px !important;
306 }
307 #login_error,
308 .message {
309 width: <?php echo absint( esc_attr( $from_width ) ) + 20; ?>px !important;
310 }
311 .login-action-login #loginform .gglcptch,
312 .login-action-lostpassword #lostpasswordform .gglcptch,
313 .login-action-register #registerform .gglcptch {
314 margin-bottom: 10px;
315 }
316 </style>
317 <?php
318 }
319 }
320 echo gglcptch_display();
321 return true;
322 }
323 }
324
325 if ( ! function_exists( 'gglcptch_login_check' ) ) {
326 /**
327 * Check google captcha in login form
328 *
329 * @param object $user User object or errros array.
330 * @return object $user User object or errros array.
331 */
332 function gglcptch_login_check( $user ) {
333 global $gglcptch_check;
334 if ( gglcptch_is_woocommerce_page() ) {
335 return $user;
336 }
337 if ( is_wp_error( $user ) && isset( $user->errors['empty_username'] ) && isset( $user->errors['empty_password'] ) ) {
338 return $user;
339 }
340 /* Skip check if connecting to XMLRPC */
341 if ( defined( 'XMLRPC_REQUEST' ) ) {
342 return $user;
343 }
344
345 $gglcptch_check = gglcptch_check( 'login_form' );
346
347 if ( ! $gglcptch_check['response'] ) {
348 if ( 'VERIFICATION_FAILED' === $gglcptch_check['reason'] ) {
349 wp_clear_auth_cookie();
350 }
351 $error_code = ( is_wp_error( $user ) ) ? $user->get_error_code() : 'incorrect_password';
352 $errors = new WP_Error( $error_code, __( 'Authentication failed.', 'google-captcha' ) );
353 if ( isset( $gglcptch_check['errors'] ) ) {
354 $gglcptch_errors = $gglcptch_check['errors']->errors;
355 foreach ( $gglcptch_errors as $code => $messages ) {
356 foreach ( $messages as $message ) {
357 $errors->add( $code, $message );
358 }
359 }
360 }
361 $gglcptch_check['errors'] = $errors;
362 return $gglcptch_check['errors'];
363 }
364 return $user;
365 }
366 }
367
368 if ( ! function_exists( 'gglcptch_register_check' ) ) {
369 /**
370 * Check google captcha in registration form
371 *
372 * @param bool $allow Flag for captcha result.
373 * @return bool $allow Flag for captcha result.
374 */
375 function gglcptch_register_check( $allow ) {
376 if ( gglcptch_is_woocommerce_page() ) {
377 return $allow;
378 }
379 /* Skip check if connecting to XMLRPC */
380 if ( defined( 'XMLRPC_REQUEST' ) ) {
381 return $allow;
382 }
383
384 $gglcptch_check = gglcptch_check( 'registration_form' );
385 if ( ! $gglcptch_check['response'] ) {
386 return $gglcptch_check['errors'];
387 }
388 $_POST['g-recaptcha-response-check'] = true;
389 return $allow;
390 }
391 }
392
393 if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) {
394 /**
395 * Check google captcha in lostpassword form
396 *
397 * @param bool $allow Flag for captcha result.
398 * @return bool $allow Flag for captcha result.
399 */
400 function gglcptch_lostpassword_check( $allow ) {
401 if ( gglcptch_is_woocommerce_page() || ( isset( $_POST['g-recaptcha-response-check'] ) && true === $_POST['g-recaptcha-response-check'] ) ) {
402 return $allow;
403 }
404 $gglcptch_check = gglcptch_check( 'reset_pwd_form' );
405 if ( ! $gglcptch_check['response'] ) {
406 return $gglcptch_check['errors'];
407 }
408 return $allow;
409 }
410 }
411
412 if ( ! function_exists( 'gglcptch_password_form_display' ) ) {
413 /**
414 * Add google captcha to the protected post password form
415 *
416 * @param string $output Form content.
417 * @param object $post Post object.
418 * @return string $expire Form content.
419 */
420 function gglcptch_password_form_display( $output, $post = null ) {
421 $recaptcha = gglcptch_display();
422 if ( '' !== $recaptcha && isset( $_COOKIE['gglcptch_password_form_errors'] ) ) {
423 $output = str_replace( '</form>', '<div class="error gglcptch-password-form-error"><p>' . wp_kses_post( wp_unslash( $_COOKIE['gglcptch_password_form_errors'] ) ) . '</p></div>' . $recaptcha . '</form>', $output );
424 } else {
425 $output = str_replace( '</form>', $recaptcha . '</form>', $output );
426 }
427 return $output;
428 }
429 }
430
431 if ( ! function_exists( 'gglcptch_password_form_cookie' ) ) {
432 /**
433 * Add google captcha to the protected post password form
434 *
435 * @param array $expire Expire time.
436 * @return array $expire Expire time.
437 */
438 function gglcptch_password_form_cookie( $expire ) {
439 if ( isset( $_POST['g-recaptcha-response'] ) ) {
440 $gglcptch_check = gglcptch_check( 'password_form' );
441 if ( ! $gglcptch_check['response'] ) {
442 setcookie( 'gglcptch_password_form_errors', $gglcptch_check['errors']->get_error_message( 'gglcptch_error' ), time() + 300, COOKIEPATH, COOKIE_DOMAIN, false );
443 } else {
444 setcookie( 'gglcptch_password_form_errors', '', -1, COOKIEPATH, COOKIE_DOMAIN, false );
445 }
446 }
447 return $expire;
448 }
449 }
450
451 if ( ! function_exists( 'gglcptch_password_form_check' ) ) {
452 /**
453 * Check google captcha in protected post password form
454 *
455 * @param bool $required Flag for required password form.
456 * @param object $post Post object.
457 * @return bool $required Flag for required password form.
458 */
459 function gglcptch_password_form_check( $required, $post ) {
460 if ( isset( $_COOKIE['gglcptch_password_form_errors'] ) ) {
461 $required = true;
462 }
463 return $required;
464 }
465 }
466
467 if ( ! function_exists( 'gglcptch_signup_display' ) ) {
468 /**
469 * Add google captcha to the multisite login form
470 *
471 * @param array $errors Login form errors.
472 */
473 function gglcptch_signup_display( $errors ) {
474 $error_message = $errors->get_error_message( 'gglcptch_error' );
475 if ( ! empty( $error_message ) ) {
476 printf( '<p class="error gglcptch_error">%s</p>', wp_kses_post( $error_message ) );
477 }
478 $error_message = $errors->get_error_message( 'lmttmpts_error' );
479 if ( ! empty( $error_message ) ) {
480 printf( '<p class="error lmttmpts_error">%s</p>', wp_kses_post( $error_message ) );
481 }
482 echo gglcptch_display();
483 }
484 }
485
486 if ( ! function_exists( 'gglcptch_signup_check' ) ) {
487 /**
488 * Check google captcha in multisite login form
489 *
490 * @param array $result Result/Error.
491 * @return array $result Result/Error.
492 */
493 function gglcptch_signup_check( $result ) {
494 global $current_user;
495 if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! empty( $current_user->data->ID ) ) {
496 return $result;
497 }
498 $gglcptch_check = gglcptch_check( 'registration_form' );
499 if ( ! $gglcptch_check['response'] ) {
500 $result['errors'] = $gglcptch_check['errors'];
501 return $result;
502 }
503 return $result;
504 }
505 }
506
507 if ( ! function_exists( 'gglcptch_commentform_display' ) ) {
508 /**
509 * Add google captcha to the comment form
510 *
511 * @return bool true
512 */
513 function gglcptch_commentform_display() {
514 if ( gglcptch_is_hidden_for_role() ) {
515 return;
516 }
517 echo gglcptch_display();
518 return true;
519 }
520 }
521
522 if ( ! function_exists( 'gglcptch_commentform_check' ) ) {
523 /**
524 * Check JS enabled for comment form
525 */
526 function gglcptch_commentform_check() {
527 $gglcptch_check = gglcptch_check( 'comments_form' );
528 if ( ! $gglcptch_check['response'] ) {
529 $message = gglcptch_get_message( $gglcptch_check['reason'] ) . '<br />';
530 if ( ! empty( $gglcptch_check['errors'] ) && is_wp_error( $gglcptch_check['errors'] ) ){
531 $lmttmpts_error = $gglcptch_check['errors']->get_error_message( 'lmttmpts_error' );
532 if ( ! empty( $lmttmpts_error ) ) {
533 $message .= sprintf(
534 '<strong>%s</strong>:&nbsp;%s<br />',
535 __( 'Error', 'google-captcha' ),
536 $gglcptch_check['errors']->get_error_message( 'lmttmpts_error' )
537 );
538 }
539 }
540
541 $error_message = sprintf(
542 '<strong>%s</strong>:&nbsp;%s&nbsp;%s',
543 __( 'Error', 'google-captcha' ),
544 $message,
545 __( 'Click the BACK button on your browser and try again.', 'google-captcha' )
546 );
547 wp_die( wp_kses_post( $error_message ) );
548 }
549 }
550 }
551
552 if ( ! function_exists( 'gglcptch_contact_form_check' ) ) {
553 /**
554 * Check google captcha in BWS Contact Form
555 *
556 * @param bool $allow (Optional) reCaptcha for contact form.
557 * @return bool $allow Result check.
558 */
559 function gglcptch_contact_form_check( $allow = true ) {
560 if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) {
561 return $allow;
562 }
563 $gglcptch_check = gglcptch_check( 'contact_form' );
564 if ( ! $gglcptch_check['response'] ) {
565 return $gglcptch_check['errors'];
566 }
567 return $allow;
568 }
569 }
570
571 if ( ! function_exists( 'gglcptch_testimonials_check' ) ) {
572 /**
573 * Check google captcha in BWS Testimonial
574 *
575 * @param bool $allow (Optional) reCaptcha for testimonials.
576 * @return bool $allow Result check.
577 */
578 function gglcptch_testimonials_check( $allow = true ) {
579 global $gglcptch_check;
580 if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) {
581 return $allow;
582 }
583 $gglcptch_check = gglcptch_check( 'testimonials' );
584 if ( ! $gglcptch_check['response'] ) {
585 return $gglcptch_check['errors'];
586 }
587 return $allow;
588 }
589 }
590
591 if ( ! function_exists( 'gglcptch_add_login_register_forms' ) ) {
592 /**
593 * Check google captcha in BWS Testimonial
594 *
595 * @param string $content Content.
596 * @param string $form Form name.
597 * @return string $content Content after update.
598 */
599 function gglcptch_add_login_register_forms( $content, $form ) {
600 $is_user_logged_in = is_user_logged_in();
601 if ( gglcptch_is_recaptcha_required( 'bws_login_form', $is_user_logged_in ) && 'login' === $form ) {
602 return gglcptch_display( array(), $content );
603 } elseif ( gglcptch_is_recaptcha_required( 'bws_register_form', $is_user_logged_in ) && 'register' === $form ) {
604 return gglcptch_display( array(), $content );
605 } elseif( gglcptch_is_recaptcha_required( 'bws_forgot_pass_form', $is_user_logged_in ) && 'forgot_password' === $form ) {
606 return gglcptch_display( array(), $content );
607 }
608 return $content;
609 }
610 }
611
612 if ( ! function_exists( 'gglcptch_check_login_register_forms' ) ) {
613 /**
614 * Check google captcha in BWS Testimonial
615 *
616 * @param string $form Form name.
617 * @return string $error_message Error for reCaptcha.
618 */
619 function gglcptch_check_login_register_forms( $form ) {
620 global $gglcptch_options;
621 $gglcptch_check = gglcptch_check( 'bws_' . $form . '_form' );
622 if ( ! $gglcptch_check['response'] ) {
623 $error_message = implode( '<br>', $gglcptch_check['errors']->get_error_messages() );
624 return $error_message;
625 }
626 return '';
627 }
628 }
629
630 if ( ! function_exists( 'gglcptch_validate_password_reset_form' ) ) {
631 function gglcptch_validate_password_reset_form( $errors, $user ) {
632 if ( isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) {
633
634 global $gglcptch_options;
635
636 if ( empty( $gglcptch_options ) ) {
637 $gglcptch_options = get_option( 'gglcptch_options' );
638 }
639
640 $result = gglcptch_validate_password( $_POST['pass1'] );
641 if ( false === $result ) {
642 $errors->add( 'error', str_replace( '{min_length}', $gglcptch_options['fsp_length'], $gglcptch_options['fsp_error_message'] ), 'gglcptch-security' );
643 }
644 }
645
646 return $errors;
647 }
648 }
649
650 if ( ! function_exists( 'gglcptch_validate_password' ) ) {
651 function gglcptch_validate_password( $password ) {
652 global $gglcptch_options;
653
654 if ( empty( $gglcptch_options ) ) {
655 $gglcptch_options = get_option( 'gglcptch_options' );
656 }
657
658 $pattern = '/^[a-zA-Z\d\!\@\#\$\%\^\&\*\(\)\-\_\[\]\{\}\<\>\~\`\+\=\,\.\;\:\/\?\|\'\"\\\\]{' . $gglcptch_options['fsp_length'] . ',25}$/';
659
660 if ( strlen( $password ) < $gglcptch_options['fsp_length'] || ! preg_match( $pattern, $password ) ) {
661 return false;
662 }
663 return true;
664 }
665 }
666
667