false, // iubenda_parse 'skip_parsing' => true, // skip_parsing 'ctype' => true, // iubenda_ctype 'parse' => false, // iubenda_parse 'parser_engine' => 'new', // parser_engine 'output_feed' => true, // iubenda_output_feed 'code_default' => false, // iubenda-code-default, 'menu_position' => 'topmenu', 'custom_scripts' => array(), 'custom_iframes' => array(), 'deactivation' => false ); public $version = '1.15.5'; public $no_html = false; public $links = array(); public $multilang = false; public $languages = array(); public $lang_default = ''; /** * Class constructor. */ public function __construct() { register_activation_hook( __FILE__, array( $this, 'activation' ) ); register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) ); // settings $this->options = array_merge( $this->defaults, (array) get_option( 'iubenda_cookie_law_solution', $this->defaults ) ); // actions add_action( 'admin_init', array( $this, 'register_options' ) ); add_action( 'admin_init', array( $this, 'update_plugin' ), 9 ); add_action( 'admin_init', array( $this, 'admin_page_redirect' ), 20 ); add_action( 'admin_menu', array( $this, 'admin_menu_options' ) ); add_action( 'admin_notices', array( $this, 'settings_errors' ) ); add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); add_action( 'plugins_loaded', array( $this, 'init' ) ); add_action( 'after_setup_theme', array( $this, 'register_shortcode' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); add_action( 'admin_print_styles', array( $this, 'admin_print_styles' ) ); add_action( 'wp_head', array( $this, 'wp_head' ), 99 ); add_action( 'template_redirect', array( $this, 'output_start' ), 0 ); add_action( 'shutdown', array( $this, 'output_end' ), 100 ); } /** * Initialize plugin. * * @return void */ public function init() { // check if WPML or Polylang is active include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Polylang support if ( ( is_plugin_active( 'polylang/polylang.php' ) || is_plugin_active( 'polylang-pro/polylang.php' ) ) && function_exists( 'PLL' ) ) { $this->multilang = true; // get registered languages $registered_languages = PLL()->model->get_languages_list(); if ( ! empty( $registered_languages ) ) { foreach ( $registered_languages as $language ) $this->languages[$language->slug] = $language->name; } // get default language $this->lang_default = pll_default_language(); // WPML support } elseif ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && class_exists( 'SitePress' ) ) { $this->multilang = true; global $sitepress; // get registered languages $registered_languages = icl_get_languages(); if ( ! empty( $registered_languages ) ) { foreach ( $registered_languages as $language ) $this->languages[$language['code']] = $language['display_name']; } // get default language $this->lang_default = $sitepress->get_default_language(); } // load iubenda parser require_once( dirname( __FILE__ ) . '/iubenda-cookie-class/iubenda.class.php' ); $links = array( 'en' => array( 'guide' => 'https://www.iubenda.com/en/iubenda-cookie-law-solution', 'plugin_page' => 'https://www.iubenda.com/en/help/posts/1215', 'generating_code' => 'https://www.iubenda.com/en/help/posts/1177', 'support_forum' => 'https://support.iubenda.com/forums/314835-general/suggestions/9670701-discussion-regarding-the-iubenda-cookie-law-soluti', 'documentation' => 'https://www.iubenda.com/en/help/posts/1215' ), 'it' => array( 'guide' => 'https://www.iubenda.com/it/soluzione-cookie-law', 'plugin_page' => 'https://www.iubenda.com/it/help/posts/810', 'generating_code' => 'https://www.iubenda.com/it/help/posts/680', 'support_forum' => 'https://support.iubenda.com/forums/314835-general/suggestions/9670701-discussion-regarding-the-iubenda-cookie-law-soluti', 'documentation' => 'https://www.iubenda.com/it/help/posts/810', ) ); $locale = explode( '_', get_locale() ); $locale_code = $locale[0]; // assign links $this->links = in_array( $locale_code, array_keys( $links ) ) ? $links[$locale_code] : $links['en']; } /** * Plugin activation. * * @return void */ public function activation() { add_option( 'iubenda_cookie_law_solution', $this->options, '', 'no' ); add_option( 'iubenda_cookie_law_version', $this->version, '', 'no' ); } /** * Plugin deactivation. * * @return void */ public function deactivation() { // remove options from database? if ( $this->options['deactivation'] ) { delete_option( 'iubenda_cookie_law_solution' ); delete_option( 'iubenda_cookie_law_version' ); } } /** * Plugin options migration for versions < 1.14.0 * * @return void */ public function update_plugin() { if ( ! current_user_can( 'install_plugins' ) ) return; $db_version = get_option( 'iubenda_cookie_law_version' ); $db_version = ! $db_version ? '1.13.0' : $db_version; if ( $db_version != false ) { if ( version_compare( $db_version, '1.14.0', '<' ) ) { $options = array(); $old_new = array( 'iubenda_parse' => 'parse', 'skip_parsing' => 'skip_parsing', 'iubenda_ctype' => 'ctype', 'iubenda_parse' => 'parse', 'parser_engine' => 'parser_engine', 'iubenda_output_feed' => 'output_feed', 'iubenda-code-default' => 'code_default', 'default_skip_parsing' => '', 'default_iubendactype' => '', 'default_iubendaparse' => '', 'default_parser_engine' => '', 'iub_code' => '', ); foreach ( $old_new as $old => $new ) { if ( $new ) { $options[$new] = get_option( $old ); } delete_option( $old ); } // multilang support if ( ! empty( $this->languages ) ) { foreach ( $this->languages as $lang ) { $code = get_option( 'iubenda-code-' . $lang ); if ( ! empty( $code ) ) { $options['code_' . $lang] = $code; delete_option( 'iubenda-code-' . $lang ); } } } add_option( 'iubenda_cookie_law_solution', $options, '', 'no' ); add_option( 'iubenda_cookie_law_version', $this->version, '', 'no' ); } } } /** * Register shortcode function. * * @return void */ public function register_shortcode() { add_shortcode( 'iub-cookie-policy', array( $this, 'shortcode' ) ); } /** * Handle shortcode function. * * @param array $atts * @param mixed $content * @return mixed */ public function shortcode( $atts, $content = '' ) { return '' . do_shortcode( $content ) . ''; } /** * Add submenu. * * @return void */ public function admin_menu_options() { if ( $this->options['menu_position'] === 'submenu' ) { // sub menu add_submenu_page( 'options-general.php', 'iubenda', 'iubenda', apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ), 'iubenda-cookie-law-solution', array( $this, 'options_page' ), 'none' ); } else { // top menu add_menu_page( 'iubenda', 'iubenda', apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ), 'iubenda-cookie-law-solution', array( $this, 'options_page' ), 'none' ); } } /** * Load textdomain. * * @return void */ public function load_textdomain() { load_plugin_textdomain( 'iubenda-cookie-law-solution', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } /** * Load admin scripts and styles. * * @param string $page * @return void */ public function admin_enqueue_scripts( $page ) { if ( ! in_array( $page, array( 'toplevel_page_iubenda-cookie-law-solution', 'settings_page_iubenda-cookie-law-solution' ) ) ) return; wp_enqueue_script( 'iubenda-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ) ); wp_enqueue_style( 'iubenda-admin', plugins_url( 'css/admin.css', __FILE__ ) ); } /** * Load admin style inline, for menu icon only. * * @return mixed */ public function admin_print_styles() { echo ' '; } /** * Redirect to the correct urle after switching menu position. * * @global string $pagenow * @return void */ public function admin_page_redirect() { if ( ! empty( $_GET['settings-updated'] ) && ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'iubenda-cookie-law-solution' ) ) ) { global $pagenow; // no redirect by default $redirect_to = false; if ( $this->options['menu_position'] === 'submenu' && $pagenow === 'admin.php' ) { // sub menu $redirect_to = admin_url( 'options-general.php?page=iubenda-cookie-law-solution' ); } elseif ( $this->options['menu_position'] === 'topmenu' && $pagenow === 'options-general.php' ) { // top menu $redirect_to = admin_url( 'admin.php?page=iubenda-cookie-law-solution' ); } if ( $redirect_to ) { // make sure it's current host location wp_safe_redirect( add_query_arg( 'settings-updated', true, $redirect_to ) ); exit; } } } /** * Add wp_head content. * * @return void */ public function wp_head() { // break on admin side if ( is_admin() ) return; // check content type if ( (bool) $this->options['ctype'] == true ) { $iub_headers = headers_list(); $destroy = true; foreach ( $iub_headers as $header ) { if ( strpos( $header, "Content-Type: text/html" ) !== false || strpos( $header, "Content-type: text/html" ) !== false ) { $destroy = false; break; } } if ( $destroy ) $this->no_html = true; } // is post or not html content type? if ( $_POST || $this->no_html ) return; // initial head output $iubenda_code = ""; if ( $this->multilang === true && defined( 'ICL_LANGUAGE_CODE' ) && isset( $this->options['code_' . ICL_LANGUAGE_CODE] ) ) { $iubenda_code .= $this->options['code_' . ICL_LANGUAGE_CODE]; // no code for current language, use default if ( ! $iubenda_code ) $iubenda_code .= $this->options['code_default']; } else $iubenda_code .= $this->options['code_default']; $iubenda_code = trim( $iubenda_code ); if ( $iubenda_code !== '' ) { $iubenda_code .= "\n "; echo $iubenda_code; } } /** * Initialize html output. * * @return void */ public function output_start() { if ( ! is_admin() ) ob_start( array( $this, 'output_callback' ) ); } /** * Finish html output. * * @return void */ public function output_end() { if ( ! is_admin() && ob_get_level() ) ob_end_flush(); } /** * Handle final html output. * * @param mixed $output * @return mixed */ public function output_callback( $output ) { // check whether to run parser or not // bail on ajax, xmlrpc or iub_no_parse request if ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_SERVER["HTTP_X_REQUESTED_WITH"] ) || isset( $_GET['iub_no_parse'] ) ) return $output; // bail on admin side if ( is_admin() ) return $output; // bail on rss feed if ( is_feed() && $this->options['output_feed'] ) return $output; if ( strpos( $output, " 200 ) return $output; // bail if skripts blocking disabled if ( ! $this->options['parse'] ) return $output; // bail if consent given and skip parsing enabled if ( iubendaParser::consent_given() && $this->options['skip_parsing'] ) return $output; // bail if bot detectd, no html in output or it's a post request if ( iubendaParser::bot_detected() || $_POST || $this->no_html ) return $output; $startime = microtime( true ); $output = apply_filters( 'iubenda_initial_output', $output ); // experimental class if ( $this->options['parser_engine'] == 'new' ) { $iubenda = new iubendaParser( mb_convert_encoding( $output, 'HTML-ENTITIES', 'UTF-8' ), array( 'type' => 'faster', 'scripts' => $this->options['custom_scripts'], 'iframes' => $this->options['custom_iframes'] ) ); // render output $output = $iubenda->parse(); // append signature $output .= ''; // default class } else { $iubenda = new iubendaParser( $output, array( 'type' => 'page', 'scripts' => $this->options['custom_scripts'], 'iframes' => $this->options['custom_iframes'] ) ); // render output $output = $iubenda->parse(); // append signature $output .= ''; } return apply_filters( 'iubenda_final_output', $output ); } /** * Register plugin options. * * @return void */ public function register_options() { register_setting( 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution', array( $this, 'save_options' ) ); add_settings_section( 'iubenda_cookie_law_solution', '', '', 'iubenda_cookie_law_solution' ); add_settings_field( 'iub_code', __( 'Code', 'iubenda-cookie-law-solution' ), array( $this, 'iub_code' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' ); add_settings_field( 'iub_parse', __( 'Scripts blocking', 'iubenda-cookie-law-solution' ), array( $this, 'iub_parse' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' ); add_settings_field( 'iub_custom_scripts', __( 'Custom scripts', 'iubenda-cookie-law-solution' ), array( $this, 'iub_custom_scripts' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' ); add_settings_field( 'iub_ctype', __( 'Content type', 'iubenda-cookie-law-solution' ), array( $this, 'iub_ctype' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' ); add_settings_field( 'iub_output_feed', __( 'RSS feed', 'iubenda-cookie-law-solution' ), array( $this, 'iub_output_feed' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' ); add_settings_field( 'iub_menu_position', __( 'Menu position', 'iubenda-cookie-law-solution' ), array( $this, 'iub_menu_position' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' ); add_settings_field( 'iub_deactivation', __( 'Deactivation', 'iubenda-cookie-law-solution' ), array( $this, 'iub_deactivation' ), 'iubenda_cookie_law_solution', 'iubenda_cookie_law_solution' ); } /** * 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' ) settings_errors( 'iub_settings_errors' ); } /** * Code option. * * @return mixed */ public function iub_code() { // multilang support if ( $this->multilang && ! empty( $this->languages ) ) { echo ' '; } else { echo '

' . __( 'Enter the iubenda code.', 'iubenda-cookie-law-solution' ) . '

'; } } /** * Custom scripts option. * * @return void */ public function iub_custom_scripts() { echo ' '; } /** * Parsing option. * * @return mixed */ public function iub_parse() { echo '

' . '(' . sprintf( __( "see our documentation for the list of detected scripts.", 'iubenda-cookie-law-solution' ), $this->links['documentation'] ) . ')' . '

options['parse'] === false ? ' style="display: none;"' : '' ) . '>

' . __( 'Select parsing engine.', 'iubenda-cookie-law-solution' ) . '

(' . __( "improves performance, highly recommended, to be deactivated only if your site uses a caching system", 'iubenda-cookie-law-solution' ) . ')

'; } /** * Ctype option. * * @return mixed */ public function iub_ctype() { echo '
'; } /** * RSS feed option. * * @return mixed */ public function iub_output_feed() { echo '
'; } /** * Menu option. * * @return mixed */ public function iub_menu_position() { echo '

' . __( 'Select whether to display iubenda in a top admin menu or the Settings submenu.', 'iubenda-cookie-law-solution' ) . '

'; } /** * Deactivation option. * * @return mixed */ public function iub_deactivation() { echo '
'; } /** * Save options. * * @return void */ public function save_options( $input ) { if ( ! current_user_can( apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ) ) ) return $input; // save options if ( isset( $_POST['save_iubenda_options'] ) ) { $input['parse'] = (bool) isset( $input['parse'] ); $input['parser_engine'] = isset( $input['parser_engine'] ) && in_array( $input['parser_engine'], array( 'default', 'new' ) ) ? $input['parser_engine'] : $this->defaults['parser_engine']; $input['skip_parsing'] = (bool) isset( $input['skip_parsing'] ); $input['ctype'] = (bool) isset( $input['ctype'] ); $input['output_feed'] = (bool) isset( $input['output_feed'] ); $input['menu_position'] = isset( $input['menu_position'] ) && in_array( $input['menu_position'], array( 'topmenu', 'submenu' ) ) ? $input['menu_position'] : $this->defaults['menu_position']; $input['deactivation'] = (bool) isset( $input['deactivation'] ); // multilang support if ( $this->multilang && ! empty( $this->languages ) ) { foreach ( $this->languages as $lang_id => $lang_name ) { $input['code_' . $lang_id] = ! empty( $input['code_' . $lang_id] ) ? wp_kses( $input['code_' . $lang_id], $this->get_allowed_html() ) : ''; // handle default lang too if ( $lang_id == $this->lang_default ) { $input['code_default'] = ! empty( $input['code_' . $lang_id] ) ? wp_kses( $input['code_' . $lang_id], $this->get_allowed_html() ) : $this->options['code_default']; } } } else { $input['code_default'] = ! empty( $input['code_default'] ) ? wp_kses( $input['code_default'], $this->get_allowed_html() ) : ''; } // scripts if ( isset( $input['custom_scripts'] ) ) { $input['custom_scripts'] = trim( $input['custom_scripts'] ); if ( ! empty( $input['custom_scripts'] ) ) $input['custom_scripts'] = array_map( 'trim', explode( "\n", str_replace( "\r", '', $input['custom_scripts'] ) ) ); else $input['custom_scripts'] = array(); } else $input['custom_scripts'] = array(); // iframes if ( isset( $input['custom_iframes'] ) ) { $input['custom_iframes'] = trim( $input['custom_iframes'] ); if ( ! empty( $input['custom_iframes'] ) ) $input['custom_iframes'] = array_map( 'trim', explode( "\n", str_replace( "\r", '', $input['custom_iframes'] ) ) ); else $input['custom_iframes'] = array(); } else $input['custom_iframes'] = array(); add_settings_error( 'iub_settings_errors', 'iub_settings_updated', __( 'Settings saved.', 'iubenda-cookie-law-solution' ), 'updated' ); // reset options } elseif ( isset( $_POST['reset_iubenda_options'] ) ) { $input = $this->defaults; // multilang support if ( $this->multilang && ! empty( $this->languages ) ) { foreach ( $this->languages as $lang_id => $lang_name ) { $input['code_' . $lang_id] = ''; } } add_settings_error( 'iub_settings_errors', 'iub_settings_restored', __( 'Settings restored to defaults.', 'iubenda-cookie-law-solution' ), 'updated' ); } return $input; } /** * Get allowed iubenda script HTML. * * @return array */ public function get_allowed_html() { return apply_filters( 'iub_code_allowed_html', array_merge( wp_kses_allowed_html( 'post' ), array( 'script' => array( 'type' => array(), 'src' => array(), 'charset' => array(), 'async' => array() ), 'noscript' => array(), 'style' => array( 'type' => array() ), 'iframe' => array( 'src' => array(), 'height' => array(), 'width' => array(), 'frameborder' => array(), 'allowfullscreen' => array() ) ) ) ); } /** * Load admin options page. * * @return void */ public function options_page() { if ( ! current_user_can( apply_filters( 'iubenda_cookie_law_cap', 'manage_options' ) ) ) { wp_die( __( "You don't have permission to access this page.", 'iubenda-cookie-law-solution' ) ); } ?>

' . __( "This plugin is the easiest and most comprehensive way to adapt your WordPress site to the European cookie law. Upon your user's first visit, the plugin will take care of collecting their consent, of blocking the most popular among the scripts that install cookies and subsequently reactivate these scripts as soon as consent is provided. The basic settings include obtaining consent by a simple scroll action (the most effective method) and script reactivation without refreshing the page.", 'iubenda-cookie-law-solution' ) . '

' . __( "Would you like to know more about the cookie law?", 'iubenda-cookie-law-solution' ) . '
' . sprintf( __( "Read our complete guide to the cookie law.", 'iubenda-cookie-law-solution' ), $this->links['guide'] ) . '

' . __( "What is the full functionality of the plugin?", 'iubenda-cookie-law-solution' ) . '
' . sprintf( __( "Visit our plugin page.", 'iubenda-cookie-law-solution' ), $this->links['plugin_page'] ) . '

' . __( "Enter the iubenda code for the Cookie Solution below.", 'iubenda-cookie-law-solution' ) . '
' . sprintf( __( "In order to run the plugin, you need to enter the iubenda code that activates the cookie law banner and the cookie policy in the form below. This code can be generated on www.iubenda.com, following this guide.", 'iubenda-cookie-law-solution' ), $this->links['generating_code'] ) . '

'; ?>
'; submit_button( '', 'primary', 'save_iubenda_options', false ); echo ' '; submit_button( __( 'Reset to defaults', 'iubenda-cookie-law-solution' ), 'secondary', 'reset_iubenda_options', false ); echo '

'; ?>
' . __( 'Need support for this plugin?', 'iubenda-cookie-law-solution' ) . '
' . sprintf( __( "Visit our support forum.", 'iubenda-cookie-law-solution' ), $this->links['support_forum'] ) . '

' . __( 'Want to try a beta version of this plugin with the latest features?', 'iubenda-cookie-law-solution' ) . '
' . sprintf( __( "Visit our documentation pages and follow the instructions to install a beta version.", 'iubenda-cookie-law-solution' ), $this->links['documentation'] ) . '

'; ?>