• Resolved paulnewson

    (@paulnewson)


    Hi,

    Custom consents are not being saved.

    In functions.php, I have the following:-

    add_action(‘init’, function() {
    gdpr(‘consent’)->register(‘consent-newsletter’,’I want to receive a weekly newsletter from you’);
    });

    This shows up in the dashboard as it should.

    In footer.php I have added the following for testing purposes (email address redacted):-

    <?php
    $dataSubject = gdpr(‘data-subject’)->getByEmail(‘pn*****@***********.com’);
    $dataSubject->giveConsent(‘consent-newsletter’);
    $consents=$dataSubject->getConsents();
    var_dump($dataSubject);
    var_dump($consents);
    ?>

    This is the output (email address redacted):-

    object(Codelight\GDPR\DataSubject\DataSubject)#4795 (5) { [“email”:protected]=> string(25) “pn*****@***********.com” [“user”:protected]=> NULL [“consentManager”:protected]=> object(Codelight\GDPR\Components\Consent\ConsentManager)#267 (3) { [“model”:protected]=> object(Codelight\GDPR\Components\Consent\UserConsentModel)#264 (3) { [“tableName”]=> string(17) “wp_2_gdpr_consent” [“version”]=> string(3) “1.0” [“primaryKey”]=> string(2) “id” } [“defaultConsentTypes”:protected]=> array(3) { [“privacy-policy”]=> array(4) { [“slug”]=> string(14) “privacy-policy” [“title”]=> string(103) “I accept the Privacy Policy” [“description”]=> string(126) “This consent is not visible by default. If someone wishes to withdraw it, they should simply request to delete all their data.” [“visible”]=> bool(false) } [“terms-conditions”]=> array(4) { [“slug”]=> string(16) “terms-conditions” [“title”]=> string(107) “I accept the Terms & Conditions” [“description”]=> string(126) “This consent is not visible by default. If someone wishes to withdraw it, they should simply request to delete all their data.” [“visible”]=> bool(false) } [“consent-newsletter”]=> array(4) { [“slug”]=> string(18) “consent-newsletter” [“title”]=> string(46) “I want to receive a weekly newsletter from you” [“description”]=> NULL [“visible”]=> bool(true) } } [“customConsentTypes”:protected]=> array(0) { } } [“consents”:protected]=> array(0) { } [“dataRepository”]=> object(Codelight\GDPR\DataSubject\DataRepository)#4796 (1) { [“email”]=> string(25) “pn*****@***********.com” } } array(0) { }

    EDIT: Having checked the database, the consent data is saving correctly, it is retrieving it that is failing.

    • This topic was modified 6 years, 10 months ago by paulnewson.
Viewing 2 replies - 1 through 2 (of 2 total)
  • 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 6 years, 10 months ago by paulnewson.

    Great, thank you so much for finding the issue!! I will add this to the next release!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Consent not Saving’ is closed to new replies.