Customize: Add support for `post_type_archive` nav menu items.

Props celloexpressions, westonruter.
Fixes #16075.

Built from https://develop.svn.wordpress.org/trunk@35500


git-svn-id: http://core.svn.wordpress.org/trunk@35464 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2015-11-04 04:30:26 +00:00
parent e0cab8383c
commit 77e365efbf
3 changed files with 23 additions and 3 deletions

View File

@ -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(

View File

@ -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.

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-beta2-35499';
$wp_version = '4.4-beta2-35500';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.