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