class-wp-customize-control.php 25 KB

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