From 5084a0b28acff38b819f02d71643e5f0c95337de Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 4 Nov 2015 04:29:39 +0000 Subject: [PATCH] Customize: Add support for `post_type_archive` nav menu items. Props celloexpressions, westonruter. Fixes #16075. git-svn-id: https://develop.svn.wordpress.org/trunk@35500 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-customize-nav-menus.php | 12 ++++++++++++ .../class-wp-customize-nav-menu-item-setting.php | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-customize-nav-menus.php b/src/wp-includes/class-wp-customize-nav-menus.php index adccacd130..6f5944f59c 100644 --- a/src/wp-includes/class-wp-customize-nav-menus.php +++ b/src/wp-includes/class-wp-customize-nav-menus.php @@ -109,6 +109,8 @@ final class WP_Customize_Nav_Menus { if ( 'post_type' === $type ) { if ( ! get_post_type_object( $object ) ) { return new WP_Error( 'nav_menus_invalid_post_type' ); + } else { + $post_type = get_post_type_object( $object ); } if ( 0 === $page && 'page' === $object ) { @@ -121,6 +123,16 @@ final class WP_Customize_Nav_Menus { 'object' => '', 'url' => home_url(), ); + } elseif ( 'post' !== $object && 0 === $page && $post_type->has_archive ) { + // Add a post type archive link. + $items[] = array( + 'id' => $object . '-archive', + 'title' => $post_type->labels->archives, + 'type' => 'post_type_archive', + 'type_label' => __( 'Post Type Archive' ), + 'object' => $object, + 'url' => get_post_type_archive_link( $object ), + ); } $posts = get_posts( array( diff --git a/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php b/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php index f8aaec73ae..463da87afe 100644 --- a/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php +++ b/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php @@ -324,12 +324,20 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { } } + if ( ! isset( $this->value['title'] ) ) { + $this->value['title'] = ''; + } + if ( ! isset( $this->value['_invalid'] ) ) { - $this->value['_invalid'] = ( - ( 'post_type' === $this->value['type'] && ! post_type_exists( $this->value['object'] ) ) + $this->value['_invalid'] = false; + $is_known_invalid = ( + ( ( 'post_type' === $this->value['type'] || 'post_type_archive' === $this->value['type'] ) && ! post_type_exists( $this->value['object'] ) ) || ( 'taxonomy' === $this->value['type'] && ! taxonomy_exists( $this->value['object'] ) ) ); + if ( $is_known_invalid ) { + $this->value['_invalid'] = true; + } } // Remove remaining properties available on a setup nav_menu_item post object which aren't relevant to the setting value.