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