Advertisement
Digitalraindrops

Theme Setup.php

Jun 8th, 2012
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.11 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Digital Raindrops Theme Flex Slider Options
  4.  */
  5.  
  6.  function dr_slider_admin_enqueue_scripts( $hook_suffix ) {
  7.     wp_admin_css( 'dashboard' );
  8.     wp_enqueue_style( 'dr-flex-slider-admin', get_stylesheet_directory_uri() . '/css/flex-slider-admin.css', false, '2012-03-20' );
  9.     wp_enqueue_script( 'dashboard' );
  10. }
  11. add_action( 'admin_print_styles-appearance_page_theme_setup', 'dr_slider_admin_enqueue_scripts' );
  12.  
  13. function dr_slider_theme_options_init() {
  14.    
  15.     register_setting(
  16.         'dr_slider_options',
  17.         'dr_slider_theme_options',
  18.         'dr_slider_theme_options_validate'
  19.     );
  20. }
  21. add_action( 'admin_init', 'dr_slider_theme_options_init' );
  22.  
  23. /* Add our theme colors page to the admin menu */
  24. function dr_slider_theme_options_add_page() {
  25.     $option_page = add_theme_page(
  26.         __( 'Flex Slider Setup', 'dr_slider' ),
  27.         __( 'Flex Slider Setup', 'dr_slider' ),
  28.         'edit_theme_options',
  29.         'theme_setup',
  30.         'dr_slider_options_render_page'
  31.     );
  32. }
  33. add_action( 'admin_menu', 'dr_slider_theme_options_add_page' );
  34.    
  35. function dr_slider_options_render_page() {
  36.     ?>
  37.     <div class="wrap">
  38.                
  39.         <?php screen_icon(); ?>
  40.         <h2><?php printf( __( '%s - Flex Slider Setup', 'dr_slider' ), get_current_theme() ); ?></h2><br />
  41.         <?php settings_errors(); ?>
  42.        
  43.         <form method="post" action="options.php">
  44.             <?php
  45.                 settings_fields( 'dr_slider_options' );
  46.                 global $dr_slider_settings, $dr_slider_theme_options;
  47.                 $dr_slider_theme_options = dr_slider_theme_admin_options();
  48.             ?>
  49.                        
  50.             <div class='postbox-container' style='width:750px;'>
  51.                    
  52.             <?php foreach ($dr_slider_theme_options as $value) {
  53.                 $default="";
  54.                 switch ( $value['type'] ) {
  55.                                    
  56.                 case "section":
  57.                 ?>
  58.                
  59.                 <div class="postbox<?php echo $style; ?>">
  60.                     <div class="handlediv" title="Click to toggle">
  61.                     </div>
  62.                     <h3 class="hndle">
  63.                         <span><?php echo $value['name']; ?></span>
  64.                     </h3>
  65.                     <div class="inside">
  66.                    
  67.                 <?php
  68.                     $style=" closed";
  69.                 break;
  70.                
  71.                 case 'text':
  72.                     $id = $value["id"];
  73.                     if( isset( $dr_slider_settings[$id] ) ) {
  74.                         if( $dr_slider_settings[$id] ) $current_value = $dr_slider_settings[$id];
  75.                             else $current_value = $value['default'];
  76.                     }
  77.                     else $current_value = $value['default'];
  78.                     ?>
  79.                         <label for="dr_slider_theme_options[<?php echo $id;?>]"><?php echo $value["name"];?></label></th>
  80.                         <fieldset><legend class="screen-reader-text"><span><?php echo $value['name']; ?></span></legend>
  81.                             <input type="text" name="dr_slider_theme_options[<?php echo $id;?>]" value="<?php echo $current_value;?>" />
  82.                             <p><small><?php echo $value["desc"]; ?></small></p>
  83.                             <div class="clearfix"></div>
  84.                         </fieldset>
  85.                 <?php
  86.                 break;
  87.                
  88.                 case "textarea":
  89.                     $id=$value['id'];
  90.                 ?>
  91.                         <label for="dr_slider_theme_options[<?php echo $id;?>]"><?php echo $value['name'];?></label></th>
  92.                         <fieldset><legend class="screen-reader-text"><span><?php echo $value['name']; ?></span></legend>
  93.                             <textarea name="dr_slider_theme_options[<?php echo $value["id"]; ?>]" cols="1" rows="1" >
  94.                             <?php if ( isset( $dr_slider_settings[$id] ) && $dr_slider_settings[$id] ) { echo $dr_slider_settings[$id] ; } else { echo $value['default']; } ?></textarea>
  95.                             <p><small><?php echo $value["desc"]; ?></small></p>
  96.                             <div class="clearfix"></div>
  97.                         </fieldset>
  98.                 <?php
  99.                 break;
  100.                
  101.                 case 'select':
  102.                     $id=$value['id'];
  103.                 ?>
  104.                     <label for="dr_slider_theme_options[<?php echo $id;?>]"><?php echo $value['name']; ?></label></th> 
  105.                     <fieldset><legend class="screen-reader-text"><span><?php echo $value['name']; ?></span></legend>
  106.                         <select id="dr_slider_theme_options[<?php echo $id; ?>]" name="dr_slider_theme_options[<?php echo $id; ?>]" style="width: <?php echo $value["width"]; ?>px;">
  107.                         <?php foreach ($value['options'] as $option) {
  108.                             $selected = ( isset($dr_slider_settings[$id]) && ($dr_slider_settings[$id] == esc_attr( $option['value']) ) ) ? ' selected = "selected" ' : '';
  109.                             $output = '<option '.$selected .'value="' . $option['value'];
  110.                             $output = $output .'">';
  111.                             $output = $output .$option['label'];
  112.                             $output = $output .'</option>';
  113.                             echo $output;
  114.                         } ?>   
  115.                         </select>
  116.                         <p><small><?php echo $value["desc"]; ?></small></p>
  117.                         <div class="clearfix"></div>
  118.                     </fieldset>
  119.                 <?php
  120.                 break;
  121.                
  122.                 case "checkbox":
  123.                     $id=$value['id'];
  124.                 ?>
  125.                 <label for="dr_slider_theme_options[<?php echo $id;?>]"><?php echo $value['name']; ?></label></th>
  126.                 <fieldset><legend class="screen-reader-text"><span><?php echo $value['name']; ?></span></legend>
  127.                     <?php if(isset( $dr_slider_settings[$id] ) && $dr_slider_settings[$id]){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
  128.                     <input type="checkbox" name="dr_slider_theme_options[<?php echo $id;?>]" value="true" <?php echo $checked; ?> />
  129.                     <p><small><?php echo $value["desc"]; ?></small></p>
  130.                 </fieldset>
  131.                 <?php break;
  132.  
  133.                 case "close":
  134.                 ?>
  135.                     <?php submit_button(); ?>
  136.                     </div>
  137.                 </div>
  138.                 <?php
  139.                 break;
  140.                 }
  141.             } ?>
  142.                 <div style="float: left; position: relative; line-height: 20px; font-size:12px; color: #777777; margin-bottom:10px;">Theme Flex Slider Options Page <a href="http://digitalraindrops.net/">created by Digital Raindrops</a></div>
  143.             </div>
  144.         </form>
  145.     </div> 
  146. <?php
  147. }
  148.  
  149.  
  150. function dr_slider_theme_options_validate( $input ) {
  151.     global $dr_slider_theme_options;
  152.    
  153.     foreach($dr_slider_theme_options as $theme_option) {
  154.        
  155.         $option_type = $theme_option['type'];
  156.         if (!$option_type=='open' && !$option_type=='close' && !$option_type=='section') {
  157.             $id  = $theme_option['id'];
  158.             if( !isset( $input[$id] ) ) $input[$id] = $theme_option['default'];
  159.             switch ($option_type) {
  160.                
  161.             case 'text':
  162.                 $input[$id] = trim( wp_filter_nohtml_kses( $input[$id] ) );
  163.                 break;
  164.                
  165.                 case 'textarea':
  166.                     $input[$id] = trim( wp_filter_post_kses( $input[$id] ) );
  167.                 break;
  168.                
  169.                 case 'select':
  170.                     $options = $theme_option['options'];
  171.                     if ( array_search( $input[$id], $options ) != 0 )
  172.                         $input[$id] = null;
  173.                 break;         
  174.             }
  175.             if( !isset( $input[$id] ) ) $input[$id] = $theme_option['default'];
  176.         }
  177.     }
  178.     return $input;
  179. }
  180.  
  181. /* Options for the Theme Slider Setup page */
  182. function dr_slider_theme_admin_options() {
  183.    
  184.     /* Menu Options */
  185.     $the_cats = get_categories();
  186.     $theme_categories = array();
  187.     $theme_categories[] = array( 'value'=>'', 'label'=>'' );   
  188.     if($the_cats) {
  189.         foreach( $the_cats as $the_cat ) :
  190.             $theme_categories[$the_cat->cat_ID] = array('value'=>$the_cat->cat_ID, 'label'=>$the_cat->cat_name );
  191.         endforeach;
  192.     }
  193.    
  194.     $menu = array(
  195.         '' => array(
  196.             'value' => '',
  197.             'label' => 'Do Not Show'
  198.         ),
  199.         'all' => array(
  200.             'value' => 'all',
  201.             'label' => 'Show on All'
  202.         ),
  203.         'nohome' => array(
  204.             'value' => 'nohome',
  205.             'label' => 'Hidden on Home Page'
  206.         ),
  207.         'home' => array(
  208.             'value' => 'home',
  209.             'label' => 'Only on Home Page'
  210.         ),
  211.     );
  212.            
  213.     $general_options = array (
  214.                
  215.         array( 
  216.             "name"  =>  __('Main Flex Slider', THEME_NS),
  217.             "type"  =>  "section"),
  218.        
  219.         array( "type"   => "open"),
  220.            
  221.         array(
  222.             'id' => 'main_slider',
  223.             'name' => __('Show Main Slider', THEME_NS),
  224.             'desc' => __('Select where to use the Main Flex Slider', THEME_NS),
  225.             'type' => 'select',
  226.             'width' => '200',
  227.             'options' => $menu,
  228.             'default' => '',   
  229.         ),
  230.  
  231.         array(
  232.             'id' => 'main_slider_pages',
  233.             'name' => __('Slider Pages', THEME_NS),
  234.             'desc' => __('Select to use Page Feature Images for Slider Images', THEME_NS),
  235.             'type' => 'checkbox',
  236.             "default"   => false,
  237.         ),
  238.  
  239.         array(
  240.             'id' => 'main_slider_cat',
  241.             'name' => __('Slider Category', THEME_NS),
  242.             'type' => 'select',
  243.             'width' => '200',
  244.             'options' => $theme_categories,
  245.             'desc' => __('Use this Category to use the Featured Images for Slider Images', THEME_NS),
  246.             'default' => ''
  247.         ),
  248.  
  249.         array(
  250.             'id' => 'main_slider_caption',
  251.             'name' => __('Slider Captions', THEME_NS),
  252.             'desc' => __('Select to use Post or Page titles as Slider Captions', THEME_NS),
  253.             'type' => 'checkbox',
  254.             "default"   => true,
  255.         ),
  256.                        
  257.         array(
  258.             'id' => 'main_image_links',
  259.             'name' => __('HyperLinks', THEME_NS),
  260.             'desc' => __('Select to Hyperlink Slider Content to the Post or Page', THEME_NS),
  261.             'type' => 'checkbox',
  262.             "default"   => false,
  263.         ),
  264.        
  265.         array(
  266.             'id' => 'main_slider_excerpt',
  267.             'name' => __('Show Excerpt', THEME_NS),
  268.             'desc' => __('Select to show the Post or Page Excerpt', THEME_NS),
  269.             'type' => 'checkbox',
  270.             "default"   => false,
  271.         ),
  272.        
  273.         array(
  274.             'id' => 'main_slider_count',
  275.             'name' => __('Slider Count', THEME_NS),
  276.             'type' => 'select',
  277.             'width' => '100',
  278.             'options' => array(
  279.                 array('value' => '3', 'label' => 'Three'),
  280.                 array('value' => '4', 'label' => 'Four'),
  281.                 array('value' => '5', 'label' => 'Five'),
  282.                 array('value' => '6', 'label' => 'Six'),
  283.                 array('value' => '7', 'label' => 'Seven'),
  284.                 array('value' => '8', 'label' => 'Eight'),
  285.                 array('value' => '9', 'label' => 'Nine'),
  286.                 array('value' => '10', 'label' => 'Ten'),                              
  287.             ),
  288.             'desc' => __('Number of Image to Slide', THEME_NS),
  289.             'default' => '5'
  290.         ),
  291.        
  292.         array(
  293.             'id' => 'main_animation',
  294.             'name' => __('Slider Animation', THEME_NS),
  295.             'type' => 'select',
  296.             'width' => '100',
  297.             'options' => array(
  298.                 array('value' => 'fade', 'label' => 'Fade'),
  299.                 array('value' => 'slide', 'label' => 'Slide'),
  300.             ),
  301.             'desc' => __('Select your animation type Fade or Slide', THEME_NS),
  302.             'default' => 'fade'
  303.         ),
  304.        
  305.         array(
  306.             'id' => 'main_slideDirection',
  307.             'name' => __('Slider Direction', THEME_NS),
  308.             'type' => 'select',
  309.             'width' => '100',
  310.             'options' => array(
  311.                 array('value' => 'horizontal', 'label' => 'Horizontal'),
  312.                 array('value' => 'vertical', 'label' => 'Vertical'),
  313.             ),
  314.             'desc' => __('Select the sliding direction, Horizontal or Vertical', THEME_NS),
  315.             'default' => 'horizontal'
  316.         ),
  317.        
  318.         array(
  319.             'id' => 'main_slideshow',
  320.             'name' => __('Slideshow', THEME_NS),
  321.             'desc' => __('Select to Animate the Slider Automatically', THEME_NS),
  322.             'type' => 'checkbox',
  323.             "default"   => true,
  324.         ),
  325.        
  326.         array(
  327.             'id' => 'main_slideshowSpeed',
  328.             'name' => __('Slideshow Speed', THEME_NS),
  329.             'desc' => __('Set the Speed of the Slideshow Cycling in Milliseconds', THEME_NS),
  330.             'type' => 'text',
  331.             'integer' => true,
  332.             'size' => 5,
  333.             'maxlength' => 4,
  334.             "default"   => 7000,
  335.         ),
  336.        
  337.         array(
  338.             'id' => 'main_animationDuration',
  339.             'name' => __('Animation Duration', THEME_NS),
  340.             'desc' => __('Set the Speed of Animations in Milliseconds', THEME_NS),
  341.             'type' => 'text',
  342.             'integer' => true,
  343.             'size' => 4,
  344.             'maxlength' => 3,
  345.             "default"   => 600,
  346.         ),
  347.  
  348.         array(
  349.             'id' => 'main_directionNav',
  350.             'name' => __('Navigation', THEME_NS),
  351.             'desc' => __('Show Navigation for Previous and Next', THEME_NS),
  352.             'type' => 'checkbox',
  353.             "default"   => true,
  354.         ),
  355.        
  356.         array(
  357.             'id' => 'main_prevText',
  358.             'name' => __('Previous Text', THEME_NS),
  359.             'desc' => __('Set the Text for the Previous Navigation', THEME_NS),
  360.             'type' => 'text',
  361.             "default"   => 'Previous',
  362.         ), 
  363.         array(
  364.             'id' => 'main_nextText',
  365.             'name' => __('Next Text', THEME_NS),
  366.             'desc' => __('Set the Text for the Next Navigation', THEME_NS),
  367.             'type' => 'text',
  368.             "default"   => 'Next',
  369.         ), 
  370.    
  371.         array(
  372.             'id' => 'main_randomize',
  373.             'name' => __('Randomize Slides', THEME_NS),
  374.             'desc' => __('Randomize the Order of the Slides', THEME_NS),
  375.             'type' => 'checkbox',
  376.             "default"   => true,
  377.         ),
  378.            
  379.         array( "type"   => "close"),
  380.        
  381.         array( 
  382.             "name"  =>  __('Widget Flex Slider', THEME_NS),
  383.             "type"  =>  "section"),
  384.        
  385.         array( "type"   => "open"),
  386.            
  387.        
  388.         array(
  389.             'id' => 'widget_slider',
  390.             'name' => __('Show Widget Slider', THEME_NS),
  391.             'desc' => __('Select where to use the Widget Flex Slider', THEME_NS),
  392.             'type' => 'select',
  393.             'width' => '200',
  394.             'options' => $menu,
  395.             'default' => '',       
  396.         ),
  397.  
  398.         array(
  399.             'id' => 'widget_slider_caption',
  400.             'name' => __('Slider Captions', THEME_NS),
  401.             'desc' => __('Select to use Post or Page titles as Slider Captions', THEME_NS),
  402.             'type' => 'checkbox',
  403.             "default"   => true,
  404.         ),
  405.        
  406.         array(
  407.             'id' => 'widget_image_links',
  408.             'name' => __('Hyperlinks', THEME_NS),
  409.             'desc' => __('Select to Hyperlink Slider Content to the Post or Page', THEME_NS),
  410.             'type' => 'checkbox',
  411.             "default"   => false,
  412.         ),
  413.        
  414.         array(
  415.             'id' => 'widget_slider_excerpt',
  416.             'name' => __('Show Excerpt', THEME_NS),
  417.             'desc' => __('Select to show the Post or Page Excerpt', THEME_NS),
  418.             'type' => 'checkbox',
  419.             "default"   => false,
  420.         ),
  421.  
  422.         array(
  423.             'id' => 'widget_slider_count',
  424.             'name' => __('Slider Count', THEME_NS),
  425.             'type' => 'select',
  426.             'width' => '100',
  427.             'options' => array(
  428.                 array('value' => '3', 'label' => 'Three'),
  429.                 array('value' => '4', 'label' => 'Four'),
  430.                 array('value' => '5', 'label' => 'Five'),
  431.                 array('value' => '6', 'label' => 'Six'),
  432.                 array('value' => '7', 'label' => 'Seven'),
  433.                 array('value' => '8', 'label' => 'Eight'),
  434.                 array('value' => '9', 'label' => 'Nine'),
  435.                 array('value' => '10', 'label' => 'Ten'),              
  436.             ),
  437.             'desc' => __('Number of Image to Slide', THEME_NS),
  438.             'default' => '5'
  439.         ),
  440.        
  441.         array(
  442.             'id' => 'widget_animation',
  443.             'name' => __('Slider Animation', THEME_NS),
  444.             'type' => 'select',
  445.             'width' => '100',
  446.             'options' => array(
  447.                 array('value' => 'fade', 'label' => 'Fade'),
  448.                 array('value' => 'slide', 'label' => 'Slide'),
  449.             ),
  450.             'desc' => __('Select your animation type Fade or Slide', THEME_NS),
  451.             'default' => 'fade'
  452.         ),
  453.        
  454.         array(
  455.             'id' => 'widget_slideDirection',
  456.             'name' => __('Slider Direction', THEME_NS),
  457.             'type' => 'select',
  458.             'width' => '100',
  459.             'options' => array(
  460.                 array('value' => 'horizontal', 'label' => 'Horizontal'),
  461.                 array('value' => 'vertical', 'label' => 'Vertical'),
  462.             ),
  463.             'desc' => __('Select the sliding direction, Horizontal or Vertical', THEME_NS),
  464.             'default' => 'horizontal'
  465.         ),
  466.        
  467.         array(
  468.             'id' => 'widget_slideshow',
  469.             'name' => __('Slideshow', THEME_NS),
  470.             'desc' => __('Select to Animate the Slider Automatically', THEME_NS),
  471.             'type' => 'checkbox',
  472.             "default"   => true,
  473.         ),
  474.        
  475.         array(
  476.             'id' => 'widget_slideshowSpeed',
  477.             'name' => __('Slideshow Speed', THEME_NS),
  478.             'desc' => __('Set the Speed of the Slideshow Cycling in Milliseconds', THEME_NS),
  479.             'type' => 'text',
  480.             'integer' => true,
  481.             'size' => 5,
  482.             'maxlength' => 4,
  483.             "default"   => 7000,
  484.         ),
  485.        
  486.         array(
  487.             'id' => 'widget_animationDuration',
  488.             'name' => __('Animation Duration', THEME_NS),
  489.             'desc' => __('Set the Speed of Animations in Milliseconds', THEME_NS),
  490.             'type' => 'text',
  491.             'integer' => true,
  492.             'size' => 4,
  493.             'maxlength' => 3,
  494.             "default"   => 600,
  495.         ),
  496.  
  497.         array(
  498.             'id' => 'widget_directionNav',
  499.             'name' => __('Navigation', THEME_NS),
  500.             'desc' => __('Show Navigation for Previous and Next', THEME_NS),
  501.             'type' => 'checkbox',
  502.             "default"   => true,
  503.         ),
  504.        
  505.         array(
  506.             'id' => 'widget_prevText',
  507.             'name' => __('Previous Text', THEME_NS),
  508.             'desc' => __('Set the Text for the Previous Navigation', THEME_NS),
  509.             'type' => 'text',
  510.             "default"   => 'Previous',
  511.         ), 
  512.         array(
  513.             'id' => 'widget_nextText',
  514.             'name' => __('Next Text', THEME_NS),
  515.             'desc' => __('Set the Text for the Next Navigation', THEME_NS),
  516.             'type' => 'text',
  517.             "default"   => 'Next',
  518.         ), 
  519.    
  520.         array(
  521.             'id' => 'widget_randomize',
  522.             'name' => __('Randomize Slides', THEME_NS),
  523.             'desc' => __('Randomize the Order of the Slides', THEME_NS),
  524.             'type' => 'checkbox',
  525.             "default"   => true,
  526.         ),
  527.            
  528.         array( "type"   => "close"),
  529.    
  530.     );
  531.     return $general_options;
  532. }
  533. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement