• Resolved prototypead

    (@prototypead)


    Hello,

    I have added cookie block helper function to the functions.php page and noticed a warning in WordPress Dashboard and any other admin page. Though, that error does not show up on the site itself. Does it mean cookie function doesn’t work and will not block cookies?

    Warning message (XXX is used to not disclose folder names)
    “Cannot modify header information – headers already sent by (output started at /home/XXX/public_html/wp-content/themes/XXX/functions.php:64) in /home/XXX/public_html/wp-admin/includes/misc.php on line 1116”

    Also, no longer cannot login to wordpress, this is the warning message:
    “Warning: Cannot modify header information – headers already sent by (output started at /home/XXX/public_html/wp-content/themes/XXX/functions.php:60) in /home/XXX/public_html/wp-includes/pluggable.php on line 1216”

    This is how functions.php file looks: (XXX is used to not disclose sensitive info)

    <?php
    	add_action( 'wp_enqueue_scripts', 'XXX_child_theme_scripts' );
    	function XXX_child_theme_scripts() {
    	    wp_enqueue_style( 'parent-theme-css', get_template_directory_uri() . '/style.css' );
    	}
    
    	//Cookie Opt-Out code for GDPR
    	//Google Analytics
    
    	add_action( 'wp_head', 'my_google_opt_out' );
    	function my_google_opt_out() {
      		if ( is_allowed_cookie( '_ga' ) ) {
        ?>
        <script>
      	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      	})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    
      	ga('create', 'XX-XXXXXXXXX-X', 'auto');
      	ga('send', 'pageview');
    
    	</script>
    
        	
        <?php
      	}
    	}
    
    	//SharpSpring Analytics
    
    	add_action( 'wp_head', 'my_sharpspring_opt_out' );
    	function my_sharpspring_opt_out() {
      		if ( is_allowed_cookie( '_ss' ) ) {
        ?>
        <script type="text/javascript">
    	var _ss = _ss || [];
    	_ss.push(['_setDomain', 'XXXXXX']);
    	_ss.push(['_setAccount', 'XXXXXX']);
    	_ss.push(['_trackPageView']);
    		(function() {
        		var ss = document.createElement('script');
        		ss.type = 'text/javascript'; ss.async = true;
    
        		ss.src = ('https:' == document.location.protocol ? 'https://' : 'https://') + 'XXXXX/ss.js?ver=1.1.1';
        		var scr = document.getElementsByTagName('script')[0];
        		scr.parentNode.insertBefore(ss, scr);
    		})();
    	</script>
    
        	
        <?php
      	}
    	}
    ?>
    • This topic was modified 6 years, 10 months ago by prototypead.
    • This topic was modified 6 years, 10 months ago by James Huff.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter prototypead

    (@prototypead)

    Ok, I figured it out – had placed a closing php tag.

    Though, I am confused how all this works. When I test on the site using the code above on initial website load (browser cookies are cleared) the ga cookie doesn’t seem to be “on”. Then I agree to terms and the ga cookies is still not on. Only when I go to preferences and “turn on” the cookie, it shows up.

    What I want to accomplish is when user agrees to Privacy Policy (the language in the privacy policy does state if they agree to terms the cookie will be enabled), the ga cookie turns “on”. Then, if they want to turn it off, then they have to go to privacy policy and turn it off.

    How do I achieve that, what code to use?

    Thank you.

    Plugin Author Fernando Claussen

    (@fclaussen)

    Hi @prototypead

    I’m glad you got this working.

    Initially, from the interpretation I got from multiple users, checkboxes should not be checked by default.

    This is not the first time people have the same issue as you where they want some stuff to be on.

    I’m currently working on the next release with some major changes and improvements.

    One of the improvements is that you will be able to pick how you want the cookie status to be.

    Required, On, Off, On except if DNT.

    Thread Starter prototypead

    (@prototypead)

    Look forward to the update. Thank you for all your hard work!

    I do have a question regarding php code. I am trying to understand what is the difference between these two codes?

    1.
    if ( is_allowed_cookie( '_ga' ) ) {
    and
    2.
    if ( ! has_consent( 'privacy-policy' ) || ! is_allowed_cookie( '_ga' ) ) {

    Thanks

    Plugin Author Fernando Claussen

    (@fclaussen)

    They are similar.
    Depending on the specific situation, you might want to check for one of the consents, for a specific cookie or for both.

    It all depends.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Cookie block helper function added warning message to WP Dashboard’ is closed to new replies.