home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-includes / class-wp-customize-control.php < prev    next >
Encoding:
PHP Script  |  2017-10-27  |  24.4 KB  |  795 lines

  1. <?php
  2. /**
  3.  * WordPress Customize Control classes
  4.  *
  5.  * @package WordPress
  6.  * @subpackage Customize
  7.  * @since 3.4.0
  8.  */
  9.  
  10. /**
  11.  * Customize Control class.
  12.  *
  13.  * @since 3.4.0
  14.  */
  15. class WP_Customize_Control {
  16.  
  17.     /**
  18.      * Incremented with each new class instantiation, then stored in $instance_number.
  19.      *
  20.      * Used when sorting two instances whose priorities are equal.
  21.      *
  22.      * @since 4.1.0
  23.      *
  24.      * @static
  25.      * @var int
  26.      */
  27.     protected static $instance_count = 0;
  28.  
  29.     /**
  30.      * Order in which this instance was created in relation to other instances.
  31.      *
  32.      * @since 4.1.0
  33.      * @var int
  34.      */
  35.     public $instance_number;
  36.  
  37.     /**
  38.      * Customizer manager.
  39.      *
  40.      * @since 3.4.0
  41.      * @var WP_Customize_Manager
  42.      */
  43.     public $manager;
  44.  
  45.     /**
  46.      * Control ID.
  47.      *
  48.      * @since 3.4.0
  49.      * @var string
  50.      */
  51.     public $id;
  52.  
  53.     /**
  54.      * All settings tied to the control.
  55.      *
  56.      * @since 3.4.0
  57.      * @var array
  58.      */
  59.     public $settings;
  60.  
  61.     /**
  62.      * The primary setting for the control (if there is one).
  63.      *
  64.      * @since 3.4.0
  65.      * @var string
  66.      */
  67.     public $setting = 'default';
  68.  
  69.     /**
  70.      * Capability required to use this control.
  71.      *
  72.      * Normally this is empty and the capability is derived from the capabilities
  73.      * of the associated `$settings`.
  74.      *
  75.      * @since 4.5.0
  76.      * @var string
  77.      */
  78.     public $capability;
  79.  
  80.     /**
  81.      * Order priority to load the control in Customizer.
  82.      *
  83.      * @since 3.4.0
  84.      * @var int
  85.      */
  86.     public $priority = 10;
  87.  
  88.     /**
  89.      * Section the control belongs to.
  90.      *
  91.      * @since 3.4.0
  92.      * @var string
  93.      */
  94.     public $section = '';
  95.  
  96.     /**
  97.      * Label for the control.
  98.      *
  99.      * @since 3.4.0
  100.      * @var string
  101.      */
  102.     public $label = '';
  103.  
  104.     /**
  105.      * Description for the control.
  106.      *
  107.      * @since 4.0.0
  108.      * @var string
  109.      */
  110.     public $description = '';
  111.  
  112.     /**
  113.      * List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values.
  114.      *
  115.      * @since 3.4.0
  116.      * @var array
  117.      */
  118.     public $choices = array();
  119.  
  120.     /**
  121.      * List of custom input attributes for control output, where attribute names are the keys and values are the values.
  122.      *
  123.      * Not used for 'checkbox', 'radio', 'select', 'textarea', or 'dropdown-pages' control types.
  124.      *
  125.      * @since 4.0.0
  126.      * @var array
  127.      */
  128.     public $input_attrs = array();
  129.  
  130.     /**
  131.      * Show UI for adding new content, currently only used for the dropdown-pages control.
  132.      *
  133.      * @since 4.7.0
  134.      * @var bool
  135.      */
  136.     public $allow_addition = false;
  137.  
  138.     /**
  139.      * @deprecated It is better to just call the json() method
  140.      * @since 3.4.0
  141.      * @var array
  142.      */
  143.     public $json = array();
  144.  
  145.     /**
  146.      * Control's Type.
  147.      *
  148.      * @since 3.4.0
  149.      * @var string
  150.      */
  151.     public $type = 'text';
  152.  
  153.     /**
  154.      * Callback.
  155.      *
  156.      * @since 4.0.0
  157.      *
  158.      * @see WP_Customize_Control::active()
  159.      *
  160.      * @var callable Callback is called with one argument, the instance of
  161.      *               WP_Customize_Control, and returns bool to indicate whether
  162.      *               the control is active (such as it relates to the URL
  163.      *               currently being previewed).
  164.      */
  165.     public $active_callback = '';
  166.  
  167.     /**
  168.      * Constructor.
  169.      *
  170.      * Supplied `$args` override class property defaults.
  171.      *
  172.      * If `$args['settings']` is not defined, use the $id as the setting ID.
  173.      *
  174.      * @since 3.4.0
  175.      *
  176.      * @param WP_Customize_Manager $manager Customizer bootstrap instance.
  177.      * @param string               $id      Control ID.
  178.      * @param array                $args    {
  179.      *     Optional. Arguments to override class property defaults.
  180.      *
  181.      *     @type int                  $instance_number Order in which this instance was created in relation
  182.      *                                                 to other instances.
  183.      *     @type WP_Customize_Manager $manager         Customizer bootstrap instance.
  184.      *     @type string               $id              Control ID.
  185.      *     @type array                $settings        All settings tied to the control. If undefined, `$id` will
  186.      *                                                 be used.
  187.      *     @type string               $setting         The primary setting for the control (if there is one).
  188.      *                                                 Default 'default'.
  189.      *     @type int                  $priority        Order priority to load the control. Default 10.
  190.      *     @type string               $section         Section the control belongs to. Default empty.
  191.      *     @type string               $label           Label for the control. Default empty.
  192.      *     @type string               $description     Description for the control. Default empty.
  193.      *     @type array                $choices         List of choices for 'radio' or 'select' type controls, where
  194.      *                                                 values are the keys, and labels are the values.
  195.      *                                                 Default empty array.
  196.      *     @type array                $input_attrs     List of custom input attributes for control output, where
  197.      *                                                 attribute names are the keys and values are the values. Not
  198.      *                                                 used for 'checkbox', 'radio', 'select', 'textarea', or
  199.      *                                                 'dropdown-pages' control types. Default empty array.
  200.      *     @type array                $json            Deprecated. Use WP_Customize_Control::json() instead.
  201.      *     @type string               $type            Control type. Core controls include 'text', 'checkbox',
  202.      *                                                 'textarea', 'radio', 'select', and 'dropdown-pages'. Additional
  203.      *                                                 input types such as 'email', 'url', 'number', 'hidden', and
  204.      *                                                 'date' are supported implicitly. Default 'text'.
  205.      * }
  206.      */
  207.     public function __construct( $manager, $id, $args = array() ) {
  208.         $keys = array_keys( get_object_vars( $this ) );
  209.         foreach ( $keys as $key ) {
  210.             if ( isset( $args[ $key ] ) ) {
  211.                 $this->$key = $args[ $key ];
  212.             }
  213.         }
  214.  
  215.         $this->manager = $manager;
  216.         $this->id = $id;
  217.         if ( empty( $this->active_callback ) ) {
  218.             $this->active_callback = array( $this, 'active_callback' );
  219.         }
  220.         self::$instance_count += 1;
  221.         $this->instance_number = self::$instance_count;
  222.  
  223.         // Process settings.
  224.         if ( ! isset( $this->settings ) ) {
  225.             $this->settings = $id;
  226.         }
  227.  
  228.         $settings = array();
  229.         if ( is_array( $this->settings ) ) {
  230.             foreach ( $this->settings as $key => $setting ) {
  231.                 $settings[ $key ] = $this->manager->get_setting( $setting );
  232.             }
  233.         } else if ( is_string( $this->settings ) ) {
  234.             $this->setting = $this->manager->get_setting( $this->settings );
  235.             $settings['default'] = $this->setting;
  236.         }
  237.         $this->settings = $settings;
  238.     }
  239.  
  240.     /**
  241.      * Enqueue control related scripts/styles.
  242.      *
  243.      * @since 3.4.0
  244.      */
  245.     public function enqueue() {}
  246.  
  247.     /**
  248.      * Check whether control is active to current Customizer preview.
  249.      *
  250.      * @since 4.0.0
  251.      *
  252.      * @return bool Whether the control is active to the current preview.
  253.      */
  254.     final public function active() {
  255.         $control = $this;
  256.         $active = call_user_func( $this->active_callback, $this );
  257.  
  258.         /**
  259.          * Filters response of WP_Customize_Control::active().
  260.          *
  261.          * @since 4.0.0
  262.          *
  263.          * @param bool                 $active  Whether the Customizer control is active.
  264.          * @param WP_Customize_Control $control WP_Customize_Control instance.
  265.          */
  266.         $active = apply_filters( 'customize_control_active', $active, $control );
  267.  
  268.         return $active;
  269.     }
  270.  
  271.     /**
  272.      * Default callback used when invoking WP_Customize_Control::active().
  273.      *
  274.      * Subclasses can override this with their specific logic, or they may
  275.      * provide an 'active_callback' argument to the constructor.
  276.      *
  277.      * @since 4.0.0
  278.      *
  279.      * @return true Always true.
  280.      */
  281.     public function active_callback() {
  282.         return true;
  283.     }
  284.  
  285.     /**
  286.      * Fetch a setting's value.
  287.      * Grabs the main setting by default.
  288.      *
  289.      * @since 3.4.0
  290.      *
  291.      * @param string $setting_key
  292.      * @return mixed The requested setting's value, if the setting exists.
  293.      */
  294.     final public function value( $setting_key = 'default' ) {
  295.         if ( isset( $this->settings[ $setting_key ] ) ) {
  296.             return $this->settings[ $setting_key ]->value();
  297.         }
  298.     }
  299.  
  300.     /**
  301.      * Refresh the parameters passed to the JavaScript via JSON.
  302.      *
  303.      * @since 3.4.0
  304.      */
  305.     public function to_json() {
  306.         $this->json['settings'] = array();
  307.         foreach ( $this->settings as $key => $setting ) {
  308.             $this->json['settings'][ $key ] = $setting->id;
  309.         }
  310.  
  311.         $this->json['type'] = $this->type;
  312.         $this->json['priority'] = $this->priority;
  313.         $this->json['active'] = $this->active();
  314.         $this->json['section'] = $this->section;
  315.         $this->json['content'] = $this->get_content();
  316.         $this->json['label'] = $this->label;
  317.         $this->json['description'] = $this->description;
  318.         $this->json['instanceNumber'] = $this->instance_number;
  319.  
  320.         if ( 'dropdown-pages' === $this->type ) {
  321.             $this->json['allow_addition'] = $this->allow_addition;
  322.         }
  323.     }
  324.  
  325.     /**
  326.      * Get the data to export to the client via JSON.
  327.      *
  328.      * @since 4.1.0
  329.      *
  330.      * @return array Array of parameters passed to the JavaScript.
  331.      */
  332.     public function json() {
  333.         $this->to_json();
  334.         return $this->json;
  335.     }
  336.  
  337.     /**
  338.      * Checks if the user can use this control.
  339.      *
  340.      * Returns false if the user cannot manipulate one of the associated settings,
  341.      * or if one of the associated settings does not exist. Also returns false if
  342.      * the associated section does not exist or if its capability check returns
  343.      * false.
  344.      *
  345.      * @since 3.4.0
  346.      *
  347.      * @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true.
  348.      */
  349.     final public function check_capabilities() {
  350.         if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) {
  351.             return false;
  352.         }
  353.  
  354.         foreach ( $this->settings as $setting ) {
  355.             if ( ! $setting || ! $setting->check_capabilities() ) {
  356.                 return false;
  357.             }
  358.         }
  359.  
  360.         $section = $this->manager->get_section( $this->section );
  361.         if ( isset( $section ) && ! $section->check_capabilities() ) {
  362.             return false;
  363.         }
  364.  
  365.         return true;
  366.     }
  367.  
  368.     /**
  369.      * Get the control's content for insertion into the Customizer pane.
  370.      *
  371.      * @since 4.1.0
  372.      *
  373.      * @return string Contents of the control.
  374.      */
  375.     final public function get_content() {
  376.         ob_start();
  377.         $this->maybe_render();
  378.         return trim( ob_get_clean() );
  379.     }
  380.  
  381.     /**
  382.      * Check capabilities and render the control.
  383.      *
  384.      * @since 3.4.0
  385.      * @uses WP_Customize_Control::render()
  386.      */
  387.     final public function maybe_render() {
  388.         if ( ! $this->check_capabilities() )
  389.             return;
  390.  
  391.         /**
  392.          * Fires just before the current Customizer control is rendered.
  393.          *
  394.          * @since 3.4.0
  395.          *
  396.          * @param WP_Customize_Control $this WP_Customize_Control instance.
  397.          */
  398.         do_action( 'customize_render_control', $this );
  399.  
  400.         /**
  401.          * Fires just before a specific Customizer control is rendered.
  402.          *
  403.          * The dynamic portion of the hook name, `$this->id`, refers to
  404.          * the control ID.
  405.          *
  406.          * @since 3.4.0
  407.          *
  408.          * @param WP_Customize_Control $this WP_Customize_Control instance.
  409.          */
  410.         do_action( "customize_render_control_{$this->id}", $this );
  411.  
  412.         $this->render();
  413.     }
  414.  
  415.     /**
  416.      * Renders the control wrapper and calls $this->render_content() for the internals.
  417.      *
  418.      * @since 3.4.0
  419.      */
  420.     protected function render() {
  421.         $id    = 'customize-control-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id );
  422.         $class = 'customize-control customize-control-' . $this->type;
  423.  
  424.         printf( '<li id="%s" class="%s">', esc_attr( $id ), esc_attr( $class ) );
  425.         $this->render_content();
  426.         echo '</li>';
  427.     }
  428.  
  429.     /**
  430.      * Get the data link attribute for a setting.
  431.      *
  432.      * @since 3.4.0
  433.      * @since 4.9.0 Return a `data-customize-setting-key-link` attribute if a setting is not registered for the supplied setting key.
  434.      *
  435.      * @param string $setting_key
  436.      * @return string Data link parameter, a `data-customize-setting-link` attribute if the `$setting_key` refers to a pre-registered setting,
  437.      *                and a `data-customize-setting-key-link` attribute if the setting is not yet registered.
  438.      */
  439.     public function get_link( $setting_key = 'default' ) {
  440.         if ( isset( $this->settings[ $setting_key ] ) && $this->settings[ $setting_key ] instanceof WP_Customize_Setting ) {
  441.             return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
  442.         } else {
  443.             return 'data-customize-setting-key-link="' . esc_attr( $setting_key ) . '"';
  444.         }
  445.     }
  446.  
  447.     /**
  448.      * Render the data link attribute for the control's input element.
  449.      *
  450.      * @since 3.4.0
  451.      * @uses WP_Customize_Control::get_link()
  452.      *
  453.      * @param string $setting_key
  454.      */
  455.     public function link( $setting_key = 'default' ) {
  456.         echo $this->get_link( $setting_key );
  457.     }
  458.  
  459.     /**
  460.      * Render the custom attributes for the control's input element.
  461.      *
  462.      * @since 4.0.0
  463.      */
  464.     public function input_attrs() {
  465.         foreach ( $this->input_attrs as $attr => $value ) {
  466.             echo $attr . '="' . esc_attr( $value ) . '" ';
  467.         }
  468.     }
  469.  
  470.     /**
  471.      * Render the control's content.
  472.      *
  473.      * Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`.
  474.      *
  475.      * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
  476.      * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
  477.      *
  478.      * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template().
  479.      *
  480.      * @since 3.4.0
  481.      */
  482.     protected function render_content() {
  483.         $input_id = '_customize-input-' . $this->id;
  484.         $description_id = '_customize-description-' . $this->id;
  485.         $describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '" ' : '';
  486.         switch ( $this->type ) {
  487.             case 'checkbox':
  488.                 ?>
  489.                 <span class="customize-inside-control-row">
  490.                     <input
  491.                         id="<?php echo esc_attr( $input_id ); ?>"
  492.                         <?php echo $describedby_attr; ?>
  493.                         type="checkbox"
  494.                         value="<?php echo esc_attr( $this->value() ); ?>"
  495.                         <?php $this->link(); ?>
  496.                         <?php checked( $this->value() ); ?>
  497.                     />
  498.                     <label for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_html( $this->label ); ?></label>
  499.                     <?php if ( ! empty( $this->description ) ) : ?>
  500.                         <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
  501.                     <?php endif; ?>
  502.                 </span>
  503.                 <?php
  504.                 break;
  505.             case 'radio':
  506.                 if ( empty( $this->choices ) ) {
  507.                     return;
  508.                 }
  509.  
  510.                 $name = '_customize-radio-' . $this->id;
  511.                 ?>
  512.                 <?php if ( ! empty( $this->label ) ) : ?>
  513.                     <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  514.                 <?php endif; ?>
  515.                 <?php if ( ! empty( $this->description ) ) : ?>
  516.                     <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description ; ?></span>
  517.                 <?php endif; ?>
  518.  
  519.                 <?php foreach ( $this->choices as $value => $label ) : ?>
  520.                     <span class="customize-inside-control-row">
  521.                         <input
  522.                             id="<?php echo esc_attr( $input_id . '-radio-' . $value ); ?>"
  523.                             type="radio"
  524.                             <?php echo $describedby_attr; ?>
  525.                             value="<?php echo esc_attr( $value ); ?>"
  526.                             name="<?php echo esc_attr( $name ); ?>"
  527.                             <?php $this->link(); ?>
  528.                             <?php checked( $this->value(), $value ); ?>
  529.                             />
  530.                         <label for="<?php echo esc_attr( $input_id . '-radio-' . $value ); ?>"><?php echo esc_html( $label ); ?></label>
  531.                     </span>
  532.                 <?php endforeach; ?>
  533.                 <?php
  534.                 break;
  535.             case 'select':
  536.                 if ( empty( $this->choices ) ) {
  537.                     return;
  538.                 }
  539.  
  540.                 ?>
  541.                 <?php if ( ! empty( $this->label ) ) : ?>
  542.                     <label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label>
  543.                 <?php endif; ?>
  544.                 <?php if ( ! empty( $this->description ) ) : ?>
  545.                     <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
  546.                 <?php endif; ?>
  547.  
  548.                 <select id="<?php echo esc_attr( $input_id ); ?>" <?php echo $describedby_attr; ?> <?php $this->link(); ?>>
  549.                     <?php
  550.                     foreach ( $this->choices as $value => $label ) {
  551.                         echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
  552.                     }
  553.                     ?>
  554.                 </select>
  555.                 <?php
  556.                 break;
  557.             case 'textarea':
  558.                 ?>
  559.                 <?php if ( ! empty( $this->label ) ) : ?>
  560.                     <label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label>
  561.                 <?php endif; ?>
  562.                 <?php if ( ! empty( $this->description ) ) : ?>
  563.                     <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
  564.                 <?php endif; ?>
  565.                 <textarea
  566.                     id="<?php echo esc_attr( $input_id ); ?>"
  567.                     rows="5"
  568.                     <?php echo $describedby_attr; ?>
  569.                     <?php $this->input_attrs(); ?>
  570.                     <?php $this->link(); ?>>
  571.                     <?php echo esc_textarea( $this->value() ); ?>
  572.                 </textarea>
  573.                 <?php
  574.                 break;
  575.             case 'dropdown-pages':
  576.                 ?>
  577.                 <?php if ( ! empty( $this->label ) ) : ?>
  578.                     <label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label>
  579.                 <?php endif; ?>
  580.                 <?php if ( ! empty( $this->description ) ) : ?>
  581.                     <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
  582.                 <?php endif; ?>
  583.  
  584.                 <?php
  585.                 $dropdown_name = '_customize-dropdown-pages-' . $this->id;
  586.                 $show_option_none = __( '— Select —' );
  587.                 $option_none_value = '0';
  588.                 $dropdown = wp_dropdown_pages(
  589.                     array(
  590.                         'name'              => $dropdown_name,
  591.                         'echo'              => 0,
  592.                         'show_option_none'  => $show_option_none,
  593.                         'option_none_value' => $option_none_value,
  594.                         'selected'          => $this->value(),
  595.                     )
  596.                 );
  597.                 if ( empty( $dropdown ) ) {
  598.                     $dropdown = sprintf( '<select id="%1$s" name="%1$s">', esc_attr( $dropdown_name ) );
  599.                     $dropdown .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $option_none_value ), esc_html( $show_option_none ) );
  600.                     $dropdown .= '</select>';
  601.                 }
  602.  
  603.                 // Hackily add in the data link parameter.
  604.                 $dropdown = str_replace( '<select', '<select ' . $this->get_link() . ' id="' . esc_attr( $input_id ) . '" ' . $describedby_attr, $dropdown );
  605.  
  606.                 // Even more hacikly add auto-draft page stubs.
  607.                 // @todo Eventually this should be removed in favor of the pages being injected into the underlying get_pages() call. See <https://github.com/xwp/wp-customize-posts/pull/250>.
  608.                 $nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' );
  609.                 if ( $nav_menus_created_posts_setting && current_user_can( 'publish_pages' ) ) {
  610.                     $auto_draft_page_options = '';
  611.                     foreach ( $nav_menus_created_posts_setting->value() as $auto_draft_page_id ) {
  612.                         $post = get_post( $auto_draft_page_id );
  613.                         if ( $post && 'page' === $post->post_type ) {
  614.                             $auto_draft_page_options .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $post->ID ), esc_html( $post->post_title ) );
  615.                         }
  616.                     }
  617.                     if ( $auto_draft_page_options ) {
  618.                         $dropdown = str_replace( '</select>', $auto_draft_page_options . '</select>', $dropdown );
  619.                     }
  620.                 }
  621.  
  622.                 echo $dropdown;
  623.                 ?>
  624.                 <?php if ( $this->allow_addition && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?>
  625.                     <button type="button" class="button-link add-new-toggle">
  626.                         <?php
  627.                         /* translators: %s: add new page label */
  628.                         printf( __( '+ %s' ), get_post_type_object( 'page' )->labels->add_new_item );
  629.                         ?>
  630.                     </button>
  631.                     <div class="new-content-item">
  632.                         <label for="create-input-<?php echo $this->id; ?>"><span class="screen-reader-text"><?php _e( 'New page title' ); ?></span></label>
  633.                         <input type="text" id="create-input-<?php echo $this->id; ?>" class="create-item-input" placeholder="<?php esc_attr_e( 'New page title…' ); ?>">
  634.                         <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button>
  635.                     </div>
  636.                 <?php endif; ?>
  637.                 <?php
  638.                 break;
  639.             default:
  640.                 ?>
  641.                 <?php if ( ! empty( $this->label ) ) : ?>
  642.                     <label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label>
  643.                 <?php endif; ?>
  644.                 <?php if ( ! empty( $this->description ) ) : ?>
  645.                     <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
  646.                 <?php endif; ?>
  647.                 <input
  648.                     id="<?php echo esc_attr( $input_id ); ?>"
  649.                     type="<?php echo esc_attr( $this->type ); ?>"
  650.                     <?php echo $describedby_attr; ?>
  651.                     <?php $this->input_attrs(); ?>
  652.                     <?php if ( ! isset( $this->input_attrs['value'] ) ) : ?>
  653.                         value="<?php echo esc_attr( $this->value() ); ?>"
  654.                     <?php endif; ?>
  655.                     <?php $this->link(); ?>
  656.                     />
  657.                 <?php
  658.                 break;
  659.         }
  660.     }
  661.  
  662.     /**
  663.      * Render the control's JS template.
  664.      *
  665.      * This function is only run for control types that have been registered with
  666.      * WP_Customize_Manager::register_control_type().
  667.      *
  668.      * In the future, this will also print the template for the control's container
  669.      * element and be override-able.
  670.      *
  671.      * @since 4.1.0
  672.      */
  673.     final public function print_template() {
  674.         ?>
  675.         <script type="text/html" id="tmpl-customize-control-<?php echo $this->type; ?>-content">
  676.             <?php $this->content_template(); ?>
  677.         </script>
  678.         <?php
  679.     }
  680.  
  681.     /**
  682.      * An Underscore (JS) template for this control's content (but not its container).
  683.      *
  684.      * Class variables for this control class are available in the `data` JS object;
  685.      * export custom variables by overriding WP_Customize_Control::to_json().
  686.      *
  687.      * @see WP_Customize_Control::print_template()
  688.      *
  689.      * @since 4.1.0
  690.      */
  691.     protected function content_template() {}
  692.  
  693. }
  694.  
  695. /**
  696.  * WP_Customize_Color_Control class.
  697.  */
  698. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-color-control.php' );
  699.  
  700. /**
  701.  * WP_Customize_Media_Control class.
  702.  */
  703. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-media-control.php' );
  704.  
  705. /**
  706.  * WP_Customize_Upload_Control class.
  707.  */
  708. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-upload-control.php' );
  709.  
  710. /**
  711.  * WP_Customize_Image_Control class.
  712.  */
  713. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-image-control.php' );
  714.  
  715. /**
  716.  * WP_Customize_Background_Image_Control class.
  717.  */
  718. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php' );
  719.  
  720. /**
  721.  * WP_Customize_Background_Position_Control class.
  722.  */
  723. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-position-control.php' );
  724.  
  725. /**
  726.  * WP_Customize_Cropped_Image_Control class.
  727.  */
  728. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php' );
  729.  
  730. /**
  731.  * WP_Customize_Site_Icon_Control class.
  732.  */
  733. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-site-icon-control.php' );
  734.  
  735. /**
  736.  * WP_Customize_Header_Image_Control class.
  737.  */
  738. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php' );
  739.  
  740. /**
  741.  * WP_Customize_Theme_Control class.
  742.  */
  743. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php' );
  744.  
  745. /**
  746.  * WP_Widget_Area_Customize_Control class.
  747.  */
  748. require_once( ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php' );
  749.  
  750. /**
  751.  * WP_Widget_Form_Customize_Control class.
  752.  */
  753. require_once( ABSPATH . WPINC . '/customize/class-wp-widget-form-customize-control.php' );
  754.  
  755. /**
  756.  * WP_Customize_Nav_Menu_Control class.
  757.  */
  758. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-control.php' );
  759.  
  760. /**
  761.  * WP_Customize_Nav_Menu_Item_Control class.
  762.  */
  763. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-control.php' );
  764.  
  765. /**
  766.  * WP_Customize_Nav_Menu_Location_Control class.
  767.  */
  768. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-location-control.php' );
  769.  
  770. /**
  771.  * WP_Customize_Nav_Menu_Name_Control class.
  772.  *
  773.  * As this file is deprecated, it will trigger a deprecation notice if instantiated. In a subsequent
  774.  * release, the require_once() here will be removed and _deprecated_file() will be called if file is
  775.  * required at all.
  776.  *
  777.  * @deprecated 4.9.0 This file is no longer used due to new menu creation UX.
  778.  */
  779. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-name-control.php' );
  780.  
  781. /**
  782.  * WP_Customize_Nav_Menu_Locations_Control class.
  783.  */
  784. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-locations-control.php' );
  785.  
  786. /**
  787.  * WP_Customize_Nav_Menu_Auto_Add_Control class.
  788.  */
  789. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-auto-add-control.php' );
  790.  
  791. /**
  792.  * WP_Customize_Date_Time_Control class.
  793.  */
  794. require_once( ABSPATH . WPINC . '/customize/class-wp-customize-date-time-control.php' );
  795.