PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.74
reCaptcha by BestWebSoft v1.74
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 2 years ago class-gglcptch-settings-tabs.php 2 years ago forms.php 2 years ago pro_banners.php 2 years ago
forms.php
557 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 $gglcptch_errors = $gglcptch_check['errors']->errors;
323 foreach ( $gglcptch_errors as $code => $messages ) {
324 foreach ( $messages as $message ) {
325 $errors->add( $code, $message );
326 }
327 }
328 $gglcptch_check['errors'] = $errors;
329 return $gglcptch_check['errors'];
330 }
331 return $user;
332 }
333 }
334
335 if ( ! function_exists( 'gglcptch_register_check' ) ) {
336 /**
337 * Check google captcha in registration form
338 *
339 * @param bool $allow Flag for captcha result.
340 * @return bool $allow Flag for captcha result.
341 */
342 function gglcptch_register_check( $allow ) {
343 if ( gglcptch_is_woocommerce_page() ) {
344 return $allow;
345 }
346 /* Skip check if connecting to XMLRPC */
347 if ( defined( 'XMLRPC_REQUEST' ) ) {
348 return $allow;
349 }
350
351 $gglcptch_check = gglcptch_check( 'registration_form' );
352 if ( ! $gglcptch_check['response'] ) {
353 return $gglcptch_check['errors'];
354 }
355 $_POST['g-recaptcha-response-check'] = true;
356 return $allow;
357 }
358 }
359
360 if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) {
361 /**
362 * Check google captcha in lostpassword form
363 *
364 * @param bool $allow Flag for captcha result.
365 * @return bool $allow Flag for captcha result.
366 */
367 function gglcptch_lostpassword_check( $allow ) {
368 if ( gglcptch_is_woocommerce_page() || ( isset( $_POST['g-recaptcha-response-check'] ) && true === $_POST['g-recaptcha-response-check'] ) ) {
369 return $allow;
370 }
371 $gglcptch_check = gglcptch_check( 'reset_pwd_form' );
372 if ( ! $gglcptch_check['response'] ) {
373 return $gglcptch_check['errors'];
374 }
375 return $allow;
376 }
377 }
378
379 if ( ! function_exists( 'gglcptch_password_form_display' ) ) {
380 /**
381 * Add google captcha to the protected post password form
382 *
383 * @param string $output Form content.
384 * @param object $post Post object.
385 * @return string $expire Form content.
386 */
387 function gglcptch_password_form_display( $output, $post ) {
388 $recaptcha = gglcptch_display();
389 if ( '' !== $recaptcha && isset( $_COOKIE['gglcptch_password_form_errors'] ) ) {
390 $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 );
391 } else {
392 $output = str_replace( '</form>', $recaptcha . '</form>', $output );
393 }
394 return $output;
395 }
396 }
397
398 if ( ! function_exists( 'gglcptch_password_form_cookie' ) ) {
399 /**
400 * Add google captcha to the protected post password form
401 *
402 * @param array $expire Expire time.
403 * @return array $expire Expire time.
404 */
405 function gglcptch_password_form_cookie( $expire ) {
406 if ( isset( $_POST['g-recaptcha-response'] ) ) {
407 $gglcptch_check = gglcptch_check( 'password_form' );
408 if ( ! $gglcptch_check['response'] ) {
409 setcookie( 'gglcptch_password_form_errors', $gglcptch_check['errors']->get_error_message( 'gglcptch_error' ), time() + 300, COOKIEPATH, COOKIE_DOMAIN, false );
410 } else {
411 setcookie( 'gglcptch_password_form_errors', '', -1, COOKIEPATH, COOKIE_DOMAIN, false );
412 }
413 }
414 return $expire;
415 }
416 }
417
418 if ( ! function_exists( 'gglcptch_password_form_check' ) ) {
419 /**
420 * Check google captcha in protected post password form
421 *
422 * @param bool $required Flag for required password form.
423 * @param object $post Post object.
424 * @return bool $required Flag for required password form.
425 */
426 function gglcptch_password_form_check( $required, $post ) {
427 if ( isset( $_COOKIE['gglcptch_password_form_errors'] ) ) {
428 $required = true;
429 }
430 return $required;
431 }
432 }
433
434 if ( ! function_exists( 'gglcptch_signup_display' ) ) {
435 /**
436 * Add google captcha to the multisite login form
437 *
438 * @param array $errors Login form errors.
439 */
440 function gglcptch_signup_display( $errors ) {
441 $error_message = $errors->get_error_message( 'gglcptch_error' );
442 if ( ! empty( $error_message ) ) {
443 printf( '<p class="error gglcptch_error">%s</p>', wp_kses_post( $error_message ) );
444 }
445 $error_message = $errors->get_error_message( 'lmttmpts_error' );
446 if ( ! empty( $error_message ) ) {
447 printf( '<p class="error lmttmpts_error">%s</p>', wp_kses_post( $error_message ) );
448 }
449 echo gglcptch_display();
450 }
451 }
452
453 if ( ! function_exists( 'gglcptch_signup_check' ) ) {
454 /**
455 * Check google captcha in multisite login form
456 *
457 * @param array $result Result/Error.
458 * @return array $result Result/Error.
459 */
460 function gglcptch_signup_check( $result ) {
461 global $current_user;
462 if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! empty( $current_user->data->ID ) ) {
463 return $result;
464 }
465 $gglcptch_check = gglcptch_check( 'registration_form' );
466 if ( ! $gglcptch_check['response'] ) {
467 $result['errors'] = $gglcptch_check['errors'];
468 return $result;
469 }
470 return $result;
471 }
472 }
473
474 if ( ! function_exists( 'gglcptch_commentform_display' ) ) {
475 /**
476 * Add google captcha to the comment form
477 *
478 * @return bool true
479 */
480 function gglcptch_commentform_display() {
481 if ( gglcptch_is_hidden_for_role() ) {
482 return;
483 }
484 echo gglcptch_display();
485 return true;
486 }
487 }
488
489 if ( ! function_exists( 'gglcptch_commentform_check' ) ) {
490 /**
491 * Check JS enabled for comment form
492 */
493 function gglcptch_commentform_check() {
494 $gglcptch_check = gglcptch_check( 'comments_form' );
495 if ( ! $gglcptch_check['response'] ) {
496 $message = gglcptch_get_message( $gglcptch_check['reason'] ) . '<br />';
497 if ( ! empty( $gglcptch_check['errors'] ) && is_wp_error( $gglcptch_check['errors'] ) ){
498 $lmttmpts_error = $gglcptch_check['errors']->get_error_message( 'lmttmpts_error' );
499 if ( ! empty( $lmttmpts_error ) ) {
500 $message .= sprintf(
501 '<strong>%s</strong>:&nbsp;%s<br />',
502 __( 'Error', 'google-captcha' ),
503 $gglcptch_check['errors']->get_error_message( 'lmttmpts_error' )
504 );
505 }
506 }
507
508 $error_message = sprintf(
509 '<strong>%s</strong>:&nbsp;%s&nbsp;%s',
510 __( 'Error', 'google-captcha' ),
511 $message,
512 __( 'Click the BACK button on your browser and try again.', 'google-captcha' )
513 );
514 wp_die( wp_kses_post( $error_message ) );
515 }
516 }
517 }
518
519 if ( ! function_exists( 'gglcptch_contact_form_check' ) ) {
520 /**
521 * Check google captcha in BWS Contact Form
522 *
523 * @param bool $allow (Optional) reCaptcha for contact form.
524 * @return bool $allow Result check.
525 */
526 function gglcptch_contact_form_check( $allow = true ) {
527 if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) {
528 return $allow;
529 }
530 $gglcptch_check = gglcptch_check( 'contact_form' );
531 if ( ! $gglcptch_check['response'] ) {
532 return $gglcptch_check['errors'];
533 }
534 return $allow;
535 }
536 }
537
538 if ( ! function_exists( 'gglcptch_testimonials_check' ) ) {
539 /**
540 * Check google captcha in BWS Testimonial
541 *
542 * @param bool $allow (Optional) reCaptcha for testimonials.
543 * @return bool $allow Result check.
544 */
545 function gglcptch_testimonials_check( $allow = true ) {
546 global $gglcptch_check;
547 if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) {
548 return $allow;
549 }
550 $gglcptch_check = gglcptch_check( 'testimonials' );
551 if ( ! $gglcptch_check['response'] ) {
552 return $gglcptch_check['errors'];
553 }
554 return $allow;
555 }
556 }
557