Changeset 2712286
- Timestamp:
- 04/20/2022 06:00:08 PM (3 years ago)
- Location:
- simpleform-recaptcha/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
simpleform-recaptcha/trunk/README.txt
r2537040 r2712286 2 2 Contributors: simpleform 3 3 Donate link: https://wpsform.com/ 4 Tags: contact form, spam, recaptcha, antispam, simpleform addon, spam manager, google, bot, captcha, v2, invisible, v35 Requires at least: 5. 16 Tested up to: 5. 74 Tags: contact form, spam, recaptcha, antispam, simpleform addon, spam manager, google, bot, captcha, form 5 Requires at least: 5.6 6 Tested up to: 5.9 7 7 Requires PHP: 5.6 8 Stable tag: 1.1. 18 Stable tag: 1.1.2 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 60 60 == Changelog == 61 61 62 = 1.1.2 (20 April 2022) = 63 * Fixed: missing control on recaptcha_threshold setting in form submitted without AJAX 64 * Added: compatibility with SimpleForm 2.1.7 version 65 62 66 = 1.1.1 (25 May 2021) = 63 67 * Added: compatibility with SimpleForm 2.0 version … … 73 77 74 78 You don’t know SimpleForm yet? Check out our [Demo](https://wpsform.com/demo/) and find out how it works. 79 80 == Upgrade Notice == 81 82 = 1.1.2 = 83 This version requires SimpleForm 2.1.7 or greater installed. Please do not update until the required SimpleForm version is installed! -
simpleform-recaptcha/trunk/admin/class-admin.php
r2537040 r2712286 346 346 } 347 347 348 /**349 * Retrieve captcha field type.350 *351 * @since 1.0352 */353 354 public function captcha_type($attributes) {355 356 $settings = get_option('sform_settings');357 $recaptcha = ! empty( $settings['recaptcha'] ) ? esc_attr($settings['recaptcha']) : 'false';358 $captcha_field = ! empty( $attributes['captcha_field'] ) ? esc_attr($attributes['captcha_field']) : 'hidden';359 $captcha_type = ! empty( $attributes['captcha_type'] ) ? esc_attr($attributes['captcha_type']) : 'math';360 $field_label = $captcha_field == 'hidden' || ( $captcha_type != 'math' && $recaptcha != 'false' ) ? 'hidden' : '';361 362 return $field_label;363 364 }365 366 348 /** 367 349 * Add reCAPTCHA related fields values in the attributes array. … … 469 451 470 452 /** 471 * Invoke the reCAPTCHA challenge when AJAX is enabled. 472 * 473 * @since 1.0 474 */ 475 476 public function invoke_ajax_challenge($attributes, $captcha_one, $captcha_two, $captcha_result, $captcha_answer, $field_error ) { 477 478 $settings = get_option('sform_settings'); 479 $recaptcha = ! empty( $settings['recaptcha'] ) ? esc_attr($settings['recaptcha']) : 'false'; 480 $captcha_field = ! empty( $attributes['captcha_field'] ) ? esc_attr($attributes['captcha_field']) : 'hidden'; 453 * Invoke the reCAPTCHA challenge. 454 * 455 * @since 1.0 456 * @version 1.2 457 */ 458 459 public function invoke_challenge($errors,$form_id,$captcha_question,$captcha_answer) { 460 461 $util = new SimpleForm_Util(); 462 $attributes = $util->sform_attributes($form_id); 463 $settings = $util->sform_settings($form_id); 464 $ajax = ! empty( $settings['ajax_submission'] ) ? esc_attr($settings['ajax_submission']) : 'false'; 481 465 $captcha_type = ! empty( $attributes['captcha_type'] ) ? esc_attr($attributes['captcha_type']) : 'math'; 482 483 if ( empty($field_error) && ($captcha_type == 'math' || $recaptcha == 'false') ) { 484 485 if ( ( $captcha_field == 'visible' || $captcha_field == 'registered' && is_user_logged_in() || $captcha_field == 'anonymous' && ! is_user_logged_in() ) && ! empty($captcha_one) && ! empty($captcha_two) && ( empty($captcha_answer) || $captcha_result != $captcha_answer ) ) { 486 $error_captcha_label = ! empty( $settings['invalid_captcha'] ) ? stripslashes(esc_attr($settings['invalid_captcha'])) : __( 'Please enter a valid captcha value', 'simpleform' ); 487 $error = ! empty( $settings['captcha_error'] ) ? stripslashes(esc_attr($settings['captcha_error'])) : __('Error occurred validating the captcha', 'simpleform'); 488 echo json_encode(array('error' => true, 'notice' => $error_captcha_label, 'showerror' => true, 'captcha' => $error_captcha_label ) ); 489 exit; 490 } 491 492 } 493 494 else { 495 496 $recaptcha_type = ! empty( $settings['recaptcha_type'] ) ? esc_attr($settings['recaptcha_type']) : 'v2'; 497 $recaptcha_site_key = ! empty( $settings['recaptcha_site_key'] ) ? esc_attr($settings['recaptcha_site_key']) : ''; 498 $recaptcha_secret_key = ! empty( $settings['recaptcha_secret_key'] ) ? esc_attr($settings['recaptcha_secret_key']) : ''; 499 $threshold = ! empty( $settings['recaptcha_threshold'] ) ? esc_attr($settings['recaptcha_threshold']) : '0.5'; 466 $main_settings = get_option('sform_settings'); 467 $recaptcha = ! empty( $main_settings['recaptcha'] ) ? esc_attr($main_settings['recaptcha']) : 'false'; 468 $empty_error = $ajax == 'false' ? '' : array(); 469 $errors = empty($errors) ? $empty_error : $errors; 470 471 if ( $captcha_type == 'recaptcha' && $recaptcha == 'true' ) { 472 473 $main_settings = get_option('sform_settings'); 474 $recaptcha_type = ! empty( $main_settings['recaptcha_type'] ) ? esc_attr($main_settings['recaptcha_type']) : 'v2'; 475 $recaptcha_site_key = ! empty( $main_settings['recaptcha_site_key'] ) ? esc_attr($main_settings['recaptcha_site_key']) : ''; 476 $recaptcha_secret_key = ! empty( $main_settings['recaptcha_secret_key'] ) ? esc_attr($main_settings['recaptcha_secret_key']) : ''; 477 $threshold = ! empty( $main_settings['recaptcha_threshold'] ) ? esc_attr($main_settings['recaptcha_threshold']) : '0.5'; 500 478 $unverified_recaptcha = ! empty( $settings['unverified_recaptcha'] ) ? esc_attr($settings['unverified_recaptcha']) : __( 'Please prove you are not a robot', 'simpleform-recaptcha' ); 501 479 $invalid_recaptcha = ! empty( $settings['invalid_recaptcha'] ) ? esc_attr($settings['invalid_recaptcha']) : __( 'Robot verification failed, please try again', 'simpleform-recaptcha' ); 502 480 $user_response = isset($_POST['g-recaptcha-response']) ? $_POST['g-recaptcha-response'] : ''; 503 504 if ( empty($field_error) && ( $captcha_field == 'visible' || $captcha_field == 'registered' && is_user_logged_in() || $captcha_field == 'anonymous' && ! is_user_logged_in() ) && $captcha_type == 'recaptcha' && $recaptcha == 'true') { 505 506 if ( $recaptcha_type == 'v2' && empty($user_response) /* && $this->recaptcha_verification($user_response) */ ) { 507 echo json_encode(array('error' => true, 'notice' => $unverified_recaptcha, 'showerror' => true )); 508 exit; 481 482 if ( $recaptcha_type == 'v2' && empty($user_response) ) { 483 484 if ( $ajax != 'false' ) { 485 $errors['error'] = true; 486 $errors['showerror'] = true; 487 $errors['field_focus'] = false; 488 $errors['notice'] = $unverified_recaptcha; 489 } 490 else { 491 $errors .= $form_id.';unverified_recaptcha;'; 492 } 493 494 } 495 496 else { 497 498 if ( $this->recaptcha_verification($user_response) ) { 499 500 if ( $ajax != 'false' ) { 501 $errors['error'] = true; 502 $errors['showerror'] = true; 503 $errors['field_focus'] = false; 504 $errors['notice'] = $invalid_recaptcha; 505 } 506 else { 507 $errors .= $form_id.';recaptcha;'; 508 } 509 509 510 } 510 511 if ( $this->recaptcha_verification($user_response) ) { 512 echo json_encode(array('error' => true, 'notice' => $invalid_recaptcha, 'showerror' => true )); 513 exit; 514 } 515 511 516 512 } 517 513 518 514 } 519 520 } 521 522 /** 523 * Invoke the reCAPTCHA challenge when AJAX is not enabled. 524 * 525 * @since 1.0 526 */ 527 528 public function invoke_challenge($attributes, $errors_list) { 529 530 $error = ''; 531 $settings = get_option('sform_settings'); 532 $recaptcha = ! empty( $settings['recaptcha'] ) ? esc_attr($settings['recaptcha']) : 'false'; 533 $captcha_field = ! empty( $attributes['captcha_field'] ) ? esc_attr($attributes['captcha_field']) : 'hidden'; 534 $captcha_type = ! empty( $attributes['captcha_type'] ) ? esc_attr($attributes['captcha_type']) : 'math'; 535 $recaptcha_type = ! empty( $settings['recaptcha_type'] ) ? esc_attr($settings['recaptcha_type']) : 'v2'; 536 $recaptcha_site_key = ! empty( $settings['recaptcha_site_key'] ) ? esc_attr($settings['recaptcha_site_key']) : ''; 537 $recaptcha_secret_key = ! empty( $settings['recaptcha_secret_key'] ) ? esc_attr($settings['recaptcha_secret_key']) : ''; 538 $user_response = isset($_POST['g-recaptcha-response']) ? $_POST['g-recaptcha-response'] : ''; 539 540 if ( empty($errors_list) && ! empty($captcha_field) && ( $captcha_field == 'visible' || $captcha_field == 'registered' && is_user_logged_in() || $captcha_field == 'anonymous' && ! is_user_logged_in() ) && $captcha_type == 'recaptcha' && $recaptcha == 'true' ) { 541 542 if ( $recaptcha_type == 'v2' && empty($user_response) ) { 543 $error = 'unverified_recaptcha;'; 544 } 545 546 else { 547 if ( $this->recaptcha_verification($user_response) ) { 548 $error = 'recaptcha;'; 549 } 550 } 551 552 } 553 554 return $error; 515 516 else { 517 518 $outside_error = ! empty( $settings['outside_error'] ) ? esc_attr($settings['outside_error']) : 'bottom'; 519 $showerror = $outside_error == 'top' || $outside_error == 'bottom' ? true : false; 520 $empty_fields = ! empty( $settings['empty_fields'] ) ? stripslashes(esc_attr($settings['empty_fields'])) : __( 'There were some errors that need to be fixed', 'simpleform' ); 521 $error_captcha_label = ! empty( $settings['invalid_captcha'] ) ? stripslashes(esc_attr($settings['invalid_captcha'])) : esc_attr__( 'Please enter a valid captcha value', 'simpleform' ); 522 $error = ! empty( $settings['captcha_error'] ) ? stripslashes(esc_attr($settings['captcha_error'])) : __('Error occurred validating the captcha', 'simpleform'); 523 524 if ( ! empty($captcha_question) && ( empty($captcha_answer) || $captcha_question != $captcha_answer ) ) { 525 if ( $ajax != 'false' ) { 526 $errors['error'] = true; 527 $errors['showerror'] = $showerror; 528 $errors['captcha'] = $error_captcha_label; 529 $errors['notice'] = count($errors) < 5 ? $error : $empty_fields; 530 } 531 else { 532 $errors .= $form_id.';captcha;'; 533 } 534 } 535 536 } 537 538 return $errors; 555 539 556 540 } … … 669 653 670 654 $simpleform_data = get_plugin_data( WP_PLUGIN_DIR.'/simpleform/simpleform.php'); 671 $version = '<b>'. SFORM_VERSION_REQUIRED_FOR_SIMPLEFORM_RECAPTCHA .'</b>'; 672 $message = sprintf( __( 'The new version requires SimpleForm version %s or greater installed. Please update SimpleForm to make it work properly!', 'simpleform-recaptcha' ), $version ); 673 674 if ( version_compare ( $simpleform_data['Version'], SFORM_VERSION_REQUIRED_FOR_SIMPLEFORM_RECAPTCHA, '<') ) { 675 echo '<br><span style="margin-left:26px"><b>'.__( 'Upgrade Notice', 'simpleform-recaptcha' ).':</b> '.$message.'</span>'; 655 $version = '<b>'. SIMPLEFORM_REQUIRED_VERSION_FOR_RECAPTCHA .'</b>'; 656 $message = sprintf( __( 'The new version requires SimpleForm %s or greater installed. Please do not update until the required SimpleForm version is installed!', 'simpleform-recaptcha' ), $version ); 657 658 if ( version_compare ( $simpleform_data['Version'], SIMPLEFORM_REQUIRED_VERSION_FOR_RECAPTCHA, '<') ) { 659 echo '<br><span style="margin-left:26px; color: #d54e21; "><b>'.__( 'Upgrade Notice', 'simpleform-recaptcha' ).':</b> '.$message.'</span>'; 660 676 661 } 677 662 -
simpleform-recaptcha/trunk/includes/class-activator.php
r2537040 r2712286 42 42 43 43 public static function sform_recaptcha_settings() { 44 44 45 45 $main_attributes = get_option('sform_attributes'); 46 46 $main_settings = get_option('sform_settings'); 47 48 47 $new_attributes = array( 'captcha_type' => 'math' ); 49 48 -
simpleform-recaptcha/trunk/includes/class-core.php
r2537040 r2712286 40 40 */ 41 41 42 protected $version_required = ' 1.10.7';42 protected $version_required = '2.1.7'; 43 43 44 44 /** … … 59 59 60 60 if ( defined( 'SIMPLEFORM_RECAPTCHA_VERSION' ) ) { $this->version = SIMPLEFORM_RECAPTCHA_VERSION; } 61 else { $this->version = '1.1. 1'; }61 else { $this->version = '1.1.2'; } 62 62 $this->plugin_name = 'simpleform-recaptcha'; 63 63 $this->requirements_matching(); … … 106 106 if ( $admin_notices == 'false' ) { 107 107 global $pagenow; 108 if ( ( isset($_GET['page']) && ( 'sform- submissions' === $_GET['page'] || 'sform-editor' === $_GET['page'] || 'sform-settings' === $_GET['page'] || 'sform-entrie' === $_GET['page'] ) ) || $pagenow == 'plugins.php' ) {108 if ( ( isset($_GET['page']) && ( 'sform-entries' === $_GET['page'] || 'sform-forms' === $_GET['page'] || 'sform-form' === $_GET['page'] || 'sform-new' === $_GET['page'] || 'sform-editor' === $_GET['page'] || 'sform-settings' === $_GET['page'] || 'sform-support' === $_GET['page'] || 'sform-entrie' === $_GET['page'] ) ) || $pagenow == 'plugins.php' ) { 109 109 $addon = SIMPLEFORM_RECAPTCHA_NAME; 110 110 $version = '<b>'. $this->version_required .'</b>'; … … 153 153 // Check for core plugin updated 154 154 if ( $this->is_version_compatible() ) { 155 156 $plugin_data = get_plugin_data( WP_PLUGIN_DIR.'/simpleform/simpleform.php');157 if ( version_compare ( $plugin_data['Version'], '2.0', '<') ) {158 // Register the scripts for the admin area159 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts_old' );160 // Add reCAPTCHA fields in the Settings page161 $this->loader->add_filter( 'recaptcha_settings_filter', $plugin_admin, 'settings_fields_old' );162 } else {163 155 // Register the scripts for the admin area 164 156 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); 165 157 // Add reCAPTCHA fields in the Settings page 166 158 $this->loader->add_filter( 'recaptcha_settings_filter', $plugin_admin, 'settings_fields' ); 167 }168 159 // Add reCAPTCHA error message fields in the Settings page 169 160 $this->loader->add_filter( 'recaptcha_error_message', $plugin_admin, 'error_messages' ); … … 174 165 // Add reCAPTCHA field in the Form Editor page 175 166 $this->loader->add_action( 'sform_recaptcha_field', $plugin_admin, 'recaptcha_field' ); 176 // Retrieve captcha field type177 $this->loader->add_filter( 'sform_captcha_type', $plugin_admin, 'captcha_type' );178 167 // Add reCAPTCHA related fields values in the attributes array 179 168 $this->loader->add_filter( 'sform_recaptcha_attributes', $plugin_admin, 'recaptcha_attributes' ); 180 169 // Add reCAPTCHA field in the contact form 181 170 $this->loader->add_filter( 'sform_captcha_field', $plugin_admin, 'recaptcha_form_field', 10, 5 ); 182 // Invoke the reCAPTCHA challenge when AJAX is enabled 183 $this->loader->add_action( 'recaptcha_ajax_challenge', $plugin_admin, 'invoke_ajax_challenge', 10, 6 ); 184 // Invoke the reCAPTCHA challenge when AJAX is not enabled 185 $this->loader->add_filter( 'recaptcha_challenge', $plugin_admin, 'invoke_challenge', 10, 2 ); 171 // Invoke the reCAPTCHA challenge 172 $this->loader->add_filter( 'recaptcha_challenge', $plugin_admin, 'invoke_challenge', 10, 4 ); 186 173 // Display an error when AJAX is not enabled and the reCAPTCHA challenge is not passed 187 174 $this->loader->add_filter( 'recaptcha_error', $plugin_admin, 'recaptcha_error' ); … … 202 189 203 190 } 204 191 205 192 /** 206 193 * Check if the core plugin is listed in the active plugins in the WordPress database. -
simpleform-recaptcha/trunk/simpleform-recaptcha.php
r2537040 r2712286 4 4 * 5 5 * Plugin Name: SimpleForm reCAPTCHA 6 * Description: Stop Bot Spam! This addon for SimpleForm allows you to require users to confirm that they are not a robot by completing the Google reCAPTCHA before form submission.7 * Version: 1.1. 16 * Description: Stop Bot Spam! This SimpleForm addon allows you to require users to confirm that they are not a robot by completing the Google reCAPTCHA. 7 * Version: 1.1.2 8 8 * Author: WPSForm Team 9 9 * Author URI: https://wpsform.com … … 24 24 25 25 define( 'SIMPLEFORM_RECAPTCHA_NAME', 'SimpleForm reCAPTCHA' ); 26 define( 'SIMPLEFORM_RECAPTCHA_VERSION', '1.1. 1' );26 define( 'SIMPLEFORM_RECAPTCHA_VERSION', '1.1.2' ); 27 27 define( 'SIMPLEFORM_RECAPTCHA_DB_VERSION', '1.0' ); 28 28 define( 'SIMPLEFORM_RECAPTCHA_BASENAME', plugin_basename( __FILE__ ) ); 29 29 define( 'SIMPLEFORM_RECAPTCHA_PATH', plugin_dir_path( __FILE__ ) ); 30 define( 'S FORM_VERSION_REQUIRED_FOR_SIMPLEFORM_RECAPTCHA', '1.10.7' );30 define( 'SIMPLEFORM_REQUIRED_VERSION_FOR_RECAPTCHA', '2.1.7' ); 31 31 32 32 /**
Note: See TracChangeset
for help on using the changeset viewer.