Index: trunk/wp-admin/includes/nav-menu.php
===================================================================
--- trunk/wp-admin/includes/nav-menu.php (revision 13512)
+++ trunk/wp-admin/includes/nav-menu.php (revision 13704)
@@ -1,273 +1,383 @@
'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' );
- $link_objects = new WP_Query( $args );
-
- $items_counter = $counter;
-
- if ( !$link_objects->posts ) {
- _e('Not Found');
- return $items_counter;
- }
-
- // Display Loop
- foreach ( $link_objects->posts as $item ) {
- if ( 0 == $item->parent ) {
- $item = wp_setup_nav_menu_item( $item, 'item', $items_counter );
-
- switch ( $context ) {
- case 'menu':
- ?>
-
-
-
- ID;
- $items_counter++;
- $items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'default' );
- ?>
-
- true ), 'object' );
+
+ if ( !$post_types )
+ return false;
+
+ foreach ( $post_types as $post_type ) {
+ $id = sanitize_title_with_dashes( $post_type->label );
+
+ // delete_transient( "nav_menu_items_{$post_type->name}" );
+ // delete_transient( "nav_menu_sub_items_{$post_type->name}" );
+
+ add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'menus', 'side', 'default', $post_type );
+ }
+}
+
+/**
+ * Creates metaboxes for any taxonomy menu item.
+ *
+ * @since 3.0.0
+ */
+function wp_nav_menu_taxonomy_metaboxes() {
+ $taxonomies = get_taxonomies( array( 'show_ui' => true ), 'object' );
+
+ if ( !$taxonomies )
+ return false;
+
+ foreach ( $taxonomies as $tax ) {
+ $id = sanitize_title_with_dashes( $tax->label );
+
+ // delete_transient( "nav_menu_items_{$tax->name}" );
+ // delete_transient( "nav_menu_sub_items_{$tax->name}" );
+
+ add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'menus', 'side', 'default', $tax );
+ }
+}
+
+/**
+ * Displays a metabox for managing the active menu being edited.
+ *
+ * @since 3.0.0
+ */
+function wp_nav_menu_manage_menu_metabox( $object, $menu ) { ?>
+
+
+
+
+
+
+ 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' );
+
+ // Cache the query for a day. @todo: Make sure to flush transient when links are updated.
+ $query = get_transient( 'menu_item_query_custom_links' );
+ if ( false == $query ) {
+ $query = new WP_Query( $args );
+ set_transient( 'menu_item_query_custom_links', $query, 86400 );
+ }
+
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+ posts, 'custom' ); ?>
+
+
+
+
+
+ $post_type['args']->name, );
+
+ if ( 'attachment' == $post_type['args']->name )
+ $args['post_status'] = 'any';
+
+ // Cache the query for a day. @todo: Make sure to flush transient when objects are updated.
+ $query = get_transient( "nav_menu_items_{$post_type['args']->name}" );
+ if ( false == $query ) {
+ $query = new WP_Query( $args );
+ set_transient( "nav_menu_items_{$post_type['args']->name}", $query, 86400 );
+ }
+
+ if ( !$query->posts )
+ $error = ''. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'';
+
+ $pt_names = '';
+ if ( is_array($query->posts) ) {
+ foreach ( $query->posts as $post ) {
+ if ( $post->post_title ) {
+ $pt_names .= htmlentities( $post->post_title ) .'|';
+ } else {
+ $pt_names = sprintf( __('No %s exists'), $post_type['args']->label );
}
}
}
- return $items_counter;
-}
-
-/**
- * Displays a list of pages and thier sub items.
- *
- * @since 3.0.0
- *
- * @param string $counter
- * @param string $context
- */
-function wp_nav_menu_get_pages( $counter, $context ) {
- $pages_args = array(
- 'child_of' => 0,
- 'sort_order' => 'ASC',
- 'sort_column' => 'post_title',
- 'hierarchical' => 1,
- 'exclude' => '',
- 'include' => '',
- 'meta_key' => '',
- 'meta_value' => '',
- 'authors' => '',
- 'parent' => -1,
- 'exclude_tree' => '',
- 'number' => '',
- 'offset' => 0 );
-
- // Get all pages
- $pages_array = get_pages( $pages_args );
-
- $items_counter = $counter;
- $parentli = $items_counter;
-
- if ( !$pages_array ) {
- echo __('Not Found');
- return $items_counter;
- }
-
- // Display Loop
- foreach ( $pages_array as $post ) {
- if ( $post->post_parent == 0 ) {
- $post = wp_setup_nav_menu_item( $post, 'page', $items_counter );
- if ( $context == 'menu' ) {
- ?>
-
-
-
- ID;
- $items_counter++;
- $items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'default' );
- ?>
-
- label );
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ posts, 'post_type', $post_type['args']->name ); ?>
+
+
+
+
+
+
+
+ 0, 'orderby' => 'name', 'order' => 'ASC',
+ 'hide_empty' => false, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '',
+ 'include' => '', 'number' => '', 'pad_counts' => false
+ );
+
+ // Cache the query for a day. @todo: Make sure to flush transient when terms are updated.
+ $terms = get_transient( "nav_menu_items_{$taxonomy['args']->name}" );
+ if ( false == $terms ) {
+ $terms = get_terms( $taxonomy['args']->name, $args );
+ set_transient( "nav_menu_items_{$taxonomy['args']->name}", $terms, 86400 );
+ }
+
+ if ( !$terms )
+ $error = ''. sprintf( __( 'No %s exists' ), $taxonomy['args']->label ) .'';
+
+ $term_names = '';
+ if ( is_array($terms) ) {
+ foreach ( $terms as $term ) {
+ if ( $term->name ) {
+ $term_names .= htmlentities( $term->name ) .'|';
+ } else {
+ $term_names = sprintf( __('No %s exists'), $taxonomy['args']->label );
}
}
}
- return $items_counter;
-}
-
-/**
- * Displays a list of categories and thier sub items.
- *
- * @since 3.0.0
- *
- * @param string $counter
- * @param string $context
- */
-function wp_nav_menu_get_categories( $counter, $context ) {
- $category_args = array(
- 'type' => 'post',
- 'child_of' => 0,
- 'orderby' => 'name',
- 'order' => 'ASC',
- 'hide_empty' => false,
- 'include_last_update_time' => false,
- 'hierarchical' => 1,
- 'exclude' => '',
- 'include' => '',
- 'number' => '',
- 'pad_counts' => false );
-
- $items_counter = $counter;
-
- // Get all categories
- $categories_array = get_categories( $category_args );
-
- if ( !$categories_array ) {
- _e('Not Found');
- return $items_counter;
- }
-
- // Display Loop
- foreach ( $categories_array as $cat_item ) {
- if ( $cat_item->parent == 0 ) {
- $cat_item = wp_setup_nav_menu_item( $cat_item, 'category', $items_counter );
- // Custom Menu
- if ( $context == 'menu' ) {
- ?>
-
-
-
- cat_ID;
- $items_counter++;
- $items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'default' );
- ?>
-
- label );
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ post_parent) )
+ $menu_item->post_parent = $menu_item->parent;
+
+ // Cleanest way to get all attachements
+ if ( 'attachment' == $object )
+ $menu_item->post_parent = 0;
+
+ if ( 0 == $menu_item->post_parent ) {
+ // Setup the menu item
+ $menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object );
+ $attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : '';
+
+ $output .= '';
+ $output .= wp_get_nav_menu_item( $menu_item, $object_type, $object );
+ $output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object, $context );
+ $output .= '';
+
+ ++$i;
+ }
+ }
+
+ return $output;
+}
+
+/**
+ * Recursive function to retrieve sub menu items.
+ *
+ * @since 3.0.0
+ *
+ * @param string $childof The Parent ID.
+ * @param string $object_type The object type.
+ * @param string $object The object name.
+ * @return string $output sub menu items.
+ */
+function wp_get_nav_menu_sub_items( $childof, $object_type, $object = null, $context = 'frontend' ) {
+ $args = array( 'child_of' => $childof, 'parent' => $childof, 'hide_empty' => false, );
+
+ switch ( $object_type ) {
+ case 'post_type':
+ $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
+ if ( in_array( $object, $hierarchical_post_types ) ) {
+ $args['post_type'] = $object;
+ $sub_menu_items = get_pages( $args );
+ } else {
+ $sub_menu_items = array();
}
+ break;
+
+ case 'taxonomy':
+ if ( is_taxonomy_hierarchical( $object ) ) {
+ $sub_menu_items = get_terms( $object, $args );
+ } else {
+ $sub_menu_items = array();
+ }
+ break;
+
+ default:
+ $sub_menu_items = array();
+ break;
+ }
+
+ $output = '';
+ $i = 1;
+ if ( !empty($sub_menu_items) && !is_wp_error($sub_menu_items) ) {
+ $output .= '