Make WordPress Core

Ticket #31078: 31078.9.diff

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

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

     
    3333                elseif ( is_search() )
    3434                        printf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() );
    3535                else
    36                         printf( ent2ncr( __( 'Comments for %s' ) ), get_bloginfo_rss( 'name' ) . get_wp_title_rss() );
     36                        printf( ent2ncr( __( 'Comments for %s' ) ), get_wp_title_rss() );
    3737        ?></title>
    3838        <subtitle type="text"><?php bloginfo_rss('description'); ?></subtitle>
    3939
  • src/wp-includes/feed-atom.php

     
    2727  do_action( 'atom_ns' );
    2828  ?>
    2929 >
    30         <title type="text"><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
     30        <title type="text"><?php wp_title_rss(); ?></title>
    3131        <subtitle type="text"><?php bloginfo_rss("description") ?></subtitle>
    3232
    3333        <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></updated>
  • src/wp-includes/feed-rdf.php

     
    3030        ?>
    3131>
    3232<channel rdf:about="<?php bloginfo_rss("url") ?>">
    33         <title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
     33        <title><?php wp_title_rss(); ?></title>
    3434        <link><?php bloginfo_rss('url') ?></link>
    3535        <description><?php bloginfo_rss('description') ?></description>
    3636        <dc:date><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></dc:date>
  • src/wp-includes/feed-rss.php

     
    1111echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
    1212<rss version="0.92">
    1313<channel>
    14         <title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
     14        <title><?php wp_title_rss(); ?></title>
    1515        <link><?php bloginfo_rss('url') ?></link>
    1616        <description><?php bloginfo_rss('description') ?></description>
    1717        <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
  • src/wp-includes/feed-rss2-comments.php

     
    3838                elseif ( is_search() )
    3939                        printf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() );
    4040                else
    41                         printf( ent2ncr( __( 'Comments for %s' ) ), get_bloginfo_rss( 'name' ) . get_wp_title_rss() );
     41                        printf( ent2ncr( __( 'Comments for %s' ) ), get_wp_title_rss() );
    4242        ?></title>
    4343        <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    4444        <link><?php (is_single()) ? the_permalink_rss() : bloginfo_rss("url") ?></link>
  • src/wp-includes/feed-rss2.php

     
    3838>
    3939
    4040<channel>
    41         <title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
     41        <title><?php wp_title_rss(); ?></title>
    4242        <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    4343        <link><?php bloginfo_rss('url') ?></link>
    4444        <description><?php bloginfo_rss("description") ?></description>
  • src/wp-includes/feed.php

     
    9191 * Retrieve the blog title for the feed title.
    9292 *
    9393 * @since 2.2.0
     94 * @since 4.4.0 Deprecated argument.
    9495 *
    95  * @param string $sep Optional. How to separate the title. See wp_title() for more info.
    96  * @return string Error message on failure or blog title on success.
     96 * @param string $deprecated Deprecated.
     97 * @return string The document title.
    9798 */
    98 function get_wp_title_rss( $sep = '&#187;' ) {
    99         $title = wp_title( $sep, false );
    100 
    101         if ( is_wp_error( $title ) ) {
    102                 return $title->get_error_message();
    103         }
    104 
    105         if ( $title && $sep && ' ' !== substr( $title, 0, 1 ) ) {
    106                 $title = " $sep " . $title;
     99function get_wp_title_rss( $deprecated = '&#8211;' ) {
     100        if ( '&#8211;' !== $deprecated ) {
     101                _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) );
    107102        }
    108103
    109104        /**
    110105         * Filter the blog title for use as the feed title.
    111106         *
    112107         * @since 2.2.0
     108         * @since 4.4.0 Deprecated argument.
    113109         *
    114          * @param string $title The current blog title.
    115          * @param string $sep   Separator used by wp_title().
     110         * @param string $title      The current blog title.
     111         * @param string $deprecated Deprecated.
    116112         */
    117         $title = apply_filters( 'get_wp_title_rss', $title, $sep );
    118         return $title;
     113        return apply_filters( 'get_wp_title_rss', wp_get_document_title(), $deprecated );
    119114}
    120115
    121116/**
    122117 * Display the blog title for display of the feed title.
    123118 *
    124119 * @since 2.2.0
    125  * @see wp_title() $sep parameter usage.
     120 * @since 4.4.0 Deprecated argument.
    126121 *
    127  * @param string $sep Optional.
     122 * @param string $deprecated Optional.
    128123 */
    129 function wp_title_rss( $sep = '&#187;' ) {
     124function wp_title_rss( $deprecated = '&#8211;' ) {
     125        if ( '&#8211;' !== $deprecated ) {
     126                _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) );
     127        }
     128
    130129        /**
    131130         * Filter the blog title for display of the feed title.
    132131         *
    133132         * @since 2.2.0
     133         * @since 4.4.0 Deprecated argument.
    134134         *
    135135         * @see get_wp_title_rss()
    136136         *
    137          * @param string $wp_title The current blog title.
    138          * @param string $sep      Separator used by wp_title().
     137         * @param string $wp_title_rss The current blog title.
     138         * @param string $deprecated   Deprecated.
    139139         */
    140         echo apply_filters( 'wp_title_rss', get_wp_title_rss( $sep ), $sep );
     140        echo apply_filters( 'wp_title_rss', get_wp_title_rss(), $deprecated );
    141141}
    142142
    143143/**
  • src/wp-includes/general-template.php

     
    775775}
    776776
    777777/**
    778  * Display title tag with contents.
     778 * Returns document title for the current page.
    779779 *
    780  * @ignore
    781  * @since 4.1.0
    782  * @access private
     780 * @since 4.4.0
    783781 *
    784  * @see wp_title()
     782 * @global int $page  Page number of a single post.
     783 * @global int $paged Page number of a list of posts.
     784 *
     785 * @return string Tag with the document title.
    785786 */
    786 function _wp_render_title_tag() {
    787         if ( ! current_theme_supports( 'title-tag' ) ) {
    788                 return;
    789         }
     787function wp_get_document_title() {
    790788
    791         // This can only work internally on wp_head.
    792         if ( ! did_action( 'wp_head' ) && ! doing_action( 'wp_head' ) ) {
    793                 return;
     789        /**
     790         * Allows to short-circuit the title generation.
     791         *
     792         * @since 4.4.0
     793         *
     794         * @param string $title The document title. Default empty string.
     795         */
     796        $title = apply_filters( 'pre_get_document_title', '' );
     797        if ( ! empty( $title ) ) {
     798                return $title;
    794799        }
    795800
    796         echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
    797 }
     801        global $page, $paged;
    798802
    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;
     803        $title = array(
     804                'title' => '',
     805        );
    827806
    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 = '';
     807        if ( is_home() && is_front_page() ) {
     808                $title['title'] = get_bloginfo( 'name', 'display' );
    834809
    835         $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
     810                /*
     811                 * If we're on the blog page and that page is not the homepage or a single page that is designated as
     812                 * the homepage, use the container page's title.
     813                 */
     814        } elseif ( ( is_home() && ! is_front_page() ) || ( ! is_home() && is_front_page() ) ) {
     815                $title['title'] = single_post_title( '', false );
    836816
    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         }
     817                // If we're on a post / page.
     818        } elseif ( is_singular() ) {
     819                $title['title'] = single_post_title( '', false );
     820
     821                // If we're on a category or tag or taxonomy archive.
     822        } elseif ( is_category() || is_tag() || is_tax() ) {
     823                $title['title'] = single_term_title( '', false );
    841824
    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         }
     825                // If it's a search.
     826        } elseif ( is_search() ) {
     827                /* translators: %s: search phrase */
     828                $title['title'] = sprintf( __( 'Search Results for &#8220;%s&#8221;' ), get_search_query() );
    851829
    852         // If there's a category or tag
    853         if ( is_category() || is_tag() ) {
    854                 $title = single_term_title( '', false );
    855         }
     830                // If we're on an author archive.
     831        } elseif ( is_author() && $author = get_queried_object() ) {
     832                $title['title'] = $author->display_name;
    856833
    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 );
    863                 }
    864         }
     834                // If we're on a post type archive.
     835        } elseif ( is_post_type_archive() ) {
     836                $title['title'] = post_type_archive_title( '', false );
    865837
    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         }
     838                // If it's a date archive.
     839        } elseif ( is_year() ) {
     840                $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );
    872841
    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 );
     842        } elseif ( is_month() ) {
     843                $title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
    876844
    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         }
     845        } elseif ( is_day() ) {
     846                $title['title'] = get_the_date();
    884847
    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);
     848                // If it's a 404 page.
     849        } elseif ( is_404() ) {
     850                $title['title'] = __( 'Page not found' );
    892851        }
    893852
    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));
     853        // Add a page number if necessary.
     854        if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
     855                $title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) );
    898856        }
    899857
    900         // If it's a 404 page
    901         if ( is_404() ) {
    902                 $title = __('Page not found');
     858        // Append the description or site title to give context.
     859        if ( is_home() && is_front_page() ) {
     860                $title['tagline'] = get_bloginfo( 'description', 'display' );
     861        } else {
     862                $title['site'] = get_bloginfo( 'name', 'display' );
    903863        }
    904864
    905         $prefix = '';
    906         if ( !empty($title) )
    907                 $prefix = " $sep ";
    908 
    909865        /**
    910          * Filter the parts of the page title.
     866         * Filters the separator for the document title.
    911867         *
    912          * @since 4.0.0
     868         * @since 4.4.0
    913869         *
    914          * @param array $title_array Parts of the page title.
     870         * @param string $sep The separator. Default '-'.
    915871         */
    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         }
     872        $sep = apply_filters( 'document_title_separator', '-' );
    938873
    939874        /**
    940          * Filter the text of the page title.
     875         * Filters the parts of the document title.
    941876         *
    942          * @since 2.0.0
     877         * @since 4.4.0
    943878         *
    944          * @param string $title       Page title.
    945          * @param string $sep         Title separator.
    946          * @param string $seplocation Location of the separator (left or right).
    947          */
    948         $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
     879         * @param array $title {
     880         *     The document title parts.
     881         *
     882         *     @type string $title   Title of the viewed page.
     883         *     @type string $page    Optional. Page number if paginated.
     884         *     @type string $tagline Optional. Site description when on home page.
     885         *     @type string $site    Optional. Site title when not on home page.
     886         * }
     887         */
     888        $title = apply_filters( 'document_title_parts', $title );
     889
     890        $title = implode( " $sep ", array_filter( $title ) );
     891        $title = wptexturize( $title );
     892        $title = convert_chars( $title );
     893        $title = esc_html( $title );
     894        $title = capital_P_dangit( $title );
    949895
    950         // Send it out
    951         if ( $display )
    952                 echo $title;
    953         else
    954                 return $title;
     896        return $title;
     897}
     898
     899/**
     900 * Display title tag with contents.
     901 *
     902 * @ignore
     903 * @since 4.1.0
     904 * @since 4.4.0 Improved title output replaced `wp_title()`.
     905 * @access private
     906 */
     907function _wp_render_title_tag() {
     908        if ( ! current_theme_supports( 'title-tag' ) ) {
     909                return;
     910        }
    955911
     912        echo '<title>' . wp_get_document_title() . '</title>' . "\n";
    956913}
    957914
    958915/**
     
    1033990/**
    1034991 * Display or retrieve page title for category archive.
    1035992 *
    1036  * This is useful for category template file or files, because it is optimized
    1037  * for category page title and with less overhead than {@link wp_title()}.
    1038  *
    1039  * It does not support placing the separator after the title, but by leaving the
    1040  * prefix parameter empty, you can set the title separator manually. The prefix
    1041  * does not automatically place a space between the prefix, so if there should
    1042  * be a space, the parameter value will need to have it at the end.
     993 * Useful for category template files for displaying the category page title.
     994 * The prefix does not automatically place a space between the prefix, so if
     995 * there should be a space, the parameter value will need to have it at the end.
    1043996 *
    1044997 * @since 0.71
    1045998 *
     
    10541007/**
    10551008 * Display or retrieve page title for tag post archive.
    10561009 *
    1057  * Useful for tag template files for displaying the tag page title. It has less
    1058  * overhead than {@link wp_title()}, because of its limited implementation.
    1059  *
    1060  * It does not support placing the separator after the title, but by leaving the
    1061  * prefix parameter empty, you can set the title separator manually. The prefix
     1010 * Useful for tag template files for displaying the tag page title. The prefix
    10621011 * does not automatically place a space between the prefix, so if there should
    10631012 * be a space, the parameter value will need to have it at the end.
    10641013 *
     
    10761025 * Display or retrieve page title for taxonomy term archive.
    10771026 *
    10781027 * Useful for taxonomy term template files for displaying the taxonomy term page title.
    1079  * It has less overhead than {@link wp_title()}, because of its limited implementation.
    1080  *
    1081  * It does not support placing the separator after the title, but by leaving the
    1082  * prefix parameter empty, you can set the title separator manually. The prefix
    1083  * does not automatically place a space between the prefix, so if there should
     1028 * The prefix does not automatically place a space between the prefix, so if there should
    10841029 * be a space, the parameter value will need to have it at the end.
    10851030 *
    10861031 * @since 3.1.0
     
    11381083/**
    11391084 * Display or retrieve page title for post archive based on date.
    11401085 *
    1141  * Useful for when the template only needs to display the month and year, if
    1142  * either are available. Optimized for just this purpose, so if it is all that
    1143  * is needed, should be better than {@link wp_title()}.
    1144  *
    1145  * It does not support placing the separator after the title, but by leaving the
    1146  * prefix parameter empty, you can set the title separator manually. The prefix
    1147  * does not automatically place a space between the prefix, so if there should
    1148  * be a space, the parameter value will need to have it at the end.
     1086 * Useful for when the template only needs to display the month and year,
     1087 * if either are available. The prefix does not automatically place a space
     1088 * between the prefix, so if there should be a space, the parameter value
     1089 * will need to have it at the end.
    11491090 *
    11501091 * @since 0.71
    11511092 *
  • src/wp-includes/theme-compat/header.php

     
    1515<link rel="profile" href="http://gmpg.org/xfn/11" />
    1616<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    1717
    18 <title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
     18<title><?php echo wp_get_document_title(); ?></title>
    1919
    2020<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    2121<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
  • 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;
  • tests/phpunit/tests/general/document-title.php

     
     1<?php
     2
     3/**
     4 * A set of unit tests for functions in wp-includes/general-template.php
     5 *
     6 * @group template
     7 * @group document-title
     8 */
     9class Tests_Document_Title extends WP_UnitTestCase {
     10
     11        function setUp() {
     12                parent::setUp();
     13
     14                add_action( 'after_setup_theme', array( $this, '_add_title_tag_support' ) );
     15
     16                $this->category_id = $this->factory->category->create( array(
     17                        'name' => 'test_category',
     18                ) );
     19
     20                $this->author_id = $this->factory->user->create( array(
     21                        'role'        => 'author',
     22                        'user_login'  => 'test_author',
     23                        'description' => 'test_author',
     24                ) );
     25
     26                $this->post_id = $this->factory->post->create( array(
     27                        'post_author'  => $this->author_id,
     28                        'post_status'  => 'publish',
     29                        'post_content' => rand_str(),
     30                        'post_title'   => 'test_title',
     31                        'post_type'    => 'post',
     32                        'post_date'    => '2015-09-22 18:52:17',
     33                        'category'     => $this->category_id,
     34                ) );
     35
     36                setup_postdata( get_post( $this->post_id ) );
     37        }
     38
     39        function tearDown() {
     40                wp_reset_postdata();
     41                parent::tearDown();
     42        }
     43
     44        function _add_title_tag_support() {
     45                add_theme_support( 'title-tag' );
     46        }
     47
     48        function test_short_circuiting_title() {
     49                $this->go_to( '/' );
     50
     51                add_filter( 'title_tag_pre', array( $this, '_short_circuit_title' ) );
     52
     53                $this->expectOutputString( "<title>A Wild Title</title>\n" );
     54                _wp_render_title_tag();
     55        }
     56
     57        function _short_circuit_title( $title ) {
     58                return 'A Wild Title';
     59        }
     60
     61        function test_front_page_title() {
     62                update_option( 'show_on_front', 'page' );
     63                update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
     64                update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
     65
     66                $this->go_to( '/' );
     67
     68                $this->expectOutputString( "<title>front-page &#8211; Test Blog</title>\n" );
     69                _wp_render_title_tag();
     70
     71                update_option( 'show_on_front', 'posts' );
     72        }
     73
     74        function test_home_title() {
     75                $this->go_to( '/' );
     76
     77                add_filter( 'title_tag_parts', array( $this, '_home_title_parts' ) );
     78
     79                $this->expectOutputString( "<title>Test Blog &#8211; Just another WordPress site</title>\n" );
     80                _wp_render_title_tag();
     81        }
     82
     83        function _home_title_parts( $parts ) {
     84                $this->assertArrayHasKey( 'title', $parts );
     85                $this->assertArrayHasKey( 'tagline', $parts );
     86                $this->assertArrayNotHasKey( 'site', $parts );
     87
     88                return $parts;
     89        }
     90
     91        function test_paged_title() {
     92                $this->go_to( '?page=4' );
     93
     94                add_filter( 'title_tag_parts', array( $this, '_paged_title_parts' ) );
     95
     96                $this->expectOutputString( "<title>Test Blog &#8211; Page 4 &#8211; Just another WordPress site</title>\n" );
     97                _wp_render_title_tag();
     98        }
     99
     100        function _paged_title_parts( $parts ) {
     101                $this->assertArrayHasKey( 'page', $parts );
     102                $this->assertArrayHasKey( 'title', $parts );
     103                $this->assertArrayHasKey( 'tagline', $parts );
     104                $this->assertArrayNotHasKey( 'site', $parts );
     105
     106                return $parts;
     107        }
     108
     109        function test_singular_title() {
     110                $this->go_to( '?p=' . $this->post_id );
     111
     112                add_filter( 'title_tag_parts', array( $this, '_singular_title_parts' ) );
     113
     114                $this->expectOutputString( "<title>test_title &#8211; Test Blog</title>\n" );
     115                _wp_render_title_tag();
     116        }
     117
     118        function _singular_title_parts( $parts ) {
     119                $this->assertArrayHasKey( 'site', $parts );
     120                $this->assertArrayHasKey( 'title', $parts );
     121                $this->assertArrayNotHasKey( 'tagline', $parts );
     122
     123                return $parts;
     124        }
     125
     126        function test_category_title() {
     127                $this->go_to( '?cat=' . $this->category_id );
     128
     129                $this->expectOutputString( "<title>test_category &#8211; Test Blog</title>\n" );
     130                _wp_render_title_tag();
     131        }
     132
     133        function test_search_title() {
     134                $this->go_to( '?s=test_title' );
     135
     136                $this->expectOutputString( "<title>Search Results for &#8220;test_title&#8221; &#8211; Test Blog</title>\n" );
     137                _wp_render_title_tag();
     138        }
     139
     140        function test_author_title() {
     141                $this->go_to( '?author=' . $this->author_id );
     142
     143                $this->expectOutputString( "<title>test_author &#8211; Test Blog</title>\n" );
     144                _wp_render_title_tag();
     145        }
     146
     147        function test_post_type_archive_title() {
     148                register_post_type( 'cpt', array(
     149                        'public'      => true,
     150                        'has_archive' => true,
     151                        'labels'      => array(
     152                                'name' => 'test_cpt',
     153                        ),
     154                ) );
     155
     156                $this->factory->post->create( array(
     157                        'post_type' => 'cpt',
     158                ) );
     159
     160                $this->go_to( '?post_type=cpt' );
     161
     162                $this->expectOutputString( "<title>test_cpt &#8211; Test Blog</title>\n" );
     163                _wp_render_title_tag();
     164        }
     165
     166        function test_year_title() {
     167                $this->go_to( '?year=2015' );
     168
     169                $this->expectOutputString( "<title>2015 &#8211; Test Blog</title>\n" );
     170                _wp_render_title_tag();
     171        }
     172
     173        function test_month_title() {
     174                $this->go_to( '?monthnum=09' );
     175
     176                $this->expectOutputString( "<title>September 2015 &#8211; Test Blog</title>\n" );
     177                _wp_render_title_tag();
     178        }
     179
     180        function test_day_title() {
     181                $this->go_to( '?day=22' );
     182
     183                $this->expectOutputString( "<title>September 22, 2015 &#8211; Test Blog</title>\n" );
     184                _wp_render_title_tag();
     185        }
     186
     187        function test_404_title() {
     188                $this->go_to( '?m=404' );
     189
     190                $this->expectOutputString( "<title>Page not found &#8211; Test Blog</title>\n" );
     191                _wp_render_title_tag();
     192        }
     193
     194        function test_paged_post_title() {
     195                $this->go_to( '?paged=4&p=' . $this->post_id );
     196
     197                add_filter( 'title_tag_parts', array( $this, '_paged_post_title_parts' ) );
     198
     199                $this->expectOutputString( "<title>test_title &#8211; Page 4 &#8211; Test Blog</title>\n" );
     200                _wp_render_title_tag();
     201        }
     202
     203        function _paged_post_title_parts( $parts ) {
     204                $this->assertArrayHasKey( 'page', $parts );
     205                $this->assertArrayHasKey( 'site', $parts );
     206                $this->assertArrayHasKey( 'title', $parts );
     207                $this->assertArrayNotHasKey( 'tagline', $parts );
     208
     209                return $parts;
     210        }
     211
     212        function test_rearrange_title_parts() {
     213                $this->go_to( '?p=' . $this->post_id );
     214
     215                add_filter( 'title_tag_parts', array( $this, '_rearrange_title_parts' ) );
     216
     217                $this->expectOutputString( "<title>Test Blog &#8211; test_title</title>\n" );
     218                _wp_render_title_tag();
     219        }
     220
     221        function _rearrange_title_parts( $parts ) {
     222                $parts = array(
     223                        $parts['site'],
     224                        $parts['title'],
     225                );
     226
     227                return $parts;
     228        }
     229
     230        function test_change_title_separator() {
     231                $this->go_to( '?p=' . $this->post_id );
     232
     233                add_filter( 'title_tag_separator', array( $this, '_change_title_separator' ) );
     234
     235                $this->expectOutputString( "<title>test_title %% Test Blog</title>\n" );
     236                _wp_render_title_tag();
     237        }
     238
     239        function _change_title_separator( $sep ) {
     240                return '%%';
     241        }
     242}