Skip to:
Content

BuddyPress.org

Ticket #6107: 6107.05.patch

File 6107.05.patch, 5.5 KB (added by hnla, 6 years ago)

Bail out if this is component directory

  • src/bp-core/bp-core-filters.php

     
    509509 * @param string $seplocation Direction to display title.
    510510 * @return string New page title.
    511511 */
    512 function bp_modify_page_title( $title, $sep = '', $seplocation = '' ) {
     512function bp_modify_page_title( $title, $sep = '»', $seplocation = 'right' ) {
    513513
    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() ) {
    516518                return $title;
    517519        }
    518520
     
    526528                return $title;
    527529        }
    528530
    529         $bp    = buddypress();
    530         $title = '';
     531        $bp          = buddypress();
     532        $title_parts = array();
    531533
    532534        // Displayed user
    533535        if ( bp_get_displayed_user_fullname() && ! is_404() ) {
     
    566568
    567569                // If on the user profile's landing page, just use the fullname
    568570                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();
    570572
    571573                // Use component name on member pages
    572574                } else {
     575                        $title_parts = array_merge( $title_parts, array_map( 'strip_tags', array(
     576                                bp_get_displayed_user_fullname(),
     577                                $component_name,
     578                        ) ) );
     579
    573580                        // If we have a subnav name, add it separately for localization
    574581                        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 );
    581583                        }
    582584                }
    583585
    584586        // A single group
    585587        } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) {
    586588                $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 );
    589590
    590591        // A single item from a component other than groups
    591592        } 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'] );
    594594
    595         // An index or directory
    596         } 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 
    606595        // Sign up page
    607596        } elseif ( bp_is_register_page() ) {
    608                 $title = __( 'Create an Account', 'buddypress' );
     597                $title_parts = array( __( 'Create an Account', 'buddypress' ) );
    609598
    610599        // Activation page
    611600        } elseif ( bp_is_activation_page() ) {
    612                 $title = __( 'Activate your Account', 'buddypress' );
     601                $title_parts = array( __( 'Activate your Account', 'buddypress' ) );
    613602
    614603        // Group creation page
    615604        } elseif ( bp_is_group_create() ) {
    616                 $title = __( 'Create a Group', 'buddypress' );
     605                $title_parts = array( __( 'Create a Group', 'buddypress' ) );
    617606
    618607        // Blog creation page
    619608        } elseif ( bp_is_create_blog() ) {
    620                 $title = __( 'Create a Site', 'buddypress' );
     609                $title_parts = array( __( 'Create a Site', 'buddypress' ) );
    621610        }
    622611
    623612        // 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);
    625616
    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 );
    627627}
    628 add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 );
     628add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 );
    629629add_filter( 'bp_modify_page_title', 'wptexturize'     );
    630630add_filter( 'bp_modify_page_title', 'convert_chars'   );
    631631add_filter( 'bp_modify_page_title', 'esc_html'        );