class-wp-customize-control.php 24 KB

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