Ticket #6107: 6107.05.patch
File 6107.05.patch, 5.5 KB (added by , 9 years ago) |
---|
-
src/bp-core/bp-core-filters.php
509 509 * @param string $seplocation Direction to display title. 510 510 * @return string New page title. 511 511 */ 512 function bp_modify_page_title( $title, $sep = ' ', $seplocation = '' ) {512 function bp_modify_page_title( $title, $sep = '»', $seplocation = 'right' ) { 513 513 514 // If this is not a BP page, just return the title produced by WP 515 if ( bp_is_blog_page() ) { 514 // If this is not a BP page or this is a BP component directory, 515 // just return the title produced by WP. This allows thirdparty plugins to 516 // modify page title tag strings 517 if ( bp_is_blog_page() || bp_is_directory() ) { 516 518 return $title; 517 519 } 518 520 … … 526 528 return $title; 527 529 } 528 530 529 $bp = buddypress();530 $title = '';531 $bp = buddypress(); 532 $title_parts = array(); 531 533 532 534 // Displayed user 533 535 if ( bp_get_displayed_user_fullname() && ! is_404() ) { … … 566 568 567 569 // If on the user profile's landing page, just use the fullname 568 570 if ( bp_is_current_component( $bp->default_component ) && bp_get_requested_url() === bp_displayed_user_domain() ) { 569 $title = bp_get_displayed_user_fullname();571 $title_parts[] = bp_get_displayed_user_fullname(); 570 572 571 573 // Use component name on member pages 572 574 } else { 575 $title_parts = array_merge( $title_parts, array_map( 'strip_tags', array( 576 bp_get_displayed_user_fullname(), 577 $component_name, 578 ) ) ); 579 573 580 // If we have a subnav name, add it separately for localization 574 581 if ( ! empty( $component_subnav_name ) ) { 575 // translators: construct the page title. 1 = user name, 2 = component name, 3 = separator, 4 = component subnav name 576 $title = strip_tags( sprintf( __( '%1$s %3$s %2$s %3$s %4$s', 'buddypress' ), bp_get_displayed_user_fullname(), $component_name, $sep, $component_subnav_name ) ); 577 578 } else { 579 // translators: construct the page title. 1 = user name, 2 = component name, 3 = separator 580 $title = strip_tags( sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), bp_get_displayed_user_fullname(), $component_name, $sep ) ); 582 $title_parts[] = strip_tags( $component_subnav_name ); 581 583 } 582 584 } 583 585 584 586 // A single group 585 587 } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) { 586 588 $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'] : ''; 587 // translators: 1 = group name, 2 = group nav section name, 3 = separator 588 $title = sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), $bp->bp_options_title, $subnav, $sep ); 589 $title_parts = array( $bp->bp_options_title, $subnav ); 589 590 590 591 // A single item from a component other than groups 591 592 } elseif ( bp_is_single_item() ) { 592 // translators: 1 = component item name, 2 = component nav section name, 3 = separator 593 $title = sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'], $sep ); 593 $title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] ); 594 594 595 // An index or directory596 } elseif ( bp_is_directory() ) {597 $current_component = bp_current_component();598 599 // No current component (when does this happen?)600 if ( empty( $current_component ) ) {601 $title = _x( 'Directory', 'component directory title', 'buddypress' );602 } else {603 $title = bp_get_directory_title( $current_component );604 }605 606 595 // Sign up page 607 596 } elseif ( bp_is_register_page() ) { 608 $title = __( 'Create an Account', 'buddypress');597 $title_parts = array( __( 'Create an Account', 'buddypress' ) ); 609 598 610 599 // Activation page 611 600 } elseif ( bp_is_activation_page() ) { 612 $title = __( 'Activate your Account', 'buddypress');601 $title_parts = array( __( 'Activate your Account', 'buddypress' ) ); 613 602 614 603 // Group creation page 615 604 } elseif ( bp_is_group_create() ) { 616 $title = __( 'Create a Group', 'buddypress');605 $title_parts = array( __( 'Create a Group', 'buddypress' ) ); 617 606 618 607 // Blog creation page 619 608 } elseif ( bp_is_create_blog() ) { 620 $title = __( 'Create a Site', 'buddypress');609 $title_parts = array( __( 'Create a Site', 'buddypress' ) ); 621 610 } 622 611 623 612 // Some BP nav items contain item counts. Remove them 624 $title = preg_replace( '|<span>[0-9]+</span>|', '', $title ); 613 $title_parts = array_map( function( $t ) { 614 return preg_replace( '|<span>[0-9]+</span>|' , '', $t ); 615 }, $title_parts); 625 616 626 return apply_filters( 'bp_modify_page_title', $title . ' ' . $sep . ' ', $title, $sep, $seplocation ); 617 // Append the site title to title parts 618 $title_parts = array_merge( $title_parts, array( get_bloginfo( 'name', 'display' ) ) ); 619 620 /** 621 * @param string the BuddyPress page title 622 * @param string $title the original WordPress page title 623 * @param string $sep the title parts separator 624 * @param string $seplocation Location of the separator (left or right). 625 */ 626 return apply_filters( 'bp_modify_page_title', join( ' ' . $sep . ' ', $title_parts ), $title, $sep, $seplocation ); 627 627 } 628 add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 );628 add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 ); 629 629 add_filter( 'bp_modify_page_title', 'wptexturize' ); 630 630 add_filter( 'bp_modify_page_title', 'convert_chars' ); 631 631 add_filter( 'bp_modify_page_title', 'esc_html' );