WordPress 4.4
[autoinstalls/wordpress.git] / wp-admin / includes / class-walker-nav-menu-edit.php
1 <?php
2 /**
3  * Navigation Menu API: Walker_Nav_Menu_Edit class
4  *
5  * @package WordPress
6  * @subpackage Administration
7  * @since 4.4.0
8  */
9
10 /**
11  * Create HTML list of nav menu input items.
12  *
13  * @package WordPress
14  * @since 3.0.0
15  * @uses Walker_Nav_Menu
16  */
17 class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
18         /**
19          * Starts the list before the elements are added.
20          *
21          * @see Walker_Nav_Menu::start_lvl()
22          *
23          * @since 3.0.0
24          *
25          * @param string $output Passed by reference.
26          * @param int    $depth  Depth of menu item. Used for padding.
27          * @param array  $args   Not used.
28          */
29         public function start_lvl( &$output, $depth = 0, $args = array() ) {}
30
31         /**
32          * Ends the list of after the elements are added.
33          *
34          * @see Walker_Nav_Menu::end_lvl()
35          *
36          * @since 3.0.0
37          *
38          * @param string $output Passed by reference.
39          * @param int    $depth  Depth of menu item. Used for padding.
40          * @param array  $args   Not used.
41          */
42         public function end_lvl( &$output, $depth = 0, $args = array() ) {}
43
44         /**
45          * Start the element output.
46          *
47          * @see Walker_Nav_Menu::start_el()
48          * @since 3.0.0
49          *
50          * @global int $_wp_nav_menu_max_depth
51          *
52          * @param string $output Passed by reference. Used to append additional content.
53          * @param object $item   Menu item data object.
54          * @param int    $depth  Depth of menu item. Used for padding.
55          * @param array  $args   Not used.
56          * @param int    $id     Not used.
57          */
58         public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
59                 global $_wp_nav_menu_max_depth;
60                 $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
61
62                 ob_start();
63                 $item_id = esc_attr( $item->ID );
64                 $removed_args = array(
65                         'action',
66                         'customlink-tab',
67                         'edit-menu-item',
68                         'menu-item',
69                         'page-tab',
70                         '_wpnonce',
71                 );
72
73                 $original_title = '';
74                 if ( 'taxonomy' == $item->type ) {
75                         $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
76                         if ( is_wp_error( $original_title ) )
77                                 $original_title = false;
78                 } elseif ( 'post_type' == $item->type ) {
79                         $original_object = get_post( $item->object_id );
80                         $original_title = get_the_title( $original_object->ID );
81                 } elseif ( 'post_type_archive' == $item->type ) {
82                         $original_object = get_post_type_object( $item->object );
83                         $original_title = $original_object->labels->archives;
84                 }
85
86                 $classes = array(
87                         'menu-item menu-item-depth-' . $depth,
88                         'menu-item-' . esc_attr( $item->object ),
89                         'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
90                 );
91
92                 $title = $item->title;
93
94                 if ( ! empty( $item->_invalid ) ) {
95                         $classes[] = 'menu-item-invalid';
96                         /* translators: %s: title of menu item which is invalid */
97                         $title = sprintf( __( '%s (Invalid)' ), $item->title );
98                 } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
99                         $classes[] = 'pending';
100                         /* translators: %s: title of menu item in draft status */
101                         $title = sprintf( __('%s (Pending)'), $item->title );
102                 }
103
104                 $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
105
106                 $submenu_text = '';
107                 if ( 0 == $depth )
108                         $submenu_text = 'style="display: none;"';
109
110                 ?>
111                 <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
112                         <div class="menu-item-bar">
113                                 <div class="menu-item-handle">
114                                         <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
115                                         <span class="item-controls">
116                                                 <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
117                                                 <span class="item-order hide-if-js">
118                                                         <a href="<?php
119                                                                 echo wp_nonce_url(
120                                                                         add_query_arg(
121                                                                                 array(
122                                                                                         'action' => 'move-up-menu-item',
123                                                                                         'menu-item' => $item_id,
124                                                                                 ),
125                                                                                 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
126                                                                         ),
127                                                                         'move-menu_item'
128                                                                 );
129                                                         ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
130                                                         |
131                                                         <a href="<?php
132                                                                 echo wp_nonce_url(
133                                                                         add_query_arg(
134                                                                                 array(
135                                                                                         'action' => 'move-down-menu-item',
136                                                                                         'menu-item' => $item_id,
137                                                                                 ),
138                                                                                 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
139                                                                         ),
140                                                                         'move-menu_item'
141                                                                 );
142                                                         ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
143                                                 </span>
144                                                 <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
145                                                         echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
146                                                 ?>"><?php _e( 'Edit Menu Item' ); ?></a>
147                                         </span>
148                                 </div>
149                         </div>
150
151                         <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
152                                 <?php if ( 'custom' == $item->type ) : ?>
153                                         <p class="field-url description description-wide">
154                                                 <label for="edit-menu-item-url-<?php echo $item_id; ?>">
155                                                         <?php _e( 'URL' ); ?><br />
156                                                         <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
157                                                 </label>
158                                         </p>
159                                 <?php endif; ?>
160                                 <p class="description description-wide">
161                                         <label for="edit-menu-item-title-<?php echo $item_id; ?>">
162                                                 <?php _e( 'Navigation Label' ); ?><br />
163                                                 <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
164                                         </label>
165                                 </p>
166                                 <p class="field-title-attribute description description-wide">
167                                         <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
168                                                 <?php _e( 'Title Attribute' ); ?><br />
169                                                 <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
170                                         </label>
171                                 </p>
172                                 <p class="field-link-target description">
173                                         <label for="edit-menu-item-target-<?php echo $item_id; ?>">
174                                                 <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
175                                                 <?php _e( 'Open link in a new tab' ); ?>
176                                         </label>
177                                 </p>
178                                 <p class="field-css-classes description description-thin">
179                                         <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
180                                                 <?php _e( 'CSS Classes (optional)' ); ?><br />
181                                                 <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
182                                         </label>
183                                 </p>
184                                 <p class="field-xfn description description-thin">
185                                         <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
186                                                 <?php _e( 'Link Relationship (XFN)' ); ?><br />
187                                                 <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
188                                         </label>
189                                 </p>
190                                 <p class="field-description description description-wide">
191                                         <label for="edit-menu-item-description-<?php echo $item_id; ?>">
192                                                 <?php _e( 'Description' ); ?><br />
193                                                 <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
194                                                 <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
195                                         </label>
196                                 </p>
197
198                                 <p class="field-move hide-if-no-js description description-wide">
199                                         <label>
200                                                 <span><?php _e( 'Move' ); ?></span>
201                                                 <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></a>
202                                                 <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></a>
203                                                 <a href="#" class="menus-move menus-move-left" data-dir="left"></a>
204                                                 <a href="#" class="menus-move menus-move-right" data-dir="right"></a>
205                                                 <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></a>
206                                         </label>
207                                 </p>
208
209                                 <div class="menu-item-actions description-wide submitbox">
210                                         <?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
211                                                 <p class="link-to-original">
212                                                         <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
213                                                 </p>
214                                         <?php endif; ?>
215                                         <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
216                                         echo wp_nonce_url(
217                                                 add_query_arg(
218                                                         array(
219                                                                 'action' => 'delete-menu-item',
220                                                                 'menu-item' => $item_id,
221                                                         ),
222                                                         admin_url( 'nav-menus.php' )
223                                                 ),
224                                                 'delete-menu_item_' . $item_id
225                                         ); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
226                                                 ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
227                                 </div>
228
229                                 <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
230                                 <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
231                                 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
232                                 <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
233                                 <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
234                                 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
235                         </div><!-- .menu-item-settings-->
236                         <ul class="menu-item-transport"></ul>
237                 <?php
238                 $output .= ob_get_clean();
239         }
240
241 } // Walker_Nav_Menu_Edit