Skip to:
Content

BuddyPress.org

Ticket #6107: 6107.02.patch

File 6107.02.patch, 7.2 KB (added by imath, 8 years ago)

Patch Updated to r9485

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

    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 
    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() {
     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        }
    513529
    514530        // If this is not a BP page, just return the title produced by WP
    515531        if ( bp_is_blog_page() ) {
    516                 return $title;
     532                return $args[0];
    517533        }
    518534
    519535        // If this is a 404, let WordPress handle it
    520536        if ( is_404() ) {
    521                 return $title;
     537                return $args[0];
    522538        }
    523539
    524540        // If this is the front page of the site, return WP's title
    525541        if ( is_front_page() || is_home() ) {
    526                 return $title;
     542                return $args[0];
    527543        }
    528544
    529         $bp    = buddypress();
    530         $title = '';
     545        $bp       = buddypress();
     546        $bp_title = array();
    531547
    532548        // Displayed user
    533549        if ( bp_get_displayed_user_fullname() && ! is_404() ) {
    function bp_modify_page_title( $title, $sep = '', $seplocation = '' ) { 
    566582
    567583                // If on the user profile's landing page, just use the fullname
    568584                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();
    570586
    571587                // Use component name on member pages
    572588                } else {
     589                        $bp_title = array_merge( $bp_title, array_map( 'strip_tags', array(
     590                                bp_get_displayed_user_fullname(),
     591                                $component_name,
     592                        ) ) );
     593
    573594                        // If we have a subnav name, add it separately for localization
    574595                        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 );
    581597                        }
    582598                }
    583599
    584600        // A single group
    585601        } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) {
    586602                $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 );
    589604
    590605        // A single item from a component other than groups
    591606        } 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'] );
    594608
    595609        // An index or directory
    596610        } elseif ( bp_is_directory() ) {
    597611                $current_component = bp_current_component();
    598612
    599613                // 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 ) );
    604618                }
    605619
    606620        // Sign up page
    607621        } elseif ( bp_is_register_page() ) {
    608                 $title = __( 'Create an Account', 'buddypress' );
     622                $bp_title = array( __( 'Create an Account', 'buddypress' ) );
    609623
    610624        // Activation page
    611625        } elseif ( bp_is_activation_page() ) {
    612                 $title = __( 'Activate your Account', 'buddypress' );
     626                $bp_title = array( __( 'Activate your Account', 'buddypress' ) );
    613627
    614628        // Group creation page
    615629        } elseif ( bp_is_group_create() ) {
    616                 $title = __( 'Create a Group', 'buddypress' );
     630                $bp_title = array( __( 'Create a Group', 'buddypress' ) );
    617631
    618632        // Blog creation page
    619633        } elseif ( bp_is_create_blog() ) {
    620                 $title = __( 'Create a Site', 'buddypress' );
     634                $bp_title = array( __( 'Create a Site', 'buddypress' ) );
    621635        }
    622636
    623637        // 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 &raquo; in WordPress
     662                $sep = '&raquo;';
     663                if ( ! empty( $args[1] ) ) {
     664                        $sep = $args[1];
     665                }
    625666
    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        }
    627683}
    628 add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 );
     684add_filter( 'wp_title_parts', 'bp_modify_page_title', 10, 1 );
     685add_filter( 'wp_title',       'bp_modify_page_title', 10, 3 );
    629686add_filter( 'bp_modify_page_title', 'wptexturize'     );
    630687add_filter( 'bp_modify_page_title', 'convert_chars'   );
    631688add_filter( 'bp_modify_page_title', 'esc_html'        );