Ticket #6107: 6107.patch
| File 6107.patch, 7.1 KB (added by , 12 years ago) |
|---|
-
src/bp-core/bp-core-filters.php
diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php index f033c64..c788bd0 100644
add_filter( 'wpmu_signup_user_notification', 'bp_core_activation_signup_user_not 510 510 * @param string $seplocation Direction to display title. 511 511 * @return string New page title. 512 512 */ 513 function bp_modify_page_title( $title, $sep = '', $seplocation = '') {513 function bp_modify_page_title() { 514 514 global $bp; 515 515 516 $args = func_get_args(); 517 $return_array = false; 518 519 /** 520 * wp_title_parts was introduced in WordPress 4.0 521 * 522 * We first try to use it, if it fails, we still can count on the wp_title filter. We're 523 * using this new way of filtering the title since the introduction of the 'title-tag' 524 * feature (WordPress 4.1) in order to let WordPress build the title with our data. 525 */ 526 if ( 'wp_title_parts' == current_filter() ) { 527 $return_array = true; 528 529 // Remove the wp_title filter as we don't need it in this case 530 remove_filter( 'wp_title', 'bp_modify_page_title', 10, 3 ); 531 } 532 516 533 // If this is not a BP page, just return the title produced by WP 517 534 if ( bp_is_blog_page() ) { 518 return $ title;535 return $args[0]; 519 536 } 520 537 521 538 // If this is a 404, let WordPress handle it 522 539 if ( is_404() ) { 523 return $ title;540 return $args[0]; 524 541 } 525 542 526 543 // If this is the front page of the site, return WP's title 527 544 if ( is_front_page() || is_home() ) { 528 return $ title;545 return $args[0]; 529 546 } 530 547 531 $ title = '';548 $bp_title = array(); 532 549 533 550 // Displayed user 534 551 if ( bp_get_displayed_user_fullname() && ! is_404() ) { … … function bp_modify_page_title( $title, $sep = '', $seplocation = '' ) { 567 584 568 585 // If on the user profile's landing page, just use the fullname 569 586 if ( bp_is_current_component( $bp->default_component ) && bp_get_requested_url() === bp_displayed_user_domain() ) { 570 $ title= bp_get_displayed_user_fullname();587 $bp_title[] = bp_get_displayed_user_fullname(); 571 588 572 589 // Use component name on member pages 573 590 } else { 591 $bp_title = array_merge( $bp_title, array_map( 'strip_tags', array( 592 bp_get_displayed_user_fullname(), 593 $component_name, 594 ) ) ); 595 574 596 // If we have a subnav name, add it separately for localization 575 597 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 ) ); 598 $bp_title[] = strip_tags( $component_subnav_name ); 582 599 } 583 600 } 584 601 585 602 // A single group 586 603 } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) { 587 604 $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 ); 605 $bp_title = array( $bp->bp_options_title, $subnav ); 590 606 591 607 // A single item from a component other than groups 592 608 } 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 ); 609 $bp_title = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] ); 595 610 596 611 // An index or directory 597 612 } elseif ( bp_is_directory() ) { 598 613 $current_component = bp_current_component(); 599 614 600 615 // 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);616 $bp_title = array( _x( 'Directory', 'component directory title', 'buddypress' ) ); 617 618 if ( ! empty( $current_component ) ) { 619 $bp_title = array( bp_get_directory_title( $current_component ) ); 605 620 } 606 621 607 622 // Sign up page 608 623 } elseif ( bp_is_register_page() ) { 609 $ title = __( 'Create an Account', 'buddypress');624 $bp_title = array( __( 'Create an Account', 'buddypress' ) ); 610 625 611 626 // Activation page 612 627 } elseif ( bp_is_activation_page() ) { 613 $ title = __( 'Activate your Account', 'buddypress');628 $bp_title = array( __( 'Activate your Account', 'buddypress' ) ); 614 629 615 630 // Group creation page 616 631 } elseif ( bp_is_group_create() ) { 617 $ title = __( 'Create a Group', 'buddypress');632 $bp_title = array( __( 'Create a Group', 'buddypress' ) ); 618 633 619 634 // Blog creation page 620 635 } elseif ( bp_is_create_blog() ) { 621 $ title = __( 'Create a Site', 'buddypress');636 $bp_title = array( __( 'Create a Site', 'buddypress' ) ); 622 637 } 623 638 624 639 // Some BP nav items contain item counts. Remove them 625 $title = preg_replace( '|<span>[0-9]+</span>|', '', $title ); 640 $bp_title = array_map( function( $t ) { 641 return preg_replace( '|<span>[0-9]+</span>|' , '', $t ); 642 }, $bp_title); 643 644 if ( ! empty( $return_array ) ) { 645 $title = array_reverse( $bp_title ); 646 647 if ( ! bp_is_directory() && ! bp_is_register_page() && ! bp_is_activation_page() ) { 648 $title = array_merge( array( '' ), $title ); 649 } 626 650 627 return apply_filters( 'bp_modify_page_title', $title . ' ' . $sep . ' ', $title, $sep, $seplocation ); 651 /** 652 * The filters wptexturize, convert_chars and esc_html 653 * will be applied by WordPress later in wp_title() just 654 * before returning the title. 655 * 656 * @param array $title list of BuddyPress page title parts 657 */ 658 return apply_filters( 'bp_modify_page_title_parts', $title ); 659 660 // Build the title it used to be done before 'title-tag' feature 661 } else { 662 663 // Default separator is » in WordPress 664 $sep = '»'; 665 if ( ! empty( $args[1] ) ) { 666 $sep = $args[1]; 667 } 668 669 // Arbitrary default seplocation if not set 670 $seplocation = 'right'; 671 if ( ! empty( $args[2] ) ) { 672 $seplocation = $args[2]; 673 } 674 675 $title = join( ' ' . $sep . ' ', $bp_title ) . ' ' . $sep . ' '; 676 677 /** 678 * @param string $title the BuddyPress page title 679 * @param string $args[0] the original WordPress page title 680 * @param string $sep the title parts separator 681 * @param string $seplocation Location of the separator (left or right). 682 */ 683 return apply_filters( 'bp_modify_page_title', $title, $args[0], $sep, $seplocation ); 684 } 628 685 } 629 add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 ); 686 add_filter( 'wp_title_parts', 'bp_modify_page_title', 10, 1 ); 687 add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 ); 630 688 add_filter( 'bp_modify_page_title', 'wptexturize' ); 631 689 add_filter( 'bp_modify_page_title', 'convert_chars' ); 632 690 add_filter( 'bp_modify_page_title', 'esc_html' );
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)