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