PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.79
reCaptcha by BestWebSoft v1.79
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 1 year ago class-gglcptch-settings-tabs.php 1 year ago forms.php 1 year ago pro_banners.php 1 year ago
forms.php
559 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 );
28
29 $custom_forms = apply_filters( 'gglcptch_add_custom_form', array() );
30 $gglcptch_forms = array_merge( $default_forms, $custom_forms );
31
32 foreach ( $gglcptch_forms as $form_slug => $form_data ) {
33 $gglcptch_forms[ $form_slug ]['form_notice'] = gglcptch_get_form_notice( $form_slug );
34 }
35
36 $gglcptch_forms = apply_filters( 'gglcptch_forms', $gglcptch_forms );
37
38 return $gglcptch_forms;
39 }
40 }
41
42 if ( ! function_exists( 'gglcptch_get_sections' ) ) {
43 /**
44 * Google captcha sections for dashboard setting page
45 *
46 * @return array $gglcptch_sections Google captcha sections.
47 */
48 function gglcptch_get_sections() {
49 global $gglcptch_sections;
50
51 $default_sections = array(
52 'standard' => array(
53 'name' => __( 'WordPress default', 'google-captcha' ),
54 'forms' => array(
55 'login_form',
56 'registration_form',
57 'reset_pwd_form',
58 'password_form',
59 'comments_form',
60 ),
61 ),
62 'external' => array(
63 'name' => __( 'External Plugins', 'google-captcha' ),
64 'forms' => array(
65 'contact_form',
66 'testimonials',
67 ),
68 ),
69 );
70
71 $custom_forms = apply_filters( 'gglcptch_add_custom_form', array() );
72
73 $custom_sections = ( empty( $custom_forms ) ) ? array() : array(
74 'custom' => array(
75 'name' => __( 'Custom Forms', 'google-captcha' ),
76 'forms' => array_keys( $custom_forms ),
77 ),
78 );
79 $gglcptch_sections = array_merge( $default_sections, $custom_sections );
80
81 foreach ( $gglcptch_sections as $section_slug => $section_data ) {
82 $gglcptch_sections[ $section_slug ]['section_notice'] = gglcptch_get_section_notice( $section_slug );
83 }
84
85 $gglcptch_sections = apply_filters( 'gglcptch_sections', $gglcptch_sections );
86
87 return $gglcptch_sections;
88 }
89 }
90
91 if ( ! function_exists( 'gglcptch_add_lmtttmpts_forms' ) ) {
92 /**
93 * Add reCaptcha forms to the Limit Attempts plugin
94 *
95 * @param array $forms (Optional) Forms array.
96 * @return array $forms Forms array.
97 */
98 function gglcptch_add_lmtttmpts_forms( $forms = array() ) {
99 if ( ! is_array( $forms ) ) {
100 $forms = array();
101 }
102
103 $forms['gglcptch'] = array(
104 'name' => __( 'reCaptcha Plugin', 'google-captcha' ),
105 'forms' => array(),
106 );
107
108 $recaptcha_forms = gglcptch_get_forms();
109
110 foreach ( $recaptcha_forms as $form_slug => $form_data ) {
111 $forms['gglcptch']['forms'][ "{$form_slug}_captcha_check" ] = $form_data;
112 if ( empty( $form_data['form_notice'] ) ) {
113 $forms['gglcptch']['forms'][ "{$form_slug}_captcha_check" ]['form_notice'] = gglcptch_get_section_notice( $form_slug );
114 }
115 }
116
117 return $forms;
118 }
119 }
120
121 if ( ! function_exists( 'gglcptch_get_section_notice' ) ) {
122 /**
123 * Display section notice
124 *
125 * @access public
126 * @param string $section_slug Section slug for notice.
127 * @return array The action results.
128 */
129 function gglcptch_get_section_notice( $section_slug = '' ) {
130 $section_notice = '';
131 $plugins = array( /* Example: 'bbpress' => 'bbpress/bbpress.php' */ );
132 $plugins = apply_filters( 'gglcptch_custom_plugin_section_notice', $plugins );
133
134 $is_network_admin = is_network_admin();
135
136 if ( isset( $plugins[ $section_slug ] ) ) {
137 $slug = explode( '/', $plugins[ $section_slug ] );
138 $slug = $slug[0];
139 $plugin_info = gglcptch_plugin_status( $plugins[ $section_slug ], get_plugins(), $is_network_admin );
140 if ( 'deactivated' === $plugin_info['status'] ) {
141 $section_notice = '<a href="' . self_admin_url( 'plugins.php' ) . '">' . __( 'Activate', 'google-captcha' ) . '</a>';
142 } elseif ( 'not_installed' === $plugin_info['status'] ) {
143 $section_notice = sprintf( '<a href="http://wordpress.org/plugins/%s/" target="_blank">%s</a>', $slug, __( 'Install Now', 'google-captcha' ) );
144 }
145 }
146
147 return apply_filters( 'gglcptch_section_notice', $section_notice, $section_slug );
148 }
149 }
150
151 if ( ! function_exists( 'gglcptch_get_form_notice' ) ) {
152 /**
153 * Add Settings and Support links
154 *
155 * @param string $form_slug Form slug.
156 * @return string apply_filters result.
157 */
158 function gglcptch_get_form_notice( $form_slug = '' ) {
159 global $wp_version, $gglcptch_plugin_info;
160 $form_notice = '';
161
162 $plugins = array(
163 'contact_form' => array( 'contact-form-plugin/contact_form.php', 'contact-form-pro/contact_form_pro.php', 'contact-form-plus/contact-form-plus.php' ),
164 'testimonials' => array( 'bws-testimonials/bws-testimonials.php', 'bws-testimonials-pro/bws-testimonials-pro.php' ),
165 );
166
167 if ( isset( $plugins[ $form_slug ] ) ) {
168 $plugin_info = gglcptch_plugin_status( $plugins[ $form_slug ], get_plugins(), is_network_admin() );
169
170 if ( 'deactivated' === $plugin_info['status'] ) {
171 $form_notice = '<a href="' . self_admin_url( 'plugins.php' ) . '">' . __( 'Activate', 'google-captcha' ) . '</a>';
172 } elseif ( 'not_installed' === $plugin_info['status'] ) {
173 if ( 'contact_form' === $form_slug ) {
174 $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>';
175 } else {
176 $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>';
177 }
178 }
179 }
180 return apply_filters( 'gglcptch_form_notice', $form_notice, $form_slug );
181 }
182 }
183
184 if ( ! function_exists( 'gglcptch_add_actions' ) ) {
185 /**
186 * Add Settings and Support links
187 */
188 function gglcptch_add_actions() {
189 global $gglcptch_options;
190
191 $is_user_logged_in = is_user_logged_in();
192
193 if ( ! empty( $gglcptch_options['login_form'] ) || ! empty( $gglcptch_options['reset_pwd_form'] ) || ! empty( $gglcptch_options['registration_form'] ) ) {
194
195 if ( gglcptch_is_recaptcha_required( 'login_form', $is_user_logged_in ) ) {
196 add_action( 'login_form', 'gglcptch_login_display' );
197 add_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
198 }
199
200 if ( gglcptch_is_recaptcha_required( 'registration_form', $is_user_logged_in ) ) {
201 if ( ! is_multisite() ) {
202 add_action( 'register_form', 'gglcptch_login_display', 99 );
203 add_action( 'registration_errors', 'gglcptch_register_check', 10, 1 );
204 } else {
205 add_action( 'signup_extra_fields', 'gglcptch_signup_display' );
206 add_action( 'signup_blogform', 'gglcptch_signup_display' );
207 add_filter( 'wpmu_validate_user_signup', 'gglcptch_signup_check', 10, 3 );
208 }
209 }
210
211 if ( gglcptch_is_recaptcha_required( 'reset_pwd_form', $is_user_logged_in ) ) {
212 add_action( 'lostpassword_form', 'gglcptch_login_display' );
213 add_action( 'allow_password_reset', 'gglcptch_lostpassword_check' );
214 }
215 }
216
217 /* Add Google Captcha to Protected post password */
218 if ( gglcptch_is_recaptcha_required( 'password_form', $is_user_logged_in ) ) {
219 add_filter( 'the_password_form', 'gglcptch_password_form_display', 10, 2 );
220 add_filter( 'post_password_expires', 'gglcptch_password_form_cookie' );
221 add_filter( 'post_password_required', 'gglcptch_password_form_check', 10, 2 );
222 }
223
224 /* Add Google Captcha to WP comments */
225 if ( gglcptch_is_recaptcha_required( 'comments_form', $is_user_logged_in ) ) {
226 add_action( 'comment_form_after_fields', 'gglcptch_commentform_display' );
227 add_action( 'comment_form_logged_in_after', 'gglcptch_commentform_display' );
228 add_action( 'pre_comment_on_post', 'gglcptch_commentform_check' );
229 }
230
231 /* Add Google Captcha to Contact Form by BestWebSoft */
232 if ( gglcptch_is_recaptcha_required( 'contact_form', $is_user_logged_in ) ) {
233 add_filter( 'cntctfrm_display_captcha', 'gglcptch_display', 10, 1 );
234 add_filter( 'cntctfrm_check_form', 'gglcptch_contact_form_check' );
235 }
236
237 /* Add Google Captcha to Testimonials by BestWebSoft */
238 if ( gglcptch_is_recaptcha_required( 'testimonials', $is_user_logged_in ) ) {
239 add_filter( 'tstmnls_display_recaptcha', 'gglcptch_display', 10, 0 );
240 }
241
242 do_action( 'gglcptch_add_plus_actions', $is_user_logged_in );
243 }
244 }
245
246 if ( ! function_exists( 'gglcptch_echo_recaptcha' ) ) {
247 /**
248 * Echo google captcha
249 *
250 * @param string $content Content without captcha.
251 */
252 function gglcptch_echo_recaptcha( $content = '' ) {
253 echo gglcptch_display( $content );
254 }
255 }
256
257 if ( ! function_exists( 'gglcptch_login_display' ) ) {
258 /**
259 * Add google captcha to the login form
260 *
261 * @return bool true
262 */
263 function gglcptch_login_display() {
264
265 global $gglcptch_options;
266
267 if ( isset( $gglcptch_options['recaptcha_version'] ) ) {
268 if ( 'v2' === $gglcptch_options['recaptcha_version'] ) {
269 $from_width = 302; ?>
270 <style type="text/css" media="screen">
271 .login-action-login #loginform,
272 .login-action-lostpassword #lostpasswordform,
273 .login-action-register #registerform {
274 width: <?php echo esc_attr( $from_width ); ?>px !important;
275 }
276 #login_error,
277 .message {
278 width: <?php echo absint( esc_attr( $from_width ) ) + 20; ?>px !important;
279 }
280 .login-action-login #loginform .gglcptch,
281 .login-action-lostpassword #lostpasswordform .gglcptch,
282 .login-action-register #registerform .gglcptch {
283 margin-bottom: 10px;
284 }
285 </style>
286 <?php
287 }
288 }
289 echo gglcptch_display();
290 return true;
291 }
292 }
293
294 if ( ! function_exists( 'gglcptch_login_check' ) ) {
295 /**
296 * Check google captcha in login form
297 *
298 * @param object $user User object or errros array.
299 * @return object $user User object or errros array.
300 */
301 function gglcptch_login_check( $user ) {
302 global $gglcptch_check;
303 if ( gglcptch_is_woocommerce_page() ) {
304 return $user;
305 }
306 if ( is_wp_error( $user ) && isset( $user->errors['empty_username'] ) && isset( $user->errors['empty_password'] ) ) {
307 return $user;
308 }
309 /* Skip check if connecting to XMLRPC */
310 if ( defined( 'XMLRPC_REQUEST' ) ) {
311 return $user;
312 }
313
314 $gglcptch_check = gglcptch_check( 'login_form' );
315
316 if ( ! $gglcptch_check['response'] ) {
317 if ( 'VERIFICATION_FAILED' === $gglcptch_check['reason'] ) {
318 wp_clear_auth_cookie();
319 }
320 $error_code = ( is_wp_error( $user ) ) ? $user->get_error_code() : 'incorrect_password';
321 $errors = new WP_Error( $error_code, __( 'Authentication failed.', 'google-captcha' ) );
322 if ( isset( $gglcptch_check['errors'] ) ) {
323 $gglcptch_errors = $gglcptch_check['errors']->errors;
324 foreach ( $gglcptch_errors as $code => $messages ) {
325 foreach ( $messages as $message ) {
326 $errors->add( $code, $message );
327 }
328 }
329 }
330 $gglcptch_check['errors'] = $errors;
331 return $gglcptch_check['errors'];
332 }
333 return $user;
334 }
335 }
336
337 if ( ! function_exists( 'gglcptch_register_check' ) ) {
338 /**
339 * Check google captcha in registration form
340 *
341 * @param bool $allow Flag for captcha result.
342 * @return bool $allow Flag for captcha result.
343 */
344 function gglcptch_register_check( $allow ) {
345 if ( gglcptch_is_woocommerce_page() ) {
346 return $allow;
347 }
348 /* Skip check if connecting to XMLRPC */
349 if ( defined( 'XMLRPC_REQUEST' ) ) {
350 return $allow;
351 }
352
353 $gglcptch_check = gglcptch_check( 'registration_form' );
354 if ( ! $gglcptch_check['response'] ) {
355 return $gglcptch_check['errors'];
356 }
357 $_POST['g-recaptcha-response-check'] = true;
358 return $allow;
359 }
360 }
361
362 if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) {
363 /**
364 * Check google captcha in lostpassword form
365 *
366 * @param bool $allow Flag for captcha result.
367 * @return bool $allow Flag for captcha result.
368 */
369 function gglcptch_lostpassword_check( $allow ) {
370 if ( gglcptch_is_woocommerce_page() || ( isset( $_POST['g-recaptcha-response-check'] ) && true === $_POST['g-recaptcha-response-check'] ) ) {
371 return $allow;
372 }
373 $gglcptch_check = gglcptch_check( 'reset_pwd_form' );
374 if ( ! $gglcptch_check['response'] ) {
375 return $gglcptch_check['errors'];
376 }
377 return $allow;
378 }
379 }
380
381 if ( ! function_exists( 'gglcptch_password_form_display' ) ) {
382 /**
383 * Add google captcha to the protected post password form
384 *
385 * @param string $output Form content.
386 * @param object $post Post object.
387 * @return string $expire Form content.
388 */
389 function gglcptch_password_form_display( $output, $post = null ) {
390 $recaptcha = gglcptch_display();
391 if ( '' !== $recaptcha && isset( $_COOKIE['gglcptch_password_form_errors'] ) ) {
392 $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 );
393 } else {
394 $output = str_replace( '</form>', $recaptcha . '</form>', $output );
395 }
396 return $output;
397 }
398 }
399
400 if ( ! function_exists( 'gglcptch_password_form_cookie' ) ) {
401 /**
402 * Add google captcha to the protected post password form
403 *
404 * @param array $expire Expire time.
405 * @return array $expire Expire time.
406 */
407 function gglcptch_password_form_cookie( $expire ) {
408 if ( isset( $_POST['g-recaptcha-response'] ) ) {
409 $gglcptch_check = gglcptch_check( 'password_form' );
410 if ( ! $gglcptch_check['response'] ) {
411 setcookie( 'gglcptch_password_form_errors', $gglcptch_check['errors']->get_error_message( 'gglcptch_error' ), time() + 300, COOKIEPATH, COOKIE_DOMAIN, false );
412 } else {
413 setcookie( 'gglcptch_password_form_errors', '', -1, COOKIEPATH, COOKIE_DOMAIN, false );
414 }
415 }
416 return $expire;
417 }
418 }
419
420 if ( ! function_exists( 'gglcptch_password_form_check' ) ) {
421 /**
422 * Check google captcha in protected post password form
423 *
424 * @param bool $required Flag for required password form.
425 * @param object $post Post object.
426 * @return bool $required Flag for required password form.
427 */
428 function gglcptch_password_form_check( $required, $post ) {
429 if ( isset( $_COOKIE['gglcptch_password_form_errors'] ) ) {
430 $required = true;
431 }
432 return $required;
433 }
434 }
435
436 if ( ! function_exists( 'gglcptch_signup_display' ) ) {
437 /**
438 * Add google captcha to the multisite login form
439 *
440 * @param array $errors Login form errors.
441 */
442 function gglcptch_signup_display( $errors ) {
443 $error_message = $errors->get_error_message( 'gglcptch_error' );
444 if ( ! empty( $error_message ) ) {
445 printf( '<p class="error gglcptch_error">%s</p>', wp_kses_post( $error_message ) );
446 }
447 $error_message = $errors->get_error_message( 'lmttmpts_error' );
448 if ( ! empty( $error_message ) ) {
449 printf( '<p class="error lmttmpts_error">%s</p>', wp_kses_post( $error_message ) );
450 }
451 echo gglcptch_display();
452 }
453 }
454
455 if ( ! function_exists( 'gglcptch_signup_check' ) ) {
456 /**
457 * Check google captcha in multisite login form
458 *
459 * @param array $result Result/Error.
460 * @return array $result Result/Error.
461 */
462 function gglcptch_signup_check( $result ) {
463 global $current_user;
464 if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! empty( $current_user->data->ID ) ) {
465 return $result;
466 }
467 $gglcptch_check = gglcptch_check( 'registration_form' );
468 if ( ! $gglcptch_check['response'] ) {
469 $result['errors'] = $gglcptch_check['errors'];
470 return $result;
471 }
472 return $result;
473 }
474 }
475
476 if ( ! function_exists( 'gglcptch_commentform_display' ) ) {
477 /**
478 * Add google captcha to the comment form
479 *
480 * @return bool true
481 */
482 function gglcptch_commentform_display() {
483 if ( gglcptch_is_hidden_for_role() ) {
484 return;
485 }
486 echo gglcptch_display();
487 return true;
488 }
489 }
490
491 if ( ! function_exists( 'gglcptch_commentform_check' ) ) {
492 /**
493 * Check JS enabled for comment form
494 */
495 function gglcptch_commentform_check() {
496 $gglcptch_check = gglcptch_check( 'comments_form' );
497 if ( ! $gglcptch_check['response'] ) {
498 $message = gglcptch_get_message( $gglcptch_check['reason'] ) . '<br />';
499 if ( ! empty( $gglcptch_check['errors'] ) && is_wp_error( $gglcptch_check['errors'] ) ){
500 $lmttmpts_error = $gglcptch_check['errors']->get_error_message( 'lmttmpts_error' );
501 if ( ! empty( $lmttmpts_error ) ) {
502 $message .= sprintf(
503 '<strong>%s</strong>:&nbsp;%s<br />',
504 __( 'Error', 'google-captcha' ),
505 $gglcptch_check['errors']->get_error_message( 'lmttmpts_error' )
506 );
507 }
508 }
509
510 $error_message = sprintf(
511 '<strong>%s</strong>:&nbsp;%s&nbsp;%s',
512 __( 'Error', 'google-captcha' ),
513 $message,
514 __( 'Click the BACK button on your browser and try again.', 'google-captcha' )
515 );
516 wp_die( wp_kses_post( $error_message ) );
517 }
518 }
519 }
520
521 if ( ! function_exists( 'gglcptch_contact_form_check' ) ) {
522 /**
523 * Check google captcha in BWS Contact Form
524 *
525 * @param bool $allow (Optional) reCaptcha for contact form.
526 * @return bool $allow Result check.
527 */
528 function gglcptch_contact_form_check( $allow = true ) {
529 if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) {
530 return $allow;
531 }
532 $gglcptch_check = gglcptch_check( 'contact_form' );
533 if ( ! $gglcptch_check['response'] ) {
534 return $gglcptch_check['errors'];
535 }
536 return $allow;
537 }
538 }
539
540 if ( ! function_exists( 'gglcptch_testimonials_check' ) ) {
541 /**
542 * Check google captcha in BWS Testimonial
543 *
544 * @param bool $allow (Optional) reCaptcha for testimonials.
545 * @return bool $allow Result check.
546 */
547 function gglcptch_testimonials_check( $allow = true ) {
548 global $gglcptch_check;
549 if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) {
550 return $allow;
551 }
552 $gglcptch_check = gglcptch_check( 'testimonials' );
553 if ( ! $gglcptch_check['response'] ) {
554 return $gglcptch_check['errors'];
555 }
556 return $allow;
557 }
558 }
559