diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index bc3a756d03..d7ef448d80 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -1159,6 +1159,10 @@ function wp_ajax_add_menu_item() { $_object = get_post( $menu_item_data['menu-item-object-id'] ); break; + case 'post_type_archive' : + $_object = get_post_type_object( $menu_item_data['menu-item-object'] ); + break; + case 'taxonomy' : $_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] ); break; diff --git a/src/wp-admin/includes/class-walker-nav-menu-edit.php b/src/wp-admin/includes/class-walker-nav-menu-edit.php index 6d6a63b2c3..105e613a4f 100644 --- a/src/wp-admin/includes/class-walker-nav-menu-edit.php +++ b/src/wp-admin/includes/class-walker-nav-menu-edit.php @@ -78,6 +78,9 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { } elseif ( 'post_type' == $item->type ) { $original_object = get_post( $item->object_id ); $original_title = get_the_title( $original_object->ID ); + } elseif ( 'post_type_archive' == $item->type ) { + $original_object = get_post_type_object( $item->object ); + $original_title = $original_object->labels->archives; } $classes = array( diff --git a/src/wp-admin/includes/nav-menu.php b/src/wp-admin/includes/nav-menu.php index 1ba4995630..b2c70d6873 100644 --- a/src/wp-admin/includes/nav-menu.php +++ b/src/wp-admin/includes/nav-menu.php @@ -493,6 +493,23 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) { } } + $post_type = get_post_type_object( $post_type_name ); + $archive_link = get_post_type_archive_link( $post_type_name ); + if ( $post_type->has_archive ) { + $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; + array_unshift( $posts, (object) array( + 'ID' => 0, + 'object_id' => $_nav_menu_placeholder, + 'object' => $post_type_name, + 'post_content' => '', + 'post_excerpt' => '', + 'post_title' => $post_type->labels->archives, + 'post_type' => 'nav_menu_item', + 'type' => 'post_type_archive', + 'url' => get_post_type_archive_link( $post_type_name ), + ) ); + } + /** * Filter the posts displayed in the 'View All' tab of the current * post type's menu items meta box. diff --git a/src/wp-includes/nav-menu-template.php b/src/wp-includes/nav-menu-template.php index 8c74758b09..253b6547cd 100644 --- a/src/wp-includes/nav-menu-template.php +++ b/src/wp-includes/nav-menu-template.php @@ -578,6 +578,13 @@ function _wp_menu_item_classes_by_context( &$menu_items ) { $active_parent_object_ids[] = (int) $menu_item->post_parent; $active_object = $menu_item->object; + // if the menu item corresponds to the currently-queried post type archive + } elseif ( + 'post_type_archive' == $menu_item->type && + is_post_type_archive( array( $menu_item->object ) ) + ) { + $classes[] = 'current-menu-item'; + $menu_items[$key]->current = true; // if the menu item corresponds to the currently-requested URL } elseif ( 'custom' == $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) { $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 9cce24fbff..1fe2bc339a 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -403,6 +403,9 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item $original_object = get_post( $args['menu-item-object-id'] ); $original_parent = (int) $original_object->post_parent; $original_title = $original_object->post_title; + } elseif ( 'post_type_archive' == $args['menu-item-type'] ) { + $original_object = get_post_type_object( $args['menu-item-object'] ); + $original_title = $original_object->labels->archives; } if ( $args['menu-item-title'] == $original_title ) @@ -731,6 +734,17 @@ function wp_setup_nav_menu_item( $menu_item ) { $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; + } elseif ( 'post_type_archive' == $menu_item->type ) { + $object = get_post_type_object( $menu_item->object ); + if ( $object ) { + $menu_item->title = '' == $menu_item->post_title ? $object->labels->archives : $menu_item->post_title; + } else { + $menu_item->_invalid = true; + } + + $menu_item->type_label = __( 'Post Type Archive' ); + $menu_item->description = ''; + $menu_item->url = get_post_type_archive_link( $menu_item->object ); } elseif ( 'taxonomy' == $menu_item->type ) { $object = get_taxonomy( $menu_item->object ); if ( $object ) { diff --git a/src/wp-includes/post-functions.php b/src/wp-includes/post-functions.php index 1d6b328819..58961fe025 100644 --- a/src/wp-includes/post-functions.php +++ b/src/wp-includes/post-functions.php @@ -1323,6 +1323,7 @@ function _post_type_meta_capabilities( $capabilities = null ) { * - parent_item_colon - This string isn't used on non-hierarchical types. In hierarchical * ones the default is 'Parent Page:'. * - all_items - String for the submenu. Default is All Posts/All Pages. + * - archives - String for use with archives in nav menus. Default is Post Archives/Page Archives. * - insert_into_item - String for the media frame button. Default is Insert into post/Insert into page. * - uploaded_to_this_item - String for the media frame filter. Default is Uploaded to this post/Uploaded to this page. * - featured_image - Default is Featured Image. @@ -1362,6 +1363,7 @@ function get_post_type_labels( $post_type_object ) { 'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ), 'parent_item_colon' => array( null, __('Parent Page:') ), 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), + 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ), 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ), 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ), 'featured_image' => array( __( 'Featured Image' ), __( 'Featured Image' ) ), @@ -1428,6 +1430,10 @@ function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) { if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) $object->labels['all_items'] = $object->labels['menu_name']; + if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) { + $object->labels['archives'] = $object->labels['all_items']; + } + $defaults = array(); foreach ( $nohier_vs_hier_defaults as $key => $value ) { $defaults[$key] = $object->hierarchical ? $value[1] : $value[0];