Support Forum Support Forum GDPR Cookie Compliance PHP checks returning false?

Topic Resolution: Resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Avatarelby
    March 16, 2020 @ 11:08 pm

    Hello,
    We have an issue on our Stage environment, so we haven’t tested it on the live site with the active license key, yet. I’ve written a check in functions.php that looks for any cookie types being accepted and if that fails, all scripts are removed (below). The issue is that no matter what cookies are accepted, it goes to else and removes all the scripts. function_exists does return true — when I’ve removed the gdpr_cookie_is_accepted checks from the if statement, the if is executed but none of the scripts are added.
    It would seem that the PHP part of the cookie acceptance isn’t taking effect — or am I missing something obvious?
    Thank you!
    Elby

    /**
     * GDPR Compliance Loader - Moove
     */
    function check_for_moove_cookies() {
    
    	// At least one is permitted.
    	if ( function_exists( 'gdpr_cookie_is_accepted' )
    		&& ( gdpr_cookie_is_accepted( 'strict' ) 
    			|| gdpr_cookie_is_accepted( 'thirdparty' ) 
    			|| gdpr_cookie_is_accepted( 'advanced' ) ) ) {
    
    		// Strictly Necessary accepted.
    		if ( gdpr_cookie_is_accepted( 'strict' ) ) {
    
    		}
    
    		// Third Party accepted.
    		if ( gdpr_cookie_is_accepted( 'thirdparty' ) ) {
    
    			// Add Google Analytics.
    			add_action( 'wp_enqueue_scripts', 'vtc_enqueue_scripts' );
    		}
    
    		// Functionality accepted.
    		if ( gdpr_cookie_is_accepted( 'advanced' ) ) {
    
    			// Activate plugins.
    			add_filter( 'option_active_plugins', function( $plugins ) {
    
    				// LiveChat.
    				$livechat = array( 'wp-live-chat-software-for-wordpress/livechat.php' );
    				array_push( $livechat, $plugins );
    
    				return $plugins;
    			} );
    		}
    
    	// None are allowed.
    	} else {
    
    		// Google Analytics.
    		remove_action( 'wp_enqueue_scripts', 'vtc_enqueue_scripts' );
    
    		// Deactivate cookie plugins.
    		add_filter( 'option_active_plugins', function( $plugins ) {
    
    			// Remove LiveChat.
    			$livechat = array_search( 'wp-live-chat-software-for-wordpress/livechat.php', $plugins );
    			unset( $plugins[ $livechat ] );
    
    			return $plugins;
    		} );
    	}
    }
    add_action( 'init', 'check_for_moove_cookies' );
    add_action( 'gdpr_force_reload', '__return_true' );
    
    Moove AgencyMoove Agency
    March 17, 2020 @ 8:44 am

    Hi elby,

    Thanks for using our plugins.

    Please note, you using ‘init’ hook you can’t change the active plugins. You can create a hook in ‘wp_enqueue_scripts’ in order to remove the restricted scripts / styles based on cookies accepted.
    You can find an example below for live chat feature:

    /**
     * Removing script or style based on cookies accepted
     */
    function gdrp_dequeue_script_and_styles () {
      if ( function_exists( 'gdpr_cookie_is_accepted' ) ) :
      	if ( ! gdpr_cookie_is_accepted( 'thirdparty' ) ) :
    		  wp_deregister_script( 'livechat-widget' );
    		endif;
    	endif;
    }
    add_action('wp_enqueue_scripts', 'gdrp_dequeue_script_and_styles', 999);

    So you have to handle the PHP cookie checks ‘vtc_enqueue_scripts’ function, and use the above method to exclude the live chat if the cookies are not accepted.

    Hope this helps.

    Avatarelby
    March 17, 2020 @ 11:39 am

    Thanks for catching that! That still leaves the scripts never being added back, though. As you can see on the site attached to the ticket, selecting “Accept All” only results in the moove_gdpr_popup cookie being created and none of the others are made.

    Moove AgencyMoove Agency
    March 18, 2020 @ 1:18 pm

    Hi elby,

    This seems a caching issue on WPEngine. Please speak to the WPE support team to whitelist the “moove_gdpr_popup” cookie for you.
    Read more about the PHP Cookies and Session in WPEngine: https://wpengine.com/support/cookies-and-php-sessions/

    Hope this helps.

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.