General: Add support for the post type archive description to get_the_archive_description(), and thereby also the_archive_description().

Props henrywright.
Fixes #38487.


git-svn-id: https://develop.svn.wordpress.org/trunk@40976 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Drew Jaynes 2017-07-01 05:14:18 +00:00
parent 0b5b1a667f
commit 336d718bfc

View File

@ -1540,18 +1540,34 @@ function the_archive_description( $before = '', $after = '' ) {
}
/**
* Retrieve category, tag, term, or author description.
* Retrieves the description for an author, post type, or term archive.
*
* @since 4.1.0
* @since 4.7.0 Added support for author archives.
* @since 4.9.0 Added support for post type archives.
*
* @see term_description()
*
* @return string Archive description.
*/
function get_the_archive_description() {
$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 = term_description();
}