Advertisement
Guest User

Untitled

a guest
Aug 19th, 2011
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.15 KB | None | 0 0
  1. <?php
  2.  
  3.     if( is_admin() ){
  4.         // Insert the theme page menu item
  5.         add_action('admin_menu', 'option_page_menu_insert');
  6.  
  7.         // Initiate theme options and page
  8.         add_action('admin_init', 'register_theme_settings');
  9.     }
  10.     else{
  11.         //play in a sandbox
  12.     }
  13.  
  14.     function option_page_menu_insert() {
  15.         /* Add a menu item inter the 'Appearance' menu
  16.          * Function Definition:
  17.          * add_options_page(unique text id,  displayed title, function to display, callback page)
  18.          */
  19.         add_theme_page( 'WSU Theme Options', 'WSU Theme Options', 'edit_theme_options', 'WSU_Theme_Options', 'theme_options_page');
  20.     }
  21.  
  22.     function register_theme_settings() {
  23.         // Create the main setting group: 'wsuy-theme-options'
  24.         register_setting('wsuy_theme_options', 'wsuy-theme-options');
  25.  
  26.         /* Add a settings group sub-section: 'wsuy-theme-options-section'
  27.          * Function Definition:
  28.          * add_settings_section(unique text id,  displayed title, function to display, callback page)
  29.          */
  30.         add_settings_section('wsuy_theme_options_section', 'WSU Theme (Yoko): Options', 'section_description', __FILE__);
  31.  
  32.         /* Define theme options fields:
  33.         * Function Definition:
  34.         * add_settings_field(unique  id,    displayed title,        display,        callback page,   section id)
  35.         */
  36.         add_settings_field('wsuy_logo',     'Website logo',         'field_logo',   __FILE__, 'wsuy_theme_options_section');
  37.         add_settings_field('wsuy_color',    'Website header color', 'field_color',  __FILE__, 'wsuy_theme_options_section');
  38.  
  39.     }
  40.  
  41.     function field_logo(){
  42.         $options = get_option('wsuy_theme_options');
  43.         echo "<input id='wsuy_logo' name='wsuy_theme_options[wsuy_logo]' disabled='disabled' size='40' type='text' value='{$options['wsuy_logo']}' style='display:none'/><br>";
  44.         $path = str_replace("style.css", "logos/", get_stylesheet_uri());
  45.         echo "<ul id='logo'>";
  46.             echo '<li id="l1">  <img class="logo" src="' . $path . 'ce.PNG" width="100px;"/>                </li>';
  47.             echo '<li id="l2">  <img class="logo" src="' . $path . 'cepm.png" width="100px;"/>              </li>';
  48.             echo '<li id="l3">  <img class="logo" src="' . $path . 'west.PNG" width="100px;"/>              </li>';
  49.             echo '<li id="l4">  <img class="logo" src="' . $path . 'concurrent.PNG" width="100px;"/>        </li>';
  50.             echo '<li id="l5">  <img class="logo" src="' . $path . 'conferences.PNG" width="100px;"/>       </li>';
  51.             echo '<li id="l6">  <img class="logo" src="' . $path . 'early-credit.PNG" width="100px;"/>      </li>';
  52.             echo '<li id="l7">  <img class="logo" src="' . $path . 'hybrid.PNG" width="100px;"/>            </li>';
  53.             echo '<li id="l8">  <img class="logo" src="' . $path . 'kaysville.PNG" width="100px;"/>         </li>';
  54.             echo '<li id="l9">  <img class="logo" src="' . $path . 'lifelong-learning.PNG" width="100px;"/> </li>';
  55.             echo '<li id="l10"> <img class="logo" src="' . $path . 'morgan.PNG" width="100px;"/>            </li>';
  56.             echo '<li id="l11"> <img class="logo" src="' . $path . 'police.PNG" width="100px;"/>            </li>';
  57.             echo '<li id="l12"> <img class="logo" src="' . $path . 'prof-dev.PNG" width="100px;"/>          </li>';
  58.             echo '<li id="l13"> <img class="logo" src="' . $path . 'study-abroad.PNG" width="100px;"/>      </li>';
  59.             echo '<div style="clear:both"></div>';
  60.         echo "</ul>";
  61.     }
  62.  
  63.     function field_color(){
  64.         $options = get_option('wsuy_theme_options');
  65.         echo "<input id='wsuy_color' name='wsuy_theme_options[wsuy_color]' size='40' type='color' data-hex='true' value='{$options['wsuy_color']}' />";
  66.     }
  67.  
  68.     function section_description() {}
  69.  
  70.     function validate($input){
  71.         // Do nothing
  72.         return $input;
  73.     }
  74.  
  75.     function theme_options_page() {
  76.         //Check the users permission level
  77.         if (!current_user_can('manage_options'))  {
  78.             wp_die( __('You do not have sufficient permissions to access this page.') );
  79.         }
  80.  
  81.         //Generate the html for the options page:
  82.         ?>
  83.         <style type="text/css">
  84.             #logo{
  85.                 list-style:none;
  86.                 display:block;
  87.                 background:#eaeaea;
  88.             }
  89.             #logo li{
  90.                 display:inline;
  91.                 float:left;
  92.                 margin:10px;
  93.                 width:120px;
  94.                 height:30px;
  95.                 border:1px solid #d5d5d5;
  96.                 background:#fff;
  97.                 padding:10px;
  98.                 cursor:pointer;
  99.                 border-radius:5px;
  100.                 -moz-border-radius:5px;
  101.                 -webkit-border-radius:5px;
  102.                 text-align:center;
  103.             }
  104.             #logo li:hover{
  105.                 border:1px solid #aeaeae;
  106.             }
  107.             .selected{
  108.                 background:#fffce0 !important;
  109.                 border:1px solid #aeaeae !important;
  110.             }
  111.         </style>
  112.         <div class="wrap">
  113.             <h1>WSU Theme Options</h1>
  114.             <form method="post" action="options.php">
  115.                 <?php settings_fields('wsuy_theme_options_section'); ?>
  116.                 <?php do_settings_sections(__FILE__); ?>
  117.                 <div class="clear"><br /></div>
  118.                 <input style="margin-left:800px;" name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" class="button-primary"/>
  119.             </form>
  120.         </div>
  121.         <!-- ColorPicker Javascript -->
  122.         <script type="text/javascript" src="http://meta100.github.com/mColorPicker/javascripts/mColorPicker_min.js" charset="UTF-8"></script>
  123.         <script type="text/javascript">
  124.             jQuery(document).ready(function($) {
  125.                 $("#logo li").click(function() {
  126.                     file = $(this).find("img").attr("src");
  127.                     $("#wsuy_logo").val(file);
  128.                     $("#logo li").removeClass("selected");
  129.                     $(this).addClass("selected");
  130.                 });
  131.             });        
  132.         </script>
  133.     <?php }
  134. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement