1 <?php |
1 <?php |
2 |
2 /** |
3 /** |
3 * Core Navigation Menu API |
4 * Create HTML list of nav menu input items. |
|
5 * |
4 * |
6 * @package WordPress |
5 * @package WordPress |
7 * @since 3.0.0 |
6 * @subpackage Nav_Menus |
8 * @uses Walker_Nav_Menu |
7 * @since 3.0.0 |
9 */ |
8 */ |
10 class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { |
9 |
11 /** |
10 /** Walker_Nav_Menu_Edit class */ |
12 * Starts the list before the elements are added. |
11 require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-edit.php' ); |
13 * |
12 |
14 * @see Walker_Nav_Menu::start_lvl() |
13 /** Walker_Nav_Menu_Checklist class */ |
15 * |
14 require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php' ); |
16 * @since 3.0.0 |
|
17 * |
|
18 * @param string $output Passed by reference. |
|
19 * @param int $depth Depth of menu item. Used for padding. |
|
20 * @param array $args Not used. |
|
21 */ |
|
22 public function start_lvl( &$output, $depth = 0, $args = array() ) {} |
|
23 |
|
24 /** |
|
25 * Ends the list of after the elements are added. |
|
26 * |
|
27 * @see Walker_Nav_Menu::end_lvl() |
|
28 * |
|
29 * @since 3.0.0 |
|
30 * |
|
31 * @param string $output Passed by reference. |
|
32 * @param int $depth Depth of menu item. Used for padding. |
|
33 * @param array $args Not used. |
|
34 */ |
|
35 public function end_lvl( &$output, $depth = 0, $args = array() ) {} |
|
36 |
|
37 /** |
|
38 * Start the element output. |
|
39 * |
|
40 * @see Walker_Nav_Menu::start_el() |
|
41 * @since 3.0.0 |
|
42 * |
|
43 * @param string $output Passed by reference. Used to append additional content. |
|
44 * @param object $item Menu item data object. |
|
45 * @param int $depth Depth of menu item. Used for padding. |
|
46 * @param array $args Not used. |
|
47 * @param int $id Not used. |
|
48 */ |
|
49 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
|
50 global $_wp_nav_menu_max_depth; |
|
51 $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; |
|
52 |
|
53 ob_start(); |
|
54 $item_id = esc_attr( $item->ID ); |
|
55 $removed_args = array( |
|
56 'action', |
|
57 'customlink-tab', |
|
58 'edit-menu-item', |
|
59 'menu-item', |
|
60 'page-tab', |
|
61 '_wpnonce', |
|
62 ); |
|
63 |
|
64 $original_title = ''; |
|
65 if ( 'taxonomy' == $item->type ) { |
|
66 $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); |
|
67 if ( is_wp_error( $original_title ) ) |
|
68 $original_title = false; |
|
69 } elseif ( 'post_type' == $item->type ) { |
|
70 $original_object = get_post( $item->object_id ); |
|
71 $original_title = get_the_title( $original_object->ID ); |
|
72 } |
|
73 |
|
74 $classes = array( |
|
75 'menu-item menu-item-depth-' . $depth, |
|
76 'menu-item-' . esc_attr( $item->object ), |
|
77 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'), |
|
78 ); |
|
79 |
|
80 $title = $item->title; |
|
81 |
|
82 if ( ! empty( $item->_invalid ) ) { |
|
83 $classes[] = 'menu-item-invalid'; |
|
84 /* translators: %s: title of menu item which is invalid */ |
|
85 $title = sprintf( __( '%s (Invalid)' ), $item->title ); |
|
86 } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) { |
|
87 $classes[] = 'pending'; |
|
88 /* translators: %s: title of menu item in draft status */ |
|
89 $title = sprintf( __('%s (Pending)'), $item->title ); |
|
90 } |
|
91 |
|
92 $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label; |
|
93 |
|
94 $submenu_text = ''; |
|
95 if ( 0 == $depth ) |
|
96 $submenu_text = 'style="display: none;"'; |
|
97 |
|
98 ?> |
|
99 <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>"> |
|
100 <dl class="menu-item-bar"> |
|
101 <dt class="menu-item-handle"> |
|
102 <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> |
|
103 <span class="item-controls"> |
|
104 <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span> |
|
105 <span class="item-order hide-if-js"> |
|
106 <a href="<?php |
|
107 echo wp_nonce_url( |
|
108 add_query_arg( |
|
109 array( |
|
110 'action' => 'move-up-menu-item', |
|
111 'menu-item' => $item_id, |
|
112 ), |
|
113 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) |
|
114 ), |
|
115 'move-menu_item' |
|
116 ); |
|
117 ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">↑</abbr></a> |
|
118 | |
|
119 <a href="<?php |
|
120 echo wp_nonce_url( |
|
121 add_query_arg( |
|
122 array( |
|
123 'action' => 'move-down-menu-item', |
|
124 'menu-item' => $item_id, |
|
125 ), |
|
126 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) |
|
127 ), |
|
128 'move-menu_item' |
|
129 ); |
|
130 ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">↓</abbr></a> |
|
131 </span> |
|
132 <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php |
|
133 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 ) ) ); |
|
134 ?>"><?php _e( 'Edit Menu Item' ); ?></a> |
|
135 </span> |
|
136 </dt> |
|
137 </dl> |
|
138 |
|
139 <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>"> |
|
140 <?php if( 'custom' == $item->type ) : ?> |
|
141 <p class="field-url description description-wide"> |
|
142 <label for="edit-menu-item-url-<?php echo $item_id; ?>"> |
|
143 <?php _e( 'URL' ); ?><br /> |
|
144 <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 ); ?>" /> |
|
145 </label> |
|
146 </p> |
|
147 <?php endif; ?> |
|
148 <p class="description description-thin"> |
|
149 <label for="edit-menu-item-title-<?php echo $item_id; ?>"> |
|
150 <?php _e( 'Navigation Label' ); ?><br /> |
|
151 <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 ); ?>" /> |
|
152 </label> |
|
153 </p> |
|
154 <p class="description description-thin"> |
|
155 <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> |
|
156 <?php _e( 'Title Attribute' ); ?><br /> |
|
157 <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 ); ?>" /> |
|
158 </label> |
|
159 </p> |
|
160 <p class="field-link-target description"> |
|
161 <label for="edit-menu-item-target-<?php echo $item_id; ?>"> |
|
162 <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' ); ?> /> |
|
163 <?php _e( 'Open link in a new window/tab' ); ?> |
|
164 </label> |
|
165 </p> |
|
166 <p class="field-css-classes description description-thin"> |
|
167 <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> |
|
168 <?php _e( 'CSS Classes (optional)' ); ?><br /> |
|
169 <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 ) ); ?>" /> |
|
170 </label> |
|
171 </p> |
|
172 <p class="field-xfn description description-thin"> |
|
173 <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> |
|
174 <?php _e( 'Link Relationship (XFN)' ); ?><br /> |
|
175 <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 ); ?>" /> |
|
176 </label> |
|
177 </p> |
|
178 <p class="field-description description description-wide"> |
|
179 <label for="edit-menu-item-description-<?php echo $item_id; ?>"> |
|
180 <?php _e( 'Description' ); ?><br /> |
|
181 <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> |
|
182 <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span> |
|
183 </label> |
|
184 </p> |
|
185 |
|
186 <p class="field-move hide-if-no-js description description-wide"> |
|
187 <label> |
|
188 <span><?php _e( 'Move' ); ?></span> |
|
189 <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></a> |
|
190 <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></a> |
|
191 <a href="#" class="menus-move menus-move-left" data-dir="left"></a> |
|
192 <a href="#" class="menus-move menus-move-right" data-dir="right"></a> |
|
193 <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></a> |
|
194 </label> |
|
195 </p> |
|
196 |
|
197 <div class="menu-item-actions description-wide submitbox"> |
|
198 <?php if( 'custom' != $item->type && $original_title !== false ) : ?> |
|
199 <p class="link-to-original"> |
|
200 <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> |
|
201 </p> |
|
202 <?php endif; ?> |
|
203 <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php |
|
204 echo wp_nonce_url( |
|
205 add_query_arg( |
|
206 array( |
|
207 'action' => 'delete-menu-item', |
|
208 'menu-item' => $item_id, |
|
209 ), |
|
210 admin_url( 'nav-menus.php' ) |
|
211 ), |
|
212 'delete-menu_item_' . $item_id |
|
213 ); ?>"><?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' ) ) ); |
|
214 ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a> |
|
215 </div> |
|
216 |
|
217 <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> |
|
218 <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 ); ?>" /> |
|
219 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" /> |
|
220 <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 ); ?>" /> |
|
221 <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" /> |
|
222 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> |
|
223 </div><!-- .menu-item-settings--> |
|
224 <ul class="menu-item-transport"></ul> |
|
225 <?php |
|
226 $output .= ob_get_clean(); |
|
227 } |
|
228 |
|
229 } // Walker_Nav_Menu_Edit |
|
230 |
|
231 /** |
|
232 * Create HTML list of nav menu input items. |
|
233 * |
|
234 * @since 3.0.0 |
|
235 * @uses Walker_Nav_Menu |
|
236 */ |
|
237 class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { |
|
238 public function __construct( $fields = false ) { |
|
239 if ( $fields ) { |
|
240 $this->db_fields = $fields; |
|
241 } |
|
242 } |
|
243 |
|
244 /** |
|
245 * Starts the list before the elements are added. |
|
246 * |
|
247 * @see Walker_Nav_Menu::start_lvl() |
|
248 * |
|
249 * @since 3.0.0 |
|
250 * |
|
251 * @param string $output Passed by reference. Used to append additional content. |
|
252 * @param int $depth Depth of page. Used for padding. |
|
253 * @param array $args Not used. |
|
254 */ |
|
255 public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
256 $indent = str_repeat( "\t", $depth ); |
|
257 $output .= "\n$indent<ul class='children'>\n"; |
|
258 } |
|
259 |
|
260 /** |
|
261 * Ends the list of after the elements are added. |
|
262 * |
|
263 * @see Walker_Nav_Menu::end_lvl() |
|
264 * |
|
265 * @since 3.0.0 |
|
266 * |
|
267 * @param string $output Passed by reference. Used to append additional content. |
|
268 * @param int $depth Depth of page. Used for padding. |
|
269 * @param array $args Not used. |
|
270 */ |
|
271 public function end_lvl( &$output, $depth = 0, $args = array() ) { |
|
272 $indent = str_repeat( "\t", $depth ); |
|
273 $output .= "\n$indent</ul>"; |
|
274 } |
|
275 |
|
276 /** |
|
277 * Start the element output. |
|
278 * |
|
279 * @see Walker_Nav_Menu::start_el() |
|
280 * |
|
281 * @since 3.0.0 |
|
282 * |
|
283 * @param string $output Passed by reference. Used to append additional content. |
|
284 * @param object $item Menu item data object. |
|
285 * @param int $depth Depth of menu item. Used for padding. |
|
286 * @param array $args Not used. |
|
287 * @param int $id Not used. |
|
288 */ |
|
289 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
|
290 global $_nav_menu_placeholder; |
|
291 |
|
292 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; |
|
293 $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; |
|
294 $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; |
|
295 |
|
296 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; |
|
297 |
|
298 $output .= $indent . '<li>'; |
|
299 $output .= '<label class="menu-item-title">'; |
|
300 $output .= '<input type="checkbox" class="menu-item-checkbox'; |
|
301 |
|
302 if ( ! empty( $item->front_or_home ) ) |
|
303 $output .= ' add-to-top'; |
|
304 |
|
305 $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> '; |
|
306 |
|
307 if ( ! empty( $item->label ) ) { |
|
308 $title = $item->label; |
|
309 } elseif ( isset( $item->post_type ) ) { |
|
310 /** This filter is documented in wp-includes/post-template.php */ |
|
311 $title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
312 if ( ! empty( $item->front_or_home ) && _x( 'Home', 'nav menu home label' ) !== $title ) |
|
313 $title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $title ); |
|
314 } |
|
315 |
|
316 $output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title ); |
|
317 $output .= '</label>'; |
|
318 |
|
319 // Menu item hidden fields |
|
320 $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />'; |
|
321 $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />'; |
|
322 $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />'; |
|
323 $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />'; |
|
324 $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />'; |
|
325 $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />'; |
|
326 $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />'; |
|
327 $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />'; |
|
328 $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />'; |
|
329 $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />'; |
|
330 } |
|
331 |
|
332 } // Walker_Nav_Menu_Checklist |
|
333 |
15 |
334 /** |
16 /** |
335 * Prints the appropriate response to a menu quick search. |
17 * Prints the appropriate response to a menu quick search. |
336 * |
18 * |
337 * @since 3.0.0 |
19 * @since 3.0.0 |
547 /** |
243 /** |
548 * Check whether to disable the Menu Locations meta box submit button |
244 * Check whether to disable the Menu Locations meta box submit button |
549 * |
245 * |
550 * @since 3.6.0 |
246 * @since 3.6.0 |
551 * |
247 * |
552 * @uses global $one_theme_location_no_menus to determine if no menus exist |
248 * @global bool $one_theme_location_no_menus to determine if no menus exist |
553 * |
249 * |
554 * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu |
250 * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu |
555 * @return string Disabled attribute if at least one menu exists, false if not |
251 * @return string Disabled attribute if at least one menu exists, false if not |
556 */ |
252 */ |
557 function wp_nav_menu_disabled_check( $nav_menu_selected_id ) { |
253 function wp_nav_menu_disabled_check( $nav_menu_selected_id ) { |
558 global $one_theme_location_no_menus; |
254 global $one_theme_location_no_menus; |
559 |
255 |
560 if ( $one_theme_location_no_menus ) |
256 if ( $one_theme_location_no_menus ) |
561 return false; |
257 return false; |
562 |
258 |
563 return disabled( $nav_menu_selected_id, 0 ); |
259 return disabled( $nav_menu_selected_id, 0 ); |
564 } |
260 } |
565 |
261 |
566 /** |
262 /** |
567 * Displays a metabox for the custom links menu item. |
263 * Displays a meta box for the custom links menu item. |
568 * |
264 * |
569 * @since 3.0.0 |
265 * @since 3.0.0 |
|
266 * |
|
267 * @global int $_nav_menu_placeholder |
|
268 * @global int|string $nav_menu_selected_id |
570 */ |
269 */ |
571 function wp_nav_menu_item_link_meta_box() { |
270 function wp_nav_menu_item_link_meta_box() { |
572 global $_nav_menu_placeholder, $nav_menu_selected_id; |
271 global $_nav_menu_placeholder, $nav_menu_selected_id; |
573 |
272 |
574 $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1; |
273 $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1; |
575 |
274 |
576 ?> |
275 ?> |
577 <div class="customlinkdiv" id="customlinkdiv"> |
276 <div class="customlinkdiv" id="customlinkdiv"> |
578 <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" /> |
277 <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" /> |
579 <p id="menu-item-url-wrap"> |
278 <p id="menu-item-url-wrap" class="wp-clearfix"> |
580 <label class="howto" for="custom-menu-item-url"> |
279 <label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label> |
581 <span><?php _e('URL'); ?></span> |
280 <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" /> |
582 <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" /> |
|
583 </label> |
|
584 </p> |
281 </p> |
585 |
282 |
586 <p id="menu-item-name-wrap"> |
283 <p id="menu-item-name-wrap" class="wp-clearfix"> |
587 <label class="howto" for="custom-menu-item-name"> |
284 <label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label> |
588 <span><?php _e( 'Link Text' ); ?></span> |
285 <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox" /> |
589 <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Menu Item'); ?>" /> |
|
590 </label> |
|
591 </p> |
286 </p> |
592 |
287 |
593 <p class="button-controls"> |
288 <p class="button-controls wp-clearfix"> |
594 <span class="add-to-menu"> |
289 <span class="add-to-menu"> |
595 <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" /> |
290 <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" /> |
596 <span class="spinner"></span> |
291 <span class="spinner"></span> |
597 </span> |
292 </span> |
598 </p> |
293 </p> |
599 |
294 |
600 </div><!-- /.customlinkdiv --> |
295 </div><!-- /.customlinkdiv --> |
601 <?php |
296 <?php |
602 } |
297 } |
603 |
298 |
604 /** |
299 /** |
605 * Displays a metabox for a post type menu item. |
300 * Displays a meta box for a post type menu item. |
606 * |
301 * |
607 * @since 3.0.0 |
302 * @since 3.0.0 |
|
303 * |
|
304 * @global int $_nav_menu_placeholder |
|
305 * @global int|string $nav_menu_selected_id |
608 * |
306 * |
609 * @param string $object Not used. |
307 * @param string $object Not used. |
610 * @param string $post_type The post type object. |
308 * @param array $box { |
611 */ |
309 * Post type menu item meta box arguments. |
612 function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) { |
310 * |
|
311 * @type string $id Meta box 'id' attribute. |
|
312 * @type string $title Meta box title. |
|
313 * @type string $callback Meta box display callback. |
|
314 * @type WP_Post_Type $args Extra meta box arguments (the post type object for this meta box). |
|
315 * } |
|
316 */ |
|
317 function wp_nav_menu_item_post_type_meta_box( $object, $box ) { |
613 global $_nav_menu_placeholder, $nav_menu_selected_id; |
318 global $_nav_menu_placeholder, $nav_menu_selected_id; |
614 |
319 |
615 $post_type_name = $post_type['args']->name; |
320 $post_type_name = $box['args']->name; |
616 |
321 |
617 // Paginate browsing for large numbers of post objects. |
322 // Paginate browsing for large numbers of post objects. |
618 $per_page = 50; |
323 $per_page = 50; |
619 $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
324 $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
620 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
325 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
786 'url' => home_url('/'), |
510 'url' => home_url('/'), |
787 ) ); |
511 ) ); |
788 } |
512 } |
789 } |
513 } |
790 |
514 |
|
515 $post_type = get_post_type_object( $post_type_name ); |
|
516 |
|
517 if ( $post_type->has_archive ) { |
|
518 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; |
|
519 array_unshift( $posts, (object) array( |
|
520 'ID' => 0, |
|
521 'object_id' => $_nav_menu_placeholder, |
|
522 'object' => $post_type_name, |
|
523 'post_content' => '', |
|
524 'post_excerpt' => '', |
|
525 'post_title' => $post_type->labels->archives, |
|
526 'post_type' => 'nav_menu_item', |
|
527 'type' => 'post_type_archive', |
|
528 'url' => get_post_type_archive_link( $post_type_name ), |
|
529 ) ); |
|
530 } |
|
531 |
791 /** |
532 /** |
792 * Filter the posts displayed in the 'View All' tab of the current |
533 * Filters the posts displayed in the 'View All' tab of the current |
793 * post type's menu items meta box. |
534 * post type's menu items meta box. |
794 * |
535 * |
795 * The dynamic portion of the hook name, `$post_type_name`, refers |
536 * The dynamic portion of the hook name, `$post_type_name`, refers |
796 * to the slug of the current post type. |
537 * to the slug of the current post type. |
797 * |
538 * |
798 * @since 3.2.0 |
539 * @since 3.2.0 |
|
540 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
799 * |
541 * |
800 * @see WP_Query::query() |
542 * @see WP_Query::query() |
801 * |
543 * |
802 * @param array $posts The posts for the current post type. |
544 * @param array $posts The posts for the current post type. |
803 * @param array $args An array of WP_Query arguments. |
545 * @param array $args An array of WP_Query arguments. |
804 * @param object $post_type The current post type object for this menu item meta box. |
546 * @param WP_Post_Type $post_type The current post type object for this menu item meta box. |
805 */ |
547 */ |
806 $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); |
548 $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); |
|
549 |
807 $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args ); |
550 $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args ); |
808 |
551 |
809 if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) { |
552 if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) { |
810 $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items); |
553 $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items); |
811 |
554 |
819 <?php echo $page_links; ?> |
562 <?php echo $page_links; ?> |
820 </div> |
563 </div> |
821 <?php endif; ?> |
564 <?php endif; ?> |
822 </div><!-- /.tabs-panel --> |
565 </div><!-- /.tabs-panel --> |
823 |
566 |
824 <p class="button-controls"> |
567 <p class="button-controls wp-clearfix"> |
825 <span class="list-controls"> |
568 <span class="list-controls"> |
826 <a href="<?php |
569 <a href="<?php |
827 echo esc_url( add_query_arg( |
570 echo esc_url( add_query_arg( |
828 array( |
571 array( |
829 $post_type_name . '-tab' => 'all', |
572 $post_type_name . '-tab' => 'all', |
830 'selectall' => 1, |
573 'selectall' => 1, |
831 ), |
574 ), |
832 remove_query_arg( $removed_args ) |
575 remove_query_arg( $removed_args ) |
833 )); |
576 )); |
834 ?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a> |
577 ?>#posttype-<?php echo $post_type_name; ?>" class="select-all aria-button-if-js"><?php _e( 'Select All' ); ?></a> |
835 </span> |
578 </span> |
836 |
579 |
837 <span class="add-to-menu"> |
580 <span class="add-to-menu"> |
838 <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-post-type-menu-item" id="<?php echo esc_attr( 'submit-posttype-' . $post_type_name ); ?>" /> |
581 <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-post-type-menu-item" id="<?php echo esc_attr( 'submit-posttype-' . $post_type_name ); ?>" /> |
839 <span class="spinner"></span> |
582 <span class="spinner"></span> |
840 </span> |
583 </span> |
841 </p> |
584 </p> |
842 |
585 |
843 </div><!-- /.posttypediv --> |
586 </div><!-- /.posttypediv --> |
844 <?php |
587 <?php |
845 } |
588 } |
846 |
589 |
847 /** |
590 /** |
848 * Displays a metabox for a taxonomy menu item. |
591 * Displays a meta box for a taxonomy menu item. |
849 * |
592 * |
850 * @since 3.0.0 |
593 * @since 3.0.0 |
|
594 * |
|
595 * @global int|string $nav_menu_selected_id |
851 * |
596 * |
852 * @param string $object Not used. |
597 * @param string $object Not used. |
853 * @param string $taxonomy The taxonomy object. |
598 * @param array $box { |
854 */ |
599 * Taxonomy menu item meta box arguments. |
855 function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) { |
600 * |
|
601 * @type string $id Meta box 'id' attribute. |
|
602 * @type string $title Meta box title. |
|
603 * @type string $callback Meta box display callback. |
|
604 * @type object $args Extra meta box arguments (the taxonomy object for this meta box). |
|
605 * } |
|
606 */ |
|
607 function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) { |
856 global $nav_menu_selected_id; |
608 global $nav_menu_selected_id; |
857 $taxonomy_name = $taxonomy['args']->name; |
609 $taxonomy_name = $box['args']->name; |
|
610 $taxonomy = get_taxonomy( $taxonomy_name ); |
858 |
611 |
859 // Paginate browsing for large numbers of objects. |
612 // Paginate browsing for large numbers of objects. |
860 $per_page = 50; |
613 $per_page = 50; |
861 $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
614 $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
862 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
615 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
1160 $result = '<div id="menu-instructions" class="post-body-plain'; |
915 $result = '<div id="menu-instructions" class="post-body-plain'; |
1161 $result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">'; |
916 $result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">'; |
1162 $result .= '<p>' . __( 'Add menu items from the column on the left.' ) . '</p>'; |
917 $result .= '<p>' . __( 'Add menu items from the column on the left.' ) . '</p>'; |
1163 $result .= '</div>'; |
918 $result .= '</div>'; |
1164 |
919 |
1165 if( empty($menu_items) ) |
920 if ( empty($menu_items) ) |
1166 return $result . ' <ul class="menu" id="menu-to-edit"> </ul>'; |
921 return $result . ' <ul class="menu" id="menu-to-edit"> </ul>'; |
1167 |
922 |
1168 /** |
923 /** |
1169 * Filter the Walker class used when adding nav menu items. |
924 * Filters the Walker class used when adding nav menu items. |
1170 * |
925 * |
1171 * @since 3.0.0 |
926 * @since 3.0.0 |
1172 * |
927 * |
1173 * @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'. |
928 * @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'. |
1174 * @param int $menu_id ID of the menu being rendered. |
929 * @param int $menu_id ID of the menu being rendered. |
1175 */ |
930 */ |
1176 $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id ); |
931 $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id ); |
1177 |
932 |
1178 if ( class_exists( $walker_class_name ) ) |
933 if ( class_exists( $walker_class_name ) ) { |
1179 $walker = new $walker_class_name; |
934 $walker = new $walker_class_name; |
1180 else |
935 } else { |
1181 return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) ); |
936 return new WP_Error( 'menu_walker_not_exist', |
|
937 /* translators: %s: walker class name */ |
|
938 sprintf( __( 'The Walker class named %s does not exist.' ), |
|
939 '<strong>' . $walker_class_name . '</strong>' |
|
940 ) |
|
941 ); |
|
942 } |
1182 |
943 |
1183 $some_pending_menu_items = $some_invalid_menu_items = false; |
944 $some_pending_menu_items = $some_invalid_menu_items = false; |
1184 foreach( (array) $menu_items as $menu_item ) { |
945 foreach ( (array) $menu_items as $menu_item ) { |
1185 if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) |
946 if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) |
1186 $some_pending_menu_items = true; |
947 $some_pending_menu_items = true; |
1187 if ( ! empty( $menu_item->_invalid ) ) |
948 if ( ! empty( $menu_item->_invalid ) ) |
1188 $some_invalid_menu_items = true; |
949 $some_invalid_menu_items = true; |
1189 } |
950 } |
1190 |
951 |
1191 if ( $some_pending_menu_items ) |
952 if ( $some_pending_menu_items ) { |
1192 $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>'; |
953 $result .= '<div class="notice notice-info notice-alt inline"><p>' . __( 'Click Save Menu to make pending menu items public.' ) . '</p></div>'; |
1193 |
954 } |
1194 if ( $some_invalid_menu_items ) |
955 |
1195 $result .= '<div class="error inline"><p>' . __('There are some invalid menu items. Please check or delete them.') . '</p></div>'; |
956 if ( $some_invalid_menu_items ) { |
|
957 $result .= '<div class="notice notice-error notice-alt inline"><p>' . __( 'There are some invalid menu items. Please check or delete them.' ) . '</p></div>'; |
|
958 } |
1196 |
959 |
1197 $result .= '<ul class="menu" id="menu-to-edit"> '; |
960 $result .= '<ul class="menu" id="menu-to-edit"> '; |
1198 $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) ); |
961 $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) ); |
1199 $result .= ' </ul> '; |
962 $result .= ' </ul> '; |
1200 return $result; |
963 return $result; |