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