PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.34
reCaptcha by BestWebSoft v1.34
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
383 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, 1 );
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 global $gglcptch_check;
263 if ( gglcptch_is_woocommerce_page() )
264 return $user;
265 if ( is_wp_error( $user ) && isset( $user->errors["empty_username"] ) && isset( $user->errors["empty_password"] ) )
266 return $user;
267
268 $gglcptch_check = gglcptch_check( 'login_form' );
269
270 if ( ! $gglcptch_check['response'] ) {
271 if ( $gglcptch_check['reason'] == 'VERIFICATION_FAILED' ) {
272 wp_clear_auth_cookie();
273 }
274 $errors = new WP_Error( $user->get_error_code(), __( 'Authentication failed.', 'google-captcha' ) );
275 $gglcptch_errors = $gglcptch_check['errors']->errors;
276 foreach ( $gglcptch_errors as $code => $messages ) {
277 foreach ( $messages as $message ) {
278 $errors->add( $code, $message );
279 }
280 }
281 $gglcptch_check['errors'] = $errors;
282 return $gglcptch_check['errors'];
283 }
284 return $user;
285 }
286 }
287
288 /* Check google captcha in registration form */
289 if ( ! function_exists( 'gglcptch_register_check' ) ) {
290 function gglcptch_register_check( $allow ) {
291 if ( gglcptch_is_woocommerce_page() )
292 return $allow;
293 $gglcptch_check = gglcptch_check( 'registration_form' );
294 if ( ! $gglcptch_check['response'] ) {
295 return $gglcptch_check['errors'];
296 }
297 return $allow;
298 }
299 }
300
301 /* Check google captcha in lostpassword form */
302 if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) {
303 function gglcptch_lostpassword_check( $allow ) {
304 if ( gglcptch_is_woocommerce_page() )
305 return $allow;
306 $gglcptch_check = gglcptch_check( 'reset_pwd_form' );
307 if ( ! $gglcptch_check['response'] ) {
308 return $gglcptch_check['errors'];
309 }
310 return $allow;
311 }
312 }
313
314 /* Add google captcha to the multisite login form */
315 if ( ! function_exists( 'gglcptch_signup_display' ) ) {
316 function gglcptch_signup_display( $errors ) {
317 if ( $error_message = $errors->get_error_message( 'gglcptch_error' ) ) {
318 printf( '<p class="error gglcptch_error">%s</p>', $error_message );
319 }
320 if ( $error_message = $errors->get_error_message( 'lmttmpts_error' ) ) {
321 printf( '<p class="error lmttmpts_error">%s</p>', $error_message );
322 }
323 echo gglcptch_display();
324 }
325 }
326
327 /* Check google captcha in multisite login form */
328 if ( ! function_exists( 'gglcptch_signup_check' ) ) {
329 function gglcptch_signup_check( $result ) {
330 global $current_user;
331 if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! empty( $current_user->data->ID ) )
332 return $result;
333 $gglcptch_check = gglcptch_check( 'registration_form' );
334 if ( ! $gglcptch_check['response'] ) {
335 $result['errors'] = $gglcptch_check['errors'];
336 return $result;
337 }
338 return $result;
339 }
340 }
341
342 /* Add google captcha to the comment form */
343 if ( ! function_exists( 'gglcptch_commentform_display' ) ) {
344 function gglcptch_commentform_display() {
345 if ( gglcptch_is_hidden_for_role() ) {
346 return;
347 }
348 echo gglcptch_display();
349 return true;
350 }
351 }
352
353 /* Check JS enabled for comment form */
354 if ( ! function_exists( 'gglcptch_commentform_check' ) ) {
355 function gglcptch_commentform_check() {
356 $gglcptch_check = gglcptch_check( 'comments_form' );
357 if ( ! $gglcptch_check['response'] ) {
358 $message = gglcptch_get_message() . "<br />";
359 $error_message = sprintf(
360 '<strong>%s</strong>:&nbsp;%s&nbsp;%s',
361 __( 'Error', 'google-captcha' ),
362 $message,
363 __( 'Click the BACK button on your browser and try again.', 'google-captcha' )
364 );
365 wp_die( $error_message );
366 }
367 return;
368 }
369 }
370
371 /* Check google captcha in BWS Contact Form */
372 if ( ! function_exists( 'gglcptch_contact_form_check' ) ) {
373 function gglcptch_contact_form_check( $allow = true ) {
374 if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) {
375 return $allow;
376 }
377 $gglcptch_check = gglcptch_check( 'contact_form' );
378 if ( ! $gglcptch_check['response'] ) {
379 return $gglcptch_check['errors'];
380 }
381 return $allow;
382 }
383 }