You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

169 lines
6.4 KiB

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