<!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][9732] branches/2.2/src/bp-core/bp-core-filters.php: Core: Improvements to `bp_modify_page_title()`:</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/9732">9732</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/9732","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>johnjamesjacoby</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-04-10 23:05:19 +0000 (Fri, 10 Apr 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'>Core: Improvements to `bp_modify_page_title()`:
* Better compatibility with core themes
* Play more-nicely with plugins competing for ownership of competitive `wp_title` filter
* In 2.2 branch, for 2.2.2 release
Props hnla, mercime, imath. Fixes <a href="http://buddypress.trac.wordpress.org/ticket/6107">#6107</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branches22srcbpcorebpcorefiltersphp">branches/2.2/src/bp-core/bp-core-filters.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branches22srcbpcorebpcorefiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/2.2/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.2/src/bp-core/bp-core-filters.php 2015-04-10 00:52:38 UTC (rev 9731)
+++ branches/2.2/src/bp-core/bp-core-filters.php 2015-04-10 23:05:19 UTC (rev 9732)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -505,13 +505,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @see wp_title()
</span><span class="cx" style="display: block; padding: 0 10px"> * @global object $bp BuddyPress global settings.
</span><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 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.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @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.
</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_modify_page_title( $title, $sep = '', $seplocation = '' ) {
- global $bp;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function bp_modify_page_title( $title = '', $sep = '»', $seplocation = 'right' ) {
+ global $bp, $paged, $page, $_wp_theme_features;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If this is not a BP page, just return the title produced by WP
</span><span class="cx" style="display: block; padding: 0 10px"> if ( bp_is_blog_page() ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -528,24 +529,48 @@
</span><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">- $title = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Return WP's title if not a BuddyPress page
+ if ( ! is_buddypress() ) {
+ return $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">+ // 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();
+
+ /**
+ * Strip span tags out of title part strings.
+ *
+ * This is a temporary function for compatibility with WordPress versions
+ * less than 4.0, and should be removed at a later date.
+ *
+ * @param string $title_part
+ * @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 $title;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Displayed user
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( bp_get_displayed_user_fullname() && ! is_404() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $displayed_user_name ) && ! is_404() ) {
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Get the component's ID to try and get its name
</span><span class="cx" style="display: block; padding: 0 10px"> $component_id = $component_name = bp_current_component();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Set empty subnav name
+ $component_subnav_name = '';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Use the component nav name
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $bp->bp_nav[$component_id] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Remove counts that are added by the nav item
- $span = strpos( $bp->bp_nav[ $component_id ]['name'], '<span' );
- if ( false !== $span ) {
- $component_name = substr( $bp->bp_nav[ $component_id ]['name'], 0, $span - 1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $component_name = _bp_strip_spans_from_title( $bp->bp_nav[ $component_id ]['name'] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } else {
- $component_name = $bp->bp_nav[ $component_id ]['name'];
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Fall back on the component ID
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( ! empty( $bp->{$component_id}->id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $component_name = ucwords( $bp->{$component_id}->id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -555,78 +580,113 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $bp->bp_options_nav[ $component_id ] ) && ! empty( $bp->canonical_stack['action'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $component_subnav_name = wp_filter_object_list( $bp->bp_options_nav[ $component_id ], array( 'slug' => bp_current_action() ), 'and', 'name' );
</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 ( $component_subnav_name ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $component_subnav_name ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $component_subnav_name = array_shift( $component_subnav_name );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } else {
- $component_subnav_name = '';
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- } else {
- $component_subnav_name = '';
</del><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"> // If on the user profile's landing page, just use the fullname
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( bp_is_current_component( $bp->default_component ) && bp_get_requested_url() === bp_displayed_user_domain() ) {
- $title = bp_get_displayed_user_fullname();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( bp_is_current_component( $bp->default_component ) && ( bp_get_requested_url() === bp_displayed_user_domain() ) ) {
+ $title_parts[] = $displayed_user_name;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Use component name on member pages
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $title_parts = array_merge( $title_parts, array_map( 'strip_tags', array(
+ $displayed_user_name,
+ $component_name,
+ ) ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // If we have a subnav name, add it separately for localization
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $component_subnav_name ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // translators: construct the page title. 1 = user name, 2 = component name, 3 = separator, 4 = component subnav name
- $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 ) );
-
- } else {
- // translators: construct the page title. 1 = user name, 2 = component name, 3 = separator
- $title = strip_tags( sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), bp_get_displayed_user_fullname(), $component_name, $sep ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $title_parts[] = strip_tags( $component_subnav_name );
</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="cx" style="display: block; padding: 0 10px"> // A single group
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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'] : '';
- // translators: 1 = group name, 2 = group nav section name, 3 = separator
- $title = sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), $bp->bp_options_title, $subnav, $sep );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $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 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // A single item from a component other than groups
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( bp_is_single_item() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // translators: 1 = component item name, 2 = component nav section name, 3 = separator
- $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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // An index or directory
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( bp_is_directory() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $current_component = bp_current_component();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // No current component (when does this happen?)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $current_component ) ) {
- $title = _x( 'Directory', 'component directory title', 'buddypress' );
- } else {
- $title = bp_get_directory_title( $current_component );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $title_parts = array( _x( 'Directory', 'component directory title', 'buddypress' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $current_component ) ) {
+ $title_parts = array( bp_get_directory_title( $current_component ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Sign up page
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( bp_is_register_page() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $title = __( 'Create an Account', 'buddypress' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $title_parts = array( __( 'Create an Account', 'buddypress' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Activation page
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( bp_is_activation_page() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $title = __( 'Activate your Account', 'buddypress' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $title_parts = array( __( 'Activate your Account', 'buddypress' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Group creation page
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( bp_is_group_create() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $title = __( 'Create a Group', 'buddypress' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $title_parts = array( __( 'Create a Group', 'buddypress' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Blog creation page
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( bp_is_create_blog() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $title = __( 'Create a Site', 'buddypress' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $title_parts = array( __( 'Create a Site', 'buddypress' ) );
</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">- // Some BP nav items contain item counts. Remove them
- $title = preg_replace( '|<span>[0-9]+</span>|', '', $title );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Strip spans
+ $title_parts = array_map( '_bp_strip_spans_from_title', $title_parts );
</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 apply_filters( 'bp_modify_page_title', $title . ' ' . $sep . ' ', $title, $sep, $seplocation );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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' ), 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;
+ }
+
+ /**
+ * @param string 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 );
</ins><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', 10, 3 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_modify_page_title', 'wptexturize' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_modify_page_title', 'convert_chars' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_modify_page_title', 'esc_html' );
</span></span></pre>
</div>
</div>
</body>
</html>