mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Nav Menus: show custom post type Archive item at the top of the View All tab for the post type on the legacy Nav Menu screen.
Props aaroncampbell, DrewAPicture, seanchayes, hlashbrooke, paulwilde, ericlewis, raulillana See #16075. git-svn-id: https://develop.svn.wordpress.org/trunk@35382 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a97bf5b2ca
commit
a18feed6bd
@ -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;
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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'] );
|
||||
|
||||
@ -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 ) {
|
||||
|
||||
@ -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];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user