Formatting: Introduce get_the_post_type_description() to allow post type archive descriptions to be formatted the same as author and term archives.

Props henry.wright

Fixes #40040


git-svn-id: https://develop.svn.wordpress.org/trunk@41232 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2017-08-04 23:00:50 +00:00
parent db49a16f00
commit 1f26d318ab
2 changed files with 36 additions and 15 deletions

View File

@ -114,7 +114,7 @@ foreach ( array( 'single_post_title', 'single_cat_title', 'single_tag_title', 's
}
// Format text area for display.
foreach ( array( 'term_description', 'get_the_author_description' ) as $filter ) {
foreach ( array( 'term_description', 'get_the_author_description', 'get_the_post_type_description' ) as $filter ) {
add_filter( $filter, 'wptexturize' );
add_filter( $filter, 'convert_chars' );
add_filter( $filter, 'wpautop' );

View File

@ -1554,20 +1554,7 @@ function get_the_archive_description() {
if ( is_author() ) {
$description = get_the_author_meta( 'description' );
} elseif ( is_post_type_archive() ) {
$post_type = get_query_var( 'post_type' );
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
}
$post_type_obj = get_post_type_object( $post_type );
// Check if a description is set.
if ( isset( $post_type_obj->description ) ) {
$description = $post_type_obj->description;
} else {
$description = '';
}
$description = get_the_post_type_description();
} else {
$description = term_description();
}
@ -1582,6 +1569,40 @@ function get_the_archive_description() {
return apply_filters( 'get_the_archive_description', $description );
}
/**
* Retrieves the description for a post type archive.
*
* @since 4.9.0
*
* @return string The post type description.
*/
function get_the_post_type_description() {
$post_type = get_query_var( 'post_type' );
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
}
$post_type_obj = get_post_type_object( $post_type );
// Check if a description is set.
if ( isset( $post_type_obj->description ) ) {
$description = $post_type_obj->description;
} else {
$description = '';
}
/**
* Filters the description for a post type archive.
*
* @since 4.9.0
*
* @param string $description The post type description.
* @param WP_Post_Type $post_type_obj The post type object.
*/
return apply_filters( 'get_the_post_type_description', $description, $post_type_obj );
}
/**
* Retrieve archive link content based on predefined or custom code.
*