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