<?php

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

/**
 * A class to create a dropdown for all categories in your WordPress site
 */
 class Promos_Customize_Category_Dropdown_Control extends WP_Customize_Control {
    
    /**
     * Render the control's content.
     *
     * @return void
     * @since 1.0.0
     */
    public function render_content() {
      $promos_dropdown = wp_dropdown_categories(
          array(
            'name'              => 'customize-dropdown-categories' . $this->id,
            'echo'              => 0,
            'show_option_none'  => esc_html__( '&mdash; Select Category &mdash;','promos'),
            'option_none_value' => '0',
            'selected'          => $this->value(),
          )
      );

      // Hackily add in the data link parameter.
      $promos_dropdown = str_replace( '<select', '<select ' . $this->get_link(), $promos_dropdown );

      printf(
        '<label class="customize-control-select"><span class="customize-control-title">%1$s</span><span class="description customize-control-description">%2$s</span> %3$s </label>',
        esc_html( $this->label ),
        esc_html( $this->description ),
        wp_kses(
          $promos_dropdown,
          array(
            'select' => array(
              'name'                        => array(),
              'id'                          => array(),
              'class'                       => array(),
              'multiple'                    => array(),
              'data-customize-setting-link' => array(),
            ),
            'option' => array(
              'value'    => array(),
              'selected' => array(),
            ),
          )
        )
      );
    }
  }