Support » Plugin: GDPR Cookie Compliance » GDPR Cookie Compliance – Hooks & Code snippets

  • Plugin Author Moove Agency

    (@mooveagency)


    Below the hooks & custom scripts included in the GDPR Cookie Compliance plugin.
    Note: Some of them require some development work on your end to be extended or modified properly! These are just examples.

    HOOK to GDPR custom 3RD-PARTY script by php – HEAD

    add_action('moove_gdpr_third_party_header_assets','moove_gdpr_third_party_header_assets');
    function moove_gdpr_third_party_header_assets( $scripts ) {
    	$scripts .= '<script>console.log(“third-party-head”);</script>';
    	return $scripts;
    }

    HOOK to GDPR custom 3RD-PARTY script by php – BODY

    add_action('moove_gdpr_third_party_body_assets','moove_gdpr_third_party_body_assets');
    function moove_gdpr_third_party_body_assets( $scripts ) {
    	$scripts .= '<script>console.log(“third-party-body”);</script>';
    	return $scripts;
    }

    HOOK to GDPR custom 3RD-PARTY script by php – FOOTER

    add_action('moove_gdpr_third_party_footer_assets','moove_gdpr_third_party_footer_assets');
    function moove_gdpr_third_party_footer_assets( $scripts ) {
    	$scripts .= '<script>console.log(“third-party-footer”);</script>';
    	return $scripts;
    }

    HOOK to GDPR custom ADVANCED-PARTY script by php – HEAD

    add_action('moove_gdpr_advanced_cookies_header_assets','moove_gdpr_advanced_cookies_header_assets');
    function moove_gdpr_advanced_cookies_header_assets( $scripts ) {
    	$scripts .= '<script>console.log(“advanced-head”);</script>';
    	return $scripts;
    }

    HOOK to GDPR custom ADVANCED-PARTY script by php – BODY

    add_action('moove_gdpr_advanced_cookies_body_assets','moove_gdpr_advanced_cookies_body_assets');
    function moove_gdpr_advanced_cookies_body_assets( $scripts ) {
    	$scripts .= '<script>console.log(“advanced-body”);</script>';
    	return $scripts;
    }

    HOOK to GDPR custom ADVANCED-PARTY script by php – FOOTER

    add_action('moove_gdpr_advanced_cookies_footer_assets','moove_gdpr_advanced_cookies_footer_assets');
    function moove_gdpr_advanced_cookies_footer_assets( $scripts ) {
    	$scripts .= '<script>console.log(“advanced-footer”);</script>';
    	return $scripts;
    }

    Disable Force Reload:
    add_action( 'gdpr_force_reload', '__return_true' );

    PHP Cookie checker:

    if ( function_exists( 'gdpr_cookie_is_accepted' ) ) :
       if ( gdpr_cookie_is_accepted( 'thirdparty' ) ) :
         echo "GDPR third party ENABLED content";
       else :
         echo "GDPR third party RESTRICTED content";
       endif;
    endif;

    Extend Styles:

    add_action('moove_gdpr_inline_styles','gdpr_cookie_css_extension',10,3);
    function gdpr_cookie_css_extension( $styles, $primary, $secondary ) {
    	$styles .= '#main-header { z-index: 999; }';
    	$styles .= '#top-header { z-index: 1000 }';
    	$styles .= '.lity {z-index: 99999999;}';
    	return $styles;
    }

    Disable Monster Insights based on cookie selected:

    add_action( 'init', 'toggle_monster_insights_based_on_moove' );
    function toggle_monster_insights_based_on_moove() {
        if ( function_exists( gdpr_cookie_is_accepted ) && function_exists('monsterinsights_get_ua')) {
          if ( gdpr_cookie_is_accepted('thirdparty') ) {
                setCookie( 'ga-disable-'.monsterinsights_get_ua(), 'false' );
    	} else {
    	     setCookie( 'ga-disable-'.monsterinsights_get_ua(), 'true' );
    	}
        }
    }

    Define CDN URL for Lity library:

    add_action( 'gdpr_cdn_url', 'gdpr_cdn_url', 10, 1 );
    function gdpr_cdn_url( $plugin_url ) {
    	$cdn_url = 'https://yourcdnurl.com';
    	return str_replace( trailingslashit( site_url() ) , trailingslashit( $cdn_url ), $plugin_url );
    }

    Read cookie values with JavaScript:

    add_action( 'wp_footer', 'gdpr_js_extension', 1000 );
    function gdpr_js_extension() {
      ob_start();
      ?>
      <script>
          jQuery(document).ready(function(){
            var cookies_object = jQuery(this).moove_gdpr_read_cookies();
            if ( typeof cookies_object === 'object' ) {
                console.log(cookies_object);
                // YOUR CODE HERE
                
            }
          });
      </script>
      <?php
      echo ob_get_clean();
    }

    Compatibility with Pixel Your Site plugin:

    add_filter( 'pys_disable_by_gdpr', 'gdpr_cookie_compliance_pys' );
    function gdpr_cookie_compliance_pys() {
    	// checking if the GDPR Cookie Compliance plugin is activated and includes the latest function to check the cookies.
    	if ( function_exists( 'gdpr_cookie_is_accepted' ) ) :
    		// reading the user preferences for 3rd party cookies, if it's accepted the gdpr_is_accepted returns true
    		$disable_pys = gdpr_cookie_is_accepted( 'thirdparty' ) ? false : true;
    		return $disable_pys;
    	endif;
    	// fallback if the GDPR Cookie Compliance plugin is not activated or the PHP cookie functions are not included in the current version
    	return true;
    }
    // by default the GDPR Cookie Compliance plugin injects the scripts without page reload, this should be disabled if the PHP functions are used
    add_action( 'gdpr_force_reload', '__return_true' );
Viewing 1 replies (of 1 total)
  • Plugin Author Moove Agency

    (@mooveagency)

    Hook for WooCommerce Facebook Pixel plugin:

    add_filter('facebook_for_woocommerce_integration_pixel_enabled', 'gdpr_cookie_facebook_wc', 20);
    
    function gdpr_cookie_facebook_wc() {
    	$enable_fb_wc = true;
    	if ( function_exists( 'gdpr_cookie_is_accepted' ) ) :
    		$enable_fb_wc = gdpr_cookie_is_accepted( 'thirdparty' );
    	endif;
    	return $enable_fb_wc;
    }
    add_action( 'gdpr_force_reload', '__return_true' );
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.