<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][10402] branches/2.4/src/bp-core: Make sure document/page title tags are correctly generated for BuddyPress pages</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/10402">10402</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/10402","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-12-13 16:45:43 +0000 (Sun, 13 Dec 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="http://buddypress.trac.wordpress.org/ticket/6675">#6675</a> (branch 2.4)</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branches24srcbpcorebpcorefiltersphp">branches/2.4/src/bp-core/bp-core-filters.php</a></li>
<li><a href="#branches24srcbpcorebpcorefunctionsphp">branches/2.4/src/bp-core/bp-core-functions.php</a></li>
<li><a href="#branches24srcbpcorebpcoretemplatephp">branches/2.4/src/bp-core/bp-core-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branches24srcbpcorebpcorefiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/2.4/src/bp-core/bp-core-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/2.4/src/bp-core/bp-core-filters.php 2015-12-10 10:55:33 UTC (rev 10401)
+++ branches/2.4/src/bp-core/bp-core-filters.php 2015-12-13 16:45:43 UTC (rev 10402)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -660,123 +660,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string New page title.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_modify_page_title( $title = '', $sep = '»', $seplocation = 'right' ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $bp, $paged, $page, $_wp_theme_features;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $paged, $page, $_wp_theme_features;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // If this is not a BP page, just return the title produced by WP
- if ( bp_is_blog_page() ) {
- return $title;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Get the BuddyPress title parts
+ $bp_title_parts = bp_get_title_parts( $seplocation );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // If this is a 404, let WordPress handle it
- if ( is_404() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If not set, simply return the original title
+ if ( ! $bp_title_parts ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return $title;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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 );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Get the blog name, so we can check if the original $title included it
</span><span class="cx" style="display: block; padding: 0 10px"> $blogname = get_bloginfo( 'name', 'display' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -790,10 +683,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Append the site title to title parts if theme supports title tag
</span><span class="cx" style="display: block; padding: 0 10px"> if ( true === $title_tag_compatibility ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $title_parts[] = $blogname;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $bp_title_parts['site'] = $blogname;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
- $title_parts[] = sprintf( __( 'Page %s', 'buddypress' ), max( $paged, $page ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() && ! bp_is_single_activity() ) {
+ $bp_title_parts['page'] = sprintf( __( 'Page %s', 'buddypress' ), max( $paged, $page ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -801,7 +694,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $prefix = str_pad( $sep, strlen( $sep ) + 2, ' ', STR_PAD_BOTH );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Join the parts together
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $new_title = join( $prefix, array_filter( $title_parts ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $new_title = join( $prefix, array_filter( $bp_title_parts ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Append the prefix for pre `title-tag` compatibility
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false === $title_tag_compatibility ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -809,7 +702,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Filters the page title for BuddyPress pages.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filters the older 'wp_title' page title for BuddyPress pages.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.5.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -820,29 +713,58 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> return apply_filters( 'bp_modify_page_title', $new_title, $title, $sep, $seplocation );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 );
-add_filter( 'bp_modify_page_title', 'wptexturize' );
-add_filter( 'bp_modify_page_title', 'convert_chars' );
-add_filter( 'bp_modify_page_title', 'esc_html' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 );
+add_filter( 'bp_modify_page_title', 'wptexturize' );
+add_filter( 'bp_modify_page_title', 'convert_chars' );
+add_filter( 'bp_modify_page_title', 'esc_html' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Strip span tags out of title part strings.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filter the document title for BuddyPress pages.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * This is a temporary function for compatibility with WordPress versions
- * less than 4.0, and should be removed at a later date.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.4.3
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $title_part
- *
- * @return string
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $title The WordPress document title parts
+ * @return array the unchanged title parts or the BuddyPress ones
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function _bp_strip_spans_from_title( $title_part = '' ) {
- $title = $title_part;
- $span = strpos( $title, '<span' );
- if ( false !== $span ) {
- $title = substr( $title, 0, $span - 1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function bp_modify_document_title_parts( $title = array() ) {
+ // Get the BuddyPress title parts
+ $bp_title_parts = bp_get_title_parts();
+
+ // If not set, simply return the original title
+ if ( ! $bp_title_parts ) {
+ return $title;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $title;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Get the separator used by wp_get_document_title()
+ $sep = apply_filters( 'document_title_separator', '-' );
+
+ // Build the BuddyPress portion of the title.
+ // We don't need to sanitize this as WordPress will take care of it.
+ $bp_title = array(
+ 'title' => join( " $sep ", $bp_title_parts )
+ );
+
+ // Add the pagination number if needed (not sure if this is necessary).
+ if ( isset( $title['page'] ) && ! bp_is_single_activity() ) {
+ $bp_title['page'] = $title['page'];
+ }
+
+ // Add the sitename if needed.
+ if ( isset( $title['site'] ) ) {
+ $bp_title['site'] = $title['site'];
+ }
+
+ /**
+ * Filters BuddyPress title parts that will be used into the document title.
+ *
+ * @since 2.4.3
+ *
+ * @param array $bp_title The BuddyPress page title parts.
+ * @param array $title The original WordPress title parts.
+ */
+ return apply_filters( 'bp_modify_document_title_parts', $bp_title, $title );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'document_title_parts', 'bp_modify_document_title_parts', 20, 1 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Add BuddyPress-specific items to the wp_nav_menu.
</span></span></pre></div>
<a id="branches24srcbpcorebpcorefunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/2.4/src/bp-core/bp-core-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/2.4/src/bp-core/bp-core-functions.php 2015-12-10 10:55:33 UTC (rev 10401)
+++ branches/2.4/src/bp-core/bp-core-functions.php 2015-12-13 16:45:43 UTC (rev 10402)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2296,6 +2296,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bp_init', 'bp_remove_adjacent_posts_rel_link' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Strip the span count of a menu item or of a title part.
+ *
+ * @since 2.2.2
+ *
+ * @param string $title_part Title part to clean up.
+ * @return string
+ */
+function _bp_strip_spans_from_title( $title_part = '' ) {
+ $title = $title_part;
+ $span = strpos( $title, '<span' );
+ if ( false !== $span ) {
+ $title = substr( $title, 0, $span - 1 );
+ }
+ return trim( $title );
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /** Nav Menu ******************************************************************/
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2347,8 +2364,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $bp_menu_items as $bp_item ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Remove <span>number</span>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $item_name = preg_replace( '/([.0-9]+)/', '', $bp_item['name'] );
- $item_name = trim( strip_tags( $item_name ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $item_name = _bp_strip_spans_from_title( $bp_item['name'] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $page_args[ $bp_item['slug'] ] = (object) array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'ID' => -1,
</span></span></pre></div>
<a id="branches24srcbpcorebpcoretemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/2.4/src/bp-core/bp-core-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/2.4/src/bp-core/bp-core-template.php 2015-12-10 10:55:33 UTC (rev 10401)
+++ branches/2.4/src/bp-core/bp-core-template.php 2015-12-13 16:45:43 UTC (rev 10402)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2797,6 +2797,144 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Get the title parts of the BuddyPress displayed page
+ *
+ * @since 2.4.3
+ *
+ * @param string $seplocation
+ * @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 = '';
+
+ // 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() ) ) {
+ $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 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'] : '';
+ $bp_title_parts = array( $bp->bp_options_title, $subnav );
+
+ // A single item from a component other than groups.
+ } elseif ( bp_is_single_item() ) {
+ $bp_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?).
+ $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 );
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Customize the body class, according to the currently displayed BP content.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_the_body_class() {
</span></span></pre>
</div>
</div>
</body>
</html>