Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter paulnewson

    (@paulnewson)

    Update: The test site was using server side caching; after turning it off, the email link now works about 50% of the time, the other half giving the message about the link having expired – this is with SET_COOKE removed, so back to the original code.

    Thread Starter paulnewson

    (@paulnewson)

    I think I jumped the gun. This edit made it work for a while but it is now behaving the way it was before. Most peculiar. I thought it might be something to do with caching but I don’t think that’s it either since the /privacy-tools/ page on our test site includes Cache-Control: max-age=0, private, no-store, no-cache, must-revalidate in the response header.

    Thread Starter paulnewson

    (@paulnewson)

    SOLVED IT!

    This was caused by attempting to read $_COOKIE[‘gdpr_key’] in the same request as setcookie(‘gdpr_key’…); setcookie() does not update $_COOKIE until the next page load, so I added $_COOKIE['gdpr_key']=$email . '|' . $key; to the end of the setIdentificationCookie function in wp_content/plugins/gdpr-framework/src/DataSubject/DataSubjectAuthenticator.php as follows:-

        /**
         * Set the identification cookie with the given key
         *
         * @param $key
         */
        public function setIdentificationCookie($email)
        {
            $key = $this->dataSubjectIdentificator->generateKey($email);
    
            setcookie(
                'gdpr_key',
                $email . '|' . $key,
                time() + (15 * 60),
                COOKIEPATH,
                COOKIE_DOMAIN,
                false,
                true
            );
            
            $_COOKIE['gdpr_key']=$email . '|' . $key;
        }

    I hope the plugin author fixes this in the next update so my edit doesn’t get overwritten.

    Thread Starter paulnewson

    (@paulnewson)

    SOLVED IT!

    A little bit of digging around revealed that the problem is caused because our version of PHP (5.6.35), or any version below 7.0, returns null when attempting to use array_column() on an array of objects.

    To test, I modified wp-content/plugins/gdpr-framework/src/Components/Consent/UserConsentModel.php so that the getAll() function uses a workaround to array_column() by encoding into JSON then decoding with the assoc parameter set to true so that the objects are converted into associative arrays as follows:

        /**
         * Get all consent given by data subject
         *
         * @param $email
         */
        public function getAll($email)
        {
            global $wpdb;
            
            if(version_compare(PHP_VERSION,'7')>=0){
                return array_column($wpdb->get_results($wpdb->prepare(
                    "SELECT * FROM {$this->tableName} WHERE email = %s and status = 1;",
                    $email
                )), 'consent');
            }else{
                return array_column(json_decode(json_encode($wpdb->get_results($wpdb->prepare(
                    "SELECT * FROM {$this->tableName} WHERE email = %s and status = 1;",
                    $email
                ))),true),'consent');
            }
        }

    I hope that by the time my addition to your code is overwritten in the next update, you will have addressed the issue so that your otherwise fantastic plugin will work with PHP 5.5 rather than requiring PHP 7.0.

    EDIT: Changed if(phpversion()>7){ to if(version_compare(PHP_VERSION,’7′)>=0){

    • This reply was modified 8 years, 1 month ago by paulnewson.
Viewing 4 replies - 1 through 4 (of 4 total)