Make WordPress Core

Ticket #31078: 31078.4.diff

File 31078.4.diff, 14.3 KB (added by obenland, 9 years ago)
  • src/wp-includes/deprecated.php

     
    36203620
    36213621        return $headers;
    36223622}
     3623
     3624/**
     3625 * Formerly used to display or retrieve page title for all areas of blog.
     3626 *
     3627 * By default, the page title will display the separator before the page title,
     3628 * so that the blog title will be before the page title. This is not good for
     3629 * title display, since the blog title shows up on most tabs and not what is
     3630 * important, which is the page that the user is looking at.
     3631 *
     3632 * There are also SEO benefits to having the blog title after or to the 'right'
     3633 * or the page title. However, it is mostly common sense to have the blog title
     3634 * to the right with most browsers supporting tabs. You can achieve this by
     3635 * using the seplocation parameter and setting the value to 'right'. This change
     3636 * was introduced around 2.5.0, in case backwards compatibility of themes is
     3637 * important.
     3638 *
     3639 * @since 1.0.0
     3640 * @deprecated 4.4.0
     3641 * @deprecated Use add_theme_support( 'title-tag' );
     3642 *
     3643 * @param string $sep Optional, default is '»'. How to separate the various items within the page title.
     3644 * @param bool $display Optional, default is true. Whether to display or retrieve title.
     3645 * @param string $seplocation Optional. Direction to display title, 'right'.
     3646 * @return string|null String on retrieve, null when displaying.
     3647 */
     3648function wp_title( $sep = '»', $display = true, $seplocation = '' ) {
     3649        _deprecated_function( __FUNCTION__, '4.4', 'add_theme_support( \'title-tag\' )' );
     3650
     3651        global $wp_locale;
     3652
     3653        $m        = get_query_var( 'm' );
     3654        $year     = get_query_var( 'year' );
     3655        $monthnum = get_query_var( 'monthnum' );
     3656        $day      = get_query_var( 'day' );
     3657        $search   = get_query_var( 's' );
     3658        $title    = '';
     3659
     3660        $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
     3661
     3662        // If there is a post
     3663        if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) {
     3664                $title = single_post_title( '', false );
     3665        }
     3666
     3667        // If there's a post type archive
     3668        if ( is_post_type_archive() ) {
     3669                $post_type = get_query_var( 'post_type' );
     3670                if ( is_array( $post_type ) ) {
     3671                        $post_type = reset( $post_type );
     3672                }
     3673                $post_type_object = get_post_type_object( $post_type );
     3674                if ( ! $post_type_object->has_archive ) {
     3675                        $title = post_type_archive_title( '', false );
     3676                }
     3677        }
     3678
     3679        // If there's a category or tag
     3680        if ( is_category() || is_tag() ) {
     3681                $title = single_term_title( '', false );
     3682        }
     3683
     3684        // If there's a taxonomy
     3685        if ( is_tax() ) {
     3686                $term = get_queried_object();
     3687                if ( $term ) {
     3688                        $tax   = get_taxonomy( $term->taxonomy );
     3689                        $title = single_term_title( $tax->labels->name . $t_sep, false );
     3690                }
     3691        }
     3692
     3693        // If there's an author
     3694        if ( is_author() && ! is_post_type_archive() ) {
     3695                $author = get_queried_object();
     3696                if ( $author ) {
     3697                        $title = $author->display_name;
     3698                }
     3699        }
     3700
     3701        // Post type archives with has_archive should override terms.
     3702        if ( is_post_type_archive() && $post_type_object->has_archive ) {
     3703                $title = post_type_archive_title( '', false );
     3704        }
     3705
     3706        // If there's a month
     3707        if ( is_archive() && ! empty( $m ) ) {
     3708                $my_year  = substr( $m, 0, 4 );
     3709                $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
     3710                $my_day   = intval( substr( $m, 6, 2 ) );
     3711                $title    = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
     3712        }
     3713
     3714        // If there's a year
     3715        if ( is_archive() && ! empty( $year ) ) {
     3716                $title = $year;
     3717                if ( ! empty( $monthnum ) ) {
     3718                        $title .= $t_sep . $wp_locale->get_month( $monthnum );
     3719                }
     3720                if ( ! empty( $day ) ) {
     3721                        $title .= $t_sep . zeroise( $day, 2 );
     3722                }
     3723        }
     3724
     3725        // If it's a search
     3726        if ( is_search() ) {
     3727                /* translators: 1: separator, 2: search phrase */
     3728                $title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) );
     3729        }
     3730
     3731        // If it's a 404 page
     3732        if ( is_404() ) {
     3733                $title = __( 'Page not found' );
     3734        }
     3735
     3736        $prefix = '';
     3737        if ( ! empty( $title ) ) {
     3738                $prefix = " $sep ";
     3739        }
     3740
     3741        /**
     3742         * Filter the parts of the page title.
     3743         *
     3744         * @since 4.0.0
     3745         *
     3746         * @param array $title_array Parts of the page title.
     3747         */
     3748        $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
     3749
     3750        // Determines position of the separator and direction of the breadcrumb
     3751        if ( 'right' == $seplocation ) { // sep on right, so reverse the order
     3752                $title_array = array_reverse( $title_array );
     3753                $title       = implode( " $sep ", $title_array ) . $prefix;
     3754        } else {
     3755                $title = $prefix . implode( " $sep ", $title_array );
     3756        }
     3757
     3758        /**
     3759         * Filter the text of the page title.
     3760         *
     3761         * @since 2.0.0
     3762         *
     3763         * @param string $title Page title.
     3764         * @param string $sep Title separator.
     3765         * @param string $seplocation Location of the separator (left or right).
     3766         */
     3767        $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
     3768
     3769        // Send it out
     3770        if ( $display ) {
     3771                echo $title;
     3772        } else {
     3773                return $title;
     3774        }
     3775}
  • src/wp-includes/general-template.php

     
    779779 *
    780780 * @ignore
    781781 * @since 4.1.0
     782 * @since 4.4.0 Improved title output replaced `wp_title()`.
    782783 * @access private
    783  *
    784  * @see wp_title()
    785784 */
    786785function _wp_render_title_tag() {
    787786        if ( ! current_theme_supports( 'title-tag' ) ) {
    788787                return;
    789788        }
    790789
    791         // This can only work internally on wp_head.
    792         if ( ! did_action( 'wp_head' ) && ! doing_action( 'wp_head' ) ) {
    793                 return;
     790        /**
     791         * Allows to short-circuit the title generation.
     792         *
     793         * @since 4.4.0
     794         *
     795         * @param string $title The document title. Default: Empty string.
     796         */
     797        $title = apply_filters( 'title_tag_pre', '' );
     798        if ( ! empty( $title ) ) {
     799                echo "<title>$title</title>\n";
    794800        }
    795801
    796         echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
    797 }
     802        global $page, $paged;
    798803
    799 /**
    800  * Display or retrieve page title for all areas of blog.
    801  *
    802  * By default, the page title will display the separator before the page title,
    803  * so that the blog title will be before the page title. This is not good for
    804  * title display, since the blog title shows up on most tabs and not what is
    805  * important, which is the page that the user is looking at.
    806  *
    807  * There are also SEO benefits to having the blog title after or to the 'right'
    808  * or the page title. However, it is mostly common sense to have the blog title
    809  * to the right with most browsers supporting tabs. You can achieve this by
    810  * using the seplocation parameter and setting the value to 'right'. This change
    811  * was introduced around 2.5.0, in case backwards compatibility of themes is
    812  * important.
    813  *
    814  * @since 1.0.0
    815  *
    816  * @global WP_Locale $wp_locale
    817  * @global int       $page
    818  * @global int       $paged
    819  *
    820  * @param string $sep         Optional, default is '&raquo;'. How to separate the various items within the page title.
    821  * @param bool   $display     Optional, default is true. Whether to display or retrieve title.
    822  * @param string $seplocation Optional. Direction to display title, 'right'.
    823  * @return string|void String on retrieve.
    824  */
    825 function wp_title( $sep = '&raquo;', $display = true, $seplocation = '' ) {
    826         global $wp_locale, $page, $paged;
     804        $title = array();
    827805
    828         $m = get_query_var('m');
    829         $year = get_query_var('year');
    830         $monthnum = get_query_var('monthnum');
    831         $day = get_query_var('day');
    832         $search = get_query_var('s');
    833         $title = '';
     806        if ( is_home() && is_front_page() ) {
     807                $title['title']   = get_bloginfo( 'name', 'display' );
     808                $title['tagline'] = get_bloginfo( 'description', 'display' );
    834809
    835         $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
     810                // If we're on the blog page and that page is not the homepage, use the container page's title.
     811        } elseif ( is_home() && ! is_front_page() ) {
     812                $title['title'] = get_post( get_option( 'page_for_posts' ) )->post_title;
    836813
    837         // If there is a post
    838         if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
    839                 $title = single_post_title( '', false );
    840         }
     814                // If it's a single page, that is designated as the homepage.
     815        } elseif ( ! is_home() && is_front_page() ) {
     816                $title['title'] = single_post_title( '', false );
    841817
    842         // If there's a post type archive
    843         if ( is_post_type_archive() ) {
    844                 $post_type = get_query_var( 'post_type' );
    845                 if ( is_array( $post_type ) )
    846                         $post_type = reset( $post_type );
    847                 $post_type_object = get_post_type_object( $post_type );
    848                 if ( ! $post_type_object->has_archive )
    849                         $title = post_type_archive_title( '', false );
    850         }
     818                // If we're on a post / page.
     819        } elseif ( is_singular() ) {
     820                $title['title'] = single_post_title( '', false );
    851821
    852         // If there's a category or tag
    853         if ( is_category() || is_tag() ) {
    854                 $title = single_term_title( '', false );
    855         }
     822                // If we're on a category or tag or taxonomy archive.
     823        } elseif ( is_category() || is_tag() || is_tax() ) {
     824                $title['title'] = single_term_title( '', false );
    856825
    857         // If there's a taxonomy
    858         if ( is_tax() ) {
    859                 $term = get_queried_object();
    860                 if ( $term ) {
    861                         $tax = get_taxonomy( $term->taxonomy );
    862                         $title = single_term_title( $tax->labels->name . $t_sep, false );
     826                // If it's a search.
     827        } elseif ( is_search() ) {
     828                /* translators: 1: search phrase */
     829                $title['title'] = sprintf( __( 'Search Results for &#8220;%1$s&#8221;' ), strip_tags( get_query_var( 's' ) ) );
     830
     831                // If we're on an author archive.
     832        } elseif ( is_author() ) {
     833                if ( $author = get_queried_object() ) {
     834                        $title['title'] = $author->display_name;
    863835                }
    864         }
    865836
    866         // If there's an author
    867         if ( is_author() && ! is_post_type_archive() ) {
    868                 $author = get_queried_object();
    869                 if ( $author )
    870                         $title = $author->display_name;
    871         }
     837                // If we're on a post type archive.
     838        } elseif ( is_post_type_archive() ) {
     839                $title['title'] = post_type_archive_title( '', false );
    872840
    873         // Post type archives with has_archive should override terms.
    874         if ( is_post_type_archive() && $post_type_object->has_archive )
    875                 $title = post_type_archive_title( '', false );
     841        } elseif ( is_year() ) {
     842                $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );
    876843
    877         // If there's a month
    878         if ( is_archive() && !empty($m) ) {
    879                 $my_year = substr($m, 0, 4);
    880                 $my_month = $wp_locale->get_month(substr($m, 4, 2));
    881                 $my_day = intval(substr($m, 6, 2));
    882                 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
    883         }
     844        } elseif ( is_month() ) {
     845                $title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
    884846
    885         // If there's a year
    886         if ( is_archive() && !empty($year) ) {
    887                 $title = $year;
    888                 if ( !empty($monthnum) )
    889                         $title .= $t_sep . $wp_locale->get_month($monthnum);
    890                 if ( !empty($day) )
    891                         $title .= $t_sep . zeroise($day, 2);
    892         }
     847                // If it's a date archive.
     848        } elseif ( is_day() ) {
     849                $title['title'] = get_the_date();
    893850
    894         // If it's a search
    895         if ( is_search() ) {
    896                 /* translators: 1: separator, 2: search phrase */
    897                 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
     851                // If it's a 404 page.
     852        } elseif ( is_404() ) {
     853                $title['title'] = __( 'Page not found' );
    898854        }
    899855
    900         // If it's a 404 page
    901         if ( is_404() ) {
    902                 $title = __('Page not found');
     856        // Add a page number if necessary:
     857        if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
     858                $title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) );
    903859        }
    904860
    905         $prefix = '';
    906         if ( !empty($title) )
    907                 $prefix = " $sep ";
     861        // Append the site title if this is not the home page.
     862        if ( ! is_home() && ! is_front_page() ) {
     863                $title['site'] = get_bloginfo( 'name', 'display' );
     864        }
    908865
    909866        /**
    910          * Filter the parts of the page title.
     867         * Filters the separator for the document title.
    911868         *
    912          * @since 4.0.0
     869         * @since 4.4.0
    913870         *
    914          * @param array $title_array Parts of the page title.
     871         * @param array $title The separator.
    915872         */
    916         $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
    917 
    918         // Determines position of the separator and direction of the breadcrumb
    919         if ( 'right' == $seplocation ) { // sep on right, so reverse the order
    920                 $title_array = array_reverse( $title_array );
    921                 $title = implode( " $sep ", $title_array ) . $prefix;
    922         } else {
    923                 $title = $prefix . implode( " $sep ", $title_array );
    924         }
    925 
    926         if ( current_theme_supports( 'title-tag' ) && ! is_feed() ) {
    927                 $title .= get_bloginfo( 'name', 'display' );
    928 
    929                 $site_description = get_bloginfo( 'description', 'display' );
    930                 if ( $site_description && ( is_home() || is_front_page() ) ) {
    931                         $title .= " $sep $site_description";
    932                 }
    933 
    934                 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
    935                         $title .= " $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) );
    936                 }
    937         }
     873        $sep = apply_filters( 'title_tag_separator', '-' );
    938874
    939875        /**
    940          * Filter the text of the page title.
     876         * Filters the parts of the document title.
    941877         *
    942          * @since 2.0.0
     878         * @since 4.4.0
     879         *
     880         * @param array $title {
     881         *     The document title parts.
    943882         *
    944          * @param string $title       Page title.
    945          * @param string $sep         Title separator.
    946          * @param string $seplocation Location of the separator (left or right).
     883         *     @type string $title   Title of the viewed page.
     884         *     @type string $page    Optional. Page number if paginated.
     885         *     @type string $tagline Optional. Site description when on home page.
     886         *     @type string $site    Optional. Site title when not on home page.
     887         * }
    947888         */
    948         $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
    949 
    950         // Send it out
    951         if ( $display )
    952                 echo $title;
    953         else
    954                 return $title;
     889        $title = apply_filters( 'title_tag_parts', $title );
     890        $title = implode( " $sep ", array_filter( $title ) );
    955891
     892        echo "<title>$title</title>\n";
    956893}
    957894
    958895/**
  • src/wp-includes/theme.php

     
    17521752        if ( !isset( $_wp_theme_features[$feature] ) )
    17531753                return false;
    17541754
    1755         if ( 'title-tag' == $feature ) {
    1756                 // Don't confirm support unless called internally.
    1757                 $trace = debug_backtrace();
    1758                 if ( ! in_array( $trace[1]['function'], array( '_wp_render_title_tag', 'wp_title' ) ) ) {
    1759                         return false;
    1760                 }
    1761         }
    1762 
    17631755        // If no args passed then no extra checks need be performed
    17641756        if ( func_num_args() <= 1 )
    17651757                return true;