WPIntell

Source evidence

php helper function not working?

GDPR · support · 2020-05-20T21:23:00+00:00

mixedsentiment
mediumseverity
0.84relevance
3replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

4 / 34 rows with source links

11.8% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

30 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
Notfunny01 resolved
Hi, I have tried using the ‘ is_allowed_cookie( $cookie ) ‘ helper function to wrap code to block a cookie, I have experimented with a google gpt publisher tag snippet to see if I can get the helper function to work. The cookie is registered as an optional cookie under Advertising. What am I missing here? Should the function not somehow be added to the functions.php file first and/or in a child theme? What I have done looks like this: if ( is_allowed_cookie( ‘CONSENT’ ) { // Run my code and set the cookie. <script async src=” https://securepubads.g.doubleclick.net/tag/js/gpt.js”></script> ; } <script> window.googletag = window.googletag || {cmd: []}; googletag.cmd.push(function() { googletag.defineSlot(‘/21714798789/GE-Native-Bloc1’, [[250, 360], [300, 600], ‘fluid’], ‘div-gpt-ad-**********-0’).addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.pubads().collapseEmptyDivs(); googletag.enableServices(); }); </script> (I blanked out the Ad number) But i have tried it several different ways, with several different cookies that are set by that same script. The Ad code with the wrap function is injected into the header of each chosen post/page via Ad-Inserter, a plugin for injecting ad code, or any code, into chosen posts/pages on a site. But that shouldn’t make any difference surely? Clearly i am missing something, no? Hi, I’m not sure about your implementation specifically but if you wrap code that creates cookies in that check they do work. I can’t really identify where is the problem as the problem isn’t related to this plugin. Hi, I meant can anyone explain how to get the wrap code to work? I thought the code is part of the plugin’s functionality to Enable/Disable Cookies. Unfortunately. I can keep trying, but so far I cannot get the plugin to block cookies! Thanks. This reply was modified 6 years ago by Notfunny01 . And so, for anyone interested, I found the best way to get the is_allowed_cookie( $cookie ) helper function to work for a third-party script was to embed it with <? , { ?>, and closing <?php } ?> tags/brackets. This I put in the Child Theme’s header.php for enabling/disabling Google/Doubleclick Ads/ cookies: <? if ( is_allowed_cookie( ‘DSID’ ) ) { ?> <script async src=” https://securepubads.g.**********.***/tag/js/gpt.js”></script> ; <script> window.googletag = window.googletag || {cmd: []}; googletag.cmd.push(function() { googletag.defineSlot(‘/2**********/**-300-250-Foot’, [[300, 250], ‘fluid’], ‘div-gpt-ad-1575242906284-0’).addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices(); }); </script> <?php } ?> Except this did not work where you are trying to insert the function within an existing script, in which case it could cause syntax errors. So for example I did this to Enable/Disable Social Media Cookies/Sharing Buttons in Jetpack: if (is_allowed_cookie( ‘fr’ ) ) { $sharing_markup = apply_filters( ‘jetpack_sharing_display_markup’, $sharing_content, $enabled ); } As said in the plugin guide, the cookies must be named and listed in the plugin’s user interface for any of this work, as with Consents. Just in case anyone, like me, still needed to know!

Comments

3 shown
Fernando Claussen 2020-05-21T17:09:00+00:00

Hi, I’m not sure about your implementation specifically but if you wrap code that creates cookies in that check they do work. I can’t really identify where is the problem as the problem isn’t related to this plugin.

Notfunny01 2020-05-21T19:31:00+00:00

Hi, I meant can anyone explain how to get the wrap code to work? I thought the code is part of the plugin’s functionality to Enable/Disable Cookies. Unfortunately. I can keep trying, but so far I cannot get the plugin to block cookies! Thanks. This reply was modified 6 years ago by Notfunny01 .

Notfunny01 2020-05-29T19:02:00+00:00

And so, for anyone interested, I found the best way to get the is_allowed_cookie( $cookie ) helper function to work for a third-party script was to embed it with <? , { ?>, and closing <?php } ?> tags/brackets. This I put in the Child Theme’s header.php for enabling/disabling Google/Doubleclick Ads/ cookies: <? if ( is_allowed_cookie( ‘DSID’ ) ) { ?> <script async src=” https://securepubads.g.**********.***/tag/js/gpt.js”></script> ; <script> window.googletag = window.googletag || {cmd: []}; googletag.cmd.push(function() { googletag.defineSlot(‘/2**********/**-300-250-Foot’, [[300, 250], ‘fluid’], ‘div-gpt-ad-1575242906284-0’).addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices(); }); </script> <?php } ?> Except this did not work where you are trying to insert the function within an existing script, in which case it could cause syntax errors. So for example I did this to Enable/Disable Social Media Cookies/Sharing Buttons in Jetpack: if (is_allowed_cookie( ‘fr’ ) ) { $sharing_markup = apply_filters( ‘jetpack_sharing_display_markup’, $sharing_content, $enabled ); } As said in the plugin guide, the cookies must be named and listed in the plugin’s user interface for any of this work, as with Consents. Just in case anyone, like me, still needed to know!