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

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