Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* ================== STEP: 1 ======================= */
- /*** theme default options ***/
- if ( ! function_exists( 'aqkl_default_options' ) ) :
- function aqkl_default_options() {
- $options = array(
- 'featured_cat' => '',
- );
- return $options;
- /* ================== STEP: 2 ======================= */
- // Store categories in array
- $aqkl_categories[0] = array(
- 'value' => 0,
- 'label' => ''
- );
- $aqkl_cats = get_categories(); $i = 1;
- foreach( $aqkl_cats as $aqkl_cat ) :
- $aqkl_categories[$aqkl_cat->cat_ID] = array(
- 'value' => $aqkl_cat->cat_ID,
- 'label' => $aqkl_cat->cat_name
- );
- $i++;
- endforeach;
- /* ================== STEP: 3 ======================= */
- function aqkl_category_settings_sections() {
- add_settings_section( 'aqkl_category_options_cb', __( 'category_boxa Link Options', 'aqoonkaal' ), 'aqkl_category_options_cb', 'aqkl_options_link' );
- }
- function aqkl_category_options_cb() {
- add_settings_field( 'aqkl_featured_category_options', __( 'Fancy Drop-down Menus', 'aqoonkaal' ), 'aqkl_featured_category_options', 'aqkl_options_link', 'aqkl_category_options_cb' );
- }
- function aqkl_featured_category_options() { ?>
- <select id="featured_cat" name="aqkl_theme_options[featured_cat]">
- <?php
- foreach ( $aqkl_categories as $category ) :
- $label = $category['label'];
- $selected = '';
- if ( $category['value'] == aqkl_get_option('featured_cat') )
- $selected = 'selected="selected"';
- echo '<option style="padding-right: 10px;" value="' . esc_attr( $category['value'] ) . '" ' . $selected . '>' . $label . '</option>';
- endforeach;
- ?>
- </select>
- <?php
- }
- /* ================ STEP: 4 - Sanitize ================ */
- function aqkl_validate_theme_options( $input ) {
- if ( isset( $input['submit-general'] ) ) {
- $prev = aqkl_get_option('featured_cat');
- // We verify if the given value exists in the categories array
- if ( !array_key_exists( $input['featured_cat'], $aqkl_categories ) )
- $input['featured_cat'] = $prev;
- }
- $input = wp_parse_args( $input, get_option( 'aqkl_theme_options', aqkl_default_options() ) );
- return $input;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement