Make WordPress Core

Ticket #38545: 38545.8.diff

File 38545.8.diff, 5.5 KB (added by audrasjb, 7 years ago)

Some fixes - see @desrosj review

  • src/wp-includes/general-template.php

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index 57a7b67..6073783 100644
    a b function single_month_title( $prefix = '', $display = true ) { 
    14671467 * Display the archive title based on the queried object.
    14681468 *
    14691469 * @since 4.1.0
     1470 * @since 4.9.6 Added $span_class parameter.
    14701471 *
    14711472 * @see get_the_archive_title()
    14721473 *
    1473  * @param string $before Optional. Content to prepend to the title. Default empty.
    1474  * @param string $after  Optional. Content to append to the title. Default empty.
     1474 * @param string $before     Optional. Content to prepend to the title. Default empty.
     1475 * @param string $after      Optional. Content to append to the title. Default empty.
     1476 * @param string $span_class Optional. Class name to apply to the span around the archive type description. Default empty.
    14751477 */
    1476 function the_archive_title( $before = '', $after = '' ) {
    1477         $title = get_the_archive_title();
     1478function the_archive_title( $before = '', $after = '', $span_class = '' ) {
     1479        $title = get_the_archive_title( $span_class );
    14781480
    14791481        if ( ! empty( $title ) ) {
    14801482                echo $before . $title . $after;
    function the_archive_title( $before = '', $after = '' ) { 
    14851487 * Retrieve the archive title based on the queried object.
    14861488 *
    14871489 * @since 4.1.0
     1490 * @since 4.9.6 Added $span_class parameter.
    14881491 *
     1492 * @param string $span_class Optional. Class name to apply to the span around the archive type description. Default empty.
    14891493 * @return string Archive title.
    14901494 */
    1491 function get_the_archive_title() {
     1495function get_the_archive_title( $span_class = '' ) {
    14921496        if ( is_category() ) {
    1493                 /* translators: Category archive title. %s: Category name */
    1494                 $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
     1497                /* translators: Category archive title. */
     1498                $type = __( 'Category:' );
     1499                $name = single_cat_title( '', false );
    14951500        } elseif ( is_tag() ) {
    1496                 /* translators: Tag archive title. %s: Tag name */
    1497                 $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
     1501                /* translators: Tag archive title. */
     1502                $type = __( 'Tag:' );
     1503                $name = single_tag_title( '', false );
    14981504        } elseif ( is_author() ) {
    14991505                /* translators: Author archive title. %s: Author name */
    1500                 $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
     1506                $type = __( 'Author:' );
     1507                $name = sprintf( '<span class="vcard">%s</span>', get_the_author() );
    15011508        } elseif ( is_year() ) {
    1502                 /* translators: Yearly archive title. %s: Year */
    1503                 $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
     1509                /* translators: Yearly archive title. */
     1510                $type = __( 'Year:' );
     1511                $name = get_the_date( _x( 'Y', 'yearly archives date format' ) );
    15041512        } elseif ( is_month() ) {
    1505                 /* translators: Monthly archive title. %s: Month name and year */
    1506                 $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
     1513                /* translators: Monthly archive title. */
     1514                $type = __( 'Month:' );
     1515                $name = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
    15071516        } elseif ( is_day() ) {
    1508                 /* translators: Daily archive title. %s: Date */
    1509                 $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
    1510         } elseif ( is_tax( 'post_format' ) ) {
     1517                /* translators: Daily archive title. */
     1518                $type = __( 'Day:' );
     1519                $name = get_the_date( _x( 'F j, Y', 'daily archives date format' ) );
     1520        } elseif ( is_post_type_archive() ) {
     1521                /* translators: Post type archive title. */
     1522                $type = __( 'Archives:' );
     1523                $name = post_type_archive_title( '', false );
     1524        } elseif ( is_tax() ) {
     1525                $tax = get_taxonomy( get_queried_object()->taxonomy );
     1526                /* translators: Taxonomy singular name */
     1527                $type = sprintf( __( '%s:' ), $tax->labels->singular_name );
     1528                $name = single_term_title( '', false );
     1529        }
     1530
     1531        if ( is_tax( 'post_format' ) ) {
    15111532                if ( is_tax( 'post_format', 'post-format-aside' ) ) {
    15121533                        $title = _x( 'Asides', 'post format archive title' );
    15131534                } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
    function get_the_archive_title() { 
    15271548                } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
    15281549                        $title = _x( 'Chats', 'post format archive title' );
    15291550                }
    1530         } elseif ( is_post_type_archive() ) {
    1531                 /* translators: Post type archive title. %s: Post type name */
    1532                 $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
    1533         } elseif ( is_tax() ) {
    1534                 $tax = get_taxonomy( get_queried_object()->taxonomy );
    1535                 /* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */
    1536                 $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
     1551        } elseif ( isset( $type ) && isset( $name ) ) {
     1552                if ( ! empty( $span_class ) ) {
     1553                        $span_class = sprintf( ' class="%s"', esc_attr( $span_class ) );
     1554                        $title = sprintf( '<span%s>%s </span>%s', $span_class, $type, $name );
     1555                } else {
     1556                        $title = sprintf( '%s %s', $type, $name );
     1557                }
    15371558        } else {
    15381559                $title = __( 'Archives' );
    15391560        }
    function get_the_archive_title() { 
    15421563         * Filters the archive title.
    15431564         *
    15441565         * @since 4.1.0
     1566         * @since 4.9.6 Added $span_class parameter.
    15451567         *
    15461568         * @param string $title Archive title to be displayed.
     1569         * @param string $span_class Optional. Class name to apply to the span around the archive type description. Default empty.
    15471570         */
    1548         return apply_filters( 'get_the_archive_title', $title );
     1571        return apply_filters( 'get_the_archive_title', $title, $span_class );
    15491572}
    15501573
    15511574/**