In `wp_list_categories()`, 'All' link should point to post type archive if taxonomy is not registered for 'post' or 'page'.

Instead, we point to the post type archive of the first registered
object_type that supports archives.

Props stevegrunwell, hrishiv90, boonebgorges.
Fixes #21881.
Built from https://develop.svn.wordpress.org/trunk@32292


git-svn-id: http://core.svn.wordpress.org/trunk@32263 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-04-24 14:57:28 +00:00
parent 31fd60ae12
commit 2699d8d989
2 changed files with 23 additions and 2 deletions

View File

@ -532,7 +532,28 @@ function wp_list_categories( $args = '' ) {
}
} else {
if ( ! empty( $show_option_all ) ) {
$posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' );
$posts_page = '';
// For taxonomies that belong only to custom post types, point to a valid archive.
$taxonomy_object = get_taxonomy( $r['taxonomy'] );
if ( ! in_array( 'post', $taxonomy_object->object_type ) && ! in_array( 'page', $taxonomy_object->object_type ) ) {
foreach ( $taxonomy_object->object_type as $object_type ) {
$_object_type = get_post_type_object( $object_type );
// Grab the first one.
if ( ! empty( $_object_type->has_archive ) ) {
$posts_page = get_post_type_archive_link( $object_type );
break;
}
}
}
// Fallback for the 'All' link is the front page.
if ( ! $posts_page ) {
$posts_page = 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' );
}
$posts_page = esc_url( $posts_page );
if ( 'list' == $r['style'] ) {
$output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>";

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-alpha-32280';
$wp_version = '4.3-alpha-32292';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.