Make WordPress Core

Ticket #31078: 31078.diff

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

     
    34923492
    34933493        return false;
    34943494}
     3495
     3496/**
     3497 * Display or retrieve page title for all areas of blog.
     3498 *
     3499 * By default, the page title will display the separator before the page title,
     3500 * so that the blog title will be before the page title. This is not good for
     3501 * title display, since the blog title shows up on most tabs and not what is
     3502 * important, which is the page that the user is looking at.
     3503 *
     3504 * There are also SEO benefits to having the blog title after or to the 'right'
     3505 * or the page title. However, it is mostly common sense to have the blog title
     3506 * to the right with most browsers supporting tabs. You can achieve this by
     3507 * using the seplocation parameter and setting the value to 'right'. This change
     3508 * was introduced around 2.5.0, in case backwards compatibility of themes is
     3509 * important.
     3510 *
     3511 * @since 1.0.0
     3512 * @deprecated 4.2.0
     3513 * @deprecated Use add_theme_support( 'title-tag' );
     3514 *
     3515 * @param string $sep Optional, default is '»'. How to separate the various items within the page title.
     3516 * @param bool $display Optional, default is true. Whether to display or retrieve title.
     3517 * @param string $seplocation Optional. Direction to display title, 'right'.
     3518 * @return string|null String on retrieve, null when displaying.
     3519 */
     3520function wp_title($sep = '»', $display = true, $seplocation = '') {
     3521        _deprecated_function( __FUNCTION__, '4.2', 'add_theme_support( \'title-tag\' )' );
     3522
     3523        global $wp_locale;
     3524
     3525        $m = get_query_var('m');
     3526        $year = get_query_var('year');
     3527        $monthnum = get_query_var('monthnum');
     3528        $day = get_query_var('day');
     3529        $search = get_query_var('s');
     3530        $title = '';
     3531
     3532        $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
     3533
     3534        // If there is a post
     3535        if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
     3536                $title = single_post_title( '', false );
     3537        }
     3538
     3539        // If there's a post type archive
     3540        if ( is_post_type_archive() ) {
     3541                $post_type = get_query_var( 'post_type' );
     3542                if ( is_array( $post_type ) )
     3543                        $post_type = reset( $post_type );
     3544                $post_type_object = get_post_type_object( $post_type );
     3545                if ( ! $post_type_object->has_archive )
     3546                        $title = post_type_archive_title( '', false );
     3547        }
     3548
     3549        // If there's a category or tag
     3550        if ( is_category() || is_tag() ) {
     3551                $title = single_term_title( '', false );
     3552        }
     3553
     3554        // If there's a taxonomy
     3555        if ( is_tax() ) {
     3556                $term = get_queried_object();
     3557                if ( $term ) {
     3558                        $tax = get_taxonomy( $term->taxonomy );
     3559                        $title = single_term_title( $tax->labels->name . $t_sep, false );
     3560                }
     3561        }
     3562
     3563        // If there's an author
     3564        if ( is_author() && ! is_post_type_archive() ) {
     3565                $author = get_queried_object();
     3566                if ( $author )
     3567                        $title = $author->display_name;
     3568        }
     3569
     3570        // Post type archives with has_archive should override terms.
     3571        if ( is_post_type_archive() && $post_type_object->has_archive )
     3572                $title = post_type_archive_title( '', false );
     3573
     3574        // If there's a month
     3575        if ( is_archive() && !empty($m) ) {
     3576                $my_year = substr($m, 0, 4);
     3577                $my_month = $wp_locale->get_month(substr($m, 4, 2));
     3578                $my_day = intval(substr($m, 6, 2));
     3579                $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
     3580        }
     3581
     3582        // If there's a year
     3583        if ( is_archive() && !empty($year) ) {
     3584                $title = $year;
     3585                if ( !empty($monthnum) )
     3586                        $title .= $t_sep . $wp_locale->get_month($monthnum);
     3587                if ( !empty($day) )
     3588                        $title .= $t_sep . zeroise($day, 2);
     3589        }
     3590
     3591        // If it's a search
     3592        if ( is_search() ) {
     3593                /* translators: 1: separator, 2: search phrase */
     3594                $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
     3595        }
     3596
     3597        // If it's a 404 page
     3598        if ( is_404() ) {
     3599                $title = __('Page not found');
     3600        }
     3601
     3602        $prefix = '';
     3603        if ( !empty($title) )
     3604                $prefix = " $sep ";
     3605
     3606        /**
     3607         * Filter the parts of the page title.
     3608         *
     3609         * @since 4.0.0
     3610         *
     3611         * @param array $title_array Parts of the page title.
     3612         */
     3613        $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
     3614
     3615        // Determines position of the separator and direction of the breadcrumb
     3616        if ( 'right' == $seplocation ) { // sep on right, so reverse the order
     3617                $title_array = array_reverse( $title_array );
     3618                $title = implode( " $sep ", $title_array ) . $prefix;
     3619        } else {
     3620                $title = $prefix . implode( " $sep ", $title_array );
     3621        }
     3622
     3623        /**
     3624         * Filter the text of the page title.
     3625         *
     3626         * @since 2.0.0
     3627         *
     3628         * @param string $title       Page title.
     3629         * @param string $sep         Title separator.
     3630         * @param string $seplocation Location of the separator (left or right).
     3631         */
     3632        $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
     3633
     3634        // Send it out
     3635        if ( $display )
     3636                echo $title;
     3637        else
     3638                return $title;
     3639}
  • src/wp-includes/general-template.php

     
    734734                return;
    735735        }
    736736
    737         echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
    738 }
     737        // If wp_title() has fired, don't do anything.
     738        if ( did_action( 'wp_title' ) ) {
     739                return;
     740        }
    739741
    740 /**
    741  * Display or retrieve page title for all areas of blog.
    742  *
    743  * By default, the page title will display the separator before the page title,
    744  * so that the blog title will be before the page title. This is not good for
    745  * title display, since the blog title shows up on most tabs and not what is
    746  * important, which is the page that the user is looking at.
    747  *
    748  * There are also SEO benefits to having the blog title after or to the 'right'
    749  * or the page title. However, it is mostly common sense to have the blog title
    750  * to the right with most browsers supporting tabs. You can achieve this by
    751  * using the seplocation parameter and setting the value to 'right'. This change
    752  * was introduced around 2.5.0, in case backwards compatibility of themes is
    753  * important.
    754  *
    755  * @since 1.0.0
    756  *
    757  * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
    758  * @param bool $display Optional, default is true. Whether to display or retrieve title.
    759  * @param string $seplocation Optional. Direction to display title, 'right'.
    760  * @return string|null String on retrieve, null when displaying.
    761  */
    762 function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
    763         global $wp_locale, $page, $paged;
     742        global $page, $paged;
    764743
    765         $m = get_query_var('m');
    766         $year = get_query_var('year');
    767         $monthnum = get_query_var('monthnum');
    768         $day = get_query_var('day');
    769         $search = get_query_var('s');
    770         $title = '';
     744        $title = array();
    771745
    772         $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
     746        if ( is_home() && is_front_page() ) {
     747                $title['page'] = get_bloginfo( 'name', 'display' );
    773748
    774         // If there is a post
    775         if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
    776                 $title = single_post_title( '', false );
    777         }
    778 
    779         // If there's a post type archive
    780         if ( is_post_type_archive() ) {
    781                 $post_type = get_query_var( 'post_type' );
    782                 if ( is_array( $post_type ) )
    783                         $post_type = reset( $post_type );
    784                 $post_type_object = get_post_type_object( $post_type );
    785                 if ( ! $post_type_object->has_archive )
    786                         $title = post_type_archive_title( '', false );
    787         }
     749                $description = get_bloginfo( 'description', 'display' );
     750                if ( ! empty( $description ) ) {
     751                        $title['site'] = $description;
     752                }
    788753
    789         // If there's a category or tag
    790         if ( is_category() || is_tag() ) {
    791                 $title = single_term_title( '', false );
    792         }
     754                // If we're on the blog page and that page is not the homepage, use the container page's title.
     755        } elseif ( is_home() && ! is_front_page() ) {
     756                $title['page'] = get_post( get_option( 'page_for_posts' ) )->post_title;
    793757
    794         // If there's a taxonomy
    795         if ( is_tax() ) {
    796                 $term = get_queried_object();
    797                 if ( $term ) {
    798                         $tax = get_taxonomy( $term->taxonomy );
    799                         $title = single_term_title( $tax->labels->name . $t_sep, false );
    800                 }
    801         }
     758                // If it's a single page, that is designated as the homepage.
     759        } elseif ( ! is_home() && is_front_page() ) {
     760                $title['page'] = single_post_title( '', false );
    802761
    803         // If there's an author
    804         if ( is_author() && ! is_post_type_archive() ) {
    805                 $author = get_queried_object();
    806                 if ( $author )
    807                         $title = $author->display_name;
    808         }
     762                // If we're on a post / page.
     763        } elseif ( is_singular() ) {
     764                $title['page'] = single_post_title( '', false );
    809765
    810         // Post type archives with has_archive should override terms.
    811         if ( is_post_type_archive() && $post_type_object->has_archive )
    812                 $title = post_type_archive_title( '', false );
     766                // If we're on a category or tag or taxonomy archive.
     767        } elseif ( is_category() || is_tag() || is_tax() ) {
     768                $title['page'] = single_term_title( '', false );
    813769
    814         // If there's a month
    815         if ( is_archive() && !empty($m) ) {
    816                 $my_year = substr($m, 0, 4);
    817                 $my_month = $wp_locale->get_month(substr($m, 4, 2));
    818                 $my_day = intval(substr($m, 6, 2));
    819                 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
    820         }
     770                // If it's a search.
     771        } elseif ( is_search() ) {
     772                /* translators: 1: search phrase */
     773                $title['page'] = sprintf( esc_html__( 'Search Results for "%1$s"' ), strip_tags( get_query_var( 's' ) ) );
    821774
    822         // If there's a year
    823         if ( is_archive() && !empty($year) ) {
    824                 $title = $year;
    825                 if ( !empty($monthnum) )
    826                         $title .= $t_sep . $wp_locale->get_month($monthnum);
    827                 if ( !empty($day) )
    828                         $title .= $t_sep . zeroise($day, 2);
    829         }
     775                // If we're on an author archive.
     776        } elseif ( is_author() ) {
     777                var_dump(get_queried_object());exit;
     778                if ( $author = get_queried_object() ) {
     779                        $title['page'] = $author->display_name;
     780                }
    830781
    831         // If it's a search
    832         if ( is_search() ) {
    833                 /* translators: 1: separator, 2: search phrase */
    834                 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
    835         }
     782                // If we're on a post type archive.
     783        } elseif ( is_post_type_archive() ) {
     784                $title['page'] = post_type_archive_title( '', false );
    836785
    837         // If it's a 404 page
    838         if ( is_404() ) {
    839                 $title = __('Page not found');
    840         }
     786        } elseif ( is_year() ) {
     787                $title['page'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );
    841788
    842         $prefix = '';
    843         if ( !empty($title) )
    844                 $prefix = " $sep ";
     789        } elseif ( is_month() ) {
     790                $title['page'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
    845791
    846         /**
    847          * Filter the parts of the page title.
    848          *
    849          * @since 4.0.0
    850          *
    851          * @param array $title_array Parts of the page title.
    852          */
    853         $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
     792                // If it's a date archive.
     793        } elseif ( is_day() ) {
     794                $title['page'] = get_the_date();
    854795
    855         // Determines position of the separator and direction of the breadcrumb
    856         if ( 'right' == $seplocation ) { // sep on right, so reverse the order
    857                 $title_array = array_reverse( $title_array );
    858                 $title = implode( " $sep ", $title_array ) . $prefix;
    859         } else {
    860                 $title = $prefix . implode( " $sep ", $title_array );
     796                // If it's a 404 page.
     797        } elseif ( is_404() ) {
     798                $title['page'] = esc_html__( 'Page not found' );
    861799        }
    862800
    863         if ( current_theme_supports( 'title-tag' ) && ! is_feed() ) {
    864                 $title .= get_bloginfo( 'name', 'display' );
    865 
    866                 $site_description = get_bloginfo( 'description', 'display' );
    867                 if ( $site_description && ( is_home() || is_front_page() ) ) {
    868                         $title .= " $sep $site_description";
    869                 }
     801        // Add a page number if necessary:
     802        if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
     803                $title['number'] = sprintf( esc_html__( 'Page %s' ), max( $paged, $page ) );
     804        }
    870805
    871                 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
    872                         $title .= " $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) );
    873                 }
     806        if ( ! is_home() && ! is_front_page() ) {
     807                $title['site'] = get_bloginfo( 'name', 'display' );
    874808        }
    875809
    876         /**
    877          * Filter the text of the page title.
    878          *
    879          * @since 2.0.0
    880          *
    881          * @param string $title       Page title.
    882          * @param string $sep         Title separator.
    883          * @param string $seplocation Location of the separator (left or right).
    884          */
    885         $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
     810        // Separator, defaults to '|' as the separator between two parts of the title.
     811        $sep = '|';
    886812
    887         // Send it out
    888         if ( $display )
    889                 echo $title;
    890         else
    891                 return $title;
     813        if ( is_rtl() ) {
     814                $title = array_reverse( $title );
     815        }
     816        $title = implode( " $sep ", $title );
    892817
     818        echo "<title>$title</title>\n";
    893819}
    894820
    895821/**