Skip to:
Content

BuddyPress.org

Changeset 4536


Ignore:
Timestamp:
06/19/2011 05:29:51 PM (13 years ago)
Author:
djpaul
Message:

Rework page <title> generation to use WP's wp_title(). Fixes #2598

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-filters.php

    r4325 r4536  
    252252    add_filter( 'wpmu_signup_user_notification', 'bp_core_activation_signup_user_notification', 1, 4 );
    253253
     254/**
     255 * Filter the page title for BuddyPress pages
     256 *
     257 * @global object $bp BuddyPress global settings
     258 * @global unknown $post
     259 * @global WP_Query $wp_query WordPress query object
     260 * @param string $title Original page title
     261 * @param string $sep How to separate the various items within the page title.
     262 * @param string $seplocation Direction to display title
     263 * @return string new page title
     264 * @see wp_title()
     265 * @since 1.3
     266 */
     267function bp_modify_page_title( $title, $sep, $seplocation ) {
     268    global $bp, $post, $wp_query;
     269
     270    if ( bp_is_blog_page() )
     271        return $title;
     272
     273    $title = '';
     274
     275    // Displayed user
     276    if ( !empty( $bp->displayed_user->fullname ) && !is_404() ) {
     277        // translators: "displayed user's name | canonicalised component name"
     278        $title = strip_tags( sprintf( __( '%1$s | %2$s', 'buddypress' ), bp_get_displayed_user_fullname(), ucwords( bp_current_component() ) ) );
     279
     280    // A single group
     281    } elseif ( bp_is_active( 'groups' ) && !empty( $bp->groups->current_group ) && !empty( $bp->bp_options_nav[$bp->groups->current_group->slug] ) ) {
     282        $subnav = isset( $bp->bp_options_nav[$bp->groups->current_group->slug][$bp->current_action]['name'] ) ? $bp->bp_options_nav[$bp->groups->current_group->slug][$bp->current_action]['name'] : '';
     283        // translators: "group name | group nav section name"
     284        $title = sprintf( __( '%1$s | %2$s', 'buddypress' ), $bp->bp_options_title, $subnav );
     285
     286    // A single item from a component other than groups
     287    } elseif ( bp_is_single_item() ) {
     288        // translators: "root component name | component item name | component nav section name"
     289        $title = sprintf( __( '%1$s | %2$s | %3$s', 'buddypress' ), bp_get_name_from_root_slug(), $bp->bp_options_title, $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'] );
     290
     291    // An index or directory
     292    } elseif ( bp_is_directory() ) {
     293        if ( !bp_current_component() )
     294            $title = sprintf( __( '%s Directory', 'buddypress' ), bp_get_name_from_root_slug( $bp->members->slug ) );
     295        else
     296            $title = sprintf( __( '%s Directory', 'buddypress' ), bp_get_name_from_root_slug() );
     297
     298    // Sign up page
     299    } elseif ( bp_is_register_page() ) {
     300        $title = __( 'Create an Account', 'buddypress' );
     301
     302    // Activation page
     303    } elseif ( bp_is_activation_page() ) {
     304        $title = __( 'Activate your Account', 'buddypress' );
     305
     306    // Group creation page
     307    } elseif ( bp_is_group_create() ) {
     308        $title = __( 'Create a Group', 'buddypress' );
     309
     310    // Blog creation page
     311    } elseif ( bp_is_create_blog() ) {
     312        $title = __( 'Create a Site', 'buddypress' );
     313    }
     314
     315    return apply_filters( 'bp_modify_page_title', $title . " $sep ", $title, $sep, $seplocation );
     316}
     317add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 );
     318add_filter( 'bp_modify_page_title', 'wptexturize'   );
     319add_filter( 'bp_modify_page_title', 'convert_chars' );
     320add_filter( 'bp_modify_page_title', 'esc_html'      );
    254321?>
  • trunk/bp-core/bp-core-template.php

    r4532 r4536  
    212212function bp_get_plugin_sidebar() {
    213213    locate_template( array( 'plugin-sidebar.php' ), true );
    214 }
    215 
    216 function bp_page_title() {
    217     echo bp_get_page_title();
    218 }
    219 
    220 function bp_get_page_title() {
    221     global $bp, $post, $wp_query;
    222 
    223     $title = '';
    224 
    225     // Home
    226     if ( is_front_page() || ( is_home() && bp_is_page( 'home' ) ) ) {
    227         $title = _x( 'Home', 'Home page title', 'buddypress' );
    228 
    229     // Blog
    230     } elseif ( bp_is_blog_page() ) {
    231         if ( is_single() ) {
    232             $title = sprintf( __( 'Site &#124; %s', 'buddypress' ), $post->post_title );
    233         } else if ( is_category() ) {
    234             $title = sprintf( __( 'Site &#124; Categories &#124; %s', 'buddypress' ), ucwords( $wp_query->query_vars['category_name'] ) );
    235         } else if ( is_tag() ) {
    236             $title = sprintf( __( 'Site &#124; Tags &#124; %s', 'buddypress' ), ucwords( $wp_query->query_vars['tag'] ) );
    237         } else if ( is_page() ){
    238             $title = $post->post_title;
    239         } else
    240             $title = __( 'Site', 'buddypress' );
    241 
    242     // Displayed user
    243     } elseif ( !empty( $bp->displayed_user->fullname ) && !is_404() ) {
    244         // translators: "displayed user's name | canonicalised component name"
    245         $title = strip_tags( sprintf( __( '%1$s &#124; %2$s', 'buddypress' ), $bp->displayed_user->fullname, ucwords( bp_current_component() ) ) );
    246 
    247     // A single group
    248     } elseif ( bp_is_active( 'groups' ) && !empty( $bp->groups->current_group ) && !empty( $bp->bp_options_nav[$bp->groups->current_group->slug] ) ) {
    249         $subnav = isset( $bp->bp_options_nav[$bp->groups->current_group->slug][$bp->current_action]['name'] ) ? $bp->bp_options_nav[$bp->groups->current_group->slug][$bp->current_action]['name'] : '';
    250         // translators: "group name | group nav section name"
    251         $title = sprintf( __( '%1$s &#124; %2$s', 'buddypress' ), $bp->bp_options_title, $subnav );
    252 
    253     // A single item from a component other than groups
    254     } elseif ( bp_is_single_item() ) {
    255         // translators: "root component name | component item name | component nav section name"
    256         $title = sprintf( __( '%1$s &#124; %2$s &#124; %3$s', 'buddypress' ), bp_get_name_from_root_slug(), $bp->bp_options_title, $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'] );
    257 
    258     // An index or directory
    259     } elseif ( bp_is_directory() ) {
    260         if ( !bp_current_component() )
    261             $title = sprintf( __( '%s Directory', 'buddypress' ), bp_get_name_from_root_slug( $bp->members->slug ) );
    262         else
    263             $title = sprintf( __( '%s Directory', 'buddypress' ), bp_get_name_from_root_slug() );
    264 
    265     // Sign up page
    266     } elseif ( bp_is_register_page() ) {
    267         $title = __( 'Create an Account', 'buddypress' );
    268 
    269     // Activation page
    270     } elseif ( bp_is_activation_page() ) {
    271         $title = __( 'Activate your Account', 'buddypress' );
    272 
    273     // Group creation page
    274     } elseif ( bp_is_group_create() ) {
    275         $title = __( 'Create a Group', 'buddypress' );
    276 
    277     // Blog creation page
    278     } elseif ( bp_is_create_blog() ) {
    279         $title = __( 'Create a Site', 'buddypress' );
    280     }
    281 
    282     $site_title = get_bloginfo( 'name', 'display' );
    283 
    284     // Filter the title
    285     if ( !empty( $title ) )
    286         $site_title .= ' &#124; ' . $title;
    287 
    288     return apply_filters( 'bp_page_title', esc_attr( $site_title ), esc_attr( $site_title ) );
    289 }
    290 
    291 function bp_styles() {
    292     do_action( 'bp_styles' );
    293     wp_print_styles();
    294214}
    295215
  • trunk/bp-core/deprecated/1.3.php

    r4532 r4536  
    383383}
    384384
     385/**
     386 * Template tag version of bp_get_page_title()
     387 *
     388 * @deprecated 1.3
     389 * @deprecated Use wp_title()
     390 * @since 1.0
     391 */
     392function bp_page_title() {
     393    echo bp_get_page_title();
     394}
     395    /**
     396     * Prior to BuddyPress 1.3, this was used to generate the page's <title> text.
     397     * Now, just simply use wp_title().
     398     *
     399     * @deprecated 1.3
     400     * @deprecated Use wp_title()
     401     * @since 1.0
     402     */
     403    function bp_get_page_title() {
     404        _deprecated_function( __FUNCTION__, '1.3', 'wp_title()' );
     405        $title = wp_title( '|', false, 'right' ) . get_bloginfo( 'name', 'display' );
     406
     407        // Backpat for BP 1.2 filter
     408        $title = apply_filters( 'bp_page_title', esc_attr( $title ), esc_attr( $title ) );
     409
     410        return apply_filters( 'bp_get_page_title', $title );
     411    }
     412
     413function bp_styles() {
     414    do_action( 'bp_styles' );
     415    wp_print_styles();
     416}
    385417
    386418/** Theme *********************************************************************/
  • trunk/bp-forums/bp-forums-filters.php

    r4301 r4536  
    9595 *
    9696 * @global object $bp
    97  * @param string $title
     97 * @param string $title New page title; see bp_modify_page_title()
     98 * @param string $title Original page title
     99 * @param string $sep How to separate the various items within the page title.
     100 * @param string $seplocation Direction to display title
    98101 * @return string
    99  */
    100 function bp_forums_add_forum_topic_to_page_title( $title ) {
     102 * @see bp_modify_page_title()
     103 */
     104function bp_forums_add_forum_topic_to_page_title( $title, $original_title, $sep, $seplocation  ) {
    101105    global $bp;
    102106
    103107    if ( $bp->current_action == 'forum' && !empty( $bp->action_variables[0] ) && 'topic' == $bp->action_variables[0] )
    104108        if ( bp_has_forum_topic_posts() )
    105             $title .= ' &#124; ' . bp_get_the_topic_title();
     109            $title .= bp_get_the_topic_title() . " $sep ";
    106110
    107111    return $title;
    108112}
    109 add_filter( 'bp_page_title', 'bp_forums_add_forum_topic_to_page_title' );
     113add_filter( 'bp_modify_page_title', 'bp_forums_add_forum_topic_to_page_title', 9, 4 );
    110114
    111115/**
  • trunk/bp-themes/bp-default/header.php

    r4532 r4536  
    44    <head profile="http://gmpg.org/xfn/11">
    55        <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ) ?>; charset=<?php bloginfo( 'charset' ) ?>" />
    6         <title><?php bp_page_title() ?></title>
     6        <title><?php wp_title( '|', true, 'right' ); bloginfo( 'name' ); ?></title>
    77        <link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url') ?>" type="text/css" media="screen" />
    88
Note: See TracChangeset for help on using the changeset viewer.