class-gglcptch-settings-tabs.php
6 years ago
forms.php
6 years ago
pro_banners.php
6 years ago
whitelist.php
6 years ago
forms.php
389 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_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 ( '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 | 'testimonials' => 'bws-testimonials/bws-testimonials.php', |
| 134 | ); |
| 135 | |
| 136 | if ( isset( $plugins[ $form_slug ] ) ) { |
| 137 | $plugin_info = gglcptch_plugin_status( $plugins[ $form_slug ], get_plugins(), is_network_admin() ); |
| 138 | |
| 139 | if ( 'deactivated' == $plugin_info['status'] ) { |
| 140 | $form_notice = '<a href="' . self_admin_url( 'plugins.php' ) . '">' . __( 'Activate', 'google-captcha' ) . '</a>'; |
| 141 | } elseif ( 'not_installed' == $plugin_info['status'] ) { |
| 142 | if ( 'contact_form' == $form_slug ) { |
| 143 | $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>'; |
| 144 | } else { |
| 145 | $slug = explode( '/', $plugins[ $form_slug ] ); |
| 146 | $slug = $slug[0]; |
| 147 | $form_notice = sprintf( '<a href="http://wordpress.org/plugins/%s/" target="_blank">%s</a>', $slug, __( 'Install Now', 'google-captcha' ) ); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | return apply_filters( 'gglcptch_form_notice', $form_notice, $form_slug ); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | if ( ! function_exists( 'gglcptch_add_actions' ) ) { |
| 156 | function gglcptch_add_actions() { |
| 157 | global $gglcptch_options; |
| 158 | |
| 159 | $is_user_logged_in = is_user_logged_in(); |
| 160 | |
| 161 | if ( ! empty( $gglcptch_options['login_form'] ) || ! empty( $gglcptch_options['reset_pwd_form'] ) || ! empty( $gglcptch_options['registration_form'] ) ) { |
| 162 | |
| 163 | if ( gglcptch_is_recaptcha_required( 'login_form', $is_user_logged_in ) ) { |
| 164 | add_action( 'login_form', 'gglcptch_login_display' ); |
| 165 | add_action( 'authenticate', 'gglcptch_login_check', 21, 1 ); |
| 166 | } |
| 167 | |
| 168 | if ( gglcptch_is_recaptcha_required( 'registration_form', $is_user_logged_in ) ) { |
| 169 | if ( ! is_multisite() ) { |
| 170 | add_action( 'register_form', 'gglcptch_login_display', 99 ); |
| 171 | add_action( 'registration_errors', 'gglcptch_register_check', 10, 1 ); |
| 172 | } else { |
| 173 | add_action( 'signup_extra_fields', 'gglcptch_signup_display' ); |
| 174 | add_action( 'signup_blogform', 'gglcptch_signup_display' ); |
| 175 | add_filter( 'wpmu_validate_user_signup', 'gglcptch_signup_check', 10, 3 ); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | if ( gglcptch_is_recaptcha_required( 'reset_pwd_form', $is_user_logged_in ) ) { |
| 180 | add_action( 'lostpassword_form', 'gglcptch_login_display' ); |
| 181 | add_action( 'allow_password_reset', 'gglcptch_lostpassword_check' ); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* Add Google Captcha to WP comments */ |
| 186 | if ( gglcptch_is_recaptcha_required( 'comments_form', $is_user_logged_in ) ) { |
| 187 | add_action( 'comment_form_after_fields', 'gglcptch_commentform_display' ); |
| 188 | add_action( 'comment_form_logged_in_after', 'gglcptch_commentform_display' ); |
| 189 | add_action( 'pre_comment_on_post', 'gglcptch_commentform_check' ); |
| 190 | } |
| 191 | |
| 192 | /* Add Google Captcha to Contact Form by BestWebSoft */ |
| 193 | if ( gglcptch_is_recaptcha_required( 'contact_form', $is_user_logged_in ) ) { |
| 194 | add_filter( 'cntctfrm_display_captcha', 'gglcptch_display', 10, 1 ); |
| 195 | add_filter( 'cntctfrm_check_form', 'gglcptch_contact_form_check' ); |
| 196 | } |
| 197 | |
| 198 | /* Add Google Captcha to Testimonials by BestWebSoft */ |
| 199 | if ( gglcptch_is_recaptcha_required( 'testimonials', $is_user_logged_in ) ) { |
| 200 | add_filter( 'tstmnls_display_recaptcha', 'gglcptch_display', 10, 0 ); |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /* Echo google captcha */ |
| 206 | if ( ! function_exists( 'gglcptch_echo_recaptcha' ) ) { |
| 207 | function gglcptch_echo_recaptcha( $content = '' ) { |
| 208 | echo gglcptch_display( $content ); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /* Add google captcha to the login form */ |
| 213 | if ( ! function_exists( 'gglcptch_login_display' ) ) { |
| 214 | function gglcptch_login_display() { |
| 215 | |
| 216 | global $gglcptch_options; |
| 217 | |
| 218 | if ( isset( $gglcptch_options['recaptcha_version'] ) ) { |
| 219 | if ( 'v2' == $gglcptch_options['recaptcha_version'] ) { |
| 220 | $from_width = 302; |
| 221 | } else { |
| 222 | $from_width = 320; |
| 223 | if ( 'clean' == $gglcptch_options['theme'] ) { |
| 224 | $from_width = 450; |
| 225 | } |
| 226 | } ?> |
| 227 | <style type="text/css" media="screen"> |
| 228 | .login-action-login #loginform, |
| 229 | .login-action-lostpassword #lostpasswordform, |
| 230 | .login-action-register #registerform { |
| 231 | width: <?php echo $from_width; ?>px !important; |
| 232 | } |
| 233 | #login_error, |
| 234 | .message { |
| 235 | width: <?php echo $from_width + 20; ?>px !important; |
| 236 | } |
| 237 | .login-action-login #loginform .gglcptch, |
| 238 | .login-action-lostpassword #lostpasswordform .gglcptch, |
| 239 | .login-action-register #registerform .gglcptch { |
| 240 | margin-bottom: 10px; |
| 241 | } |
| 242 | </style> |
| 243 | <?php } |
| 244 | echo gglcptch_display(); |
| 245 | return true; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /* Check google captcha in login form */ |
| 250 | if ( ! function_exists( 'gglcptch_login_check' ) ) { |
| 251 | function gglcptch_login_check( $user ) { |
| 252 | global $gglcptch_check; |
| 253 | if ( gglcptch_is_woocommerce_page() ) |
| 254 | return $user; |
| 255 | if ( is_wp_error( $user ) && isset( $user->errors["empty_username"] ) && isset( $user->errors["empty_password"] ) ) |
| 256 | return $user; |
| 257 | |
| 258 | $gglcptch_check = gglcptch_check( 'login_form' ); |
| 259 | |
| 260 | if ( ! $gglcptch_check['response'] ) { |
| 261 | if ( $gglcptch_check['reason'] == 'VERIFICATION_FAILED' ) { |
| 262 | wp_clear_auth_cookie(); |
| 263 | } |
| 264 | $error_code = ( is_wp_error( $user ) ) ? $user->get_error_code() : 'incorrect_password'; |
| 265 | $errors = new WP_Error( $error_code, __( 'Authentication failed.', 'google-captcha' ) ); |
| 266 | $gglcptch_errors = $gglcptch_check['errors']->errors; |
| 267 | foreach ( $gglcptch_errors as $code => $messages ) { |
| 268 | foreach ( $messages as $message ) { |
| 269 | $errors->add( $code, $message ); |
| 270 | } |
| 271 | } |
| 272 | $gglcptch_check['errors'] = $errors; |
| 273 | return $gglcptch_check['errors']; |
| 274 | } |
| 275 | return $user; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /* Check google captcha in registration form */ |
| 280 | if ( ! function_exists( 'gglcptch_register_check' ) ) { |
| 281 | function gglcptch_register_check( $allow ) { |
| 282 | if ( gglcptch_is_woocommerce_page() ) |
| 283 | return $allow; |
| 284 | $gglcptch_check = gglcptch_check( 'registration_form' ); |
| 285 | if ( ! $gglcptch_check['response'] ) { |
| 286 | return $gglcptch_check['errors']; |
| 287 | } |
| 288 | return $allow; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /* Check google captcha in lostpassword form */ |
| 293 | if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) { |
| 294 | function gglcptch_lostpassword_check( $allow ) { |
| 295 | if ( gglcptch_is_woocommerce_page() ) |
| 296 | return $allow; |
| 297 | $gglcptch_check = gglcptch_check( 'reset_pwd_form' ); |
| 298 | if ( ! $gglcptch_check['response'] ) { |
| 299 | return $gglcptch_check['errors']; |
| 300 | } |
| 301 | return $allow; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | /* Add google captcha to the multisite login form */ |
| 306 | if ( ! function_exists( 'gglcptch_signup_display' ) ) { |
| 307 | function gglcptch_signup_display( $errors ) { |
| 308 | if ( $error_message = $errors->get_error_message( 'gglcptch_error' ) ) { |
| 309 | printf( '<p class="error gglcptch_error">%s</p>', $error_message ); |
| 310 | } |
| 311 | if ( $error_message = $errors->get_error_message( 'lmttmpts_error' ) ) { |
| 312 | printf( '<p class="error lmttmpts_error">%s</p>', $error_message ); |
| 313 | } |
| 314 | echo gglcptch_display(); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /* Check google captcha in multisite login form */ |
| 319 | if ( ! function_exists( 'gglcptch_signup_check' ) ) { |
| 320 | function gglcptch_signup_check( $result ) { |
| 321 | global $current_user; |
| 322 | if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! empty( $current_user->data->ID ) ) |
| 323 | return $result; |
| 324 | $gglcptch_check = gglcptch_check( 'registration_form' ); |
| 325 | if ( ! $gglcptch_check['response'] ) { |
| 326 | $result['errors'] = $gglcptch_check['errors']; |
| 327 | return $result; |
| 328 | } |
| 329 | return $result; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /* Add google captcha to the comment form */ |
| 334 | if ( ! function_exists( 'gglcptch_commentform_display' ) ) { |
| 335 | function gglcptch_commentform_display() { |
| 336 | if ( gglcptch_is_hidden_for_role() ) { |
| 337 | return; |
| 338 | } |
| 339 | echo gglcptch_display(); |
| 340 | return true; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* Check JS enabled for comment form */ |
| 345 | if ( ! function_exists( 'gglcptch_commentform_check' ) ) { |
| 346 | function gglcptch_commentform_check() { |
| 347 | $gglcptch_check = gglcptch_check( 'comments_form' ); |
| 348 | if ( ! $gglcptch_check['response'] ) { |
| 349 | $message = gglcptch_get_message($gglcptch_check['reason']) . "<br />"; |
| 350 | $error_message = sprintf( |
| 351 | '<strong>%s</strong>: %s %s', |
| 352 | __( 'Error', 'google-captcha' ), |
| 353 | $message, |
| 354 | __( 'Click the BACK button on your browser and try again.', 'google-captcha' ) |
| 355 | ); |
| 356 | wp_die( $error_message ); |
| 357 | } |
| 358 | return; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /* Check google captcha in BWS Contact Form */ |
| 363 | if ( ! function_exists( 'gglcptch_contact_form_check' ) ) { |
| 364 | function gglcptch_contact_form_check( $allow = true ) { |
| 365 | if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) { |
| 366 | return $allow; |
| 367 | } |
| 368 | $gglcptch_check = gglcptch_check( 'contact_form' ); |
| 369 | if ( ! $gglcptch_check['response'] ) { |
| 370 | return $gglcptch_check['errors']; |
| 371 | } |
| 372 | return $allow; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | /* Check google captcha in BWS Testimonials */ |
| 377 | if ( ! function_exists( 'gglcptch_testimonials_check' ) ) { |
| 378 | function gglcptch_testimonials_check( $allow = true ) { |
| 379 | global $gglcptch_check; |
| 380 | if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) { |
| 381 | return $allow; |
| 382 | } |
| 383 | $gglcptch_check = gglcptch_check( 'testimonials' ); |
| 384 | if ( ! $gglcptch_check['response'] ) { |
| 385 | return $gglcptch_check['errors']; |
| 386 | } |
| 387 | return $allow; |
| 388 | } |
| 389 | } |