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