<?php

if (!class_exists('WP_Customize_Control'))
    return NULL;

/**
 * A class to create a dropdown for all categories in your WordPress site
 */
class lois_Category_Dropdown_Custom_Control extends WP_Customize_Control
{
    private $cats = false;

    public function __construct($manager, $id, $args = array(), $options = array())
    {
        $this->cats = get_categories($options);

        parent::__construct($manager, $id, $args);
    }

    /**
     * Render the content of the category dropdown
     *
     * @return HTML
     */
    public function render_content()
    {
        if (!empty($this->cats)) { ?>
            <label>
                <span class="customize-category-select-control"><?php echo esc_html($this->label); ?></span>
                <select <?php $this->link(); ?>>
                    <option value="0" selected="selected"><?php esc_html_e('Select Category', 'lois'); ?></option>
                    <?php
                    foreach ($this->cats as $cat) {
                        printf('<option value="%s" %s>%s</option>', wp_kses( $cat->term_id , allowed_tags() ), selected($this->value(), wp_kses( $cat->term_id , allowed_tags() ), false), wp_kses( $cat->name , allowed_tags() ) );
                    }
                    ?>
                </select>
            </label>
            <?php
        }
    }
}

?>