diff --git a/cookie-notice.php b/cookie-notice.php
index 2e76118..2e8ca3c 100644
--- a/cookie-notice.php
+++ b/cookie-notice.php
@@ -2,7 +2,7 @@
/*
Plugin Name: Cookie Notice
Description: Cookie Notice allows you to elegantly inform users that your site uses cookies and to comply with the EU cookie law regulations.
-Version: 1.2.37
+Version: 1.3
Author: dFactory
Author URI: http://www.dfactory.eu/
Plugin URI: http://www.dfactory.eu/plugins/cookie-notice/
@@ -70,7 +70,7 @@ class Cookie_Notice {
'translate' => true,
'deactivation_delete' => 'no'
),
- 'version' => '1.2.37'
+ 'version' => '1.3'
);
private $positions = array();
private $styles = array();
@@ -82,6 +82,9 @@ class Cookie_Notice {
private $effects = array();
private $times = array();
private $script_placements = array();
+ private $is_network = false;
+ private $in_network_context = false;
+ private $is_network_values_forced = false;
/**
* @var $cookie, holds cookie name
@@ -102,10 +105,35 @@ public function __construct() {
$this->options = array(
'general' => array_merge( $this->defaults['general'], get_option( 'cookie_notice_options', $this->defaults['general'] ) )
);
+ if(is_multisite()){
+ if(! function_exists( 'is_plugin_active_for_network' ) ) {
+ require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
+ }
+ if ( is_plugin_active_for_network( basename(__DIR__).'/'.basename(__FILE__) ) ) {
+ $this->is_network = true;
+ // Get network settings
+ $this->network_options = array(
+ 'general' => array_merge( $this->defaults['general'], get_site_option( 'cookie_notice_options', $this->defaults['general'] ) )
+ );
+ // If network settings are forced, override local settings
+ if(isset($this->network_options['general']['force_network_values']) && $this->network_options['general']['force_network_values']==='yes'){
+ $this->options = $this->network_options;
+ $this->is_network_values_forced = true;
+ }
+ // Load local settings with network ones as default
+ else{
+ $this->options = array(
+ 'general' => array_merge( $this->network_options['general'], get_option( 'cookie_notice_options', $this->network_options['general'] ) )
+ );
+ }
+ }
+ }
// actions
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_menu', array( $this, 'admin_menu_options' ) );
+ add_action( 'network_admin_menu', array(&$this,'network_admin_menu_options'));
+ add_action('admin_post_cn_save_network_settings', array(&$this, 'save_network_settings'));
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
add_action( 'after_setup_theme', array( $this, 'load_defaults' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_load_scripts_styles' ) );
@@ -135,7 +163,8 @@ public function load_defaults() {
$this->links = array(
'custom' => __( 'Custom link', 'cookie-notice' ),
- 'page' => __( 'Page link', 'cookie-notice' )
+ 'page' => __( 'Page link', 'cookie-notice' ),
+ 'legacy' => __( 'Page for Privacy Policy', 'cookie-notice'),
);
$this->link_target = array(
@@ -179,6 +208,9 @@ public function load_defaults() {
update_option( 'cookie_notice_options', $this->options['general'] );
}
+ if(!isset($this->network_options['general']['force_network_values'])){
+ $this->network_options['general']['force_network_values'] = 'no';
+ }
// WPML >= 3.2
if ( defined( 'ICL_SITEPRESS_VERSION' ) && version_compare( ICL_SITEPRESS_VERSION, '3.2', '>=' ) ) {
@@ -238,16 +270,24 @@ public function admin_menu_options() {
__( 'Cookie Notice', 'cookie-notice' ), __( 'Cookie Notice', 'cookie-notice' ), apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ), 'cookie-notice', array( $this, 'options_page' )
);
}
+ /**
+ * Add submenu in network
+ */
+ public function network_admin_menu_options(){
+ add_submenu_page(
+ 'settings.php', __( 'Cookie Notice (Network)', 'cookie-notice' ), __( 'Cookie Notice', 'cookie-notice' ), apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ), 'cookie-notice', array( $this, 'network_options_page' )
+ );
+ }
/**
* Options page output.
- *
+ *
* @return mixed
*/
- public function options_page() {
+ public function options_page($network=false) {
echo '
' . screen_icon() . '
-
' . __( 'Cookie Notice', 'cookie-notice' ) . '
+
' . ($network ? __( 'Cookie Notice (Network)', 'cookie-notice' ) : __( 'Cookie Notice', 'cookie-notice' )) . '
-
';
}
+ /**
+ * @since 1.3
+ */
+ public function network_options_page(){
+ $this->options_page(true);
+ }
+
+ /**
+ * Parse escaped posted settings
+ * @param mixte $value
+ * @return mixte $value
+ * @since 1.3
+ */
+ private function get_setting_post_value($value){
+
+ if(is_string($value))
+ return esc_attr($value);
+
+ if(is_array($value)){
+ $values = array();
+ foreach($value as $k=>$val){
+ $values[$k] = $this->get_setting_post_value($val);
+ }
+ return $values;
+ }
+
+ }
+ /**
+ * Save network settings
+ * @since 1.3
+ */
+ public function save_network_settings(){
+
+ if (!wp_verify_nonce(filter_input(INPUT_POST, 'cn_network_settings', FILTER_SANITIZE_STRING), 'cn_network_settings'))
+ wp_die(__('Cheating, uh?', 'cookie-notice'));
+
+ $network_settings = array(
+ 'force_network_values' => isset($_POST['cookie_notice_options']['force_network_values']) ? esc_attr($_POST['cookie_notice_options']['force_network_values']) : 'no',
+ );
+ foreach ($this->defaults['general'] as $setting => $value) {
+ $network_settings[$setting] = $this->get_setting_post_value($_POST['cookie_notice_options'][$setting]);
+ }
+ update_site_option( 'cookie_notice_options', $network_settings );
+
+ wp_safe_redirect(admin_url('network/settings.php?page=cookie-notice'));
+ exit;
+ }
/**
* Regiseter plugin settings.
@@ -318,17 +421,19 @@ public function cn_section_design() {}
* Delete plugin data on deactivation.
*/
public function cn_deactivation_delete() {
+ $options = $this->in_network_context ? $this->network_options : $this->options;
echo '
- options['general']['deactivation_delete'], false ) . '/>' . __( 'Enable if you want all plugin data to be deleted on deactivation.', 'cookie-notice' ) . ' ';
+ ' . __( 'Enable if you want all plugin data to be deleted on deactivation.', 'cookie-notice' ) . ' ';
}
/**
* Cookie message option.
*/
public function cn_message_text() {
+ $options = $this->in_network_context ? $this->network_options : $this->options;
echo '
-
+
' . __( 'Enter the cookie notice message.', 'cookie-notice' ) . '
';
}
@@ -337,9 +442,10 @@ public function cn_message_text() {
* Accept cookie label option.
*/
public function cn_accept_text() {
+ $options = $this->in_network_context ? $this->network_options : $this->options;
echo '
';
}
@@ -348,18 +454,19 @@ public function cn_accept_text() {
* Enable/Disable third party non functional cookies option.
*/
public function cn_refuse_opt() {
+ $options = $this->in_network_context ? $this->network_options : $this->options;
echo '
- options['general']['refuse_opt'], false ) . ' />' . __( 'Give to the user the possibility to refuse third party non functional cookies.', 'cookie-notice' ) . ' ';
- echo 'options['general']['refuse_opt'] === 'no' ? ' style="display: none;"' : '') . '>';
+
' . __( 'Give to the user the possibility to refuse third party non functional cookies.', 'cookie-notice' ) . '';
+ echo '
';
echo '
';
echo '
-
+
' . __( 'Enter non functional cookies Javascript code here (for e.g. Google Analitycs). It will be used after cookies are accepted.', 'cookie-notice' ) . '
';
echo '
@@ -371,7 +478,7 @@ public function cn_refuse_opt() {
* Read more link option.
*/
public function cn_see_more() {
-
+ $options = $this->in_network_context ? $this->network_options : $this->options;
$pages = get_pages(
array(
'sort_order' => 'ASC',
@@ -384,49 +491,72 @@ public function cn_see_more() {
'post_status' => 'publish'
)
);
-
+
echo '
-
options['general']['see_more'], false ) . ' />' . __( 'Enable Read more link.', 'cookie-notice' ) . '
+
' . __( 'Enable Read more link.', 'cookie-notice' ) . '
' . sprintf( __( 'Need a Cookie Policy? Generate one with iubenda ', 'cookie-notice' ), 'http://iubenda.refr.cc/MXRWXMP' ) . '
';
echo '
- options['general']['see_more'] === 'no' ? ' style="display: none;"' : '') . '>
-
+
-
' . __( 'Select where to redirect user for more information about cookies.', '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, $this->options['general']['see_more_opt']['id'], false ) . '>' . esc_html( $page->post_title ) . ' ';
- }
+ if($this->in_network_context){
+ echo '
+
+
+
' . __( 'Page redirect not available in network context', 'cookie-notice' ) . '
+
';
}
+ else{
+ echo '
+
+
+ ' . __( '-- select page --', 'cookie-notice' ) . ' ';
+
+ if ( $pages ) {
+ foreach ( $pages as $page ) {
+ echo '
+ ID, $options['general']['see_more_opt']['id'], false ) . '>' . esc_html( $page->post_title ) . ' ';
+ }
+ }
+ echo '
+
+
' . __( 'Select from one of your site\'s pages', 'cookie-notice' ) . '
+
';
+ }
echo '
-
-
' . __( 'Select from one of your site\'s pages', 'cookie-notice' ) . '
-
-
options['general']['see_more_opt']['link_type'] === 'page' ? ' style="display: none;"' : '') . '>
-
+
+
';
}
@@ -435,12 +565,13 @@ public function cn_see_more() {
* Link target option.
*/
public function cn_link_target() {
+ $options = $this->in_network_context ? $this->network_options : $this->options;
echo '
';
foreach ( $this->link_target as $target ) {
- echo 'options['general']['link_target'] ) . '>' . esc_html( $target ) . ' ';
+ echo '' . esc_html( $target ) . ' ';
}
echo '
@@ -453,6 +584,7 @@ public function cn_link_target() {
* Expiration time option.
*/
public function cn_time() {
+ $options = $this->in_network_context ? $this->network_options : $this->options;
echo '
';
@@ -460,7 +592,7 @@ public function cn_time() {
foreach ( $this->times as $time => $arr ) {
$time = esc_attr( $time );
- echo 'options['general']['time'] ) . '>' . esc_html( $arr[0] ) . ' ';
+ echo '' . esc_html( $arr[0] ) . ' ';
}
echo '
@@ -560,7 +692,7 @@ public function cn_css_style() {
public function cn_colors() {
echo '
';
-
+
foreach ( $this->colors as $value => $label ) {
$value = esc_attr( $value );
@@ -569,14 +701,14 @@ public function cn_colors() {
' .
'
';
}
-
+
echo '
';
}
/**
* Validate options.
- *
+ *
* @param array $input
* @return array
*/
@@ -584,7 +716,7 @@ public function validate_options( $input ) {
if ( ! check_admin_referer( 'cookie_notice_options-options') )
return $input;
-
+
if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) )
return $input;
@@ -618,10 +750,10 @@ public function validate_options( $input ) {
// hide effect
$input['hide_effect'] = sanitize_text_field( isset( $input['hide_effect'] ) && in_array( $input['hide_effect'], array_keys( $this->effects ) ) ? $input['hide_effect'] : $this->defaults['general']['hide_effect'] );
-
+
// on scroll
$input['on_scroll'] = (bool) isset( $input['on_scroll'] ) ? 'yes' : 'no';
-
+
// on scroll offset
$input['on_scroll_offset'] = absint( isset( $input['on_scroll_offset'] ) && $input['on_scroll_offset'] !== '' ? $input['on_scroll_offset'] : $this->defaults['general']['on_scroll_offset'] );
@@ -651,11 +783,12 @@ public function validate_options( $input ) {
do_action( 'wpml_register_single_string', 'Cookie Notice', 'Custom link', $input['see_more_opt']['link'] );
}
} elseif ( isset( $_POST['reset_cookie_notice_options'] ) ) {
-
- $input = $this->defaults['general'];
+
+ $input = $this->is_network ? $this->network_options['general'] : $this->defaults['general'];
+
add_settings_error( 'reset_cookie_notice_options', 'reset_cookie_notice_options', __( 'Settings restored to defaults.', 'cookie-notice' ), 'updated' );
-
+
}
return $input;
@@ -663,7 +796,7 @@ public function validate_options( $input ) {
/**
* Cookie notice output.
- *
+ *
* @return mixed
*/
public function add_cookie_notice() {
@@ -702,13 +835,21 @@ public function add_cookie_notice() {
'link_target' => $this->options['general']['link_target'],
) );
+ $see_more_url = '#';
+ if($options['see_more_opt']['link_type'] === 'custom'){
+ $see_more_url = $options['see_more_opt']['link'];
+ } elseif($options['see_more_opt']['link_type'] === 'page'){
+ $see_more_url = get_permalink( $options['see_more_opt']['id'] );
+ } elseif($options['see_more_opt']['link_type'] === 'legacy'){
+ $see_more_url = get_privacy_policy_url();
+ }
// message output
$output = '
';
@@ -718,7 +859,7 @@ public function add_cookie_notice() {
/**
* Checks if cookie is setted
- *
+ *
* @return bool
*/
public function cookie_setted() {
@@ -727,7 +868,7 @@ public function cookie_setted() {
/**
* Checks if third party non functional cookies are accepted
- *
+ *
* @return bool
*/
public static function cookies_accepted() {
@@ -740,10 +881,10 @@ public static function cookies_accepted() {
public function get_defaults() {
return $this->defaults;
}
-
+
/**
* Add links to Support Forum.
- *
+ *
* @param array $links
* @param string $file
* @return array
@@ -762,7 +903,7 @@ public function plugin_extend_links( $links, $file ) {
/**
* Add links to settings page.
- *
+ *
* @param array $links
* @param string $file
* @return array
@@ -805,7 +946,7 @@ public function admin_load_scripts_styles( $page ) {
wp_enqueue_script(
'cookie-notice-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery', 'wp-color-picker' ), $this->defaults['version']
);
-
+
wp_localize_script(
'cookie-notice-admin', 'cnArgs', array(
'resetToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'cookie-notice' )
@@ -842,15 +983,15 @@ public function front_load_scripts_styles() {
wp_enqueue_style( 'cookie-notice-front', plugins_url( 'css/front.css', __FILE__ ) );
}
}
-
+
/**
* Print non functional javascript.
- *
+ *
* @return mixed
*/
public function wp_print_footer_scripts() {
$scripts = html_entity_decode( trim( wp_kses_post( $this->options['general']['refuse_code'] ) ) );
-
+
if ( $this->cookie_setted() && ! empty( $scripts ) ) {
?>