-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated CookieConsent to version 3.0.0. and some minor updates #4
base: master
Are you sure you want to change the base?
Conversation
…ckend, function/someway to add cookie table, check config file + test everything
…ending to backend and custom attributes. Updated iFramemanager to 1.2.5.
…ytics_storage if google cookies defined
|
air-cookie.php
Outdated
/** | ||
* Github updater. | ||
* Github updater. Disabled by commenting out. | ||
* | ||
* @since 0.1.0 | ||
*/ | ||
require plugin_base_path() . '/plugin-update-checker/plugin-update-checker.php'; | ||
$update_checker = \Puc_v4_Factory::buildUpdateChecker( 'https://github.com/digitoimistodude/air-cookie', __FILE__, 'air-cookie' ); | ||
// require plugin_base_path() . '/plugin-update-checker/plugin-update-checker.php'; | ||
// $update_checker = \Puc_v4_Factory::buildUpdateChecker( 'https://github.com/digitoimistodude/air-cookie', __FILE__, 'air-cookie' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These kinds of changes shouldn't be included in PRs 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was meant for local only 🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, happens to the best of us.
settings.php
Outdated
'cookie_name' => 'air_cookie', | ||
'revision' => $categories_version, // use version number to invalidate if categories change | ||
// 'theme_css' => plugin_base_url() . '/assets/cookieconsent.css', | ||
'cookie_expiration' => 182, // in days, 182 days = 6 months | ||
'auto_language' => false, | ||
'current_lang' => $lang, | ||
'autorun' => true, | ||
'page_scripts' => true, | ||
'delay' => '0', | ||
'gui_options' => [ | ||
'consent_modal' => [ | ||
'layout' => 'box', | ||
'position' => 'bottom left', | ||
'revision' => $categories_version, // use version number to invalidate if categories change | ||
'cookie' => [ | ||
'name' => 'air_cookie', | ||
'expiresAfterDays' => 182, // in days, 182 days = 6 months | ||
], | ||
|
||
'guiOptions' => [ | ||
'consentModal' => [ | ||
'layout' => 'box wide', | ||
'position' => 'bottom left', | ||
'equalWeightButtons' => false, | ||
'flipButtons' => false, | ||
], | ||
|
||
'preferencesModal' => [ | ||
'layout' => 'box', | ||
'equalWeightButtons' => true, | ||
'flipButtons' => false, | ||
], | ||
], | ||
|
||
'language' => [ | ||
'default' => $lang, | ||
'translations' => [ | ||
$lang => [] | ||
] | ||
], | ||
|
||
'categories' => [], | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactoring the settings object isn't a good practice as this will break backwards compability pretty much just for style points.
We name variables according to the WordPress Coding Standard's Naming Conventions meaning snake_case
instead of camelCase
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes are from CookieConsent, ahh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still prefer at least mapping the old keys to the new ones if they are set 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I´ll look into it.
@@ -60,13 +61,68 @@ function my_add_cookie_category( $categories ) { | |||
When adding new categories, the function itself is responsile for handling the translations for title and description. | |||
|
|||
There is also `air_cookie\categories\{category-key}` filter available to change the settings of indivual category. | |||
```php | |||
add_filter( 'air_cookie\categories\{analytics}', 'my_change_category_analytics' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be air_cookie\categories\analytics
, without the braces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I can´t get it to work without brackets. Only way to use the filter without brackets would require to change in settings.php:
$categories[ $key ] = apply_filters( "air_cookie\categories\{$category_key}", $category );
to $categories[ $key ] = apply_filters( "air_cookie\categories\\{$category_key}", $category );
Atleast that´s how PHP-docs say to handle backslashed variables 🤔
// Won't work, outputs: C:\folder\{fantastic}.txt
echo "C:\folder\{$great}.txt"
// Works, outputs: C:\folder\fantastic.txt
echo "C:\\folder\\{$great}.txt"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in the code, I meant in the example 😄
If user wants to filter analytics they need to create a filter add_filter ( 'air_cookie\categories\analytics', 'my_change_analytics' );
, which is then called by apply_filters( "air_cookie\categories\{$category_key}", $category );
.
"air_cookie\categories\{$category_key}"
gets resolved to "air_cookie\categories\analytics
as {$category_key}
is a string template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed a bug. #10
script-injection.php
Outdated
if ( ! is_array( $settings ) ) { | ||
return; | ||
return; | ||
} | ||
|
||
// Cookie Consent javascript base. | ||
wp_enqueue_script( 'cookieconsent', plugin_base_url() . '/assets/cookieconsent.js', [], get_script_version(), false ); | ||
wp_enqueue_script( 'cookieconsent', plugin_base_url() . '/assets/cookieconsent.js', [], get_script_version(), | ||
array( | ||
'in_footer' => true, | ||
'strategy' => 'defer', | ||
) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is happening here with the whitespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably VS Code auto indentation with different settings 😅
script-injection.php
Outdated
array( | ||
'in_footer' => true, | ||
'strategy' => 'defer', | ||
) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the short [] syntax instead of array().
script-injection.php
Outdated
onFirstConsent: () => { | ||
ccOnAccept(); | ||
}, | ||
|
||
onConsent: () => { | ||
checkIframeConsent(); | ||
}, | ||
|
||
onModalShow: () => { | ||
<?php if ( apply_filters( 'air_cookie\styles\set_max_width', true ) ) : ?> | ||
var cookieconsent_element = document.querySelector('div#cc-main div.cm'); | ||
if( typeof( cookieconsent_element ) != 'undefined' && cookieconsent_element != null ) { | ||
cookieconsent_element.style = 'max-width: 40em;'; | ||
} | ||
<?php endif; ?> | ||
}, | ||
|
||
onChange: () => { | ||
ccOnChange(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onFirstConsent, onConsent and onChange probably don't need to be inside a arrow function and can be passed as arguments.
onChange: ccOnChange
.
script-injection.php
Outdated
@@ -145,8 +204,7 @@ function do_category_js( $category ) { | |||
$event_key = "air_cookie_{$category_key}"; | |||
|
|||
ob_start(); ?> | |||
|
|||
if ( cc.allowedCategory( '<?php echo $category_key; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>' ) ) { | |||
if ( CookieConsent.getCookie( 'categories' ).includes( '<?php echo $category_key; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to use this instead of CookieConsent.acceptedCategory()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't working correctly in 3.0.0, but I think that´s fixed in 3.0.1 now (PR is 3.0.0).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah!
// Check if the index exists | ||
$index_exists = $wpdb->get_row( "SHOW INDEX FROM {$table_name} WHERE Key_name = 'idx_id_revision_value'" ); // phpcs:ignore | ||
|
||
// CREATE INDEX idx_id_revision_value ON wp_air_cookie (visitor_id, cookie_revision, cookie_value); | ||
if ( null === $index_exists ) { | ||
$wpdb->query( "CREATE INDEX idx_id_revision_value ON {$table_name} (visitor_id, cookie_revision, cookie_value);" ); // phpcs:ignore | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to happen on every request or could this just be ran when the plugin is activated or if the version has changed?
Thanks for comments! I´ll look into those. I was doing some testing with fork repo and didn´t notice latest changes went to PR also. |
What's the status? We are adding this to our roadmap as well, but if you are ahead of us, it all helps. Thanks. |
…nd minor formatting
Hello, I pushed latest changes which I have done. Added latest CookieConsent version, fixed #10 (comment), fixed some minor formatting and created function to allow old settings formatting, so old installations shouldn't break (but all old used settings should still be checked). Hope these help. |
Hi!
I think Cookie Consent 3.0.0 is working properly now 👨💻
Additional changes:
If you have any questions about the fixes I’m happy to discuss them 😊