Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* --- No need to wrap these with is_admin() since they are only ran in the admin section -- */
- // Insert the theme page menu item
- add_action('admin_menu', 'option_page_menu_insert');
- // Initiate theme options and page
- add_action('admin_init', 'register_theme_settings');
- add_action('init', 'add_my_options');
- /**
- * Add a menu item inter the 'Appearance' menu
- *
- * Function Definition:
- * add_options_page(unique text id, displayed title, function to display, callback page)
- */
- function option_page_menu_insert()
- {
- add_theme_page( 'WSU Theme Options', 'WSU Theme Options', 'edit_theme_options', 'WSU_Theme_Options', 'theme_options_page');
- }
- /**
- * Add Theme Options
- *
- * This adds the theme's options if they don't already exist or if they aren't in an array.
- */
- function add_my_options()
- {
- // Define option default values here ...
- $defaults = array(
- 'wsuy_logo' => '',
- 'wsuy_color' => ''
- );
- // Try getting our theme options. If they don't exist, it will return (bool)false
- $options = get_option('wsuy_theme_options');
- // If it's an array, we won't proceed.
- if( is_array($options) ) return;
- if($options === false)
- add_option('wsuy_theme_options', $defaults);
- else
- // Options weren't an array, so we'll go ahead and replace it with our defaults...
- update_option('wsuy_theme_options', $defaults);
- }
- function register_theme_settings()
- {
- // Create the main setting group: 'wsuy-theme-options'
- register_setting('wsuy_theme_options', 'wsuy_theme_options', 'validate');
- /* Add a settings group sub-section: 'wsuy-theme-options-section'
- * Function Definition:
- * add_settings_section(unique text id, displayed title, function to display, callback page)
- */
- add_settings_section('wsuy_theme_options_section', 'WSU Theme (Yoko): Options', 'section_description', __FILE__);
- /* Define theme options fields:
- * Function Definition:
- * add_settings_field(unique id, displayed title, display, callback page, section id)
- */
- add_settings_field('wsuy_logo', 'Website logo', 'field_logo', __FILE__, 'wsuy_theme_options_section');
- add_settings_field('wsuy_color', 'Website header color', 'field_color', __FILE__, 'wsuy_theme_options_section');
- }
- function field_logo()
- {
- $options = get_option('wsuy_theme_options');
- $path = get_template_directory_uri() .'logos/';
- ?>
- <input id='wsuy_logo' name='wsuy_theme_options[wsuy_logo]' size='40' type='text' value='<?php echo $options['wsuy_logo']; ?>' style='display:none'/><br>
- <ul id='logo'>
- <li id="l1"><img class="logo" src="<?php echo $path; ?>ce.PNG" width="100px;"/></li>
- <li id="l2"><img class="logo" src="<?php echo $path; ?>cepm.png" width="100px;"/></li>
- <li id="l3"><img class="logo" src="<?php echo $path; ?>west.PNG" width="100px;"/></li>
- <li id="l4"><img class="logo" src="<?php echo $path; ?>concurrent.PNG" width="100px;"/></li>
- <li id="l5"><img class="logo" src="<?php echo $path; ?>conferences.PNG" width="100px;"/></li>
- <li id="l6"><img class="logo" src="<?php echo $path; ?>early-credit.PNG" width="100px;"/></li>
- <li id="l7"><img class="logo" src="<?php echo $path; ?>hybrid.PNG" width="100px;"/></li>
- <li id="l8"><img class="logo" src="<?php echo $path; ?>kaysville.PNG" width="100px;"/></li>
- <li id="l9"><img class="logo" src="<?php echo $path; ?>lifelong-learning.PNG" width="100px;"/></li>
- <li id="l10"><img class="logo" src="<?php echo $path; ?>morgan.PNG" width="100px;"/></li>
- <li id="l11"><img class="logo" src="<?php echo $path; ?>police.PNG" width="100px;"/></li>
- <li id="l12"><img class="logo" src="<?php echo $path; ?>prof-dev.PNG" width="100px;"/></li>
- <li id="l13"><img class="logo" src="<?php echo $path; ?>study-abroad.PNG" width="100px;"/></li>
- <div style="clear:both"></div>
- </ul><?php
- }
- function field_color() {
- $options = get_option('wsuy_theme_options');
- echo "<input id='wsuy_color' name='wsuy_theme_options[wsuy_color]' size='40' type='color' data-hex='true' value='{$options['wsuy_color']}' />";
- }
- function section_description() {}
- function validate($input) {
- // Validate our settings values before saving ....
- return $input;
- }
- function theme_options_page() {
- //Check the users permission level
- if( !current_user_can('manage_options') )
- wp_die( __('You do not have sufficient permissions to access this page.') );
- //Generate the html for the options page:
- ?>
- <style type="text/css">
- #logo{ list-style:none; display:block; background:#eaeaea; }
- #logo li{ display:inline; float:left; margin:10px; width:120px; height:30px; border:1px solid #d5d5d5;
- background:#fff; padding:10px; cursor:pointer; border-radius:5px; -moz-border-radius:5px;
- -webkit-border-radius:5px; text-align:center; }
- #logo li:hover{ border:1px solid #aeaeae; }
- .selected{ background:#fffce0 !important; border:1px solid #aeaeae !important; }
- </style>
- <div class="wrap">
- <h1>WSU Theme Options</h1>
- <form method="post" action="options.php">
- <?php settings_fields('wsuy_theme_options'); ?>
- <?php do_settings_sections(__FILE__); ?>
- <div class="clear"><br /></div>
- <input style="margin-left:800px;" name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" class="button-primary"/>
- </form>
- </div>
- <!-- ColorPicker Javascript -->
- <script type="text/javascript" src="http://meta100.github.com/mColorPicker/javascripts/mColorPicker_min.js" charset="UTF-8"></script>
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- $("#logo li").click(function() {
- file = $(this).find("img").attr("src");
- $("#wsuy_logo").val(file);
- $("#logo li").removeClass("selected");
- $(this).addClass("selected");
- });
- });
- </script><?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement