'

'.$yiw_themename.' '.__('settings saved', 'yiw').'.

', 'reset' => '

'.$yiw_themename.' '.__('settings reset', 'yiw').'.

', ); if ( isset( $_REQUEST['yiw-action'] ) && $_REQUEST['yiw-action'] == 'reset' ) { echo $yiw_messages['reset']; return; } foreach( $yiw_messages as $id => $yiw_message ) if( isset( $_GET[ $id ] ) && $_GET[ $id ] ) echo $yiw_message; } /** * ARRAYS */ require_once 'arrays.php'; // ------------- $yiw_options = $yiw_theme_options = array(); foreach( $yiw_submenu_items as $item => $v ) { $file = dirname(__FILE__) . '/' . "options/$item-options.php"; if( !file_exists( $file ) ) unset( $yiw_submenu_items[$item] ); unset( $file ); } include_once 'panel_functions.php'; // includes options array of current tab if ( _is_yiw_panel() ) require_once dirname(__FILE__) . '/' . 'options/' . yiw_get_current_tab() . '-options.php'; // generate array with all default values function yiw_get_default_options() { global $yiw_options, $yiw_submenu_items; foreach( $yiw_submenu_items as $item => $v ) { $file = dirname(__FILE__) . '/' . "options/$item-options.php"; if( isset( $_GET['tab'] ) AND $_GET['tab'] == $item ) require_once $file; else require_once dirname(__FILE__) . '/' . "options/general-options.php"; unset( $file ); } $default_options = array(); foreach ( $yiw_options as $tab => $sections ) foreach ( $sections as $section ) foreach ( $section as $id => $value ) if ( isset( $value['std'] ) && isset( $value['id'] ) ) $default_options[ $value['id'] ] = $value['std']; return $default_options; } // retrive all db options $yiw_theme_options = get_option( 'yiw_theme_options' ); if ( false === $yiw_theme_options || ( isset( $_REQUEST['yiw-action'] ) && $_REQUEST['yiw-action'] == 'reset' ) ) { $yiw_theme_options = yiw_get_default_options(); update_option( 'yiw_theme_options', $yiw_theme_options ); } function yiw_add_admin() { global $yiw_themename; add_theme_page( $yiw_themename, $yiw_themename, 'edit_theme_options', 'yiw_panel', 'yiw_admin' ); } add_action('admin_menu', 'yiw_add_admin'); // add items to admin bar if( version_compare($wp_version, "3.1", ">=") ) { function yiw_add_items_admin_bar() { global $yiw_submenu_items, $wp_admin_bar, $yiw_themename; $wp_admin_bar->add_menu( array( 'parent' => false, 'title' => $yiw_themename, 'id' => "theme-options-home", 'href' => admin_url('themes.php')."?page=yiw_panel" ) ); foreach( $yiw_submenu_items as $item => $title ) { $wp_admin_bar->add_menu( array( 'parent' => "theme-options-home", 'title' => $title, 'id' => "theme-options-$item", 'href' => admin_url('themes.php')."?page=yiw_panel&tab=$item" ) ); } } add_action( 'wp_before_admin_bar_render', 'yiw_add_items_admin_bar' ); } function yiw_register_settings() { register_setting( 'yiw_theme_options', 'yiw_theme_options', 'yiw_options_validate' ); } add_action( 'admin_init', 'yiw_register_settings' ); // validation function yiw_options_validate( $input ) { $current_tab = $input['current_tab']; $yiw_options = array(); require_once dirname(__FILE__) . '/' . 'options/' . $current_tab . '-options.php'; // default $default_options = array(); foreach ( $yiw_options as $tab => $sections ) foreach ( $sections as $section ) foreach ( $section as $id => $value ) if ( isset( $value['std'] ) && isset( $value['id'] ) ) $default_options[ $value['id'] ] = $value['std']; $valid_input = get_option( 'yiw_theme_options', $default_options ); $submit = ( ! empty( $input['submit-general']) ? true : false ); $reset = ( ! empty( $input['reset-general']) ? true : false ); foreach ( $yiw_options[ $current_tab ] as $section => $data ) foreach ( $data as $option ) { if ( isset( $option['sanitize_call'] ) && isset( $option['id'] ) ) { if ( is_array( $option['sanitize_call'] ) ) : foreach ( $option['sanitize_call'] as $callback ) if ( is_array( $input[ $option['id'] ] ) ) $valid_input[ $option['id'] ] = array_map( $callback, $input[ $option['id'] ] ); else $valid_input[ $option['id'] ] = call_user_func( $callback, $input[ $option['id'] ] ); else : if ( is_array( $input[ $option['id'] ] ) ) $valid_input[ $option['id'] ] = array_map( $option['sanitize_call'], $input[ $option['id'] ] ); else $valid_input[ $option['id'] ] = call_user_func( $option['sanitize_call'], $input[ $option['id'] ] ); endif; } else $valid_input[ $option['id'] ] = $input[ $option['id'] ]; } return $valid_input; } function yiw_add_init() { $file_dir = get_template_directory_uri()."/admin-options/include"; wp_enqueue_style( "function-panel", $file_dir."/functions.css" ); wp_enqueue_style( "theme-install" ); add_thickbox(); wp_enqueue_script( "rm_script", $file_dir."/rm_script.js", array( 'jquery' ), '1.0', true ); } if ( basename( $_SERVER['PHP_SELF'] ) == 'themes.php' AND isset( $_GET['page'] ) AND $_GET['page'] == 'yiw_panel' ) add_action('admin_init', 'yiw_add_init'); function yiw_add_fields() { global $yiw_options; $current_tab = yiw_get_current_tab(); if ( !$current_tab ) return; foreach ( $yiw_options[ $current_tab ] as $section => $data ) { // section add_settings_section( "yiw_settings_{$current_tab}_{$section}", yiw_get_section_title( $section ), create_function( '', 'echo \'

\', yiw_get_section_description( \'' . $section . '\' ), \'

\';' ), 'yiw' ); // fields foreach ( $data as $option ) if ( isset( $option['id'] ) && isset( $option['type'] ) && isset( $option['name'] ) ) add_settings_field( "yiw_setting_".$option['id'], $option['name'], create_function( '', 'yiw_render_field( \'' . addslashes( serialize( $option ) ) . '\' );' ), 'yiw', "yiw_settings_{$current_tab}_{$section}", array( 'label_for' => yiw_get_id_field( $option['id'] ) ) ); } } add_action('admin_init', 'yiw_add_fields'); function yiw_get_current_tab() { if ( !isset( $_GET['page'] ) || $_GET['page'] != 'yiw_panel' ) return false; if ( isset( $_POST['yiw_tab_options'] ) ) return $_GET['yiw_tab_options']; elseif ( isset( $_GET['tab'] ) ) return $_GET['tab']; else return 'general'; } function yiw_get_tab_title() { global $yiw_options; $current_tab = yiw_get_current_tab(); foreach ( $yiw_options[ $current_tab ] as $sections => $data ) foreach ( $data as $option ) if ( isset( $option['type'] ) && $option['type'] == 'title' ) return $option['name']; } function yiw_get_section_title( $section ) { global $yiw_options; $current_tab = yiw_get_current_tab(); foreach ( $yiw_options[ $current_tab ][ $section ] as $option ) if ( isset( $option['type'] ) && $option['type'] == 'section' ) return $option['name']; } function yiw_get_section_description( $section ) { global $yiw_options; $current_tab = yiw_get_current_tab(); foreach ( $yiw_options[ $current_tab ][ $section ] as $option ) if ( isset( $option['type'] ) && isset( $option['desc'] ) && $option['type'] == 'section' ) return $option['desc']; } function yiw_get_include() { global $yiw_options; $current_tab = yiw_get_current_tab(); foreach ( $yiw_options[ $current_tab ] as $sections => $data ) foreach ( $data as $option ) if ( isset( $option['type'] ) && $option['type'] == 'title' && isset( $option['include'] ) ) include $option['include']; } function yiw_if_show_form() { global $yiw_options; $current_tab = yiw_get_current_tab(); foreach ( $yiw_options[ $current_tab ] as $section ) { foreach ( $section as $option ) { if ( !isset( $option['type'] ) || $option['type'] != 'title' ) continue; if ( isset( $option['showform'] ) ) return $option['showform']; else return true; } } } function yiw_get_name_field( $id ) { return "yiw_theme_options[$id]"; } function yiw_name_field( $id ) { echo yiw_get_name_field( $id ); } function yiw_get_id_field( $id ) { return "yiw_theme_options_$id"; } function yiw_id_field( $id ) { echo yiw_get_id_field( $id ); } function yiw_render_field( $option ) { global $yiw_theme_options; $option = unserialize( stripslashes( $option ) ); // retrieve the value from db or default value $db_value = $yiw_theme_options[ $option['id'] ]; switch( $option['type'] ) { case 'text' : ?> 1) $descr = "$option[desc]"; } ?>

1) ? $i : false ?>
$tab_value ) { $active_class = ( $current_tab == $tab ) ? ' nav-tab-active' : ''; $tabs .= "$tab_value\n"; } ?>