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