array( * 'label', * 'sections' => array( * 'fields' => array( * 'option1', * 'option2', * ... * ) * ) * ) * * @var array * @access public */ public $options = array(); /** * Options group name * * @var string * @access public */ public $option_group = 'panel_group'; /** * Option name * * @var string * @access public */ public $option_name = 'panel_options'; /** * Banner links * * @var string * @access public */ public $banner_url = 'https://yithemes.com/?ap_id=plugin'; public $banner_img = ''; /** * Constructor * * @param array $submenu Parameters for add_submenu_page * @param array $options Array of plugin options * */ public function __construct( $submenu, $options, $banner = array(), $option_group = false, $option_name = false ) { $this->_submenu = apply_filters('yith_panel_submenu', $submenu); $this->options = apply_filters('yith_panel_options', $options); if( !empty($banner) ) { $this->banner_url = $banner['url']; $this->banner_img = $banner['img']; } if( $option_group ) { $this->option_group = $option_group; } if( $option_name ) { $this->option_name = $option_name; } //add new menu item //register new settings option group //include js and css files //print browser add_action( 'admin_menu', array( $this, 'add_submenu_page') ); add_action( 'admin_init', array( $this, 'panel_register_setting') ); add_action( 'admin_enqueue_scripts', array( $this, 'panel_enqueue') ); // add the typography javascript vars add_action( 'yith_panel_after_panel', array( $this, 'js_typo_vars' ) ); } /** * Create new submenu page * * @return void * @access public * @link http://codex.wordpress.org/Function_Reference/add_submenu_page */ public function add_submenu_page() { $submenu = $this->_submenu; add_submenu_page( $submenu[0], $submenu[1], $submenu[2], $submenu[3], $submenu[4], array( $this, isset($submenu[5]) ? $submenu[5] : 'display_panel_page' ) ); } /** * Print the Panel page * * @return void * @access public */ public function display_panel_page() { // Create a header in the default WordPress 'wrap' container $page = $this->_get_tab(); ?>

option_name ); ?> option_group ) ?>

_get_tab(); $tab = isset( $this->options[$page] ) ? $this->options[$page] : array(); if( !empty($tab['sections']) ) { //add sections and fields foreach( $tab['sections'] as $section_name => $section) { //add the section add_settings_section( $section_name, $section['title'], array( $this, 'panel_section_content'), $this->option_name ); //add the fields foreach( $section['fields'] as $option_name => $option ) { $option['id'] = $option_name; $option['label_for'] = $option_name; //register settings group register_setting( $this->option_group, $option_name, array( $this, 'panel_sanitize') ); add_settings_field( $option_name, $option['title'], array( $this, 'panel_field_content' ), $this->option_name, $section_name, $option ); } } } } /** * Display sections content * * @return void * @access public */ public function panel_section_content( $section ) { $page = $this->_get_tab(); if( isset( $this->options[$page]['sections'][ $section['id'] ]['description'] )) { echo "

" . $this->options[$page]['sections'][ $section['id'] ]['description'] . "

"; } } /** * Sanitize the option's value * * @param array $input * @return array * @access public */ public function panel_sanitize( $input ) { return apply_filters('yith_panel_sanitize', $input); } /** * Get the active tab. If the page isn't provided, the function * will return the first tab name * * @return string * @access protected */ public function _get_tab() { $panel_page = ! empty( $_REQUEST['panel_page'] ) ? sanitize_title_for_query( $_REQUEST['panel_page'] ) : ''; $tabs = array_keys( $this->options ); return ! empty( $panel_page ) ? $panel_page : $tabs[0]; } /** * Enqueue scripts and styles * * @return void * @access public */ public function panel_enqueue( $hook ) { global $pagenow; $plugin_dir_url = plugin_dir_url( __FILE__ ); if( $pagenow == $this->_submenu[0] && isset( $_GET['page'] ) && $_GET['page'] == $this->_submenu[4] ) { wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'jquery-ui', $plugin_dir_url . 'assets/css/jquery-ui.css' ); wp_enqueue_script( 'jquery-ui-datepicker' ); wp_enqueue_style( 'yith-panel-css', $plugin_dir_url . 'assets/css/yith-panel.css', array('wp-color-picker'), $this->version ); wp_enqueue_script( 'yith-panel-js', $plugin_dir_url . 'assets/js/yith-panel.js', array( 'jquery', 'wp-color-picker' ), $this->version, true ); wp_enqueue_media(); do_action( 'yith_panel_enqueue' ); } } /** * Display field content * * @return void * @access public */ public function panel_field_content( $field ) { $value = get_option( $field['id'], isset($field['std']) ? $field['std'] : '' ); $id = $field['id']; $name = $field['id']; $echo = ''; switch( $field['type'] ) { case 'text': $echo = ""; if( isset($field['description']) && $field['description'] != '' ) { $echo .= "

{$field['description']}

"; } break; case 'textarea': $echo = ""; if( isset($field['description']) && $field['description'] != '' ) { $echo .= "

{$field['description']}

"; } break; case 'checkbox': $echo = ""; if( isset($field['description']) && $field['description'] != '' ) { $echo .= " "; } break; case 'select': $echo = ""; if( isset($field['description']) && $field['description'] != '' ) { $echo .= "

{$field['description']}

"; } break; case 'skin': $echo = ""; if( isset($field['description']) && $field['description'] != '' ) { $echo .= "

{$field['description']}

"; } break; case 'number': $mms = ''; if( isset( $field['min'] ) ) { $mms .= " min='{$field['min']}'"; } if( isset( $field['max'] ) ) { $mms .= " max='{$field['max']}'"; } if( isset( $field['step'] ) ) { $mms .= " step='{$field['step']}'"; } $echo = ""; if( isset($field['description']) && $field['description'] != '' ) { $echo .= "

{$field['description']}

"; } break; case 'colorpicker': $std = isset( $field['std'] ) ? $field['std'] : ''; $echo = ""; if( isset($field['description']) && $field['description'] != '' ) { $echo .= "

{$field['description']}

"; } break; case 'datepicker': $std = isset( $field['std'] ) ? $field['std'] : array( 'date' => '', 'hh' => 0, 'mm' => 0, 'ss' => 0 ); $value = ! empty( $value ) ? $value : array( 'date' => '', 'hh' => 0, 'mm' => 0, 'ss' => 0 ); if( empty( $value['mysql_date'] ) ){ $value['mysql_date'] = date( 'Y-m-d' ); } $echo = " - "; $echo .= " : "; $echo .= " : "; $echo .= ""; $echo .= ""; if( isset($field['description']) && $field['description'] != '' ) { $echo .= "

{$field['description']}

"; } break; case 'upload': $echo = '
'; $echo .= " "; $echo .= '
'; if( isset($field['description']) && $field['description'] != '' ) { $echo .= "

{$field['description']}

"; } break; case 'checkboxes': $echo = '
'; foreach ( $field['options'] as $check_value => $check_label ) { $echo .= "
"; } $echo .= "

{$field['description']}

"; break; case 'typography': $value = wp_parse_args( $value, $field['std'] ); ?>
' class='medium-text code panel-colorpicker typography_color' data-default-color='' />

The quick brown fox jumps over the lazy dog

banner_url || !$this->banner_img ) return; ?>