class-wp-customize-nav-menu-item-control.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Customize API: WP_Customize_Nav_Menu_Item_Control class
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 4.4.0
  8. */
  9. /**
  10. * Customize control to represent the name field for a given menu.
  11. *
  12. * @since 4.3.0
  13. *
  14. * @see WP_Customize_Control
  15. */
  16. class WP_Customize_Nav_Menu_Item_Control extends WP_Customize_Control {
  17. /**
  18. * Control type.
  19. *
  20. * @since 4.3.0
  21. * @var string
  22. */
  23. public $type = 'nav_menu_item';
  24. /**
  25. * The nav menu item setting.
  26. *
  27. * @since 4.3.0
  28. * @var WP_Customize_Nav_Menu_Item_Setting
  29. */
  30. public $setting;
  31. /**
  32. * Constructor.
  33. *
  34. * @since 4.3.0
  35. *
  36. * @see WP_Customize_Control::__construct()
  37. *
  38. * @param WP_Customize_Manager $manager Customizer bootstrap instance.
  39. * @param string $id The control ID.
  40. * @param array $args Optional. Overrides class property defaults.
  41. */
  42. public function __construct( $manager, $id, $args = array() ) {
  43. parent::__construct( $manager, $id, $args );
  44. }
  45. /**
  46. * Don't render the control's content - it's rendered with a JS template.
  47. *
  48. * @since 4.3.0
  49. */
  50. public function render_content() {}
  51. /**
  52. * JS/Underscore template for the control UI.
  53. *
  54. * @since 4.3.0
  55. */
  56. public function content_template() {
  57. ?>
  58. <div class="menu-item-bar">
  59. <div class="menu-item-handle">
  60. <span class="item-type" aria-hidden="true">{{ data.item_type_label }}</span>
  61. <span class="item-title" aria-hidden="true">
  62. <span class="spinner"></span>
  63. <span class="menu-item-title<# if ( ! data.title && ! data.original_title ) { #> no-title<# } #>">{{ data.title || data.original_title || wp.customize.Menus.data.l10n.untitled }}</span>
  64. </span>
  65. <span class="item-controls">
  66. <button type="button" class="button-link item-edit" aria-expanded="false"><span class="screen-reader-text">
  67. <?php
  68. /* translators: 1: Title of a menu item, 2: Type of a menu item. */
  69. printf( __( 'Edit menu item: %1$s (%2$s)' ), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.item_type_label }}' );
  70. ?>
  71. </span><span class="toggle-indicator" aria-hidden="true"></span></button>
  72. <button type="button" class="button-link item-delete submitdelete deletion"><span class="screen-reader-text">
  73. <?php
  74. /* translators: 1: Title of a menu item, 2: Type of a menu item. */
  75. printf( __( 'Remove Menu Item: %1$s (%2$s)' ), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.item_type_label }}' );
  76. ?>
  77. </span></button>
  78. </span>
  79. </div>
  80. </div>
  81. <div class="menu-item-settings" id="menu-item-settings-{{ data.menu_item_id }}">
  82. <# if ( 'custom' === data.item_type ) { #>
  83. <p class="field-url description description-thin">
  84. <label for="edit-menu-item-url-{{ data.menu_item_id }}">
  85. <?php _e( 'URL' ); ?><br />
  86. <input class="widefat code edit-menu-item-url" type="text" id="edit-menu-item-url-{{ data.menu_item_id }}" name="menu-item-url" />
  87. </label>
  88. </p>
  89. <# } #>
  90. <p class="description description-thin">
  91. <label for="edit-menu-item-title-{{ data.menu_item_id }}">
  92. <?php _e( 'Navigation Label' ); ?><br />
  93. <input type="text" id="edit-menu-item-title-{{ data.menu_item_id }}" placeholder="{{ data.original_title }}" class="widefat edit-menu-item-title" name="menu-item-title" />
  94. </label>
  95. </p>
  96. <p class="field-link-target description description-thin">
  97. <label for="edit-menu-item-target-{{ data.menu_item_id }}">
  98. <input type="checkbox" id="edit-menu-item-target-{{ data.menu_item_id }}" class="edit-menu-item-target" value="_blank" name="menu-item-target" />
  99. <?php _e( 'Open link in a new tab' ); ?>
  100. </label>
  101. </p>
  102. <p class="field-title-attribute field-attr-title description description-thin">
  103. <label for="edit-menu-item-attr-title-{{ data.menu_item_id }}">
  104. <?php _e( 'Title Attribute' ); ?><br />
  105. <input type="text" id="edit-menu-item-attr-title-{{ data.menu_item_id }}" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title" />
  106. </label>
  107. </p>
  108. <p class="field-css-classes description description-thin">
  109. <label for="edit-menu-item-classes-{{ data.menu_item_id }}">
  110. <?php _e( 'CSS Classes' ); ?><br />
  111. <input type="text" id="edit-menu-item-classes-{{ data.menu_item_id }}" class="widefat code edit-menu-item-classes" name="menu-item-classes" />
  112. </label>
  113. </p>
  114. <p class="field-xfn description description-thin">
  115. <label for="edit-menu-item-xfn-{{ data.menu_item_id }}">
  116. <?php _e( 'Link Relationship (XFN)' ); ?><br />
  117. <input type="text" id="edit-menu-item-xfn-{{ data.menu_item_id }}" class="widefat code edit-menu-item-xfn" name="menu-item-xfn" />
  118. </label>
  119. </p>
  120. <p class="field-description description description-thin">
  121. <label for="edit-menu-item-description-{{ data.menu_item_id }}">
  122. <?php _e( 'Description' ); ?><br />
  123. <textarea id="edit-menu-item-description-{{ data.menu_item_id }}" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description">{{ data.description }}</textarea>
  124. <span class="description"><?php _e( 'The description will be displayed in the menu if the current theme supports it.' ); ?></span>
  125. </label>
  126. </p>
  127. <div class="menu-item-actions description-thin submitbox">
  128. <# if ( ( 'post_type' === data.item_type || 'taxonomy' === data.item_type ) && '' !== data.original_title ) { #>
  129. <p class="link-to-original">
  130. <?php
  131. /* translators: Nav menu item original title. %s: Original title. */
  132. printf( __( 'Original: %s' ), '<a class="original-link" href="{{ data.url }}">{{ data.original_title }}</a>' );
  133. ?>
  134. </p>
  135. <# } #>
  136. <button type="button" class="button-link button-link-delete item-delete submitdelete deletion"><?php _e( 'Remove' ); ?></button>
  137. <span class="spinner"></span>
  138. </div>
  139. <input type="hidden" name="menu-item-db-id[{{ data.menu_item_id }}]" class="menu-item-data-db-id" value="{{ data.menu_item_id }}" />
  140. <input type="hidden" name="menu-item-parent-id[{{ data.menu_item_id }}]" class="menu-item-data-parent-id" value="{{ data.parent }}" />
  141. </div><!-- .menu-item-settings-->
  142. <ul class="menu-item-transport"></ul>
  143. <?php
  144. }
  145. /**
  146. * Return parameters for this control.
  147. *
  148. * @since 4.3.0
  149. *
  150. * @return array Exported parameters.
  151. */
  152. public function json() {
  153. $exported = parent::json();
  154. $exported['menu_item_id'] = $this->setting->post_id;
  155. return $exported;
  156. }
  157. }