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