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