From 79b771066d3f16a78babe122991b522fb2011de9 Mon Sep 17 00:00:00 2001 From: Janez Troha Date: Wed, 9 Jun 2021 11:31:09 +0200 Subject: [PATCH] Remove JS&CSS if GDPR is not enabled (#90) ref: https://github.com/niteoweb/woocart/issues/2216 --- Makefile | 2 +- src/classes/GDPR.php | 4 ++++ tests/GdprTest.php | 21 ++------------------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 546315c..284c43f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := 3.31.0 +VERSION := 3.31.1 PLUGINSLUG := woocart-defaults SRCPATH := $(shell pwd)/src diff --git a/src/classes/GDPR.php b/src/classes/GDPR.php index b0b945f..5c774e7 100644 --- a/src/classes/GDPR.php +++ b/src/classes/GDPR.php @@ -416,6 +416,10 @@ public function options_page() { * @return null */ public function scripts() { + $consent = get_option( 'woocommerce_allow_tracking', 'no' ); + if ( 'no' !== $consent ) { + return; + } $plugin_dir = plugin_dir_url( dirname( __FILE__ ) ); wp_enqueue_style( 'woocart-gdpr', "{$plugin_dir}assets/css/front-gdpr.css", array(), Release::Version ); diff --git a/tests/GdprTest.php b/tests/GdprTest.php index 2adc9e7..2d9354d 100644 --- a/tests/GdprTest.php +++ b/tests/GdprTest.php @@ -27,28 +27,11 @@ function tearDown() : void { * @covers ::scripts */ public function testConstructor() { - \WP_Mock::userFunction( - 'plugin_dir_url', - array( - 'times' => 1, - ) - ); - \WP_Mock::userFunction( - 'wp_enqueue_style', - array( - 'times' => 1, - ) - ); - \WP_Mock::userFunction( - 'wp_enqueue_script', - array( - 'times' => 1, - ) - ); + \WP_Mock::userFunction( 'get_option', array( - 'times' => 2, + 'times' => 3, 'return' => 'yes', ) );