Plugin Directory

Changeset 2546304


Ignore:
Timestamp:
06/11/2021 02:41:38 PM (5 years ago)
Author:
outerbridge
Message:

Fixed session issue, thanks to @tmuk. Working with WP5.7

Location:
humancaptcha/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • humancaptcha/trunk/outerbridge-humancaptcha.php

    r2228470 r2546304  
    55Description: HumanCaptcha uses questions that require human logic to answer them and which machines cannot easily answer.
    66Author: Outerbridge
    7 Version: 3.1
     7Version: 4.0.0
    88Author URI: https://outerbridge.co.uk/
    99Text Domain: humancaptcha
     
    1414/**
    1515 *
     16 *  v4.0.0  210611  Fixed session issue, thanks to @tmuk.  Working with WP5.7
     17 *
    1618 *  v3.1    200116  Improved foreign character handling
    17  *
    1819 *  v3.0    180105  Improved accessibility (thanks to Ondrej), moved admin menu to Settings, tidied admin page, added Settings link to Plugins page
    1920 *  v2.1    150130  General code tidy plus remove references to HCAC
     
    5253   
    5354    // version
    54     public $obr_humancaptcha_version = '3.1';
     55    public $obr_humancaptcha_version = '4.0.0';
    5556   
    5657    function __construct(){
     
    6970        add_action('admin_menu', array($this, 'obr_admin_menu'));
    7071        add_action('init', array($this, 'obr_init'));
     72        add_action( 'wp_loaded', array( $this, 'obr_close_session' ), 30 );
    7173
    7274        add_filter('plugin_action_links_'.plugin_basename(__FILE__), array($this, 'obr_plugin_settings_link'));
     
    187189            $question = $selected['question'];
    188190            $answer = $selected['answer'];
     191            session_start();
    189192            $_SESSION['obr_answer'] = md5(strtolower(trim($answer)));
     193            session_write_close();
    190194            // use the comment-form-email class as it works better with 2011
    191195            $outputfield = '<p class="comment-form-email"><label for="answer">' . stripslashes( $question ) . ' <span class="required">*</span></label><input id="answer" name="answer" size="30" type="text" aria-required=\'true\' /></p>';
    192             $fields['obr_hlc'] = $outputfield;
     196            if( isset( $fields ) ) {
     197                $fields['obr_hlc'] = $outputfield;
     198            }
    193199            return $fields;
    194200        }
     
    218224        $question = $selected[ 'question' ];
    219225        $answer = $selected[ 'answer' ];
     226        session_start();
    220227        $_SESSION[ 'obr_answer' ] = md5( strtolower( trim( $answer ) ) );
     228        session_write_close();
    221229        $outputfield = '<p><label for="answer">' . stripslashes( $question ) . '</label><br /><input type="text" name="answer" id="answer" class="input" value="" size="25" tabindex="20" /></p>';
    222230        echo $outputfield;
    223         $fields[ 'obr_hlc' ] = $outputfield;
     231        if( true !== empty( $fields ) ) {
     232            $fields[ 'obr_hlc' ] = $outputfield;
     233        }
    224234        return $fields;
    225235    }
     
    244254
    245255    function obr_register_validate_answer($errors, $sanitized_user_login, $user_email){
    246         if (!session_id()){
    247             session_start();
    248         }
    249256        if ((!isset($_POST['answer'])) || ($_POST['answer'] == '')){
    250257            $errors->add('obr_error', __('Error: please fill the required field (humancaptcha).', 'humancaptcha'));
    251258        } else {
    252259            $user_answer = md5(strtolower(trim($_POST['answer'])));
     260            session_start();
    253261            $obr_answer = strtolower(trim($_SESSION['obr_answer']));
     262            session_write_close();
    254263            if ($user_answer != $obr_answer){
    255264                $errors->add('obr_error', __('Error: your answer to the humancaptcha question is incorrect.', 'humancaptcha'));
     
    275284        $user_answer = md5(strtolower(trim($_POST['answer'])));
    276285        $obr_answer = strtolower(trim($_SESSION['obr_answer']));
     286        session_write_close();
    277287        if ($user_answer != $obr_answer){
    278288            wp_die(__('Error: your answer to the humancaptcha question is incorrect.  Use your browser\'s back button to try again.', 'humancaptcha'));
     
    493503        $login_on = $this->obr_get_setting_value(3);
    494504    }
     505
     506    function obr_close_session() {
     507        if ( PHP_SESSION_ACTIVE == session_status() ) {
     508            session_write_close();
     509        }
     510    }
    495511}
    496512?>
  • humancaptcha/trunk/readme.txt

    r2273866 r2546304  
    11=== HumanCaptcha by Outerbridge ===
    22Contributors: outerbridge
    3 Author URI: http://outerbridge.co.uk/
     3Author URI: https://outerbridge.co.uk/
    44Tags: captcha, text-based, human, logic, questions, answers
    55Requires at least: 4.7
    6 Tested up to: 5.4
     6Tested up to: 5.7
    77Stable tag: trunk
    88
     
    6464== Changelog ==
    6565
     66= 4.X =
     67* v4.0.0 (11 Jun 21) Fixed session issue, thanks to @tmuk.  Working with WP5.7
     68
    6669= 3.X =
    6770* v3.1 (16 Jan 20) Improved foreign character handling
     
    9598
    9699== Upgrade Notice ==
     100
     101= v4.0.0 =
     102* Fixed session issue, thanks to @tmuk.  Working with WP5.7
    97103
    98104= v3.1 =
Note: See TracChangeset for help on using the changeset viewer.