app_login_url = 'https://app.hu-manity.co/#/en/cc2/login';
}
/**
* Load plugin defaults
*/
public function load_defaults() {
$this->positions = array(
'top' => __( 'Top', 'cookie-notice' ),
'bottom' => __( 'Bottom', 'cookie-notice' )
);
$this->styles = array(
'none' => __( 'None', 'cookie-notice' ),
'wp-default' => __( 'Light', 'cookie-notice' ),
'bootstrap' => __( 'Dark', 'cookie-notice' )
);
$this->revoke_opts = array(
'automatic' => __( 'Automatic', 'cookie-notice' ),
'manual' => __( 'Manual', 'cookie-notice' )
);
$this->links = array(
'page' => __( 'Page link', 'cookie-notice' ),
'custom' => __( 'Custom link', 'cookie-notice' )
);
$this->link_targets = array(
'_blank',
'_self'
);
$this->link_positions = array(
'banner' => __( 'Banner', 'cookie-notice' ),
'message' => __( 'Message', 'cookie-notice' )
);
$this->colors = array(
'text' => __( 'Text color', 'cookie-notice' ),
'button' => __( 'Button color', 'cookie-notice' ),
'bar' => __( 'Bar color', 'cookie-notice' ),
);
$this->times = apply_filters(
'cn_cookie_expiry',
array(
'hour' => array( __( 'An hour', 'cookie-notice' ), 3600 ),
'day' => array( __( '1 day', 'cookie-notice' ), 86400 ),
'week' => array( __( '1 week', 'cookie-notice' ), 604800 ),
'month' => array( __( '1 month', 'cookie-notice' ), 2592000 ),
'3months' => array( __( '3 months', 'cookie-notice' ), 7862400 ),
'6months' => array( __( '6 months', 'cookie-notice' ), 15811200 ),
'year' => array( __( '1 year', 'cookie-notice' ), 31536000 ),
'infinity' => array( __( 'infinity', 'cookie-notice' ), 2147483647 )
)
);
$this->effects = array(
'none' => __( 'None', 'cookie-notice' ),
'fade' => __( 'Fade', 'cookie-notice' ),
'slide' => __( 'Slide', 'cookie-notice' )
);
$this->script_placements = array(
'header' => __( 'Header', 'cookie-notice' ),
'footer' => __( 'Footer', 'cookie-notice' ),
);
$this->level_names = array(
1 => array(
1 => __( 'Silver', 'cookie-notice' ),
2 => __( 'Gold', 'cookie-notice' ),
3 => __( 'Platinum', 'cookie-notice' )
),
2 => array(
1 => __( 'Private', 'cookie-notice' ),
2 => __( 'Balanced', 'cookie-notice' ),
3 => __( 'Personalized', 'cookie-notice' )
),
3 => array(
1 => __( 'Reject All', 'cookie-notice' ),
2 => __( 'Accept Some', 'cookie-notice' ),
3 => __( 'Accept All', 'cookie-notice' )
)
);
$this->text_strings = array(
'saveBtnText' => __( 'Save my preferences', 'cookie-notice' ),
// 'acceptBtnText' => __( 'Accept', 'cookie-notice' ),
// 'rejectBtnText' => __( 'Reject', 'cookie-notice' ),
// 'revokeBtnText' => __( 'Revoke Cookies', 'cookie-notice' ),
'privacyBtnText' => __( 'Privacy policy', 'cookie-notice' ),
'dontSellBtnText' => __( 'Do Not Sell', 'cookie-notice' ),
'customizeBtnText' => __( 'Preferences', 'cookie-notice' ),
'headingText' => __( "We believe your data is your property and support your right to privacy and transparency.", 'cookie-notice' ),
'bodyText' => __( "Select a Data Access Level and Duration to choose how we use and share your data.", 'cookie-notice' ),
'levelBodyText_1' => __( 'Highest level of privacy. Data accessed for necessary site operations only. Data shared with 3rd parties to ensure the site is secure and works on your device.', 'cookie-notice' ),
'levelBodyText_2' => __( 'Balanced experience. Data accessed for content personalisation and site optimisation. Data shared with 3rd parties may be used to track and store your preferences for this site.', 'cookie-notice' ),
'levelBodyText_3' => __( 'Highest level of personalisation. Data accessed to make ads and media more relevant. Data shared with 3rd parties may be use to track you on this site and other sites you visit.', 'cookie-notice' ),
'levelNameText_1' => $this->level_names[1][1],
'levelNameText_2' => $this->level_names[1][2],
'levelNameText_3' => $this->level_names[1][3],
'monthText' => __( 'month', 'cookie-notice' ),
'monthsText' => __( 'months', 'cookie-notice' )
);
// set default text strings
Cookie_Notice()->defaults['general']['message_text'] = __( 'We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.', 'cookie-notice' );
Cookie_Notice()->defaults['general']['accept_text'] = __( 'Ok', 'cookie-notice' );
Cookie_Notice()->defaults['general']['refuse_text'] = __( 'No', 'cookie-notice' );
Cookie_Notice()->defaults['general']['revoke_message_text'] = __( 'You can revoke your consent any time using the Revoke consent button.', 'cookie-notice' );
Cookie_Notice()->defaults['general']['revoke_text'] = __( 'Revoke consent', 'cookie-notice' );
Cookie_Notice()->defaults['general']['see_more_opt']['text'] = __( 'Privacy policy', 'cookie-notice' );
// set translation strings on plugin activation
if ( Cookie_Notice()->options['general']['translate'] === true ) {
Cookie_Notice()->options['general']['translate'] = false;
Cookie_Notice()->options['general']['message_text'] = Cookie_Notice()->defaults['general']['message_text'];
Cookie_Notice()->options['general']['accept_text'] = Cookie_Notice()->defaults['general']['accept_text'];
Cookie_Notice()->options['general']['refuse_text'] = Cookie_Notice()->defaults['general']['refuse_text'];
Cookie_Notice()->options['general']['revoke_message_text'] = Cookie_Notice()->defaults['general']['revoke_message_text'];
Cookie_Notice()->options['general']['revoke_text'] = Cookie_Notice()->defaults['general']['revoke_text'];
Cookie_Notice()->options['general']['see_more_opt']['text'] = Cookie_Notice()->defaults['general']['see_more_opt']['text'];
update_option( 'cookie_notice_options', Cookie_Notice()->options['general'] );
}
// WPML >= 3.2
if ( defined( 'ICL_SITEPRESS_VERSION' ) && version_compare( ICL_SITEPRESS_VERSION, '3.2', '>=' ) ) {
$this->register_wpml_strings();
// WPML and Polylang compatibility
} elseif ( function_exists( 'icl_register_string' ) ) {
icl_register_string( 'Cookie Notice', 'Message in the notice', Cookie_Notice()->options['general']['message_text'] );
icl_register_string( 'Cookie Notice', 'Button text', Cookie_Notice()->options['general']['accept_text'] );
icl_register_string( 'Cookie Notice', 'Refuse button text', Cookie_Notice()->options['general']['refuse_text'] );
icl_register_string( 'Cookie Notice', 'Revoke message text', Cookie_Notice()->options['general']['revoke_message_text'] );
icl_register_string( 'Cookie Notice', 'Revoke button text', Cookie_Notice()->options['general']['revoke_text'] );
icl_register_string( 'Cookie Notice', 'Privacy policy text', Cookie_Notice()->options['general']['see_more_opt']['text'] );
icl_register_string( 'Cookie Notice', 'Custom link', Cookie_Notice()->options['general']['see_more_opt']['link'] );
}
}
/**
* Add submenu.
*/
public function admin_menu_options() {
add_menu_page( __( 'Cookie Notice', 'cookie-notice' ), __( 'Cookies', 'cookie-notice' ), apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ), 'cookie-notice', array( $this, 'options_page' ), 'none', '99.3' );
}
/**
* Options page output.
*
* @return mixed
*/
public function options_page() {
echo '
' . __( 'Cookie Notice & Compliance for GDPR/CCPA', 'cookie-notice' ) . '
';
// compliance enabled
if ( Cookie_Notice()->get_status() === 'active' ) {
echo '
We\'re Promoting Privacy™
' . __( 'Promote the privacy of your website visitors without affecting how you do your business.', 'cookie-notice' ) . '
';
} else {
echo '
Cookie Compliance™
' . __( 'The next generation of Cookie Notice', 'cookie-notice' ) . '
' . __( 'A free web application to help you deliver better consent experiences and comply with GDPR, CCPA and other data privacy laws more effectively.', 'cookie-notice' ) . '
' . __( 'Free Upgrade', 'cookie-notice' ) . ' ';
}
echo '
';
}
/**
* Regiseter plugin settings.
*/
public function register_settings() {
register_setting( 'cookie_notice_options', 'cookie_notice_options', array( $this, 'validate_options' ) );
// compliance enabled
if ( Cookie_Notice()->get_status() === 'active' ) {
// configuration
add_settings_section( 'cookie_notice_compliance', __( 'Compliance Settings', 'cookie-notice' ), array( $this, 'cn_section_compliance' ), 'cookie_notice_options' );
add_settings_field( 'cn_app_status', __( 'Compliance status', 'cookie-notice' ), array( $this, 'cn_app_status' ), 'cookie_notice_options', 'cookie_notice_compliance' );
add_settings_field( 'cn_app_id', __( 'App ID', 'cookie-notice' ), array( $this, 'cn_app_id' ), 'cookie_notice_options', 'cookie_notice_compliance' );
add_settings_field( 'cn_app_key', __( 'App Key', 'cookie-notice' ), array( $this, 'cn_app_key' ), 'cookie_notice_options', 'cookie_notice_compliance' );
add_settings_section( 'cookie_notice_configuration', __( 'Miscellaneous Settings', 'cookie-notice' ), array( $this, 'cn_section_configuration' ), 'cookie_notice_options' );
add_settings_field( 'cn_app_blocking', __( 'Autoblocking', 'cookie-notice' ), array( $this, 'cn_app_blocking' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_hide_banner', __( 'Hide for logged in', 'cookie-notice' ), array( $this, 'cn_hide_banner' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_app_purge_cache', __( 'Cache', 'cookie-notice' ), array( $this, 'cn_app_purge_cache' ), '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_deactivation_delete', __( 'Deactivation', 'cookie-notice' ), array( $this, 'cn_deactivation_delete' ), 'cookie_notice_options', 'cookie_notice_configuration' );
// compliance disabled
} else {
// configuration
add_settings_section( 'cookie_notice_compliance', __( 'Compliance Settings', 'cookie-notice' ), array( $this, 'cn_section_compliance' ), 'cookie_notice_options' );
add_settings_field( 'cn_app_status', __( 'Compliance status', 'cookie-notice' ), array( $this, 'cn_app_status' ), 'cookie_notice_options', 'cookie_notice_compliance' );
add_settings_field( 'cn_app_id', __( 'App ID', 'cookie-notice' ), array( $this, 'cn_app_id' ), 'cookie_notice_options', 'cookie_notice_compliance' );
add_settings_field( 'cn_app_key', __( 'App Key', 'cookie-notice' ), array( $this, 'cn_app_key' ), 'cookie_notice_options', 'cookie_notice_compliance' );
add_settings_section( 'cookie_notice_configuration', __( 'Notice Settings', 'cookie-notice' ), array( $this, 'cn_section_configuration' ), 'cookie_notice_options' );
add_settings_field( 'cn_message_text', __( 'Message', 'cookie-notice' ), array( $this, 'cn_message_text' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_accept_text', __( 'Button text', 'cookie-notice' ), array( $this, 'cn_accept_text' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_see_more', __( 'Privacy policy', 'cookie-notice' ), array( $this, 'cn_see_more' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_refuse_opt', __( 'Refuse consent', 'cookie-notice' ), array( $this, 'cn_refuse_opt' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_revoke_opt', __( 'Revoke consent', 'cookie-notice' ), array( $this, 'cn_revoke_opt' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_refuse_code', __( 'Script blocking', 'cookie-notice' ), array( $this, 'cn_refuse_code' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_redirection', __( 'Reloading', 'cookie-notice' ), array( $this, 'cn_redirection' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_on_scroll', __( 'On scroll', 'cookie-notice' ), array( $this, 'cn_on_scroll' ), 'cookie_notice_options', 'cookie_notice_configuration' );
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', __( 'Accepted expiry', 'cookie-notice' ), array( $this, 'cn_time' ), 'cookie_notice_options', 'cookie_notice_configuration' );
add_settings_field( 'cn_time_rejected', __( 'Rejected expiry', 'cookie-notice' ), array( $this, 'cn_time_rejected' ), '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_deactivation_delete', __( 'Deactivation', 'cookie-notice' ), array( $this, 'cn_deactivation_delete' ), 'cookie_notice_options', 'cookie_notice_configuration' );
// design
add_settings_section( 'cookie_notice_design', __( 'Notice Design', 'cookie-notice' ), array( $this, 'cn_section_design' ), 'cookie_notice_options' );
add_settings_field( 'cn_position', __( 'Position', 'cookie-notice' ), array( $this, 'cn_position' ), 'cookie_notice_options', 'cookie_notice_design' );
add_settings_field( 'cn_hide_effect', __( 'Animation', 'cookie-notice' ), array( $this, 'cn_hide_effect' ), 'cookie_notice_options', 'cookie_notice_design' );
add_settings_field( 'cn_colors', __( 'Colors', 'cookie-notice' ), array( $this, 'cn_colors' ), 'cookie_notice_options', 'cookie_notice_design' );
add_settings_field( 'cn_css_class', __( 'Button class', 'cookie-notice' ), array( $this, 'cn_css_class' ), 'cookie_notice_options', 'cookie_notice_design' );
}
}
/**
* Section callback: fix for WP < 3.3
*/
public function cn_section_configuration() {}
public function cn_section_compliance() {}
public function cn_section_design() {}
/**
* Compliance status.
*/
public function cn_app_status() {
$app_status = Cookie_Notice()->get_status();
switch ( $app_status ) {
case 'active':
echo '
' . __( 'Notice', 'cookie-notice' ) . ': ' . __( 'Active', 'cookie-notice' ) . '
' . __( 'Autoblocking', 'cookie-notice' ) . ': ' . __( 'Active', 'cookie-notice' ) . '
' . __( 'Cookie Categories', 'cookie-notice' ) . ': ' . __( 'Active', 'cookie-notice' ) . '
' . __( 'Proof-of-Consent', 'cookie-notice' ) . ': ' . __( 'Active', 'cookie-notice' ) . '
';
break;
case 'pending':
echo '
' . __( 'Notice', 'cookie-notice' ) . ': ' . __( 'Active', 'cookie-notice' ) . '
' . __( 'Autoblocking', 'cookie-notice' ) . ': ' . __( 'Pending', 'cookie-notice' ) . '
' . __( 'Cookie Categories', 'cookie-notice' ) . ': ' . __( 'Pending', 'cookie-notice' ) . '
' . __( 'Proof-of-Consent', 'cookie-notice' ) . ': ' . __( 'Pending', 'cookie-notice' ) . '
';
break;
default:
echo '
' . __( 'Notice', 'cookie-notice' ) . ': ' . __( 'Active', 'cookie-notice' ) . '
' . __( 'Autoblocking', 'cookie-notice' ) . ': ' . __( 'Inactive', 'cookie-notice' ) . '
' . __( 'Cookie Categories', 'cookie-notice' ) . ': ' . __( 'Inactive', 'cookie-notice' ) . '
' . __( 'Proof-of-Consent', 'cookie-notice' ) . ': ' . __( 'Inactive', 'cookie-notice' ) . '
';
break;
}
}
/**
* App welcome.
*/
public function cn_app_id() {
echo '
';
}
/**
* App ID option.
*/
public function cn_app_key() {
echo '
';
}
/**
* App autoblocking.
*/
public function cn_app_blocking() {
echo '
options['general']['app_blocking'], false ) . ' />' . __( 'Enable to automatically block 3rd party scripts before user consent.', 'cookie-notice' ) . '
' . __( "In case you're experiencing issues with your site disable that feature temporarily.", 'cookie-notice' ) . '
';
}
/**
* App ID option.
*/
public function cn_app_purge_cache() {
echo '
' . __( 'Click the Purge Cache button to refresh the app configuration.', 'cookie-notice' ) . '
';
}
/**
* Hide banner.
*/
public function cn_hide_banner() {
echo '
options['general']['hide_banner'], false ) . ' />' . __( 'Enable to hide the consent banner for logged in users.', 'cookie-notice' ) . '
';
}
/**
* App Key option.
*/
public function cn_message_text() {
echo '
' . __( 'Enter the cookie notice message.', 'cookie-notice' ) . '
';
}
/**
* Accept cookie label option.
*/
public function cn_accept_text() {
echo '
';
}
/**
* Enable/Disable third party non functional cookies option.
*/
public function cn_refuse_opt() {
echo '
options['general']['refuse_opt'], false ) . ' />' . __( 'Enable to give to the user the possibility to refuse third party non functional cookies.', 'cookie-notice' ) . '
options['general']['refuse_opt'] === false ? ' style="display: none;"' : '' ) . '>
';
}
/**
* Non functional cookies code.
*/
public function cn_refuse_code() {
$allowed_html = Cookie_Notice()->get_allowed_html();
$active = ! empty( Cookie_Notice()->options['general']['refuse_code'] ) && empty( Cookie_Notice()->options['general']['refuse_code_head'] ) ? 'body' : 'head';
echo '
' . __( 'The code to be used in your site header, before the closing head tag.', 'cookie-notice' ) . '
' . __( 'The code to be used in your site footer, before the closing body tag.', 'cookie-notice' ) . '
' . __( 'Enter non functional cookies Javascript code here (for e.g. Google Analitycs) to be used after the notice is accepted.', 'cookie-notice' ) . '' . __( 'To get the user consent status use the cn_cookies_accepted() function.', 'cookie-notice' ) . '
';
}
/**
* Revoke cookies option.
*/
public function cn_revoke_opt() {
echo '
options['general']['revoke_cookies'], false ) . ' />' . __( 'Enable to give to the user the possibility to revoke their consent (requires "Refuse consent" option enabled) .', 'cookie-notice' ) . '
options['general']['revoke_cookies'] ? '' : ' style="display: none;"' ) . '>
' . __( 'Enter the revoke message.', 'cookie-notice' ) . '
' . __( 'The text of the button to revoke the consent.', 'cookie-notice' ) . '
';
foreach ( $this->revoke_opts as $value => $label ) {
echo '
options['general']['revoke_cookies_opt'], false ) . ' />' . esc_html( $label ) . '';
}
echo '
' . __( 'Select the method for displaying the revoke button - automatic (in the banner) or manual using [cookies_revoke] shortcode.', 'cookie-notice' ) . '
';
}
/**
* Redirection on cookie accept.
*/
public function cn_redirection() {
echo '
options['general']['redirection'], false ) . ' />' . __( 'Enable to reload the page after the notice is accepted.', 'cookie-notice' ) . '
';
}
/**
* Privacy policy link option.
*/
public function cn_see_more() {
$pages = get_pages(
array(
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'hierarchical' => 0,
'child_of' => 0,
'parent' => -1,
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
)
);
echo '
options['general']['see_more'], false ) . ' />' . __( 'Enable privacy policy link.', 'cookie-notice' ) . '
options['general']['see_more'] === false ? ' style="display: none;"' : '') . '>
' . __( 'The text of the privacy policy button.', 'cookie-notice' ) . '
';
foreach ( $this->links as $value => $label ) {
$value = esc_attr( $value );
echo '
options['general']['see_more_opt']['link_type'], false ) . ' />' . esc_html( $label ) . ' ';
}
echo '
' . __( 'Select where to redirect user for more information.', 'cookie-notice' ) . '
options['general']['see_more_opt']['link_type'] === 'custom' ? ' style="display: none;"' : '') . '>
options['general']['see_more_opt']['id'], false ) . '>' . __( '-- select page --', 'cookie-notice' ) . ' ';
if ( $pages ) {
foreach ( $pages as $page ) {
echo '
ID, Cookie_Notice()->options['general']['see_more_opt']['id'], false ) . '>' . esc_html( $page->post_title ) . ' ';
}
}
echo '
' . __( 'Select from one of your site\'s pages.', 'cookie-notice' ) . '
';
global $wp_version;
if ( version_compare( $wp_version, '4.9.6', '>=' ) ) {
echo '
options['general']['see_more_opt']['sync'], false ) . ' />' . __( 'Synchronize with WordPress Privacy Policy page.', 'cookie-notice' ) . '';
}
echo '
';
foreach ( $this->link_targets as $target ) {
echo '
options['general']['link_target'], false ) . ' />' . $target . '';
}
echo '
' . esc_html__( 'Select the privacy policy link target.', 'cookie-notice' ) . '
';
foreach ( $this->link_positions as $position => $label ) {
echo '
options['general']['link_position'], false ) . ' />' . esc_html( $label ) . '';
}
echo '
' . esc_html__( 'Select the privacy policy link position.', 'cookie-notice' ) . '
';
}
/**
* Expiration time option.
*/
public function cn_time() {
echo '
';
foreach ( $this->times as $time => $arr ) {
$time = esc_attr( $time );
echo '
options['general']['time'] ) . '>' . esc_html( $arr[0] ) . ' ';
}
echo '
' . __( 'The amount of time that the cookie should be stored for when user accepts the notice.', 'cookie-notice' ) . '
';
}
/**
* Expiration time option.
*/
public function cn_time_rejected() {
echo '
';
foreach ( $this->times as $time => $arr ) {
$time = esc_attr( $time );
echo '
options['general']['time_rejected'] ) . '>' . esc_html( $arr[0] ) . ' ';
}
echo '
' . __( 'The amount of time that the cookie should be stored for when the user doesn\'t accept the notice.', 'cookie-notice' ) . '
';
}
/**
* Script placement option.
*/
public function cn_script_placement() {
echo '
';
foreach ( $this->script_placements as $value => $label ) {
echo '
options['general']['script_placement'], false ) . ' />' . esc_html( $label ) . ' ';
}
echo '
' . __( 'Select where all the plugin scripts should be placed.', 'cookie-notice' ) . '
';
}
/**
* Position option.
*/
public function cn_position() {
echo '
';
foreach ( $this->positions as $value => $label ) {
$value = esc_attr( $value );
echo '
options['general']['position'], false ) . ' />' . esc_html( $label ) . '';
}
echo '
' . __( 'Select location for the notice.', 'cookie-notice' ) . '
';
}
/**
* Animation effect option.
*/
public function cn_hide_effect() {
echo '
';
foreach ( $this->effects as $value => $label ) {
$value = esc_attr( $value );
echo '
options['general']['hide_effect'], false ) . ' />' . esc_html( $label ) . '';
}
echo '
' . __( 'Select the animation style.', 'cookie-notice' ) . '
';
}
/**
* On scroll option.
*/
public function cn_on_scroll() {
echo '
options['general']['on_scroll'], false ) . ' />' . __( 'Enable to accept the notice when user scrolls.', 'cookie-notice' ) . '
';
}
/**
* On click option.
*/
public function cn_on_click() {
echo '
options['general']['on_click'], false ) . ' />' . __( 'Enable to accept the notice on any click on the page.', 'cookie-notice' ) . '
';
}
/**
* Delete plugin data on deactivation.
*/
public function cn_deactivation_delete() {
echo '
options['general']['deactivation_delete'], false ) . '/>' . __( 'Enable if you want all plugin data to be deleted on deactivation.', 'cookie-notice' ) . '
';
}
/**
* CSS style option.
*/
public function cn_css_class() {
echo '
';
}
/**
* Colors option.
*/
public function cn_colors() {
echo '
';
foreach ( $this->colors as $value => $label ) {
$value = esc_attr( $value );
echo '
' . esc_html( $label ) . '
' .
'
';
}
// print_r( Cookie_Notice()->options['general']['colors'] );
echo '
';
echo '
';
}
/**
* Validate options.
*
* @param array $input
* @return array
*/
public function validate_options( $input ) {
if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) )
return $input;
// get main instance
$cn = Cookie_Notice();
if ( isset( $_POST['save_cookie_notice_options'] ) ) {
// app id
$input['app_id'] = sanitize_text_field( isset( $input['app_id'] ) ? $input['app_id'] : $cn->defaults['general']['app_id'] );
// app key
$input['app_key'] = sanitize_text_field( isset( $input['app_key'] ) ? $input['app_key'] : $cn->defaults['general']['app_key'] );
// set app status
if ( ! empty( $input['app_id'] ) && ! empty( $input['app_key'] ) ) {
$app_status = esc_attr( $cn->welcome_api->get_app_status( $input['app_id'] ) );
update_option( 'cookie_notice_status', $app_status );
} else {
update_option( 'cookie_notice_status', '' );
}
// app blocking
$input['app_blocking'] = (bool) isset( $input['app_blocking'] );
// hide banner
$input['hide_banner'] = (bool) isset( $input['hide_banner'] );
// position
$input['position'] = sanitize_text_field( isset( $input['position'] ) && in_array( $input['position'], array_keys( $this->positions ) ) ? $input['position'] : $cn->defaults['general']['position'] );
// colors
$input['colors']['text'] = sanitize_text_field( isset( $input['colors']['text'] ) && $input['colors']['text'] !== '' && preg_match( '/^#[a-f0-9]{6}$/', $input['colors']['text'] ) === 1 ? $input['colors']['text'] : $cn->defaults['general']['colors']['text'] );
$input['colors']['button'] = sanitize_text_field( isset( $input['colors']['button'] ) && $input['colors']['button'] !== '' && preg_match( '/^#[a-f0-9]{6}$/', $input['colors']['button'] ) === 1 ? $input['colors']['button'] : $cn->defaults['general']['colors']['button'] );
$input['colors']['bar'] = sanitize_text_field( isset( $input['colors']['bar'] ) && $input['colors']['bar'] !== '' && preg_match( '/^#[a-f0-9]{6}$/', $input['colors']['bar'] ) === 1 ? $input['colors']['bar'] : $cn->defaults['general']['colors']['bar'] );
$input['colors']['bar_opacity'] = absint( isset( $input['colors']['bar_opacity'] ) && $input['colors']['bar_opacity'] >= 50 ? $input['colors']['bar_opacity'] : $cn->defaults['general']['colors']['bar_opacity'] );
// texts
$input['message_text'] = wp_kses_post( isset( $input['message_text'] ) && $input['message_text'] !== '' ? $input['message_text'] : $cn->defaults['general']['message_text'] );
$input['accept_text'] = sanitize_text_field( isset( $input['accept_text'] ) && $input['accept_text'] !== '' ? $input['accept_text'] : $cn->defaults['general']['accept_text'] );
$input['refuse_text'] = sanitize_text_field( isset( $input['refuse_text'] ) && $input['refuse_text'] !== '' ? $input['refuse_text'] : $cn->defaults['general']['refuse_text'] );
$input['revoke_message_text'] = wp_kses_post( isset( $input['revoke_message_text'] ) && $input['revoke_message_text'] !== '' ? $input['revoke_message_text'] : $cn->defaults['general']['revoke_message_text'] );
$input['revoke_text'] = sanitize_text_field( isset( $input['revoke_text'] ) && $input['revoke_text'] !== '' ? $input['revoke_text'] : $cn->defaults['general']['revoke_text'] );
$input['refuse_opt'] = (bool) isset( $input['refuse_opt'] );
$input['revoke_cookies'] = isset( $input['revoke_cookies'] );
$input['revoke_cookies_opt'] = isset( $input['revoke_cookies_opt'] ) && array_key_exists( $input['revoke_cookies_opt'], $this->revoke_opts ) ? $input['revoke_cookies_opt'] : $cn->defaults['general']['revoke_cookies_opt'];
// get allowed HTML
$allowed_html = $cn->get_allowed_html();
// body refuse code
$input['refuse_code'] = wp_kses( isset( $input['refuse_code'] ) && $input['refuse_code'] !== '' ? $input['refuse_code'] : $cn->defaults['general']['refuse_code'], $allowed_html );
// head refuse code
$input['refuse_code_head'] = wp_kses( isset( $input['refuse_code_head'] ) && $input['refuse_code_head'] !== '' ? $input['refuse_code_head'] : $cn->defaults['general']['refuse_code_head'], $allowed_html );
// css button class
$input['css_class'] = sanitize_text_field( isset( $input['css_class'] ) ? $input['css_class'] : $cn->defaults['general']['css_class'] );
// link target
$input['link_target'] = sanitize_text_field( isset( $input['link_target'] ) && in_array( $input['link_target'], array_keys( $this->link_targets ) ) ? $input['link_target'] : $cn->defaults['general']['link_target'] );
// time
$input['time'] = sanitize_text_field( isset( $input['time'] ) && in_array( $input['time'], array_keys( $this->times ) ) ? $input['time'] : $cn->defaults['general']['time'] );
$input['time_rejected'] = sanitize_text_field( isset( $input['time_rejected'] ) && in_array( $input['time_rejected'], array_keys( $this->times ) ) ? $input['time_rejected'] : $cn->defaults['general']['time_rejected'] );
// script placement
$input['script_placement'] = sanitize_text_field( isset( $input['script_placement'] ) && in_array( $input['script_placement'], array_keys( $this->script_placements ) ) ? $input['script_placement'] : $cn->defaults['general']['script_placement'] );
// hide effect
$input['hide_effect'] = sanitize_text_field( isset( $input['hide_effect'] ) && in_array( $input['hide_effect'], array_keys( $this->effects ) ) ? $input['hide_effect'] : $cn->defaults['general']['hide_effect'] );
// redirection
$input['redirection'] = isset( $input['redirection'] );
// on scroll
$input['on_scroll'] = isset( $input['on_scroll'] );
// on scroll offset
$input['on_scroll_offset'] = absint( isset( $input['on_scroll_offset'] ) && $input['on_scroll_offset'] !== '' ? $input['on_scroll_offset'] : $cn->defaults['general']['on_scroll_offset'] );
// on click
$input['on_click'] = isset( $input['on_click'] );
// deactivation
$input['deactivation_delete'] = isset( $input['deactivation_delete'] );
// privacy policy
$input['see_more'] = isset( $input['see_more'] );
$input['see_more_opt']['text'] = sanitize_text_field( isset( $input['see_more_opt']['text'] ) && $input['see_more_opt']['text'] !== '' ? $input['see_more_opt']['text'] : $cn->defaults['general']['see_more_opt']['text'] );
$input['see_more_opt']['link_type'] = sanitize_text_field( isset( $input['see_more_opt']['link_type'] ) && in_array( $input['see_more_opt']['link_type'], array_keys( $this->links ) ) ? $input['see_more_opt']['link_type'] : $cn->defaults['general']['see_more_opt']['link_type'] );
if ( $input['see_more_opt']['link_type'] === 'custom' )
$input['see_more_opt']['link'] = ( $input['see_more'] === true ? esc_url( $input['see_more_opt']['link'] ) : '' );
elseif ( $input['see_more_opt']['link_type'] === 'page' ) {
$input['see_more_opt']['id'] = ( $input['see_more'] === true ? (int) $input['see_more_opt']['id'] : 0 );
$input['see_more_opt']['sync'] = isset( $input['see_more_opt']['sync'] );
if ( $input['see_more_opt']['sync'] )
update_option( 'wp_page_for_privacy_policy', $input['see_more_opt']['id'] );
}
// policy link position
$input['link_position'] = sanitize_text_field( isset( $input['link_position'] ) && in_array( $input['link_position'], array_keys( $this->link_positions ) ) ? $input['link_position'] : $cn->defaults['general']['link_position'] );
// message link position?
if ( $input['see_more'] === true && $input['link_position'] === 'message' && strpos( $input['message_text'], '[cookies_policy_link' ) === false )
$input['message_text'] .= ' [cookies_policy_link]';
$input['update_version'] = $cn->options['general']['update_version'];
$input['update_notice'] = $cn->options['general']['update_notice'];
$input['translate'] = false;
// WPML >= 3.2
if ( defined( 'ICL_SITEPRESS_VERSION' ) && version_compare( ICL_SITEPRESS_VERSION, '3.2', '>=' ) ) {
do_action( 'wpml_register_single_string', 'Cookie Notice', 'Message in the notice', $input['message_text'] );
do_action( 'wpml_register_single_string', 'Cookie Notice', 'Button text', $input['accept_text'] );
do_action( 'wpml_register_single_string', 'Cookie Notice', 'Refuse button text', $input['refuse_text'] );
do_action( 'wpml_register_single_string', 'Cookie Notice', 'Revoke message text', $input['revoke_message_text'] );
do_action( 'wpml_register_single_string', 'Cookie Notice', 'Revoke button text', $input['revoke_text'] );
do_action( 'wpml_register_single_string', 'Cookie Notice', 'Privacy policy text', $input['see_more_opt']['text'] );
if ( $input['see_more_opt']['link_type'] === 'custom' )
do_action( 'wpml_register_single_string', 'Cookie Notice', 'Custom link', $input['see_more_opt']['link'] );
}
add_settings_error( 'cn_cookie_notice_options', 'save_cookie_notice_options', __( 'Settings saved.', 'iubenda' ), 'updated' );
// purge cache on save
delete_transient( 'cookie_notice_compliance_cache' );
} elseif ( isset( $_POST['reset_cookie_notice_options'] ) ) {
$input = $cn->defaults['general'];
add_settings_error( 'cn_cookie_notice_options', 'reset_cookie_notice_options', __( 'Settings restored to defaults.', 'cookie-notice' ), 'updated' );
// set app status
update_option( 'cookie_notice_status', '' );
// purge cache on save
delete_transient( 'cookie_notice_compliance_cache' );
}
return $input;
}
/**
* Load scripts and styles - admin.
*/
public function admin_enqueue_scripts( $page ) {
if ( $page === 'toplevel_page_cookie-notice' ) {
wp_enqueue_script(
'cookie-notice-admin', plugins_url( '../js/admin' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery', 'wp-color-picker' ), Cookie_Notice()->defaults['version']
);
wp_localize_script(
'cookie-notice-admin', 'cnArgs', array(
'ajaxURL' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'cn-purge-cache' ),
'resetToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'cookie-notice' )
)
);
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'cookie-notice-admin', plugins_url( '../css/admin' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ) );
}
}
/**
* Load admin style inline, for menu icon only.
*
* @return mixed
*/
public function admin_print_styles() {
echo '
';
}
/**
* Register WPML (>= 3.2) strings if needed.
*
* @return void
*/
private function register_wpml_strings() {
// get main instance
$cn = Cookie_Notice();
global $wpdb;
// prepare strings
$strings = array(
'Message in the notice' => $cn->options['general']['message_text'],
'Button text' => $cn->options['general']['accept_text'],
'Refuse button text' => $cn->options['general']['refuse_text'],
'Revoke message text' => $cn->options['general']['revoke_message_text'],
'Revoke button text' => $cn->options['general']['revoke_text'],
'Privacy policy text' => $cn->options['general']['see_more_opt']['text'],
'Custom link' => $cn->options['general']['see_more_opt']['link']
);
// get query results
$results = $wpdb->get_col( $wpdb->prepare( "SELECT name FROM " . $wpdb->prefix . "icl_strings WHERE context = %s", 'Cookie Notice' ) );
// check results
foreach( $strings as $string => $value ) {
// string does not exist?
if ( ! in_array( $string, $results, true ) ) {
// register string
do_action( 'wpml_register_single_string', 'Cookie Notice', $string, $value );
}
}
}
/**
* Display errors and notices.
*
* @global string $pagenow
*/
public function settings_errors() {
global $pagenow;
// force display notices in top menu settings page
if ( $pagenow == 'options-general.php' )
return;
settings_errors( 'cn_cookie_notice_options' );
}
/**
* Save compliance config caching.
*/
public function ajax_purge_cache() {
if ( ! check_ajax_referer( 'cn-purge-cache', 'nonce' ) )
echo false;
if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) )
echo false;
delete_transient( 'cookie_notice_compliance_cache' );
echo true;
exit;
}
}