esc_html( $db_options['position'] ), 'back_color' => esc_html( $db_options['back_color'] ), 'text_color' => esc_html( $db_options['text_color'] ), 'title' => esc_html( $db_options['title'] ), 'sub_title' => esc_html( $db_options['sub_title'] ), 'message' => esc_html( $db_options['message'] ), 'title_font_size' => esc_html( $db_options['title_font_size'] ), 'text_font_size' => esc_html( $db_options['text_font_size'] ), 'text_cookie_info' => esc_html( $db_options['text_cookie_info'] ), 'href_cookie_info' => esc_url( $db_options['href_cookie_info'] ), 'btn_color' => esc_html( $db_options['btn_color'] ), 'btn_text_color' => esc_html( $db_options['btn_text_color'] ), 'btn_text' => esc_html( $db_options['btn_text'] ), 'pref_btn_text' => esc_html( $db_options['pref_btn_text'] ), 'pref_btn_color' => esc_html( $db_options['pref_btn_color'] ), 'pref_btn_text_color'=> esc_html( $db_options['pref_btn_text_color'] ), 'expiry' => esc_html( $db_options['expiry'] ), 'essential' => __( 'Essential', 'asd-cookie-consent' ), 'preferences' => __( 'Preferences', 'asd-cookie-consent' ), 'analytics' => __( 'Analytics', 'asd-cookie-consent' ), 'marketing' => __( 'Marketing', 'asd-cookie-consent' ), ); wp_localize_script( 'main', 'cookie_panel', $vars ); wp_localize_script( 'main', 'ajaxData', array( 'url' => admin_url('admin-ajax.php'), 'action' => 'asd_cookie_prefs_set', 'nonce' => wp_create_nonce( 'asd_cookie_prefs_set' ) ) ); } add_action('wp_loaded', 'asd_cookie_setting'); // Check prefs & delete cookies from browser function asd_cookie_setting() { if( ! isset( $_COOKIE['asd-cookie-consent-prefs'] ) ) { return; } $pref_cookies_cat= explode(',', $_COOKIE['asd-cookie-consent-prefs']); $cookies_cat= array(); $cookies= ''; foreach ($pref_cookies_cat as $cat) { if( $cat !== NULL ) { array_push($cookies_cat, preg_replace('/[^A-Za-z0-9\-]/', '', $cat)); } } if( !in_array('preferences', $cookies_cat) ) { $cookie_var= get_option('asd_cookie_consent_category')['preferences'] . ','; $cookies .= $cookie_var; } if( !in_array('analytics', $cookies_cat) ) { $cookie_var= get_option('asd_cookie_consent_category')['analytics'] . ','; $cookies .= $cookie_var; } if( !in_array('marketing', $cookies_cat) ) { $cookie_var= get_option('asd_cookie_consent_category')['marketing'] . ','; $cookies .= $cookie_var; } $cookie_list= explode(',', $cookies); foreach ($cookie_list as $cookie) { $cookie_name= trim( $cookie ); if( isset($_COOKIE[$cookie_name]) ) { unset( $_COOKIE[$cookie_name] ); setcookie($cookie_name, null, -1, '/'); } } } add_action( 'wp_footer', 'asd_cookie_open_panel' ); // Footer link open panel cookie function asd_cookie_open_panel() { $db_options= get_option('asd_cookie_consent'); $text_color= esc_html( $db_options['open_btn_text_color'] ); $background= esc_html( $db_options['open_background_color'] ); $position= esc_html( $db_options['open_btn_position'] ); $html = '
'; echo $html; } /** * Back-end */ if( is_admin() ) { // Request init add_action('init', 'asd_cookie_update_options'); // Theme & Color setting Tab add_action('admin_menu', 'asd_cookie_add_page'); add_action('admin_init', 'asd_cookie_init'); // Category cookie tab add_action('admin_menu', 'asd_cookie_cat_add_page'); add_action('admin_init', 'asd_cookie_cat_init'); load_plugin_textdomain( 'asd-cookie-consent', false, 'asd-cookie-consent/languages' ); $plugin_info= array( 'name' => __('ASD Cookie Consent', 'asd-cookie-consent'), 'description' => __('Add cookie consent to your WordPress installation', 'asd-cookie-consent') ); } /* load template page for all pages (tabs) */ function asd_cookie_template() { include('includes/config.php'); } /** * Color & text option page */ function asd_cookie_add_page() { $page_title= esc_html__('Settings ASD Cookie Consent', 'asd-cookie-consent'); $menu_title= esc_html__('ASDCookieConsent', 'asd-cookie-consent'); $capability= 'manage_options'; $slug= 'asd-cookie-consent'; $callback= 'asd_cookie_template'; $icon= ''; $position= null; $main_menu= add_options_page( $page_title, $menu_title, $capability, $slug, $callback, $icon, $position ); } function asd_cookie_init() { // create options page $page= 'asd-cookie-consent'; $section= 'general_setting'; $options= get_option('asd_cookie_consent'); $text_domain= 'asd-cookie-consent'; add_settings_section( $section, esc_html__( 'Panel position and text setting', $text_domain ), '', 'asd-cookie-consent' ); asd_title_section_style(); // Widget Position add_settings_field( 'position', '', 'asd_cookie_input_select', $page, $section, array( 'id' => 'position', 'value' => esc_attr( $options['position'] ), 'options' => array( 'bottom-left' => esc_attr__('Bottom left', $text_domain), 'bottom-right' => esc_attr__('Bottom right', $text_domain) ) ) ); // Title add_settings_field( 'title', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'title', 'value' => esc_attr( $options['title'] ), 'type' => 'text' ) ); // Subtitle add_settings_field( 'sub_title', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'sub_title', 'value' => esc_attr( $options['sub_title'] ) , 'type' => 'text' ) ); // Message add_settings_field( 'message', '', 'asd_cookie_textarea', $page, $section, array( 'id' => 'message', 'value' => esc_attr( $options['message'] ) ) ); // Expiry add_settings_field( 'expiry', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'expiry', 'value' => esc_attr( $options['expiry'] ), 'type' => 'number', 'help_text' => esc_html__( 'Set preferences cookie expiry days (days)', $text_domain ) ) ); add_settings_section( 'font_size_section', esc_html__( 'Font size setting', $text_domain ), '', 'asd-cookie-consent' ); // Title font size add_settings_field( 'title_font_size', '', 'asd_cookie_input_text', $page, 'font_size_section', array( 'id' => 'title_font_size', 'value' => esc_attr( $options['title_font_size'] ), 'type' => 'number', 'help_text' => esc_html__( 'Set title and subtitle font size (px)', $text_domain ) ) ); // Message & other text font size add_settings_field( 'text_font_size', '', 'asd_cookie_input_text', $page, 'font_size_section', array( 'id' => 'text_font_size', 'value' => esc_attr( $options['text_font_size'] ), 'type' => 'number', 'help_text' => esc_html__( 'Set message, paragraph and text button font size (px)', $text_domain ) ) ); add_settings_section( 'panel_color_section', esc_html__( 'Panel colors', $text_domain ), '', 'asd-cookie-consent' ); // Background color add_settings_field( 'back_color', '', 'asd_cookie_input_text', $page, 'panel_color_section', array( 'id' => 'back_color', 'value' => esc_attr( $options['back_color'] ), 'type' => 'color' ) ); // Text color add_settings_field( 'text_color', '', 'asd_cookie_input_text', $page, 'panel_color_section', array( 'id' => 'text_color', 'value' => esc_attr( $options['text_color'] ), 'type' => 'color' ) ); add_settings_section( 'privacy_page_section', esc_html__( 'Privacy page', $text_domain ), '', 'asd-cookie-consent' ); // Text cookie privacy page add_settings_field( 'text_cookie_info', '', 'asd_cookie_input_text', $page, 'privacy_page_section', array( 'id' => 'text_cookie_info', 'value' => esc_attr( $options['text_cookie_info'] ), 'type' => 'text', 'help_text' => esc_html__( 'Setting text for your cookie-privacy page', $text_domain ) ) ); // Link cookie privacy page add_settings_field( 'href_cookie_info', '', 'asd_cookie_input_text', $page, 'privacy_page_section', array( 'id' => 'href_cookie_info', 'value' => esc_url($options['href_cookie_info']), 'type' => 'text', 'help_text' => esc_html__( 'Setting link to your cookie-privacy page', $text_domain ) ) ); add_settings_section( 'confirm_button_section', esc_html__( 'Confirm button setting', $text_domain ), '', 'asd-cookie-consent' ); // Accept Button Text add_settings_field( 'btn_text', '', 'asd_cookie_input_text', $page, 'confirm_button_section', array( 'id' => 'btn_text', 'value' => esc_attr( $options['btn_text'] ), 'type' => 'text' ) ); // Accept Button color add_settings_field( 'btn_color', '', 'asd_cookie_input_text', $page, 'confirm_button_section', array( 'id' => 'btn_color', 'value' => esc_attr( $options['btn_color'] ), 'type' => 'color' ) ); // Accept Button text color add_settings_field( 'btn_text_color', '', 'asd_cookie_input_text', $page, 'confirm_button_section', array( 'id' => 'btn_text_color', 'value' => esc_attr( $options['btn_text_color'] ), 'type' => 'color' ) ); add_settings_section( 'pref_button_section', esc_html__( 'Preference button setting', $text_domain ), '', 'asd-cookie-consent' ); // Preferences button text add_settings_field( 'pref_btn_text', '', 'asd_cookie_input_text', $page, 'pref_button_section', array( 'id' => 'pref_btn_text', 'value' => esc_attr( $options['pref_btn_text'] ), 'type' => 'text' ) ); // Preferences button color add_settings_field( 'pref_btn_color', '', 'asd_cookie_input_text', $page, 'pref_button_section', array( 'id' => 'pref_btn_color', 'value' => esc_attr( $options['pref_btn_color'] ), 'type' => 'color' ) ); // Preferences button text color add_settings_field( 'pref_btn_text_color', '', 'asd_cookie_input_text', $page, 'pref_button_section', array( 'id' => 'pref_btn_text_color', 'value' => esc_attr( $options['pref_btn_text_color'] ), 'type' => 'color' ) ); add_settings_section( 'panel_open_button_section', esc_html__( 'Panel open button setting', $text_domain ), '', 'asd-cookie-consent' ); // Open button text add_settings_field( 'open_btn_text', '', 'asd_cookie_input_text', $page, 'panel_open_button_section', array( 'id' => 'open_btn_text', 'value' => esc_attr( $options['open_btn_text'] ), 'type' => 'text' ) ); // Open text color add_settings_field( 'open_btn_text_color', '', 'asd_cookie_input_text', $page, 'panel_open_button_section', array( 'id' => 'open_btn_text_color', 'value' => esc_attr( $options['open_btn_text_color'] ), 'type' => 'color' ) ); // Open background add_settings_field( 'open_background_color', '', 'asd_cookie_input_text', $page, 'panel_open_button_section', array( 'id' => 'open_background_color', 'value' => esc_attr( $options['open_background_color'] ), 'type' => 'color' ) ); // Open link position add_settings_field( 'open_btn_position', '', 'asd_cookie_input_select', $page, 'panel_open_button_section', array( 'id' => 'open_btn_position', 'value' => esc_attr( $options['open_btn_position'] ), 'options' => array( 'left' => esc_attr__('Left', $text_domain), 'center'=> esc_attr__('Center', $text_domain), 'right' => esc_attr__('Right', $text_domain) ) ) ); register_setting( $section, 'position' ); register_setting( $section, 'back_color' ); register_setting( $section, 'text_color' ); register_setting( $section, 'title' ); register_setting( $section, 'sub_title' ); register_setting( $section, 'message' ); register_setting( $section, 'title_font_size' ); register_setting( $section, 'text_font_size' ); register_setting( $section, 'text_cookie_info' ); register_setting( $section, 'href_cookie_info' ); register_setting( $section, 'btn_text' ); register_setting( $section, 'btn_color' ); register_setting( $section, 'btn_text_color' ); register_setting( $section, 'pref_btn_text' ); register_setting( $section, 'pref_btn_color' ); register_setting( $section, 'pref_btn_text_color' ); register_setting( $section, 'expiry' ); register_setting( $section, 'open_btn_text' ); register_setting( $section, 'open_btn_text_color' ); register_setting( $section, 'open_btn_position' ); } /** * Cookie category page */ function asd_cookie_cat_add_page() { $page_title= esc_html__( 'Setting ASD Cookie Consent', 'asd-cookie-consent' ); $menu_title= ''; $capability= 'manage_options'; $slug= 'cookie-category'; $callback= 'asd_cookie_template'; $icon= ''; $position= null; add_options_page( $page_title, $menu_title, $capability, $slug, $callback, $icon, $position ); remove_submenu_page( 'options-general.php', $slug ); } function asd_cookie_cat_init() { // create options page $page= 'asd-cookie-category'; $section= 'category_setting'; $options= get_option('asd_cookie_consent_category'); $text_domain= 'asd-cookie-consent'; add_settings_section( $section, esc_html__( 'Cookie category', $text_domain ), 'asd_title_section_style', 'asd-cookie-category' ); // Essential cookie field add_settings_field( 'essential', '', 'asd_cookie_textarea', $page, $section, array( 'id' => 'essential', 'value' => esc_attr( $options['essential'] ), 'help_text' => esc_html__('Essential category cookie list comma separated.', $text_domain) ) ); // Preferences cookie field add_settings_field( 'preferences', '', 'asd_cookie_textarea', $page, $section, array( 'id' => 'preferences', 'value' => esc_attr( $options['preferences'] ) , 'help_text' => esc_html__('Preferences category cookie list comma separated.', $text_domain) ) ); // Analytics cookie field add_settings_field( 'analytics', '', 'asd_cookie_textarea', $page, $section, array( 'id' => 'analytics', 'value' => esc_attr( $options['analytics'] ) , 'help_text' => esc_html__('Analytics category cookie list comma separated.', $text_domain) ) ); // Marketing cookie fiels add_settings_field( 'marketing', '', 'asd_cookie_textarea', $page, $section, array( 'id' => 'marketing', 'value' => esc_attr( $options['marketing'] ), 'help_text' => esc_html__('Marketing category cookie list comma separated.', $text_domain) ) ); register_setting( $section, 'essential' ); register_setting( $section, 'preferences' ); register_setting( $section, 'analytics' ); register_setting( $section, 'marketing' ); } /** * Render component settings */ // render select position input function asd_cookie_input_select($args) { $id= $args['id']; $value= $args['value']; $html= ''; echo $html; } // render input function asd_cookie_input_text($args) { $html = ''; if($args['type'] === 'radio') { if($args['value'] === '1') { $active1= 'checked="checked"'; $active2= ''; } else { $active2= 'checked="checked"'; $active1= ''; } $html = ''; $html .= ''; $html .= ' '; $html .= ''; $html .= ''; } if(isset($args['help_text'])) { $html .= '' . $args['help_text'] . '
'; } echo $html; } // render textarea function asd_cookie_textarea($args) { $html = '