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
This commit is contained in:
parent
ff6e398b6f
commit
5084a0b28a
|
@ -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(
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue