/**
 * Filter the page title for BuddyPress pages.
 *
 * @since 1.5.0
 *
 * @see wp_title()
 * @global object $bp BuddyPress global settings.
 *
 * @param  string $title       Original page title.
 * @param  string $sep         How to separate the various items within the page title.
 * @param  string $seplocation Direction to display title.
 * @return string              New page title.
 */
function bp_modify_page_title($title = '', $sep = '»', $seplocation = 'right')
{
    global $bp, $paged, $page, $_wp_theme_features;
    // If this is not a BP page, just return the title produced by WP.
    if (bp_is_blog_page()) {
        return $title;
    }
    // If this is a 404, let WordPress handle it.
    if (is_404()) {
        return $title;
    }
    // If this is the front page of the site, return WP's title.
    if (is_front_page() || is_home()) {
        return $title;
    }
    // Return WP's title if not a BuddyPress page.
    if (!is_buddypress()) {
        return $title;
    }
    // Setup an empty title parts array.
    $title_parts = array();
    // Is there a displayed user, and do they have a name?
    $displayed_user_name = bp_get_displayed_user_fullname();
    // Displayed user.
    if (!empty($displayed_user_name) && !is_404()) {
        // Get the component's ID to try and get its name.
        $component_id = $component_name = bp_current_component();
        // Set empty subnav name.
        $component_subnav_name = '';
        // Use the component nav name.
        if (!empty($bp->bp_nav[$component_id])) {
            $component_name = _bp_strip_spans_from_title($bp->bp_nav[$component_id]['name']);
            // Fall back on the component ID.
        } elseif (!empty($bp->{$component_id}->id)) {
            $component_name = ucwords($bp->{$component_id}->id);
        }
        // Append action name if we're on a member component sub-page.
        if (!empty($bp->bp_options_nav[$component_id]) && !empty($bp->canonical_stack['action'])) {
            $component_subnav_name = wp_filter_object_list($bp->bp_options_nav[$component_id], array('slug' => bp_current_action()), 'and', 'name');
            if (!empty($component_subnav_name)) {
                $component_subnav_name = array_shift($component_subnav_name);
            }
        }
        // If on the user profile's landing page, just use the fullname.
        if (bp_is_current_component($bp->default_component) && bp_get_requested_url() === bp_displayed_user_domain()) {
            $title_parts[] = $displayed_user_name;
            // Use component name on member pages.
        } else {
            $title_parts = array_merge($title_parts, array_map('strip_tags', array($displayed_user_name, $component_name)));
            // If we have a subnav name, add it separately for localization.
            if (!empty($component_subnav_name)) {
                $title_parts[] = strip_tags($component_subnav_name);
            }
        }
        // A single group.
    } elseif (bp_is_active('groups') && !empty($bp->groups->current_group) && !empty($bp->bp_options_nav[$bp->groups->current_group->slug])) {
        $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'] : '';
        $title_parts = array($bp->bp_options_title, $subnav);
        // A single item from a component other than groups.
    } elseif (bp_is_single_item()) {
        $title_parts = array($bp->bp_options_title, $bp->bp_options_nav[bp_current_item()][bp_current_action()]['name']);
        // An index or directory.
    } elseif (bp_is_directory()) {
        $current_component = bp_current_component();
        // No current component (when does this happen?).
        $title_parts = array(_x('Directory', 'component directory title', 'buddypress'));
        if (!empty($current_component)) {
            $title_parts = array(bp_get_directory_title($current_component));
        }
        // Sign up page.
    } elseif (bp_is_register_page()) {
        $title_parts = array(__('Create an Account', 'buddypress'));
        // Activation page.
    } elseif (bp_is_activation_page()) {
        $title_parts = array(__('Activate Your Account', 'buddypress'));
        // Group creation page.
    } elseif (bp_is_group_create()) {
        $title_parts = array(__('Create a Group', 'buddypress'));
        // Blog creation page.
    } elseif (bp_is_create_blog()) {
        $title_parts = array(__('Create a Site', 'buddypress'));
    }
    // Strip spans.
    $title_parts = array_map('_bp_strip_spans_from_title', $title_parts);
    // Sep on right, so reverse the order.
    if ('right' == $seplocation) {
        $title_parts = array_reverse($title_parts);
    }
    // Get the blog name, so we can check if the original $title included it.
    $blogname = get_bloginfo('name', 'display');
    /**
     * Are we going to fake 'title-tag' theme functionality?
     *
     * @link https://buddypress.trac.wordpress.org/ticket/6107
     * @see wp_title()
     */
    $title_tag_compatibility = (bool) (!empty($_wp_theme_features['title-tag']) || strstr($title, $blogname));
    // Append the site title to title parts if theme supports title tag.
    if (true === $title_tag_compatibility) {
        $title_parts[] = $blogname;
        if (($paged >= 2 || $page >= 2) && !is_404()) {
            $title_parts[] = sprintf(__('Page %s', 'buddypress'), max($paged, $page));
        }
    }
    // Pad the separator with 1 space on each side.
    $prefix = str_pad($sep, strlen($sep) + 2, ' ', STR_PAD_BOTH);
    // Join the parts together.
    $new_title = join($prefix, array_filter($title_parts));
    // Append the prefix for pre `title-tag` compatibility.
    if (false === $title_tag_compatibility) {
        $new_title = $new_title . $prefix;
    }
    /**
     * Filters the page title for BuddyPress pages.
     *
     * @since  1.5.0
     *
     * @param  string $new_title   The BuddyPress page title.
     * @param  string $title       The original WordPress page title.
     * @param  string $sep         The title parts separator.
     * @param  string $seplocation Location of the separator (left or right).
     */
    return apply_filters('bp_modify_page_title', $new_title, $title, $sep, $seplocation);
}
/**
 * Get the title parts of the BuddyPress displayed page
 *
 * @since 2.4.3
 *
 * @param string $seplocation Location for the separator.
 * @return array the title parts
 */
function bp_get_title_parts($seplocation = 'right')
{
    $bp = buddypress();
    // Defaults to an empty array.
    $bp_title_parts = array();
    // If this is not a BP page, return the empty array.
    if (bp_is_blog_page()) {
        return $bp_title_parts;
    }
    // If this is a 404, return the empty array.
    if (is_404()) {
        return $bp_title_parts;
    }
    // If this is the front page of the site, return the empty array.
    if (is_front_page() || is_home()) {
        return $bp_title_parts;
    }
    // Return the empty array if not a BuddyPress page.
    if (!is_buddypress()) {
        return $bp_title_parts;
    }
    // Now we can build the BP Title Parts
    // Is there a displayed user, and do they have a name?
    $displayed_user_name = bp_get_displayed_user_fullname();
    // Displayed user.
    if (!empty($displayed_user_name) && !is_404()) {
        // Get the component's ID to try and get its name.
        $component_id = $component_name = bp_current_component();
        // Set empty subnav name.
        $component_subnav_name = '';
        if (!empty($bp->members->nav)) {
            $primary_nav_item = $bp->members->nav->get_primary(array('slug' => $component_id), false);
            $primary_nav_item = reset($primary_nav_item);
        }
        // Use the component nav name.
        if (!empty($primary_nav_item->name)) {
            $component_name = _bp_strip_spans_from_title($primary_nav_item->name);
            // Fall back on the component ID.
        } elseif (!empty($bp->{$component_id}->id)) {
            $component_name = ucwords($bp->{$component_id}->id);
        }
        if (!empty($bp->members->nav)) {
            $secondary_nav_item = $bp->members->nav->get_secondary(array('parent_slug' => $component_id, 'slug' => bp_current_action()), false);
            if ($secondary_nav_item) {
                $secondary_nav_item = reset($secondary_nav_item);
            }
        }
        // Append action name if we're on a member component sub-page.
        if (!empty($secondary_nav_item->name) && !empty($bp->canonical_stack['action'])) {
            $component_subnav_name = $secondary_nav_item->name;
        }
        // If on the user profile's landing page, just use the fullname.
        if (bp_is_current_component($bp->default_component) && bp_get_requested_url() === bp_displayed_user_domain()) {
            $bp_title_parts[] = $displayed_user_name;
            // Use component name on member pages.
        } else {
            $bp_title_parts = array_merge($bp_title_parts, array_map('strip_tags', array($displayed_user_name, $component_name)));
            // If we have a subnav name, add it separately for localization.
            if (!empty($component_subnav_name)) {
                $bp_title_parts[] = strip_tags($component_subnav_name);
            }
        }
        // A single item from a component other than Members.
    } elseif (bp_is_single_item()) {
        $component_id = bp_current_component();
        if (!empty($bp->{$component_id}->nav)) {
            $secondary_nav_item = $bp->{$component_id}->nav->get_secondary(array('parent_slug' => bp_current_item(), 'slug' => bp_current_action()), false);
            if ($secondary_nav_item) {
                $secondary_nav_item = reset($secondary_nav_item);
            }
        }
        $single_item_subnav = '';
        if (!empty($secondary_nav_item->name)) {
            $single_item_subnav = $secondary_nav_item->name;
        }
        $bp_title_parts = array($bp->bp_options_title, $single_item_subnav);
        // An index or directory.
    } elseif (bp_is_directory()) {
        $current_component = bp_current_component();
        // No current component (when does this happen?).
        $bp_title_parts = array(_x('Directory', 'component directory title', 'buddypress'));
        if (!empty($current_component)) {
            $bp_title_parts = array(bp_get_directory_title($current_component));
        }
        // Sign up page.
    } elseif (bp_is_register_page()) {
        $bp_title_parts = array(__('Create an Account', 'buddypress'));
        // Activation page.
    } elseif (bp_is_activation_page()) {
        $bp_title_parts = array(__('Activate Your Account', 'buddypress'));
        // Group creation page.
    } elseif (bp_is_group_create()) {
        $bp_title_parts = array(__('Create a Group', 'buddypress'));
        // Blog creation page.
    } elseif (bp_is_create_blog()) {
        $bp_title_parts = array(__('Create a Site', 'buddypress'));
    }
    // Strip spans.
    $bp_title_parts = array_map('_bp_strip_spans_from_title', $bp_title_parts);
    // Sep on right, so reverse the order.
    if ('right' === $seplocation) {
        $bp_title_parts = array_reverse($bp_title_parts);
    }
    /**
     * Filter BuddyPress title parts before joining.
     *
     * @since 2.4.3
     *
     * @param array $bp_title_parts Current BuddyPress title parts.
     * @return array
     */
    return (array) apply_filters('bp_get_title_parts', $bp_title_parts);
}
/**
 * Create fake "post" objects for BP's logged-in nav menu for use in the WordPress "Menus" settings page.
 *
 * WordPress nav menus work by representing post or tax term data as a custom
 * post type, which is then used to populate the checkboxes that appear on
 * Dashboard > Appearance > Menu as well as the menu as rendered on the front
 * end. Most of the items in the BuddyPress set of nav items are neither posts
 * nor tax terms, so we fake a post-like object so as to be compatible with the
 * menu.
 *
 * This technique also allows us to generate links dynamically, so that, for
 * example, "My Profile" will always point to the URL of the profile of the
 * logged-in user.
 *
 * @since 1.9.0
 *
 * @return mixed A URL or an array of dummy pages.
 */
function bp_nav_menu_get_loggedin_pages()
{
    // Try to catch the cached version first.
    if (!empty(buddypress()->wp_nav_menu_items->loggedin)) {
        return buddypress()->wp_nav_menu_items->loggedin;
    }
    // Pull up a list of items registered in BP's top-level nav array.
    $bp_menu_items = buddypress()->bp_nav;
    // Alphabetize.
    $bp_menu_items = bp_alpha_sort_by_key($bp_menu_items, 'name');
    // Some BP nav menu items will not be represented in bp_nav, because
    // they are not real BP components. We add them manually here.
    $bp_menu_items[] = array('name' => __('Log Out', 'buddypress'), 'slug' => 'logout', 'link' => wp_logout_url());
    // If there's nothing to show, we're done.
    if (count($bp_menu_items) < 1) {
        return false;
    }
    $page_args = array();
    foreach ($bp_menu_items as $bp_item) {
        // Remove <span>number</span>.
        $item_name = _bp_strip_spans_from_title($bp_item['name']);
        $page_args[$bp_item['slug']] = (object) array('ID' => -1, 'post_title' => $item_name, 'post_author' => 0, 'post_date' => 0, 'post_excerpt' => $bp_item['slug'], 'post_type' => 'page', 'post_status' => 'publish', 'comment_status' => 'closed', 'guid' => $bp_item['link']);
    }
    if (empty(buddypress()->wp_nav_menu_items)) {
        buddypress()->wp_nav_menu_items = new stdClass();
    }
    buddypress()->wp_nav_menu_items->loggedin = $page_args;
    return $page_args;
}