Ticket #6107: 6107.07.patch
| File 6107.07.patch, 7.9 KB (added by , 12 years ago) |
|---|
-
src/bp-core/bp-core-filters.php
505 505 * @see wp_title() 506 506 * @global object $bp BuddyPress global settings. 507 507 * 508 * @param string $title Original page title. 509 * @param string $sep How to separate the various items within the page title. 510 * @param string $seplocation Direction to display title. 511 * @return string New page title. 508 * @param string $title Original page title. 509 * @param string $sep How to separate the various items within the page title. 510 * @param string $seplocation Direction to display title. 511 * 512 * @return string New page title. 512 513 */ 513 function bp_modify_page_title( $title , $sep = '', $seplocation = '' ) {514 global $bp ;514 function bp_modify_page_title( $title = '', $sep = '»', $seplocation = 'right' ) { 515 global $bp, $paged, $page, $_wp_theme_features; 515 516 516 517 // If this is not a BP page, just return the title produced by WP 517 518 if ( bp_is_blog_page() ) { … … 528 529 return $title; 529 530 } 530 531 531 $title = ''; 532 // Return WP's title if not a BuddyPress page 533 if ( ! is_buddypress() ) { 534 return $title; 535 } 532 536 537 // Setup an empty title parts array 538 $title_parts = array(); 539 540 // Is there a displayed user, and do they have a name? 541 $displayed_user_name = bp_get_displayed_user_fullname(); 542 533 543 // Displayed user 534 if ( bp_get_displayed_user_fullname() && ! is_404() ) { 544 if ( ! empty( $displayed_user_name ) && ! is_404() ) { 545 535 546 // Get the component's ID to try and get its name 536 547 $component_id = $component_name = bp_current_component(); 537 548 … … 567 578 568 579 // If on the user profile's landing page, just use the fullname 569 580 if ( bp_is_current_component( $bp->default_component ) && bp_get_requested_url() === bp_displayed_user_domain() ) { 570 $title = bp_get_displayed_user_fullname();581 $title_parts[] = $displayed_user_name; 571 582 572 583 // Use component name on member pages 573 584 } else { 585 $title_parts = array_merge( $title_parts, array_map( 'strip_tags', array( 586 $displayed_user_name, 587 $component_name, 588 ) ) ); 589 574 590 // If we have a subnav name, add it separately for localization 575 591 if ( ! empty( $component_subnav_name ) ) { 576 // translators: construct the page title. 1 = user name, 2 = component name, 3 = separator, 4 = component subnav name 577 $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 ) ); 578 579 } else { 580 // translators: construct the page title. 1 = user name, 2 = component name, 3 = separator 581 $title = strip_tags( sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), bp_get_displayed_user_fullname(), $component_name, $sep ) ); 592 $title_parts[] = strip_tags( $component_subnav_name ); 582 593 } 583 594 } 584 595 585 596 // A single group 586 597 } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) { 587 $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'] : ''; 588 // translators: 1 = group name, 2 = group nav section name, 3 = separator 589 $title = sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), $bp->bp_options_title, $subnav, $sep ); 598 $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'] : ''; 599 $title_parts = array( $bp->bp_options_title, $subnav ); 590 600 591 601 // A single item from a component other than groups 592 602 } elseif ( bp_is_single_item() ) { 593 // translators: 1 = component item name, 2 = component nav section name, 3 = separator 594 $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 ); 603 $title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] ); 595 604 596 605 // An index or directory 597 606 } elseif ( bp_is_directory() ) { 598 607 $current_component = bp_current_component(); 599 608 600 609 // No current component (when does this happen?) 601 if ( empty( $current_component ) ) { 602 $title = _x( 'Directory', 'component directory title', 'buddypress' ); 603 } else { 604 $title = bp_get_directory_title( $current_component ); 605 } 610 $title_parts = array( _x( 'Directory', 'component directory title', 'buddypress' ) ); 606 611 612 if ( ! empty( $current_component ) ) { 613 $title_parts = array( bp_get_directory_title( $current_component ) ); 614 } 615 607 616 // Sign up page 608 617 } elseif ( bp_is_register_page() ) { 609 $title = __( 'Create an Account', 'buddypress');618 $title_parts = array( __( 'Create an Account', 'buddypress' ) ); 610 619 611 620 // Activation page 612 621 } elseif ( bp_is_activation_page() ) { 613 $title = __( 'Activate your Account', 'buddypress');622 $title_parts = array( __( 'Activate your Account', 'buddypress' ) ); 614 623 615 624 // Group creation page 616 625 } elseif ( bp_is_group_create() ) { 617 $title = __( 'Create a Group', 'buddypress');626 $title_parts = array( __( 'Create a Group', 'buddypress' ) ); 618 627 619 628 // Blog creation page 620 629 } elseif ( bp_is_create_blog() ) { 621 $title = __( 'Create a Site', 'buddypress');630 $title_parts = array( __( 'Create a Site', 'buddypress' ) ); 622 631 } 623 632 624 // Some BP nav items contain item counts. Remove them 625 $title = preg_replace( '|<span>[0-9]+</span>|', '', $title ); 633 /** 634 * Strip span tags out of title part strings. 635 * 636 * This is a temporary function for compatibility with WordPress versions 637 * less than 4.0, and should be removed at a later date. 638 * 639 * @param string $title_part 640 * @return string 641 */ 642 function _bp_strip_spans_from_title( $title_part = '' ) { 643 return preg_replace( '|<span>[0-9]+</span>|' , '', $title_part ); 644 } 626 645 627 return apply_filters( 'bp_modify_page_title', $title . ' ' . $sep . ' ', $title, $sep, $seplocation ); 646 // Strip spans 647 $title_parts = array_map( '_bp_strip_spans_from_title', $title_parts ); 648 649 // sep on right, so reverse the order 650 if ( 'right' == $seplocation ) { 651 $title_parts = array_reverse( $title_parts ); 652 } 653 654 // Get the blog name, so we can check if the original $title included it 655 $blogname = get_bloginfo( 'name', 'display' ); 656 657 /** 658 * Are we going to fake 'title-tag' theme functionality? 659 * 660 * @link https://buddypress.trac.wordpress.org/ticket/6107 661 * @see wp_title() 662 */ 663 $title_tag_compatibility = (bool) ( ! empty( $_wp_theme_features['title-tag'] ) || strstr( $title, $blogname ) ); 664 665 // Append the site title to title parts if theme supports title tag 666 if ( true === $title_tag_compatibility ) { 667 $title_parts[] = $blogname; 668 $site_description = get_bloginfo( 'description', 'display' ); 669 if ( ! empty( $site_description ) && ( is_home() || is_front_page() ) ) { 670 $title_parts[] = $site_description; 671 } 672 673 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { 674 $title_parts[] = sprintf( __( 'Page %s' ), max( $paged, $page ) ); 675 } 676 } 677 678 // Pad the separator with 1 space on each side 679 $prefix = str_pad( $sep, strlen( $sep ) + 2, ' ', STR_PAD_BOTH ); 680 681 // Join the parts together 682 $new_title = join( $prefix, array_filter( $title_parts ) ); 683 684 // 685 if ( false === $title_tag_compatibility ) { 686 $new_title = $new_title . $prefix; 687 } 688 689 /** 690 * @param string the BuddyPress page title 691 * @param string $title the original WordPress page title 692 * @param string $sep the title parts separator 693 * @param string $seplocation Location of the separator (left or right). 694 */ 695 return apply_filters( 'bp_modify_page_title', $new_title, $title, $sep, $seplocation ); 628 696 } 629 add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 );697 add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 ); 630 698 add_filter( 'bp_modify_page_title', 'wptexturize' ); 631 699 add_filter( 'bp_modify_page_title', 'convert_chars' ); 632 700 add_filter( 'bp_modify_page_title', 'esc_html' );
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)