load_db(); $tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'general'; if (isset($_GET['tab']) && !array_key_exists($_GET['tab'], $this->get_tabs())) { $tab = 'general'; } $this->current_tab = $tab; add_action('admin_init', array($this, 'admin_init')); add_action('admin_menu', array($this, 'admin_menu')); add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); add_action('admin_print_scripts', array($this, 'admin_print_scripts')); } /** * Add the Theme Option page */ public function admin_menu() { global $bln_optpage; $bln_optpage = add_theme_page(__('Theme Options', BLN_TEXTDOMAIN), __('Theme options', BLN_TEXTDOMAIN), 'edit_theme_options', 'theme_options', array($this, 'optpage_cb')); } /** * Admin scripts (and style) */ public function admin_scripts($hook) { global $bln_optpage; if ($bln_optpage == $hook) { wp_enqueue_style('bln_admin_css', BLN_URL . '/scripts/admin.css'); switch ($this->current_tab) { case 'slider' : wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-widget'); wp_enqueue_script('jquery-ui-mouse'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('bln_admin_js', BLN_URL . '/scripts/admin-slider.js', array('jquery-ui-sortable')); break; default : wp_enqueue_script('bln_admin_js', BLN_URL . '/scripts/admin-general.js'); } } } /** * Scripts in section of admin pages. */ public function admin_print_scripts() { $options = $this->options; global $bln_optpage; $scr = get_current_screen(); if ($bln_optpage == $scr->id) { $fonts = $this->get_font_stacks(); ?> update_slider_data(); if (isset($_POST['bln-nonce-general']) || isset($_POST['bln-nonce-slider'])) { $this->form_treatment(); $this->redirect(); } if (isset($_SESSION['blueline']['savepost'])) { $_POST = $_SESSION['blueline']['savepost']; unset($_SESSION['blueline']['savepost']); } if (isset($_SESSION['blueline']['notices'])) { $this->admin_notices = $_SESSION['blueline']['notices']; unset($_SESSION['blueline']['notices']); } } /** * Refresh the page after aform submission */ public function redirect() { $_SESSION['blueline']['notices'] = $this->admin_notices; $_SESSION['blueline']['savepost'] = $_POST; $running = $_SERVER['PHP_SELF']; if (!empty($_SERVER['QUERY_STRING'])) { $running .= '?' . $_SERVER['QUERY_STRING']; } wp_redirect($running); die(); } /** * Treatment after form submission */ public function form_treatment() { $options = $this->options; $ref = ($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $tabs = $this->get_tabs(); // general tab if (isset($_POST['bln-nonce-general']) && 1 === wp_verify_nonce($_POST['bln-nonce-general'], 'blueline_general') && false !== stripos($ref, $tabs['general']['url'])) { $sidebar = $this->get_sidebar_pos(); $fonts = $this->get_font_stacks(); if (array_key_exists($_POST['body-font'], $fonts)) { $options['font']['body'] = $_POST['body-font']; } if (array_key_exists($_POST['inputs-font'], $fonts)) { $options['font']['inputs'] = $_POST['inputs-font']; } if (array_key_exists($_POST['code-font'], $fonts)) { $options['font']['code'] = $_POST['code-font']; } if ($_POST['page-comments']) { $options['page_comments'] = true; } else { $options['page_comments'] = false; } if ($_POST['navbar_search']) { $options['navbar_search'] = true; } else { $options['navbar_search'] = false; } if (array_key_exists($_POST['sidebar'], $sidebar)) { $options['sidebar'] = $_POST['sidebar']; } $this->save_db($options); $this->admin_notices[] = array( 'class' => 'updated', 'msg' => __('Theme settings updated', BLN_TEXTDOMAIN), ); } // slider tab if (isset($_POST['bln-nonce-slider']) && 1 === wp_verify_nonce($_POST['bln-nonce-slider'], 'blueline_slider') && false !== stripos($ref, $tabs['slider']['url'])) { if (is_numeric($_POST['timeout'])) { $options['slider']['timeout'] = intval($_POST['timeout']); } if (is_numeric($_POST['speed'])) { $options['slider']['speed'] = intval($_POST['speed']); } $fx = $this->get_slider_effects(); if (array_key_exists($_POST['fx'], $fx)) { $options['slider']['fx'] = $_POST['fx']; } $numerize = function ($number) { return intval($number); }; $slides = (!empty($_POST['order'])) ? array_map($numerize, explode('_', trim($_POST['order'], '_'))) : array(); $options['slider']['slides'] = $slides; $this->save_db($options); $this->admin_notices[] = array( 'class' => 'updated', 'msg' => __('Slider settings updated', BLN_TEXTDOMAIN), ); } } /** * Render the Theme Option page */ public function optpage_cb() { $tabs = $this->get_tabs(); ?>

settings_error(); ?> current_tab]['tpl_path']); ?>
admin_notices as $note) { $css = ($note['class']) ? $note['class'] : 'updated'; ?>

options = $bln_default_options; update_option(BLN_OPTION_NAME, $bln_default_options); } else { if (BLN_VERSION != $options['version']) { $this->options = $this->check_data_structure(); } else { $this->options = $options; } } } /** * Save theme options * * @since 1.0 * @param array $value, the new options */ public function save_db($value) { $this->options = $value; update_option(BLN_OPTION_NAME, $value); } /** * Update theme options * * @since 1.0 */ public function check_data_structure() { /** UPDATE HERE */ $options = get_option(BLN_OPTION_NAME); $options['version'] = BLN_VERSION; update_option(BLN_OPTION_NAME, $options); return $options; } /** * Get theme options */ public function get_theme_options() { return $this->options; } public function get_current_tab() { return $this->current_tab; } /** * Get all font stacks * * @since 1.0 * @return array $stacks, all font stacks */ public function get_font_stacks() { $stacks = array( 'Arial' => 'Arial, "Helvetica Neue", Helvetica, sans-serif', 'Baskerville' => 'Baskerville, "Times New Roman", Times, serif', 'Georgia' => 'Georgia, Times, "Times New Roman", serif', 'Helvetica' => '"Helvetica Neue", Helvetica, Arial, sans-serif', 'Lucida' => '"Lucida Sans", Lucida Grande", "Lucida Sans Unicode", sans-serif', 'Monaco' => 'Monaco, Menlo, Consolas, "Courier New", monospace, serif', 'Palatino' => 'Palatino, "Palatino Linotype", Georgia, Times, "Times New Roman", serif', 'Tahoma' => 'Tahoma, Geneva, Verdana, sans-serif', 'Times' => '"Times New Roman", Times, serif', 'Trebuchet' => '"Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans", sans-serif', 'Verdana' => 'Verdana, Geneva, Tahoma, sans-serif', ); return apply_filters('bln_font_stacks', $stacks); } /** * Get all available sidebar positions * * @since 1.0 */ public function get_sidebar_pos() { return array( 'left' => array( 'desc' => __('Left Sidebar', BLN_TEXTDOMAIN), ), 'right' => array( 'desc' => __('Right Sidebar', BLN_TEXTDOMAIN), ), ); } /** * Get data on all admin tabs. */ public function get_tabs() { $tabs = array( 'general' => array( 'url' => admin_url('themes.php?page=theme_options'), 'title' => __('General options', BLN_TEXTDOMAIN), 'tpl_path' => BLN_DIR . '/incl/tpl/admin-general.php', ), 'slider' => array( 'url' => admin_url('themes.php?page=theme_options&tab=slider'), 'title' => __('Featured Pages Slider', BLN_TEXTDOMAIN), 'tpl_path' => BLN_DIR . '/incl/tpl/admin-slider.php', ), ); return $tabs; } /** * Get all slider effect. */ public function get_slider_effects() { $fx = array( 'fade' => __('Fade', BLN_TEXTDOMAIN), 'scrollHorz' => __('Scroll', BLN_TEXTDOMAIN), 'tileSlide' => __('Tile Slide', BLN_TEXTDOMAIN), 'tileBlind' => __('Tile Blind', BLN_TEXTDOMAIN), 'none' => __('No Effect', BLN_TEXTDOMAIN), ); return $fx; } /** * Update Slider data (When a post thumbnail was removed). */ public function update_slider_data() { $slides = array(); foreach ($this->options['slider']['slides'] as $id) { if (has_post_thumbnail($id)) { $slides[] = $id; } } $this->options['slider']['slides'] = $slides; $this->save_db($this->options); } /** * Thumbnails used on the slider settings page. * * @param int $id, the page ID. */ public function feat_page_thumb($id) { $page = get_post($id, 'ARRAY_A'); if (!empty($page)) { $img = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'full'); $img = $img[0]; $style = 'background: url("' . $img . '") no-repeat center center; background-size: cover;'; ?>