Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/13/2015 04:45:43 PM (6 years ago)
Author:
imath
Message:

Make sure document/page title tags are correctly generated for BuddyPress pages

  • Remove all the BuddyPress process to create BuddyPress title parts from bp_modify_page_title() and create the new function

bp_get_title_parts() and put this process here. This allowes plugin/theme to directly use it if needed.

  • Keep the filter on wp_title so that themes not supporting the title-tag feature or breadcrumb plugins can still easily get BuddyPress title parts.
  • Filter document_title_parts with a new function bp_modify_document_title_parts() to build the BuddyPress title parts if needed.
  • Both functions bp_modify_page_title() and bp_modify_document_title_parts() are using bp_get_title_parts().

Props slaFFik, mercime, r-a-y, DJPaul

See #6675 (branch 2.4)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.4/src/bp-core/bp-core-template.php

    r10209 r10402  
    27952795function bp_is_register_page() {
    27962796    return (bool) bp_is_current_component( 'register' );
     2797}
     2798
     2799/**
     2800 * Get the title parts of the BuddyPress displayed page
     2801 *
     2802 * @since 2.4.3
     2803 *
     2804 * @param string $seplocation
     2805 * @return array the title parts
     2806 */
     2807function bp_get_title_parts( $seplocation = 'right' ) {
     2808    $bp = buddypress();
     2809
     2810    // Defaults to an empty array
     2811    $bp_title_parts = array();
     2812
     2813    // If this is not a BP page, return the empty array.
     2814    if ( bp_is_blog_page() ) {
     2815        return $bp_title_parts;
     2816    }
     2817
     2818    // If this is a 404, return the empty array.
     2819    if ( is_404() ) {
     2820        return $bp_title_parts;
     2821    }
     2822
     2823    // If this is the front page of the site, return the empty array.
     2824    if ( is_front_page() || is_home() ) {
     2825        return $bp_title_parts;
     2826    }
     2827
     2828    // Return the empty array if not a BuddyPress page.
     2829    if ( ! is_buddypress() ) {
     2830        return $bp_title_parts;
     2831    }
     2832
     2833    // Now we can build the BP Title Parts
     2834    // Is there a displayed user, and do they have a name?
     2835    $displayed_user_name = bp_get_displayed_user_fullname();
     2836
     2837    // Displayed user.
     2838    if ( ! empty( $displayed_user_name ) && ! is_404() ) {
     2839
     2840        // Get the component's ID to try and get its name.
     2841        $component_id = $component_name = bp_current_component();
     2842
     2843        // Set empty subnav name.
     2844        $component_subnav_name = '';
     2845
     2846        // Use the component nav name.
     2847        if ( ! empty( $bp->bp_nav[$component_id] ) ) {
     2848            $component_name = _bp_strip_spans_from_title( $bp->bp_nav[ $component_id ]['name'] );
     2849
     2850        // Fall back on the component ID.
     2851        } elseif ( ! empty( $bp->{$component_id}->id ) ) {
     2852            $component_name = ucwords( $bp->{$component_id}->id );
     2853        }
     2854
     2855        // Append action name if we're on a member component sub-page.
     2856        if ( ! empty( $bp->bp_options_nav[ $component_id ] ) && ! empty( $bp->canonical_stack['action'] ) ) {
     2857            $component_subnav_name = wp_filter_object_list( $bp->bp_options_nav[ $component_id ], array( 'slug' => bp_current_action() ), 'and', 'name' );
     2858
     2859            if ( ! empty( $component_subnav_name ) ) {
     2860                $component_subnav_name = array_shift( $component_subnav_name );
     2861            }
     2862        }
     2863
     2864        // If on the user profile's landing page, just use the fullname.
     2865        if ( bp_is_current_component( $bp->default_component ) && ( bp_get_requested_url() === bp_displayed_user_domain() ) ) {
     2866            $bp_title_parts[] = $displayed_user_name;
     2867
     2868        // Use component name on member pages.
     2869        } else {
     2870            $bp_title_parts = array_merge( $bp_title_parts, array_map( 'strip_tags', array(
     2871                $displayed_user_name,
     2872                $component_name,
     2873            ) ) );
     2874
     2875            // If we have a subnav name, add it separately for localization.
     2876            if ( ! empty( $component_subnav_name ) ) {
     2877                $bp_title_parts[] = strip_tags( $component_subnav_name );
     2878            }
     2879        }
     2880
     2881    // A single group.
     2882    } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) {
     2883        $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'] : '';
     2884        $bp_title_parts = array( $bp->bp_options_title, $subnav );
     2885
     2886    // A single item from a component other than groups.
     2887    } elseif ( bp_is_single_item() ) {
     2888        $bp_title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] );
     2889
     2890    // An index or directory.
     2891    } elseif ( bp_is_directory() ) {
     2892        $current_component = bp_current_component();
     2893
     2894        // No current component (when does this happen?).
     2895        $bp_title_parts = array( _x( 'Directory', 'component directory title', 'buddypress' ) );
     2896
     2897        if ( ! empty( $current_component ) ) {
     2898            $bp_title_parts = array( bp_get_directory_title( $current_component ) );
     2899        }
     2900
     2901    // Sign up page.
     2902    } elseif ( bp_is_register_page() ) {
     2903        $bp_title_parts = array( __( 'Create an Account', 'buddypress' ) );
     2904
     2905    // Activation page.
     2906    } elseif ( bp_is_activation_page() ) {
     2907        $bp_title_parts = array( __( 'Activate Your Account', 'buddypress' ) );
     2908
     2909    // Group creation page.
     2910    } elseif ( bp_is_group_create() ) {
     2911        $bp_title_parts = array( __( 'Create a Group', 'buddypress' ) );
     2912
     2913    // Blog creation page.
     2914    } elseif ( bp_is_create_blog() ) {
     2915        $bp_title_parts = array( __( 'Create a Site', 'buddypress' ) );
     2916    }
     2917
     2918    // Strip spans.
     2919    $bp_title_parts = array_map( '_bp_strip_spans_from_title', $bp_title_parts );
     2920
     2921    // Sep on right, so reverse the order.
     2922    if ( 'right' === $seplocation ) {
     2923        $bp_title_parts = array_reverse( $bp_title_parts );
     2924    }
     2925
     2926    /**
     2927     * Filter BuddyPress title parts before joining.
     2928     *
     2929     * @since 2.4.3
     2930     *
     2931     * @param  array $bp_title_parts Current BuddyPress title parts
     2932     * @return array
     2933     */
     2934    return (array) apply_filters( 'bp_get_title_parts', $bp_title_parts );
    27972935}
    27982936
Note: See TracChangeset for help on using the changeset viewer.