diff --git a/cookie-notice.php b/cookie-notice.php index b19198b..455b610 100644 --- a/cookie-notice.php +++ b/cookie-notice.php @@ -73,6 +73,7 @@ class Cookie_Notice { ), 'script_placement' => 'header', 'translate' => true, + 'cookie_name' => 'cookie_notice_accepted', 'deactivation_delete' => 'no', 'update_version' => 1, 'update_notice' => true, @@ -646,6 +647,7 @@ public function register_settings() { add_settings_field( 'cn_on_click', __( 'On click', 'cookie-notice' ), array( $this, 'cn_on_click' ), 'cookie_notice_options', 'cookie_notice_configuration' ); add_settings_field( 'cn_time', __( 'Cookie expiry', 'cookie-notice' ), array( $this, 'cn_time' ), 'cookie_notice_options', 'cookie_notice_configuration' ); add_settings_field( 'cn_script_placement', __( 'Script placement', 'cookie-notice' ), array( $this, 'cn_script_placement' ), 'cookie_notice_options', 'cookie_notice_configuration' ); + add_settings_field( 'cn_cookie_name', __( 'Cookie name', 'cookie-notice' ), array( $this, 'cn_cookie_name' ), 'cookie_notice_options', 'cookie_notice_configuration' ); add_settings_field( 'cn_deactivation_delete', __( 'Deactivation', 'cookie-notice' ), array( $this, 'cn_deactivation_delete' ), 'cookie_notice_options', 'cookie_notice_configuration' ); // design @@ -663,6 +665,19 @@ public function register_settings() { public function cn_section_configuration() {} public function cn_section_design() {} + /** + * Change name of cookie notice acceptance cookie + */ + public function cn_cookie_name() { + echo ' +
+ +
'; + } + /** * Delete plugin data on deactivation. */ @@ -1098,6 +1113,9 @@ public function validate_options( $input ) { // on click $input['on_click'] = (bool) isset( $input['on_click'] ) ? 'yes' : 'no'; + // cookie name + $input['cookie_name'] = sanitize_text_field( isset( $input['cookie_name'] ) ? $input['cookie_name'] : $this->defaults['general']['cookie_name'] ); + // deactivation $input['deactivation_delete'] = (bool) isset( $input['deactivation_delete'] ) ? 'yes' : 'no'; @@ -1191,6 +1209,7 @@ public function add_cookie_notice() { 'see_more_opt' => $this->options['general']['see_more_opt'], 'link_target' => $this->options['general']['link_target'], 'link_position' => $this->options['general']['link_position'], + 'cookie_name' => $this->options['general']['cookie_name'], 'aria_label' => __( 'Cookie Notice', 'cookie-notice' ) ) ); @@ -1229,7 +1248,8 @@ public function add_cookie_notice() { * @return bool */ public static function cookies_accepted() { - return apply_filters( 'cn_is_cookie_accepted', isset( $_COOKIE['cookie_notice_accepted'] ) && $_COOKIE['cookie_notice_accepted'] === 'true' ); + $cookie_name = get_option('general')['cookie_name']; + return apply_filters( 'cn_is_cookie_accepted', isset( $_COOKIE[$cookie_name] ) && $_COOKIE[$cookie_name] === 'true' ); } /** @@ -1238,7 +1258,7 @@ public static function cookies_accepted() { * @return boolean Whether cookies are set */ public function cookies_set() { - return apply_filters( 'cn_is_cookie_set', isset( $_COOKIE['cookie_notice_accepted'] ) ); + return apply_filters( 'cn_is_cookie_set', isset( $_COOKIE[ get_option('general')['cookie_name'] ] ) ); } /** @@ -1395,7 +1415,7 @@ public function wp_enqueue_scripts() { 'onScroll' => $this->options['general']['on_scroll'], 'onScrollOffset' => $this->options['general']['on_scroll_offset'], 'onClick' => $this->options['general']['on_click'], - 'cookieName' => 'cookie_notice_accepted', + 'cookieName' => $this->options['general']['cookie_name'], 'cookieValue' => 'true', 'cookieTime' => $this->times[$this->options['general']['time']][1], 'cookiePath' => ( defined( 'COOKIEPATH' ) ? (string) COOKIEPATH : '' ), diff --git a/js/front.js b/js/front.js index 9223267..fd240a2 100644 --- a/js/front.js +++ b/js/front.js @@ -159,7 +159,7 @@ // get cookie value this.getStatus = function ( bool ) { var value = "; " + document.cookie, - parts = value.split( '; cookie_notice_accepted=' ); + parts = value.split( '; '+ cnArgs.cookieName + '=' ); if ( parts.length === 2 ) { var val = parts.pop().split( ';' ).shift(); diff --git a/js/front.min.js b/js/front.min.js index 89c41fc..c72d81a 100644 --- a/js/front.min.js +++ b/js/front.min.js @@ -1 +1 @@ -!function(){if("function"==typeof window.CustomEvent)return;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}e.prototype=window.Event.prototype,window.CustomEvent=e}(),function(){function t(e){return new RegExp("(^| )"+e+"( |$)")}function e(e,t,n){for(var i=0;iparseInt(cnArgs.onScrollOffset)&&this.setStatus("accept")},this.getClosest=function(e,t){for(Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(e){for(var t=(this.document||this.ownerDocument).querySelectorAll(e),n=t.length;0<=--n&&t.item(n)!==this;);return-1parseInt(cnArgs.onScrollOffset)&&this.setStatus("accept")},this.getClosest=function(e,t){for(Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(e){for(var t=(this.document||this.ownerDocument).querySelectorAll(e),n=t.length;0<=--n&&t.item(n)!==this;);return-1