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