Make WordPress Core

Ticket #38545: 38545.2.diff

File 38545.2.diff, 5.5 KB (added by desrosj, 6 years ago)
  • src/wp-includes/general-template.php

     
    14721472 * Display the archive title based on the queried object.
    14731473 *
    14741474 * @since 4.1.0
     1475 * @since 5.2.0 Added `$span_class` parameter.
    14751476 *
    14761477 * @see get_the_archive_title()
    14771478 *
    1478  * @param string $before Optional. Content to prepend to the title. Default empty.
    1479  * @param string $after  Optional. Content to append to the title. Default empty.
     1479 * @param string $before     Optional. Content to prepend to the title. Default empty.
     1480 * @param string $after      Optional. Content to append to the title. Default empty.
     1481 * @param string $span_class Optional. Class name to apply to a span around the archive type description. Default empty
     1482 *                           (no span displayed).
    14801483 */
    1481 function the_archive_title( $before = '', $after = '' ) {
    1482         $title = get_the_archive_title();
     1484function the_archive_title( $before = '', $after = '', $span_class = '' ) {
     1485        $title = get_the_archive_title( $span_class );
    14831486
    14841487        if ( ! empty( $title ) ) {
    14851488                echo $before . $title . $after;
     
    14901493 * Retrieve the archive title based on the queried object.
    14911494 *
    14921495 * @since 4.1.0
     1496 * @since 5.2.0 Added `$span_class` parameter.
    14931497 *
     1498 * @param string $span_class Optional. Class name to apply to a span around the archive type description. Default empty
     1499 *                           (no span displayed).
    14941500 * @return string Archive title.
    14951501 */
    1496 function get_the_archive_title() {
     1502function get_the_archive_title( $span_class = '' ) {
    14971503        if ( is_category() ) {
    1498                 /* translators: Category archive title. %s: Category name */
    1499                 $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
     1504                /* translators: Category archive title. */
     1505                $type = __( 'Category:' );
     1506                $name = single_cat_title( '', false );
    15001507        } elseif ( is_tag() ) {
    1501                 /* translators: Tag archive title. %s: Tag name */
    1502                 $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
     1508                /* translators: Tag archive title. */
     1509                $type = __( 'Tag:' );
     1510                $name = single_tag_title( '', false );
    15031511        } elseif ( is_author() ) {
    1504                 /* translators: Author archive title. %s: Author name */
    1505                 $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
     1512                /* translators: Author archive title. */
     1513                $type = __( 'Author:' );
     1514                /* translators: %s: Author name. */
     1515                $name = sprintf( '<span class="vcard">%s</span>', get_the_author() );
    15061516        } elseif ( is_year() ) {
    1507                 /* translators: Yearly archive title. %s: Year */
    1508                 $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
     1517                /* translators: Yearly archive title. */
     1518                $type = __( 'Year:' );
     1519                $name = get_the_date( _x( 'Y', 'yearly archives date format' ) );
    15091520        } elseif ( is_month() ) {
    1510                 /* translators: Monthly archive title. %s: Month name and year */
    1511                 $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
     1521                /* translators: Monthly archive title. */
     1522                $type = __( 'Month:' );
     1523                $name = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
    15121524        } elseif ( is_day() ) {
    1513                 /* translators: Daily archive title. %s: Date */
    1514                 $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
    1515         } elseif ( is_tax( 'post_format' ) ) {
     1525                /* translators: Daily archive title. */
     1526                $type = __( 'Day:' );
     1527                $name = get_the_date( _x( 'F j, Y', 'daily archives date format' ) );
     1528        } elseif ( is_post_type_archive() ) {
     1529                /* translators: Post type archive title. */
     1530                $type = __( 'Archives:' );
     1531                $name = post_type_archive_title( '', false );
     1532        } elseif ( is_tax() ) {
     1533                $tax = get_taxonomy( get_queried_object()->taxonomy );
     1534                /* translators: Taxonomy singular name */
     1535                $type = sprintf( __( '%s:' ), $tax->labels->singular_name );
     1536                $name = single_term_title( '', false );
     1537        }
     1538
     1539        if ( is_tax( 'post_format' ) ) {
    15161540                if ( is_tax( 'post_format', 'post-format-aside' ) ) {
    15171541                        $title = _x( 'Asides', 'post format archive title' );
    15181542                } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
     
    15321556                } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
    15331557                        $title = _x( 'Chats', 'post format archive title' );
    15341558                }
    1535         } elseif ( is_post_type_archive() ) {
    1536                 /* translators: Post type archive title. %s: Post type name */
    1537                 $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
    1538         } elseif ( is_tax() ) {
    1539                 $tax = get_taxonomy( get_queried_object()->taxonomy );
    1540                 /* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */
    1541                 $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
     1559        } elseif ( isset( $type ) && isset( $name ) ) {
     1560                if ( ! empty( $span_class ) ) {
     1561                        $title = sprintf( '<span class="%s">%s </span>%s', $span_class, $type, $name );
     1562                } else {
     1563                        $title = sprintf( '%s %s', $type, $name );
     1564                }
    15421565        } else {
    15431566                $title = __( 'Archives' );
    15441567        }
     
    15471570         * Filters the archive title.
    15481571         *
    15491572         * @since 4.1.0
     1573         * @since 5.2.0 Added `$span_class` parameter.
    15501574         *
    15511575         * @param string $title Archive title to be displayed.
     1576         * @param string $span_class Optional. Class name to apply to the span around the archive type description. Default empty.
    15521577         */
    1553         return apply_filters( 'get_the_archive_title', $title );
     1578        return apply_filters( 'get_the_archive_title', $title, $span_class );
    15541579}
    15551580
    15561581/**