Make WordPress Core

Ticket #31078: 31078.3.diff

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

     
    36363636        return apply_filters( 'htmledit_pre', $output );
    36373637}
    36383638
     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/general-template.php

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

     
    17421742        if ( !isset( $_wp_theme_features[$feature] ) )
    17431743                return false;
    17441744
    1745         if ( 'title-tag' == $feature ) {
    1746                 // Don't confirm support unless called internally.
    1747                 $trace = debug_backtrace();
    1748                 if ( ! in_array( $trace[1]['function'], array( '_wp_render_title_tag', 'wp_title' ) ) ) {
    1749                         return false;
    1750                 }
    1751         }
    1752 
    17531745        // If no args passed then no extra checks need be performed
    17541746        if ( func_num_args() <= 1 )
    17551747                return true;