| [ XREF Home ] [ Index ] |
PHP Cross Reference of WordPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Create HTML list of nav menu input items. 5 * 6 * @package WordPress 7 * @since 3.0.0 8 * @uses Walker_Nav_Menu 9 */ 10 class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { 11 /** 12 * @see Walker_Nav_Menu::start_lvl() 13 * @since 3.0.0 14 * 15 * @param string $output Passed by reference. 16 */ 17 function start_lvl(&$output) {} 18 19 /** 20 * @see Walker_Nav_Menu::end_lvl() 21 * @since 3.0.0 22 * 23 * @param string $output Passed by reference. 24 */ 25 function end_lvl(&$output) { 26 } 27 28 /** 29 * @see Walker::start_el() 30 * @since 3.0.0 31 * 32 * @param string $output Passed by reference. Used to append additional content. 33 * @param object $item Menu item data object. 34 * @param int $depth Depth of menu item. Used for padding. 35 * @param object $args 36 */ 37 function start_el(&$output, $item, $depth, $args) { 38 global $_wp_nav_menu_max_depth; 39 $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; 40 41 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; 42 43 ob_start(); 44 $item_id = esc_attr( $item->ID ); 45 $removed_args = array( 46 'action', 47 'customlink-tab', 48 'edit-menu-item', 49 'menu-item', 50 'page-tab', 51 '_wpnonce', 52 ); 53 54 $original_title = ''; 55 if ( 'taxonomy' == $item->type ) { 56 $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); 57 } elseif ( 'post_type' == $item->type ) { 58 $original_object = get_post( $item->object_id ); 59 $original_title = $original_object->post_title; 60 } 61 62 $classes = array( 63 'menu-item menu-item-depth-' . $depth, 64 'menu-item-' . esc_attr( $item->object ), 65 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'), 66 ); 67 68 $title = $item->title; 69 70 if ( isset( $item->post_status ) && 'draft' == $item->post_status ) { 71 $classes[] = 'pending'; 72 /* translators: %s: title of menu item in draft status */ 73 $title = sprintf( __('%s (Pending)'), $item->title ); 74 } 75 76 $title = empty( $item->label ) ? $title : $item->label; 77 78 ?> 79 <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>"> 80 <dl class="menu-item-bar"> 81 <dt class="menu-item-handle"> 82 <span class="item-title"><?php echo esc_html( $title ); ?></span> 83 <span class="item-controls"> 84 <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span> 85 <span class="item-order"> 86 <a href="<?php 87 echo wp_nonce_url( 88 add_query_arg( 89 array( 90 'action' => 'move-up-menu-item', 91 'menu-item' => $item_id, 92 ), 93 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) 94 ), 95 'move-menu_item' 96 ); 97 ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">↑</abbr></a> 98 | 99 <a href="<?php 100 echo wp_nonce_url( 101 add_query_arg( 102 array( 103 'action' => 'move-down-menu-item', 104 'menu-item' => $item_id, 105 ), 106 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) 107 ), 108 'move-menu_item' 109 ); 110 ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">↓</abbr></a> 111 </span> 112 <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php _e('Edit Menu Item'); ?>" href="<?php 113 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 ) ) ); 114 ?>"><?php _e( 'Edit Menu Item' ); ?></a> 115 </span> 116 </dt> 117 </dl> 118 119 <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>"> 120 <?php if( 'custom' == $item->type ) : ?> 121 <p class="field-url description description-wide"> 122 <label for="edit-menu-item-url-<?php echo $item_id; ?>"> 123 <?php _e( 'URL' ); ?><br /> 124 <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 ); ?>" /> 125 </label> 126 </p> 127 <?php endif; ?> 128 <p class="description description-thin"> 129 <label for="edit-menu-item-title-<?php echo $item_id; ?>"> 130 <?php _e( 'Navigation Label' ); ?><br /> 131 <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 ); ?>" /> 132 </label> 133 </p> 134 <p class="description description-thin"> 135 <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> 136 <?php _e( 'Title Attribute' ); ?><br /> 137 <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 ); ?>" /> 138 </label> 139 </p> 140 <p class="field-link-target description description-thin"> 141 <label for="edit-menu-item-target-<?php echo $item_id; ?>"> 142 <?php _e( 'Link Target' ); ?><br /> 143 <select id="edit-menu-item-target-<?php echo $item_id; ?>" class="widefat edit-menu-item-target" name="menu-item-target[<?php echo $item_id; ?>]"> 144 <option value="" <?php selected( $item->target, ''); ?>><?php _e('Same window or tab'); ?></option> 145 <option value="_blank" <?php selected( $item->target, '_blank'); ?>><?php _e('New window or tab'); ?></option> 146 </select> 147 </label> 148 </p> 149 <p class="field-css-classes description description-thin"> 150 <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> 151 <?php _e( 'CSS Classes (optional)' ); ?><br /> 152 <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 ) ); ?>" /> 153 </label> 154 </p> 155 <p class="field-xfn description description-thin"> 156 <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> 157 <?php _e( 'Link Relationship (XFN)' ); ?><br /> 158 <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 ); ?>" /> 159 </label> 160 </p> 161 <p class="field-description description description-wide"> 162 <label for="edit-menu-item-description-<?php echo $item_id; ?>"> 163 <?php _e( 'Description' ); ?><br /> 164 <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> 165 <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span> 166 </label> 167 </p> 168 169 <div class="menu-item-actions description-wide submitbox"> 170 <?php if( 'custom' != $item->type ) : ?> 171 <p class="link-to-original"> 172 <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> 173 </p> 174 <?php endif; ?> 175 <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php 176 echo wp_nonce_url( 177 add_query_arg( 178 array( 179 'action' => 'delete-menu-item', 180 'menu-item' => $item_id, 181 ), 182 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) 183 ), 184 'delete-menu_item_' . $item_id 185 ); ?>"><?php _e('Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) ) ); 186 ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a> 187 </div> 188 189 <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> 190 <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 ); ?>" /> 191 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" /> 192 <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 ); ?>" /> 193 <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" /> 194 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> 195 </div><!-- .menu-item-settings--> 196 <ul class="menu-item-transport"></ul> 197 <?php 198 $output .= ob_get_clean(); 199 } 200 } 201 202 /** 203 * Create HTML list of nav menu input items. 204 * 205 * @package WordPress 206 * @since 3.0.0 207 * @uses Walker_Nav_Menu 208 */ 209 class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { 210 function __construct( $fields = false ) { 211 if ( $fields ) { 212 $this->db_fields = $fields; 213 } 214 } 215 216 function start_lvl( &$output, $depth ) { 217 $indent = str_repeat( "\t", $depth ); 218 $output .= "\n$indent<ul class='children'>\n"; 219 } 220 221 function end_lvl( &$output, $depth ) { 222 $indent = str_repeat( "\t", $depth ); 223 $output .= "\n$indent</ul>"; 224 } 225 226 /** 227 * @see Walker::start_el() 228 * @since 3.0.0 229 * 230 * @param string $output Passed by reference. Used to append additional content. 231 * @param object $item Menu item data object. 232 * @param int $depth Depth of menu item. Used for padding. 233 * @param object $args 234 */ 235 function start_el(&$output, $item, $depth, $args) { 236 global $_nav_menu_placeholder; 237 238 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; 239 $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; 240 $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; 241 242 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; 243 244 $output .= $indent . '<li>'; 245 $output .= '<label class="menu-item-title">'; 246 $output .= '<input type="checkbox" class="menu-item-checkbox'; 247 if ( ! empty( $item->_add_to_top ) ) { 248 $output .= ' add-to-top'; 249 } 250 $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> '; 251 $output .= empty( $item->label ) ? esc_html( $item->title ) : esc_html( $item->label ); 252 $output .= '</label>'; 253 254 // Menu item hidden fields 255 $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />'; 256 $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />'; 257 $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 ) .'" />'; 258 $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />'; 259 $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />'; 260 $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />'; 261 $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />'; 262 $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 ) .'" />'; 263 $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />'; 264 $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />'; 265 } 266 } 267 268 /** 269 * Prints the appropriate response to a menu quick search. 270 * 271 * @since 3.0.0 272 * 273 * @param array $request The unsanitized request values. 274 */ 275 function _wp_ajax_menu_quick_search( $request = array() ) { 276 $args = array(); 277 $type = isset( $request['type'] ) ? $request['type'] : ''; 278 $object_type = isset( $request['object_type'] ) ? $request['object_type'] : ''; 279 $query = isset( $request['q'] ) ? $request['q'] : ''; 280 $response_format = isset( $request['response-format'] ) && in_array( $request['response-format'], array( 'json', 'markup' ) ) ? $request['response-format'] : 'json'; 281 282 if ( 'markup' == $response_format ) { 283 $args['walker'] = new Walker_Nav_Menu_Checklist; 284 } 285 286 if ( 'get-post-item' == $type ) { 287 if ( post_type_exists( $object_type ) ) { 288 if ( isset( $request['ID'] ) ) { 289 $object_id = (int) $request['ID']; 290 if ( 'markup' == $response_format ) { 291 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); 292 } elseif ( 'json' == $response_format ) { 293 $post_obj = get_post( $object_id ); 294 echo json_encode( 295 array( 296 'ID' => $object_id, 297 'post_title' => get_the_title( $object_id ), 298 'post_type' => get_post_type( $object_id ), 299 ) 300 ); 301 echo "\n"; 302 } 303 } 304 } elseif ( taxonomy_exists( $object_type ) ) { 305 if ( isset( $request['ID'] ) ) { 306 $object_id = (int) $request['ID']; 307 if ( 'markup' == $response_format ) { 308 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); 309 } elseif ( 'json' == $response_format ) { 310 $post_obj = get_term( $object_id, $object_type ); 311 echo json_encode( 312 array( 313 'ID' => $object_id, 314 'post_title' => $post_obj->name, 315 'post_type' => $object_type, 316 ) 317 ); 318 echo "\n"; 319 } 320 } 321 322 } 323 324 325 } elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) { 326 if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) { 327 query_posts(array( 328 'posts_per_page' => 10, 329 'post_type' => $matches[2], 330 's' => $query, 331 )); 332 if ( ! have_posts() ) 333 return; 334 while ( have_posts() ) { 335 the_post(); 336 if ( 'markup' == $response_format ) { 337 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref = get_the_ID() ) ) ), 0, (object) $args ); 338 } elseif ( 'json' == $response_format ) { 339 echo json_encode( 340 array( 341 'ID' => get_the_ID(), 342 'post_title' => get_the_title(), 343 'post_type' => get_post_type(), 344 ) 345 ); 346 echo "\n"; 347 } 348 } 349 } elseif ( 'taxonomy' == $matches[1] ) { 350 $terms = get_terms( $matches[2], array( 351 'name__like' => $query, 352 'number' => 10, 353 )); 354 if ( empty( $terms ) || is_wp_error( $terms ) ) 355 return; 356 foreach( (array) $terms as $term ) { 357 if ( 'markup' == $response_format ) { 358 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); 359 } elseif ( 'json' == $response_format ) { 360 echo json_encode( 361 array( 362 'ID' => $term->term_id, 363 'post_title' => $term->name, 364 'post_type' => $matches[2], 365 ) 366 ); 367 echo "\n"; 368 } 369 } 370 } 371 } 372 } 373 374 /** 375 * Register nav menu metaboxes and advanced menu items 376 * 377 * @since 3.0.0 378 **/ 379 function wp_nav_menu_setup() { 380 // Register meta boxes 381 if ( wp_get_nav_menus() ) 382 add_meta_box( 'nav-menu-theme-locations', __( 'Theme Locations' ), 'wp_nav_menu_locations_meta_box' , 'nav-menus', 'side', 'default' ); 383 add_meta_box( 'add-custom-links', __('Custom Links'), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); 384 wp_nav_menu_post_type_meta_boxes(); 385 wp_nav_menu_taxonomy_meta_boxes(); 386 387 // Register advanced menu items (columns) 388 add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns'); 389 390 // If first time editing, disable advanced items by default. 391 if( false === get_user_option( 'managenav-menuscolumnshidden' ) ) { 392 $user = wp_get_current_user(); 393 update_user_option($user->ID, 'managenav-menuscolumnshidden', 394 array( 0 => 'link-target', 1 => 'css-classes', 2 => 'xfn', 3 => 'description', ), 395 true); 396 } 397 } 398 399 /** 400 * Limit the amount of meta boxes to just links, pages and cats for first time users. 401 * 402 * @since 3.0.0 403 **/ 404 function wp_initial_nav_menu_meta_boxes() { 405 global $wp_meta_boxes; 406 407 if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array($wp_meta_boxes) ) 408 return; 409 410 $initial_meta_boxes = array( 'nav-menu-theme-locations', 'add-custom-links', 'add-page', 'add-category' ); 411 $hidden_meta_boxes = array(); 412 413 foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) { 414 foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) { 415 foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) { 416 if ( in_array( $box['id'], $initial_meta_boxes ) ) { 417 unset( $box['id'] ); 418 } else { 419 $hidden_meta_boxes[] = $box['id']; 420 } 421 } 422 } 423 } 424 425 $user = wp_get_current_user(); 426 update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true ); 427 } 428 429 /** 430 * Creates metaboxes for any post type menu item. 431 * 432 * @since 3.0.0 433 */ 434 function wp_nav_menu_post_type_meta_boxes() { 435 $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); 436 437 if ( ! $post_types ) 438 return; 439 440 foreach ( $post_types as $post_type ) { 441 $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); 442 if ( $post_type ) { 443 $id = $post_type->name; 444 add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type ); 445 } 446 } 447 } 448 449 /** 450 * Creates metaboxes for any taxonomy menu item. 451 * 452 * @since 3.0.0 453 */ 454 function wp_nav_menu_taxonomy_meta_boxes() { 455 $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' ); 456 457 if ( !$taxonomies ) 458 return; 459 460 foreach ( $taxonomies as $tax ) { 461 $tax = apply_filters( 'nav_menu_meta_box_object', $tax ); 462 if ( $tax ) { 463 $id = $tax->name; 464 add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax ); 465 } 466 } 467 } 468 469 /** 470 * Displays a metabox for the nav menu theme locations. 471 * 472 * @since 3.0.0 473 */ 474 function wp_nav_menu_locations_meta_box() { 475 global $nav_menu_selected_id; 476 477 if ( ! current_theme_supports( 'menus' ) ) { 478 // We must only support widgets. Leave a message and bail. 479 echo '<p class="howto">' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p>'; 480 return; 481 } 482 483 $locations = get_registered_nav_menus(); 484 $menus = wp_get_nav_menus(); 485 $menu_locations = get_nav_menu_locations(); 486 $num_locations = count( array_keys($locations) ); 487 488 echo '<p class="howto">' . sprintf( _n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n($num_locations) ) . '</p>'; 489 490 foreach ( $locations as $location => $description ) { 491 ?> 492 <p> 493 <label class="howto" for="locations-<?php echo $location; ?>"> 494 <span><?php echo $description; ?></span> 495 <select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>"> 496 <option value="0"></option> 497 <?php foreach ( $menus as $menu ) : ?> 498 <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?> 499 value="<?php echo $menu->term_id; ?>"><?php 500 $truncated_name = wp_html_excerpt( $menu->name, 40 ); 501 echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '…'; 502 ?></option> 503 <?php endforeach; ?> 504 </select> 505 </label> 506 </p> 507 <?php 508 } 509 ?> 510 <p class="button-controls"> 511 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 512 <?php submit_button( __( 'Save' ), 'primary', 'nav-menu-locations', false, disabled( $nav_menu_selected_id, 0, false ) ); ?> 513 </p> 514 <?php 515 } 516 517 /** 518 * Displays a metabox for the custom links menu item. 519 * 520 * @since 3.0.0 521 */ 522 function wp_nav_menu_item_link_meta_box() { 523 global $_nav_menu_placeholder, $nav_menu_selected_id; 524 $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1; 525 526 $current_tab = 'create'; 527 if ( isset( $_REQUEST['customlink-tab'] ) && in_array( $_REQUEST['customlink-tab'], array('create', 'all') ) ) { 528 $current_tab = $_REQUEST['customlink-tab']; 529 } 530 531 $removed_args = array( 532 'action', 533 'customlink-tab', 534 'edit-menu-item', 535 'menu-item', 536 'page-tab', 537 '_wpnonce', 538 ); 539 540 ?> 541 <div class="customlinkdiv" id="customlinkdiv"> 542 543 <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" /> 544 <p id="menu-item-url-wrap"> 545 <label class="howto" for="custom-menu-item-url"> 546 <span><?php _e('URL'); ?></span> 547 <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://" /> 548 </label> 549 </p> 550 551 <p id="menu-item-name-wrap"> 552 <label class="howto" for="custom-menu-item-name"> 553 <span><?php _e('Label'); ?></span> 554 <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'); ?>" /> 555 </label> 556 </p> 557 558 <p class="button-controls"> 559 <span class="add-to-menu"> 560 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 561 <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" /> 562 </span> 563 </p> 564 565 </div><!-- /.customlinkdiv --> 566 <?php 567 } 568 569 /** 570 * Displays a metabox for a post type menu item. 571 * 572 * @since 3.0.0 573 * 574 * @param string $object Not used. 575 * @param string $post_type The post type object. 576 */ 577 function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) { 578 global $_nav_menu_placeholder, $nav_menu_selected_id; 579 580 $post_type_name = $post_type['args']->name; 581 582 // paginate browsing for large numbers of post objects 583 $per_page = 50; 584 $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; 585 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; 586 587 $args = array( 588 'offset' => $offset, 589 'order' => 'ASC', 590 'orderby' => 'title', 591 'posts_per_page' => $per_page, 592 'post_type' => $post_type_name, 593 'suppress_filters' => true, 594 'update_post_term_cache' => false, 595 'update_post_meta_cache' => false 596 ); 597 598 if ( isset( $post_type['args']->_default_query ) ) 599 $args = array_merge($args, (array) $post_type['args']->_default_query ); 600 601 // @todo transient caching of these results with proper invalidation on updating of a post of this type 602 $get_posts = new WP_Query; 603 $posts = $get_posts->query( $args ); 604 if ( ! $get_posts->post_count ) { 605 echo '<p>' . __( 'No items.' ) . '</p>'; 606 return; 607 } 608 609 $post_type_object = get_post_type_object($post_type_name); 610 611 $num_pages = $get_posts->max_num_pages; 612 613 $page_links = paginate_links( array( 614 'base' => add_query_arg( 615 array( 616 $post_type_name . '-tab' => 'all', 617 'paged' => '%#%', 618 'item-type' => 'post_type', 619 'item-object' => $post_type_name, 620 ) 621 ), 622 'format' => '', 623 'prev_text' => __('«'), 624 'next_text' => __('»'), 625 'total' => $num_pages, 626 'current' => $pagenum 627 )); 628 629 if ( !$posts ) 630 $error = '<li id="error">'. $post_type['args']->labels->not_found .'</li>'; 631 632 $db_fields = false; 633 if ( is_post_type_hierarchical( $post_type_name ) ) { 634 $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); 635 } 636 637 $walker = new Walker_Nav_Menu_Checklist( $db_fields ); 638 639 $current_tab = 'most-recent'; 640 if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) { 641 $current_tab = $_REQUEST[$post_type_name . '-tab']; 642 } 643 644 if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { 645 $current_tab = 'search'; 646 } 647 648 $removed_args = array( 649 'action', 650 'customlink-tab', 651 'edit-menu-item', 652 'menu-item', 653 'page-tab', 654 '_wpnonce', 655 ); 656 657 ?> 658 <div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv"> 659 <ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs"> 660 <li <?php echo ( 'most-recent' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent"><?php _e('Most Recent'); ?></a></li> 661 <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#<?php echo $post_type_name; ?>-all"><?php _e('View All'); ?></a></li> 662 <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search"><?php _e('Search'); ?></a></li> 663 </ul> 664 665 <div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent" class="tabs-panel <?php 666 echo ( 'most-recent' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 667 ?>"> 668 <ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear"> 669 <?php 670 $recent_args = array_merge( $args, array( 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 15 ) ); 671 $most_recent = $get_posts->query( $recent_args ); 672 $args['walker'] = $walker; 673 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $most_recent), 0, (object) $args ); 674 ?> 675 </ul> 676 </div><!-- /.tabs-panel --> 677 678 <div class="tabs-panel <?php 679 echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 680 ?>" id="tabs-panel-posttype-<?php echo $post_type_name; ?>-search"> 681 <?php 682 if ( isset( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { 683 $searched = esc_attr( $_REQUEST['quick-search-posttype-' . $post_type_name] ); 684 $search_results = get_posts( array( 's' => $searched, 'post_type' => $post_type_name, 'fields' => 'all', 'order' => 'DESC', ) ); 685 } else { 686 $searched = ''; 687 $search_results = array(); 688 } 689 ?> 690 <p class="quick-search-wrap"> 691 <input type="text" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" /> 692 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 693 <?php submit_button( __( 'Search' ), 'quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?> 694 </p> 695 696 <ul id="<?php echo $post_type_name; ?>-search-checklist" class="list:<?php echo $post_type_name?> categorychecklist form-no-clear"> 697 <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> 698 <?php 699 $args['walker'] = $walker; 700 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args ); 701 ?> 702 <?php elseif ( is_wp_error( $search_results ) ) : ?> 703 <li><?php echo $search_results->get_error_message(); ?></li> 704 <?php elseif ( ! empty( $searched ) ) : ?> 705 <li><?php _e('No results found.'); ?></li> 706 <?php endif; ?> 707 </ul> 708 </div><!-- /.tabs-panel --> 709 710 711 <div id="<?php echo $post_type_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php 712 echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 713 ?>"> 714 <?php if ( ! empty( $page_links ) ) : ?> 715 <div class="add-menu-item-pagelinks"> 716 <?php echo $page_links; ?> 717 </div> 718 <?php endif; ?> 719 <ul id="<?php echo $post_type_name; ?>checklist" class="list:<?php echo $post_type_name?> categorychecklist form-no-clear"> 720 <?php 721 $args['walker'] = $walker; 722 723 // if we're dealing with pages, let's put a checkbox for the front page at the top of the list 724 if ( 'page' == $post_type_name ) { 725 $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0; 726 if ( ! empty( $front_page ) ) { 727 $front_page_obj = get_post( $front_page ); 728 $front_page_obj->_add_to_top = true; 729 $front_page_obj->label = sprintf( _x('Home: %s', 'nav menu front page title'), $front_page_obj->post_title ); 730 array_unshift( $posts, $front_page_obj ); 731 } else { 732 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; 733 array_unshift( $posts, (object) array( 734 '_add_to_top' => true, 735 'ID' => 0, 736 'object_id' => $_nav_menu_placeholder, 737 'post_content' => '', 738 'post_excerpt' => '', 739 'post_parent' => '', 740 'post_title' => _x('Home', 'nav menu home label'), 741 'post_type' => 'nav_menu_item', 742 'type' => 'custom', 743 'url' => home_url('/'), 744 ) ); 745 } 746 } 747 748 $posts = apply_filters( 'nav_menu_items_'.$post_type_name, $posts, $args, $post_type ); 749 $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args ); 750 751 if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) { 752 $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items); 753 754 } 755 756 echo $checkbox_items; 757 ?> 758 </ul> 759 <?php if ( ! empty( $page_links ) ) : ?> 760 <div class="add-menu-item-pagelinks"> 761 <?php echo $page_links; ?> 762 </div> 763 <?php endif; ?> 764 </div><!-- /.tabs-panel --> 765 766 767 <p class="button-controls"> 768 <span class="list-controls"> 769 <a href="<?php 770 echo esc_url(add_query_arg( 771 array( 772 $post_type_name . '-tab' => 'all', 773 'selectall' => 1, 774 ), 775 remove_query_arg($removed_args) 776 )); 777 ?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a> 778 </span> 779 780 <span class="add-to-menu"> 781 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 782 <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-post-type-menu-item" id="submit-posttype-<?php echo $post_type_name; ?>" /> 783 </span> 784 </p> 785 786 </div><!-- /.posttypediv --> 787 <?php 788 } 789 790 /** 791 * Displays a metabox for a taxonomy menu item. 792 * 793 * @since 3.0.0 794 * 795 * @param string $object Not used. 796 * @param string $taxonomy The taxonomy object. 797 */ 798 function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) { 799 global $nav_menu_selected_id; 800 $taxonomy_name = $taxonomy['args']->name; 801 802 // paginate browsing for large numbers of objects 803 $per_page = 50; 804 $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; 805 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; 806 807 $args = array( 808 'child_of' => 0, 809 'exclude' => '', 810 'hide_empty' => false, 811 'hierarchical' => 1, 812 'include' => '', 813 'include_last_update_time' => false, 814 'number' => $per_page, 815 'offset' => $offset, 816 'order' => 'ASC', 817 'orderby' => 'name', 818 'pad_counts' => false, 819 ); 820 821 $terms = get_terms( $taxonomy_name, $args ); 822 823 if ( ! $terms || is_wp_error($terms) ) { 824 echo '<p>' . __( 'No items.' ) . '</p>'; 825 return; 826 } 827 828 $num_pages = ceil( wp_count_terms( $taxonomy_name , array_merge( $args, array('number' => '', 'offset' => '') ) ) / $per_page ); 829 830 $page_links = paginate_links( array( 831 'base' => add_query_arg( 832 array( 833 $taxonomy_name . '-tab' => 'all', 834 'paged' => '%#%', 835 'item-type' => 'taxonomy', 836 'item-object' => $taxonomy_name, 837 ) 838 ), 839 'format' => '', 840 'prev_text' => __('«'), 841 'next_text' => __('»'), 842 'total' => $num_pages, 843 'current' => $pagenum 844 )); 845 846 $db_fields = false; 847 if ( is_taxonomy_hierarchical( $taxonomy_name ) ) { 848 $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); 849 } 850 851 $walker = new Walker_Nav_Menu_Checklist( $db_fields ); 852 853 $current_tab = 'most-used'; 854 if ( isset( $_REQUEST[$taxonomy_name . '-tab'] ) && in_array( $_REQUEST[$taxonomy_name . '-tab'], array('all', 'most-used', 'search') ) ) { 855 $current_tab = $_REQUEST[$taxonomy_name . '-tab']; 856 } 857 858 if ( ! empty( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) { 859 $current_tab = 'search'; 860 } 861 862 $removed_args = array( 863 'action', 864 'customlink-tab', 865 'edit-menu-item', 866 'menu-item', 867 'page-tab', 868 '_wpnonce', 869 ); 870 871 ?> 872 <div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv"> 873 <ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs"> 874 <li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'most-used', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-pop"><?php _e('Most Used'); ?></a></li> 875 <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-all"><?php _e('View All'); ?></a></li> 876 <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>"><?php _e('Search'); ?></a></li> 877 </ul> 878 879 <div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php 880 echo ( 'most-used' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 881 ?>"> 882 <ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" > 883 <?php 884 $popular_terms = get_terms( $taxonomy_name, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); 885 $args['walker'] = $walker; 886 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $popular_terms), 0, (object) $args ); 887 ?> 888 </ul> 889 </div><!-- /.tabs-panel --> 890 891 <div id="tabs-panel-<?php echo $taxonomy_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php 892 echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 893 ?>"> 894 <?php if ( ! empty( $page_links ) ) : ?> 895 <div class="add-menu-item-pagelinks"> 896 <?php echo $page_links; ?> 897 </div> 898 <?php endif; ?> 899 <ul id="<?php echo $taxonomy_name; ?>checklist" class="list:<?php echo $taxonomy_name?> categorychecklist form-no-clear"> 900 <?php 901 $args['walker'] = $walker; 902 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $terms), 0, (object) $args ); 903 ?> 904 </ul> 905 <?php if ( ! empty( $page_links ) ) : ?> 906 <div class="add-menu-item-pagelinks"> 907 <?php echo $page_links; ?> 908 </div> 909 <?php endif; ?> 910 </div><!-- /.tabs-panel --> 911 912 <div class="tabs-panel <?php 913 echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 914 ?>" id="tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>"> 915 <?php 916 if ( isset( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) { 917 $searched = esc_attr( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ); 918 $search_results = get_terms( $taxonomy_name, array( 'name__like' => $searched, 'fields' => 'all', 'orderby' => 'count', 'order' => 'DESC', 'hierarchical' => false ) ); 919 } else { 920 $searched = ''; 921 $search_results = array(); 922 } 923 ?> 924 <p class="quick-search-wrap"> 925 <input type="text" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" /> 926 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 927 <?php submit_button( __( 'Search' ), 'quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?> 928 </p> 929 930 <ul id="<?php echo $taxonomy_name; ?>-search-checklist" class="list:<?php echo $taxonomy_name?> categorychecklist form-no-clear"> 931 <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> 932 <?php 933 $args['walker'] = $walker; 934 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args ); 935 ?> 936 <?php elseif ( is_wp_error( $search_results ) ) : ?> 937 <li><?php echo $search_results->get_error_message(); ?></li> 938 <?php elseif ( ! empty( $searched ) ) : ?> 939 <li><?php _e('No results found.'); ?></li> 940 <?php endif; ?> 941 </ul> 942 </div><!-- /.tabs-panel --> 943 944 <p class="button-controls"> 945 <span class="list-controls"> 946 <a href="<?php 947 echo esc_url(add_query_arg( 948 array( 949 $taxonomy_name . '-tab' => 'all', 950 'selectall' => 1, 951 ), 952 remove_query_arg($removed_args) 953 )); 954 ?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all"><?php _e('Select All'); ?></a> 955 </span> 956 957 <span class="add-to-menu"> 958 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 959 <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-taxonomy-menu-item" id="submit-taxonomy-<?php echo $taxonomy_name; ?>" /> 960 </span> 961 </p> 962 963 </div><!-- /.taxonomydiv --> 964 <?php 965 } 966 967 /** 968 * Save posted nav menu item data. 969 * 970 * @since 3.0.0 971 * 972 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item. 973 * @param array $menu_data The unsanitized posted menu item data. 974 * @return array The database IDs of the items saved 975 */ 976 function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) { 977 $menu_id = (int) $menu_id; 978 $items_saved = array(); 979 980 if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) { 981 982 // Loop through all the menu items' POST values 983 foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) { 984 if ( 985 empty( $_item_object_data['menu-item-object-id'] ) && // checkbox is not checked 986 ( 987 ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set 988 in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default 989 ! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || // or it's not a custom menu item (but not the custom home page) 990 ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists 991 ) 992 ) { 993 continue; // then this potential menu item is not getting added to this menu 994 } 995 996 // if this possible menu item doesn't actually have a menu database ID yet 997 if ( 998 empty( $_item_object_data['menu-item-db-id'] ) || 999 ( 0 > $_possible_db_id ) || 1000 $_possible_db_id != $_item_object_data['menu-item-db-id'] 1001 ) { 1002 $_actual_db_id = 0; 1003 } else { 1004 $_actual_db_id = (int) $_item_object_data['menu-item-db-id']; 1005 } 1006 1007 $args = array( 1008 'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ), 1009 'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ), 1010 'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ), 1011 'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ), 1012 'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ), 1013 'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ), 1014 'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ), 1015 'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ), 1016 'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ), 1017 'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ), 1018 'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ), 1019 'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ), 1020 'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ), 1021 ); 1022 1023 $items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args ); 1024 1025 } 1026 } 1027 return $items_saved; 1028 } 1029 1030 /** 1031 * Adds custom arguments to some of the meta box object types. 1032 * 1033 * @since 3.0.0 1034 * 1035 * @access private 1036 * 1037 * @param object $object The post type or taxonomy meta-object. 1038 * @return object The post type of taxonomy object. 1039 */ 1040 function _wp_nav_menu_meta_box_object( $object = null ) { 1041 if ( isset( $object->name ) ) { 1042 1043 if ( 'page' == $object->name ) { 1044 $object->_default_query = array( 1045 'orderby' => 'menu_order title', 1046 'post_status' => 'publish', 1047 ); 1048 1049 // posts should show only published items 1050 } elseif ( 'post' == $object->name ) { 1051 $object->_default_query = array( 1052 'post_status' => 'publish', 1053 ); 1054 1055 // cats should be in reverse chronological order 1056 } elseif ( 'category' == $object->name ) { 1057 $object->_default_query = array( 1058 'orderby' => 'id', 1059 'order' => 'DESC', 1060 ); 1061 1062 // custom post types should show only published items 1063 } else { 1064 $object->_default_query = array( 1065 'post_status' => 'publish', 1066 ); 1067 } 1068 } 1069 1070 return $object; 1071 } 1072 1073 /** 1074 * Returns the menu formatted to edit. 1075 * 1076 * @since 3.0.0 1077 * 1078 * @param string $menu_id The ID of the menu to format. 1079 * @return string|WP_Error $output The menu formatted to edit or error object on failure. 1080 */ 1081 function wp_get_nav_menu_to_edit( $menu_id = 0 ) { 1082 $menu = wp_get_nav_menu_object( $menu_id ); 1083 1084 // If the menu exists, get its items. 1085 if ( is_nav_menu( $menu ) ) { 1086 $menu_items = wp_get_nav_menu_items( $menu->term_id, array('post_status' => 'any') ); 1087 $result = '<div id="menu-instructions" class="post-body-plain'; 1088 $result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">'; 1089 $result .= '<p>' . __('Select menu items (pages, categories, links) from the boxes at left to begin building your custom menu.') . '</p>'; 1090 $result .= '</div>'; 1091 1092 if( empty($menu_items) ) 1093 return $result . ' <ul class="menu" id="menu-to-edit"> </ul>'; 1094 1095 $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id ); 1096 1097 if ( class_exists( $walker_class_name ) ) 1098 $walker = new $walker_class_name; 1099 else 1100 return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) ); 1101 1102 $some_pending_menu_items = false; 1103 foreach( (array) $menu_items as $menu_item ) { 1104 if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) 1105 $some_pending_menu_items = true; 1106 } 1107 1108 if ( $some_pending_menu_items ) 1109 $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>'; 1110 1111 $result .= '<ul class="menu" id="menu-to-edit"> '; 1112 $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) ); 1113 $result .= ' </ul> '; 1114 return $result; 1115 } elseif ( is_wp_error( $menu ) ) { 1116 return $menu; 1117 } 1118 1119 1120 } 1121 1122 /** 1123 * Returns the columns for the nav menus page. 1124 * 1125 * @since 3.0.0 1126 * 1127 * @return string|WP_Error $output The menu formatted to edit or error object on failure. 1128 */ 1129 function wp_nav_menu_manage_columns() { 1130 return array( 1131 '_title' => __('Show advanced menu properties'), 1132 'cb' => '<input type="checkbox" />', 1133 'link-target' => __('Link Target'), 1134 'css-classes' => __('CSS Classes'), 1135 'xfn' => __('Link Relationship (XFN)'), 1136 'description' => __('Description'), 1137 ); 1138 } 1139 1140 /** 1141 * Deletes orphaned draft menu items 1142 * 1143 * @access private 1144 * @since 3.0.0 1145 * 1146 */ 1147 function _wp_delete_orphaned_draft_menu_items() { 1148 global $wpdb; 1149 $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); 1150 1151 // delete orphaned draft menu items 1152 $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) ); 1153 1154 foreach( (array) $menu_items_to_delete as $menu_item_id ) 1155 wp_delete_post( $menu_item_id, true ); 1156 } 1157 1158 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items'); 1159 1160 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jun 1 08:30:02 2011 |
Cross-referenced by PHPXref 0.7 Provided by Yoast and awesome WordPress Hosting |