WordPress.org

Make WordPress Core

Changeset 35382


Ignore:
Timestamp:
10/24/2015 05:45:11 PM (3 years ago)
Author:
wonderboymusic
Message:

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.

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r35371 r35382  
    11581158                case 'post_type' :
    11591159                    $_object = get_post( $menu_item_data['menu-item-object-id'] );
     1160                break;
     1161
     1162                case 'post_type_archive' :
     1163                    $_object = get_post_type_object( $menu_item_data['menu-item-object'] );
    11601164                break;
    11611165
  • trunk/src/wp-admin/includes/class-walker-nav-menu-edit.php

    r35202 r35382  
    7979            $original_object = get_post( $item->object_id );
    8080            $original_title = get_the_title( $original_object->ID );
     81        } elseif ( 'post_type_archive' == $item->type ) {
     82            $original_object = get_post_type_object( $item->object );
     83            $original_title = $original_object->labels->archives;
    8184        }
    8285
  • trunk/src/wp-admin/includes/nav-menu.php

    r35170 r35382  
    494494                }
    495495
     496                $post_type = get_post_type_object( $post_type_name );
     497                $archive_link = get_post_type_archive_link( $post_type_name );
     498                if ( $post_type->has_archive ) {
     499                    $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
     500                    array_unshift( $posts, (object) array(
     501                        'ID' => 0,
     502                        'object_id' => $_nav_menu_placeholder,
     503                        'object'     => $post_type_name,
     504                        'post_content' => '',
     505                        'post_excerpt' => '',
     506                        'post_title' => $post_type->labels->archives,
     507                        'post_type' => 'nav_menu_item',
     508                        'type' => 'post_type_archive',
     509                        'url' => get_post_type_archive_link( $post_type_name ),
     510                    ) );
     511                }
     512
    496513                /**
    497514                 * Filter the posts displayed in the 'View All' tab of the current
  • trunk/src/wp-includes/nav-menu-template.php

    r34666 r35382  
    579579            $active_object = $menu_item->object;
    580580
     581        // if the menu item corresponds to the currently-queried post type archive
     582        } elseif (
     583            'post_type_archive' == $menu_item->type &&
     584            is_post_type_archive( array( $menu_item->object ) )
     585        ) {
     586            $classes[] = 'current-menu-item';
     587            $menu_items[$key]->current = true;
    581588        // if the menu item corresponds to the currently-requested URL
    582589        } elseif ( 'custom' == $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
  • trunk/src/wp-includes/nav-menu.php

    r34769 r35382  
    404404            $original_parent = (int) $original_object->post_parent;
    405405            $original_title = $original_object->post_title;
     406        } elseif ( 'post_type_archive' == $args['menu-item-type'] ) {
     407            $original_object = get_post_type_object( $args['menu-item-object'] );
     408            $original_title = $original_object->labels->archives;
    406409        }
    407410
     
    732735                $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title;
    733736
     737            } elseif ( 'post_type_archive' == $menu_item->type ) {
     738                $object =  get_post_type_object( $menu_item->object );
     739                if ( $object ) {
     740                    $menu_item->title = '' == $menu_item->post_title ? $object->labels->archives : $menu_item->post_title;
     741                } else {
     742                    $menu_item->_invalid = true;
     743                }
     744
     745                $menu_item->type_label = __( 'Post Type Archive' );
     746                $menu_item->description = '';
     747                $menu_item->url = get_post_type_archive_link( $menu_item->object );
    734748            } elseif ( 'taxonomy' == $menu_item->type ) {
    735749                $object = get_taxonomy( $menu_item->object );
  • trunk/src/wp-includes/post-functions.php

    r35377 r35382  
    13241324 *                       ones the default is 'Parent Page:'.
    13251325 * - all_items - String for the submenu. Default is All Posts/All Pages.
     1326 * - archives - String for use with archives in nav menus. Default is Post Archives/Page Archives.
    13261327 * - insert_into_item - String for the media frame button. Default is Insert into post/Insert into page.
    13271328 * - uploaded_to_this_item - String for the media frame filter. Default is Uploaded to this post/Uploaded to this page.
     
    13631364        'parent_item_colon' => array( null, __('Parent Page:') ),
    13641365        'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ),
     1366        'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
    13651367        'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
    13661368        'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),
     
    14281430    if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) )
    14291431        $object->labels['all_items'] = $object->labels['menu_name'];
     1432
     1433    if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) {
     1434        $object->labels['archives'] = $object->labels['all_items'];
     1435    }
    14301436
    14311437    $defaults = array();
Note: See TracChangeset for help on using the changeset viewer.