Advertisement
Guest User

Untitled

a guest
Mar 28th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2. /* ================== STEP: 1 ======================= */
  3.  
  4. /***  theme default options ***/
  5. if ( ! function_exists( 'aqkl_default_options' ) ) :
  6. function aqkl_default_options() {
  7.     $options = array(  
  8.        
  9.         'featured_cat' => '',
  10.     );
  11.     return $options;
  12.    
  13.    
  14. /* ================== STEP: 2 ======================= */
  15.  
  16.  
  17. // Store categories in array
  18. $aqkl_categories[0] = array(
  19.     'value' => 0,
  20.     'label' => ''
  21. );
  22. $aqkl_cats = get_categories(); $i = 1;
  23. foreach( $aqkl_cats as $aqkl_cat ) :
  24.     $aqkl_categories[$aqkl_cat->cat_ID] = array(
  25.         'value' => $aqkl_cat->cat_ID,
  26.         'label' => $aqkl_cat->cat_name
  27.     );
  28.     $i++;
  29. endforeach;
  30.  
  31. /* ================== STEP: 3 ======================= */
  32.  
  33. function aqkl_category_settings_sections() {
  34.     add_settings_section( 'aqkl_category_options_cb', __( 'category_boxa Link Options', 'aqoonkaal' ), 'aqkl_category_options_cb', 'aqkl_options_link' );
  35. }
  36.  
  37. function aqkl_category_options_cb() {
  38.     add_settings_field( 'aqkl_featured_category_options', __( 'Fancy Drop-down Menus', 'aqoonkaal' ), 'aqkl_featured_category_options', 'aqkl_options_link', 'aqkl_category_options_cb' );
  39. }
  40.  
  41. function aqkl_featured_category_options() { ?>
  42.     <select id="featured_cat" name="aqkl_theme_options[featured_cat]">
  43.     <?php
  44.     foreach ( $aqkl_categories as $category ) :
  45.         $label = $category['label'];
  46.         $selected = '';
  47.         if ( $category['value'] == aqkl_get_option('featured_cat') )
  48.             $selected = 'selected="selected"';
  49.         echo '<option style="padding-right: 10px;" value="' . esc_attr( $category['value'] ) . '" ' . $selected . '>' . $label . '</option>';
  50.     endforeach;
  51.     ?>
  52.     </select>
  53. <?php
  54. }
  55.  
  56. /* ================ STEP: 4 - Sanitize ================ */
  57. function aqkl_validate_theme_options( $input ) {
  58.  
  59.     if ( isset( $input['submit-general'] ) ) {
  60.    
  61.         $prev = aqkl_get_option('featured_cat');
  62.         // We verify if the given value exists in the categories array
  63.         if ( !array_key_exists( $input['featured_cat'], $aqkl_categories ) )
  64.         $input['featured_cat'] = $prev;
  65.     }
  66.  
  67.        
  68.     $input = wp_parse_args( $input, get_option( 'aqkl_theme_options', aqkl_default_options() ) );
  69.    
  70.     return $input;
  71. }
  72.  
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement