esc_html( $db_options['theme'] ), 'position' => esc_html( $db_options['position'] ), 'back_color' => esc_html( $db_options['back_color'] ), 'text_color' => esc_html( $db_options['text_color'] ), 'message' => esc_html( $db_options['message'] ), 'show_link' => esc_html( $db_options['show_link'] ), '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'] ), 'expiry' => esc_html( $db_options['expiry'] ), ); wp_localize_script( 'main', 'cookie_panel', $vars ); } ////////////// // Back-end // ////////////// if( is_admin() ) { add_action('init', 'asd_cookie_update_options'); add_action('admin_menu', 'asd_cookie_add_page'); add_action('admin_init', 'asd_cookie_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') ); } // Add options 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; add_options_page( $page_title, $menu_title, $capability, $slug, $callback, $icon, $position ); } // load template page function asd_cookie_template() { include('includes/config.php'); } // Init settings 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, '', '', 'asd-cookie-consent' ); add_settings_field( 'theme', '', 'asd_cookie_input_select', $page, $section, array( 'id' => 'theme', 'value' => esc_attr( $options['theme'] ), 'options' => array( 'block' => esc_attr__('Block', $text_domain), 'edgeless' => esc_attr__('Edgeless', $text_domain), 'classic' => esc_attr__('Classic', $text_domain) ) ) ); add_settings_field( 'position', '', 'asd_cookie_input_select', $page, $section, array( 'id' => 'position', 'value' => esc_attr( $options['position'] ), 'options' => array( 'top' => esc_attr__('Top', $text_domain), 'bottom' => esc_attr__('Bottom', $text_domain), 'bottom-left' => esc_attr__('Bottom left', $text_domain), 'bottom-right' => esc_attr__('Bottom right', $text_domain) ) ) ); add_settings_field( 'back_color', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'back_color', 'value' => esc_attr( $options['back_color'] ), 'type' => 'color' ) ); add_settings_field( 'text_color', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'text_color', 'value' => esc_attr( $options['text_color'] ), 'type' => 'color' ) ); add_settings_field( 'message', '', 'asd_cookie_textarea', $page, $section, array( 'id' => 'message', 'value' => esc_attr( $options['message'] ) ) ); add_settings_field( 'show_link', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'show_link1', 'id_2' => 'show_link2', 'name' => 'show_link', 'value' => esc_attr( $options['show_link'] ), 'type' => 'radio' ) ); add_settings_field( 'text_cookie_info', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'text_cookie_info', 'value' => esc_attr( $options['text_cookie_info'] ), 'type' => 'text' ) ); add_settings_field( 'href_cookie_info', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'href_cookie_info', 'value' => esc_url($options['href_cookie_info']), 'type' => 'text' ) ); add_settings_field( 'btn_text', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'btn_text', 'value' => esc_attr( $options['btn_text'] ), 'type' => 'text' ) ); add_settings_field( 'btn_color', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'btn_color', 'value' => esc_attr( $options['btn_color'] ), 'type' => 'color' ) ); add_settings_field( 'btn_text_color', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'btn_text_color', 'value' => esc_attr( $options['btn_text_color'] ), 'type' => 'color' ) ); add_settings_field( 'expiry', '', 'asd_cookie_input_text', $page, $section, array( 'id' => 'expiry', 'value' => esc_attr( $options['expiry'] ), 'type' => 'number' ) ); register_setting( $section, 'theme' ); register_setting( $section, 'position' ); register_setting( $section, 'back_color' ); register_setting( $section, 'text_color' ); register_setting( $section, 'message' ); register_setting( $section, 'show_link' ); 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, 'expiry' ); } // 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 .= ''; } echo $html; } // render textarea function asd_cookie_textarea($args) { $html = '