Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions cookie-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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 '
<fieldset>
<div id="cn_cookie_name">
<input type="text" class="regular-text" name="cookie_notice_options[cookie_name]" value="' . esc_attr( $this->options['general']['cookie_name'] ) . '" />
<p class="description">' . __( 'Change the name of the cookie used for storing cookie notice acceptance status.', 'cookie-notice' ) . '</p>
</div>
</fieldset>';
}

/**
* Delete plugin data on deactivation.
*/
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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' )
) );

Expand Down Expand Up @@ -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' );
}

/**
Expand All @@ -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'] ] ) );
}

/**
Expand Down Expand Up @@ -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 : '' ),
Expand Down
2 changes: 1 addition & 1 deletion js/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading