Introduce 'the_category_list' filter.

Used to filter categories as structured data, before building markup in
`get_the_category_list()`.

We use this filter in addition to upstream filters (such as
'get_the_categories'`) because those upstream filters are used in numerous
contexts, while `'the_category_list'` is always used for generating markup
for display.

Props KevinB, ericlewis, SergeyBiryukov, DrewAPicture.
Fixes #9227.

git-svn-id: https://develop.svn.wordpress.org/trunk@34625 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2015-09-27 02:21:43 +00:00
parent c39a4a6447
commit de0b5c846f

View File

@ -175,7 +175,17 @@ function get_the_category_list( $separator = '', $parents='', $post_id = false )
return apply_filters( 'the_category', '', $separator, $parents );
}
$categories = get_the_category( $post_id );
/**
* Filter the categories before building the category list.
*
* @since 4.4.0
*
* @param array $categories An array of the post's categories.
* @param int|bool $post_id ID of the post we're retrieving categories for. When `false`, we assume the
* current post in the loop.
*/
$categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id );
if ( empty( $categories ) ) {
/** This filter is documented in wp-includes/category-template.php */
return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );