Plugin Directory

Changeset 2712286


Ignore:
Timestamp:
04/20/2022 06:00:08 PM (3 years ago)
Author:
simpleform
Message:

fix: compatibility with SimpleForm 2.1.7 version
fix: missing control on recaptcha_threshold setting in form submitted without AJAX

Location:
simpleform-recaptcha/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • simpleform-recaptcha/trunk/README.txt

    r2537040 r2712286  
    22Contributors: simpleform
    33Donate link: https://wpsform.com/
    4 Tags: contact form, spam, recaptcha, antispam, simpleform addon, spam manager, google, bot, captcha, v2, invisible, v3
    5 Requires at least: 5.1
    6 Tested up to: 5.7
     4Tags: contact form, spam, recaptcha, antispam, simpleform addon, spam manager, google, bot, captcha, form
     5Requires at least: 5.6
     6Tested up to: 5.9
    77Requires PHP: 5.6
    8 Stable tag: 1.1.1
     8Stable tag: 1.1.2
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    6060== Changelog ==
    6161
     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
    6266= 1.1.1 (25 May 2021) =
    6367* Added: compatibility with SimpleForm 2.0 version
     
    7377 
    7478You 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 =
     83This 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  
    346346    }   
    347347
    348    /**
    349      * Retrieve captcha field type.
    350      *
    351      * @since    1.0
    352      */
    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 
    366348    /**
    367349     * Add reCAPTCHA related fields values in the attributes array.
     
    469451 
    470452    /**
    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';
    481465      $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';   
    500478        $unverified_recaptcha = ! empty( $settings['unverified_recaptcha'] ) ? esc_attr($settings['unverified_recaptcha']) : __( 'Please prove you are not a robot', 'simpleform-recaptcha' );
    501479        $invalid_recaptcha = ! empty( $settings['invalid_recaptcha'] ) ? esc_attr($settings['invalid_recaptcha']) : __( 'Robot verification failed, please try again', 'simpleform-recaptcha' );
    502480        $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
    509510          }
    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           
    516512        }
    517 
     513       
    518514      }
    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;
    555539   
    556540    }   
     
    669653
    670654        $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         
    676661        }
    677662       
  • simpleform-recaptcha/trunk/includes/class-activator.php

    r2537040 r2712286  
    4242
    4343    public static function sform_recaptcha_settings() {
    44       
     44       
    4545       $main_attributes = get_option('sform_attributes');
    4646       $main_settings = get_option('sform_settings');
    47        
    4847       $new_attributes = array( 'captcha_type' => 'math' );
    4948       
  • simpleform-recaptcha/trunk/includes/class-core.php

    r2537040 r2712286  
    4040     */
    4141 
    42     protected $version_required = '1.10.7';
     42    protected $version_required = '2.1.7'; 
    4343
    4444    /**
     
    5959       
    6060        if ( defined( 'SIMPLEFORM_RECAPTCHA_VERSION' ) ) { $this->version = SIMPLEFORM_RECAPTCHA_VERSION; }
    61         else { $this->version = '1.1.1'; }
     61        else { $this->version = '1.1.2'; }
    6262        $this->plugin_name = 'simpleform-recaptcha';
    6363        $this->requirements_matching();
     
    106106           if ( $admin_notices == 'false' ) {
    107107             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' ) {
    109109            $addon = SIMPLEFORM_RECAPTCHA_NAME;
    110110            $version = '<b>'. $this->version_required .'</b>';
     
    153153         // Check for core plugin updated
    154154         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 area
    159            $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts_old' );         
    160            // Add reCAPTCHA fields in the Settings page
    161            $this->loader->add_filter( 'recaptcha_settings_filter', $plugin_admin, 'settings_fields_old' );
    162            } else {
    163155           // Register the scripts for the admin area
    164156           $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    165157           // Add reCAPTCHA fields in the Settings page
    166158           $this->loader->add_filter( 'recaptcha_settings_filter', $plugin_admin, 'settings_fields' );
    167            }
    168159           // Add reCAPTCHA error message fields in the Settings page
    169160           $this->loader->add_filter( 'recaptcha_error_message', $plugin_admin, 'error_messages' );
     
    174165           // Add reCAPTCHA field in the Form Editor page
    175166           $this->loader->add_action( 'sform_recaptcha_field', $plugin_admin, 'recaptcha_field' );           
    176            // Retrieve captcha field type
    177            $this->loader->add_filter( 'sform_captcha_type', $plugin_admin, 'captcha_type' );           
    178167           // Add reCAPTCHA related fields values in the attributes array
    179168           $this->loader->add_filter( 'sform_recaptcha_attributes', $plugin_admin, 'recaptcha_attributes' );           
    180169           // Add reCAPTCHA field in the contact form
    181170           $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 );
    186173           // Display an error when AJAX is not enabled and the reCAPTCHA challenge is not passed
    187174           $this->loader->add_filter( 'recaptcha_error', $plugin_admin, 'recaptcha_error' );
     
    202189
    203190    }
    204 
     191   
    205192    /**
    206193     * Check if the core plugin is listed in the active plugins in the WordPress database.
  • simpleform-recaptcha/trunk/simpleform-recaptcha.php

    r2537040 r2712286  
    44 *
    55 * 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.1
     6 * 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
    88 * Author:       WPSForm Team
    99 * Author URI:   https://wpsform.com
     
    2424 
    2525define( 'SIMPLEFORM_RECAPTCHA_NAME', 'SimpleForm reCAPTCHA' );
    26 define( 'SIMPLEFORM_RECAPTCHA_VERSION', '1.1.1' );
     26define( 'SIMPLEFORM_RECAPTCHA_VERSION', '1.1.2' );
    2727define( 'SIMPLEFORM_RECAPTCHA_DB_VERSION', '1.0' );
    2828define( 'SIMPLEFORM_RECAPTCHA_BASENAME', plugin_basename( __FILE__ ) );
    2929define( 'SIMPLEFORM_RECAPTCHA_PATH', plugin_dir_path( __FILE__ ) );
    30 define( 'SFORM_VERSION_REQUIRED_FOR_SIMPLEFORM_RECAPTCHA', '1.10.7' );
     30define( 'SIMPLEFORM_REQUIRED_VERSION_FOR_RECAPTCHA', '2.1.7' );
    3131
    3232/**
Note: See TracChangeset for help on using the changeset viewer.