<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[BuddyPress] [2285] trunk: Updating user_domain()
  fetching and caching and removing any duplication with userurl().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2285</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-01-10 11:38:25 +0000 (Sun, 10 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Updating user_domain() fetching and caching and removing any duplication with userurl().</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivityphp">trunk/bp-activity.php</a></li>
<li><a href="#trunkbpcorebpcoreclassesphp">trunk/bp-core/bp-core-classes.php</a></li>
<li><a href="#trunkbpcorebpcoretemplatetagsphp">trunk/bp-core/bp-core-templatetags.php</a></li>
<li><a href="#trunkbpcorephp">trunk/bp-core.php</a></li>
<li><a href="#trunkbpfriendsbpfriendstemplatetagsphp">trunk/bp-friends/bp-friends-templatetags.php</a></li>
<li><a href="#trunkbpfriendsphp">trunk/bp-friends.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivityphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity.php (2284 => 2285)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity.php        2010-01-09 16:16:51 UTC (rev 2284)
+++ trunk/bp-activity.php        2010-01-10 11:38:25 UTC (rev 2285)
</span><span class="lines">@@ -248,13 +248,13 @@
</span><span class="cx">         /* Redirect based on the type of activity */
</span><span class="cx">         if ( $activity-&gt;component_name == $bp-&gt;groups-&gt;id ) {
</span><span class="cx">                 if ( $activity-&gt;user_id )
</span><del>-                        $redirect = bp_core_get_userurl( $activity-&gt;user_id ) . $bp-&gt;activity-&gt;slug . '/' . $activity-&gt;id;
</del><ins>+                        $redirect = bp_core_get_user_domain( $activity-&gt;user_id, $activity-&gt;user_nicename, $activity-&gt;user_login ) . $bp-&gt;activity-&gt;slug . '/' . $activity-&gt;id;
</ins><span class="cx">                 else {
</span><span class="cx">                         if ( $group = groups_get_group( array( 'group_id' =&gt; $activity-&gt;item_id ) ) )
</span><span class="cx">                                 $redirect = bp_get_group_permalink( $group ) . $bp-&gt;activity-&gt;slug . '/' . $activity-&gt;id;
</span><span class="cx">                 }
</span><span class="cx">         } else
</span><del>-                $redirect = bp_core_get_userurl( $activity-&gt;user_id ) . $bp-&gt;activity-&gt;slug . '/' . $activity-&gt;id;
</del><ins>+                $redirect = bp_core_get_user_domain( $activity-&gt;user_id, $activity-&gt;user_nicename, $activity-&gt;user_login ) . $bp-&gt;activity-&gt;slug . '/' . $activity-&gt;id;
</ins><span class="cx"> 
</span><span class="cx">         if ( !$redirect )
</span><span class="cx">                 bp_core_redirect( $bp-&gt;root_domain );
</span></span></pre></div>
<a id="trunkbpcorebpcoreclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-classes.php (2284 => 2285)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-classes.php        2010-01-09 16:16:51 UTC (rev 2284)
+++ trunk/bp-core/bp-core-classes.php        2010-01-10 11:38:25 UTC (rev 2285)
</span><span class="lines">@@ -64,7 +64,7 @@
</span><span class="cx">                         $this-&gt;user_link = &quot;&lt;a href='{$this-&gt;user_url}' title='{$this-&gt;fullname}'&gt;{$this-&gt;fullname}&lt;/a&gt;&quot;;
</span><span class="cx">                         $this-&gt;email = attribute_escape( $this-&gt;profile_data['user_email'] );
</span><span class="cx">                 } else {
</span><del>-                        $this-&gt;user_url = bp_core_get_userurl( $this-&gt;id );
</del><ins>+                        $this-&gt;user_url = bp_core_get_user_domain( $this-&gt;id );
</ins><span class="cx">                         $this-&gt;user_link = bp_core_get_userlink( $this-&gt;id );
</span><span class="cx">                         $this-&gt;fullname = attribute_escape( bp_core_get_user_displayname( $this-&gt;id ) );
</span><span class="cx">                         $this-&gt;email = attribute_escape( bp_core_get_user_email( $this-&gt;id ) );
</span></span></pre></div>
<a id="trunkbpcorebpcoretemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-templatetags.php (2284 => 2285)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-templatetags.php        2010-01-09 16:16:51 UTC (rev 2284)
+++ trunk/bp-core/bp-core-templatetags.php        2010-01-10 11:38:25 UTC (rev 2285)
</span><span class="lines">@@ -1310,6 +1310,22 @@
</span><span class="cx">                 return apply_filters( 'bp_get_loggedin_user_fullname', $bp-&gt;loggedin_user-&gt;fullname );
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+function bp_displayed_user_username() {
+        echo bp_get_displayed_user_username();
+}
+        function bp_get_displayed_user_username() {
+                global $bp;
+                return apply_filters( 'bp_get_displayed_user_username', bp_core_get_username( $bp-&gt;displayed_user-&gt;id, $bp-&gt;displayed_user-&gt;userdata-&gt;user_nicename, $bp-&gt;displayed_user-&gt;userdata-&gt;user_login ) );
+        }
+
+function bp_loggedin_user_username() {
+        echo bp_get_loggedin_user_username();
+}
+        function bp_get_loggedin_user_username() {
+                global $bp;
+                return apply_filters( 'bp_get_loggedin_user_username', bp_core_get_username( $bp-&gt;loggedin_user-&gt;id, $bp-&gt;loggedin_user-&gt;userdata-&gt;user_nicename, $bp-&gt;loggedin_user-&gt;userdata-&gt;user_login ) );
+        }
+
</ins><span class="cx"> function bp_current_component() {
</span><span class="cx">         global $bp;
</span><span class="cx">         return apply_filters( 'bp_current_component', $bp-&gt;current_component );
</span></span></pre></div>
<a id="trunkbpcorephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core.php (2284 => 2285)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core.php        2010-01-09 16:16:51 UTC (rev 2284)
+++ trunk/bp-core.php        2010-01-10 11:38:25 UTC (rev 2285)
</span><span class="lines">@@ -536,31 +536,23 @@
</span><span class="cx"> 
</span><span class="cx">         if ( !$user_id ) return;
</span><span class="cx"> 
</span><del>-        if ( $domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) )
-                return apply_filters( 'bp_core_get_user_domain', $domain );
</del><ins>+        if ( !$domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) ) {
+                $username = bp_core_get_username( $user_id, $user_nicename, $user_login );
</ins><span class="cx"> 
</span><del>-        if ( !$user_nicename &amp;&amp; !$user_login ) {
-                $ud = get_userdata($user_id);
-                $user_nicename = $ud-&gt;user_nicename;
-                $user_login = $ud-&gt;user_login;
</del><ins>+                /* If we are using a members slug, include it. */
+                if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
+                        $domain = $bp-&gt;root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
+                else
+                        $domain = $bp-&gt;root_domain . '/' . $username . '/';
+
+                /* Cache the link */
+                wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
-                $username = $user_login;
-        else
-                $username = $user_nicename;
-
-        /* If we are using a members slug, include it. */
-        if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
-                $domain = $bp-&gt;root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
-        else
-                $domain = $bp-&gt;root_domain . '/' . $username . '/';
-
-        /* Cache the link */
-        wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
-
</del><span class="cx">         return apply_filters( 'bp_core_get_user_domain', $domain );
</span><span class="cx"> }
</span><ins>+/* DEPRECATED */
+function bp_core_get_userurl( $uid ) { return bp_core_get_user_domain( $uid ); }
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><span class="cx">  * bp_core_get_core_userdata()
</span><span class="lines">@@ -991,40 +983,38 @@
</span><span class="cx">  * @return false on no match
</span><span class="cx">  * @return str the username of the matched user.
</span><span class="cx">  */
</span><del>-function bp_core_get_username( $uid ) {
-        global $userdata;
</del><ins>+function bp_core_get_username( $uid, $user_nicename = false, $user_login = false ) {
+        global $bp;
</ins><span class="cx"> 
</span><del>-        if ( $uid == $userdata-&gt;ID )
-                $username =  __( 'You', 'buddypress' );
</del><ins>+        if ( !$username = wp_cache_get( 'bp_user_username_' . $uid, 'bp' ) ) {
+                if ( empty( $user_nicename ) &amp;&amp; empty( $user_login ) ) {
+                        $ud = false;
</ins><span class="cx"> 
</span><del>-        if ( !$ud = get_userdata($uid) )
-                return false;
</del><ins>+                        if ( $bp-&gt;loggedin_user-&gt;id == $uid )
+                                $ud = &amp;$bp-&gt;loggedin_user-&gt;userdata;
</ins><span class="cx"> 
</span><del>-        $username = $ud-&gt;user_login;
</del><ins>+                        if ( $bp-&gt;displayed_user-&gt;id == $uid )
+                                $ud = &amp;$bp-&gt;displayed_user-&gt;userdata;
</ins><span class="cx"> 
</span><del>-        return apply_filters( 'bp_core_get_username', $username );
-}
</del><ins>+                        if ( empty( $ud ) ) {
+                                if ( !$ud = bp_core_get_core_userdata($uid) )
+                                        return false;
</ins><span class="cx"> 
</span><del>-/**
- * bp_core_get_userurl()
- *
- * Returns the URL with no HTML markup for a user based on their user id.
- *
- * @package BuddyPress Core
- * @param $uid int User ID to check.
- * @global $userdata WordPress user data for the current logged in user.
- * @uses get_userdata() WordPress function to fetch the userdata for a user ID
- * @return false on no match
- * @return str The URL for the user with no HTML formatting.
- */
-function bp_core_get_userurl( $uid ) {
-        global $bp;
</del><ins>+                                $user_nicename = $ud-&gt;user_nicename;
+                                $user_login = $ud-&gt;user_login;
+                        }
+                }
</ins><span class="cx"> 
</span><del>-        if ( !$url = wp_cache_get( 'bp_user_url_' . $uid, 'bp' ) ) {
-                $url = bp_core_get_user_domain( $uid );
</del><ins>+                if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
+                        $username = $user_login;
+                else
+                        $username = $user_nicename;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        return apply_filters( 'bp_core_get_userurl', $url );
</del><ins>+        /* Add this to cache */
+        wp_cache_set( 'bp_user_username_' . $uid, 'bp' );
+
+        return apply_filters( 'bp_core_get_username', $username );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -1081,7 +1071,7 @@
</span><span class="cx">         if ( $no_anchor )
</span><span class="cx">                 return $display_name;
</span><span class="cx"> 
</span><del>-        if ( !$url = bp_core_get_userurl($user_id) )
</del><ins>+        if ( !$url = bp_core_get_user_domain($user_id) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         if ( $just_link )
</span></span></pre></div>
<a id="trunkbpfriendsbpfriendstemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-templatetags.php (2284 => 2285)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-templatetags.php        2010-01-09 16:16:51 UTC (rev 2284)
+++ trunk/bp-friends/bp-friends-templatetags.php        2010-01-10 11:38:25 UTC (rev 2285)
</span><span class="lines">@@ -43,7 +43,7 @@
</span><span class="cx">                         &lt;ul class=&quot;horiz-gallery&quot;&gt;
</span><span class="cx">                         &lt;?php for ( $i = 0; $i &lt; count( $friend_ids ); $i++ ) { ?&gt;
</span><span class="cx">                                 &lt;li&gt;
</span><del>-                                        &lt;a href=&quot;&lt;?php echo bp_core_get_userurl( $friend_ids[$i] ) ?&gt;&quot;&gt;&lt;?php echo bp_core_fetch_avatar( array( 'item_id' =&gt; $friend_ids[$i], 'type' =&gt; 'thumb' ) ) ?&gt;&lt;/a&gt;
</del><ins>+                                        &lt;a href=&quot;&lt;?php echo bp_core_get_domain( $friend_ids[$i] ) ?&gt;&quot;&gt;&lt;?php echo bp_core_fetch_avatar( array( 'item_id' =&gt; $friend_ids[$i], 'type' =&gt; 'thumb' ) ) ?&gt;&lt;/a&gt;
</ins><span class="cx">                                         &lt;h5&gt;&lt;?php echo bp_core_get_userlink($friend_ids[$i]) ?&gt;&lt;/h5&gt;
</span><span class="cx">                                 &lt;/li&gt;
</span><span class="cx">                         &lt;?php } ?&gt;
</span><span class="lines">@@ -70,7 +70,7 @@
</span><span class="cx">                 &lt;ul class=&quot;item-list&quot; id=&quot;random-members-list&quot;&gt;
</span><span class="cx">                 &lt;?php for ( $i = 0; $i &lt; count( $user_ids['users'] ); $i++ ) { ?&gt;
</span><span class="cx">                         &lt;li&gt;
</span><del>-                                &lt;a href=&quot;&lt;?php echo bp_core_get_userurl( $user_ids['users'][$i]-&gt;user_id ) ?&gt;&quot;&gt;&lt;?php echo bp_core_fetch_avatar( array( 'item_id' =&gt; $user_ids['users'][$i]-&gt;user_id, 'type' =&gt; 'thumb' ) ) ?&gt;&lt;/a&gt;
</del><ins>+                                &lt;a href=&quot;&lt;?php echo bp_core_get_user_domain( $user_ids['users'][$i]-&gt;user_id ) ?&gt;&quot;&gt;&lt;?php echo bp_core_fetch_avatar( array( 'item_id' =&gt; $user_ids['users'][$i]-&gt;user_id, 'type' =&gt; 'thumb' ) ) ?&gt;&lt;/a&gt;
</ins><span class="cx">                                 &lt;h5&gt;&lt;?php echo bp_core_get_userlink($user_ids['users'][$i]-&gt;user_id) ?&gt;&lt;/h5&gt;
</span><span class="cx">                                 &lt;?php if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?&gt;
</span><span class="cx">                                         &lt;?php $random_data = xprofile_get_random_profile_data( $user_ids['users'][$i]-&gt;user_id, true ); ?&gt;
</span></span></pre></div>
<a id="trunkbpfriendsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends.php (2284 => 2285)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends.php        2010-01-09 16:16:51 UTC (rev 2284)
+++ trunk/bp-friends.php        2010-01-10 11:38:25 UTC (rev 2285)
</span><span class="lines">@@ -312,7 +312,7 @@
</span><span class="cx">                                 return apply_filters( 'bp_friends_multiple_friendship_accepted_notification', '&lt;a href=&quot;' . $bp-&gt;loggedin_user-&gt;domain . $bp-&gt;friends-&gt;slug . '/my-friends/newest&quot; title=&quot;' . __( 'My Friends', 'buddypress' ) . '&quot;&gt;' . sprintf( __('%d friends accepted your friendship requests', 'buddypress' ), (int)$total_items ) . '&lt;/a&gt;', (int)$total_items );
</span><span class="cx">                         } else {
</span><span class="cx">                                 $user_fullname = bp_core_get_user_displayname( $item_id );
</span><del>-                                $user_url = bp_core_get_userurl( $item_id );
</del><ins>+                                $user_url = bp_core_get_domain( $item_id );
</ins><span class="cx">                                 return apply_filters( 'bp_friends_single_friendship_accepted_notification', '&lt;a href=&quot;' . $user_url . '?new&quot; title=&quot;' . $user_fullname .'\'s profile&quot;&gt;' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $user_fullname ) . '&lt;/a&gt;', $user_fullname );
</span><span class="cx">                         }
</span><span class="cx">                 break;
</span><span class="lines">@@ -322,7 +322,7 @@
</span><span class="cx">                                 return apply_filters( 'bp_friends_multiple_friendship_request_notification', '&lt;a href=&quot;' . $bp-&gt;loggedin_user-&gt;domain . $bp-&gt;friends-&gt;slug . '/requests&quot; title=&quot;' . __( 'Friendship requests', 'buddypress' ) . '&quot;&gt;' . sprintf( __('You have %d pending friendship requests', 'buddypress' ), (int)$total_items ) . '&lt;/a&gt;', $total_items );
</span><span class="cx">                         } else {
</span><span class="cx">                                 $user_fullname = bp_core_get_user_displayname( $item_id );
</span><del>-                                $user_url = bp_core_get_userurl( $item_id );
</del><ins>+                                $user_url = bp_core_get_user_domain( $item_id );
</ins><span class="cx">                                 return apply_filters( 'bp_friends_single_friendship_request_notification', '&lt;a href=&quot;' . $bp-&gt;loggedin_user-&gt;domain . $bp-&gt;friends-&gt;slug . '/requests&quot; title=&quot;' . __( 'Friendship requests', 'buddypress' ) . '&quot;&gt;' . sprintf( __('You have a friendship request from %s', 'buddypress' ), $user_fullname ) . '&lt;/a&gt;', $user_fullname );
</span><span class="cx">                         }
</span><span class="cx">                 break;
</span><span class="lines">@@ -418,7 +418,7 @@
</span><span class="cx">                 $initiator_link = bp_core_get_userlink( $friendship-&gt;initiator_user_id );
</span><span class="cx">                 $friend_link = bp_core_get_userlink( $friendship-&gt;friend_user_id );
</span><span class="cx"> 
</span><del>-                $primary_link = apply_filters( 'friends_activity_friendship_accepted_primary_link', bp_core_get_userurl( $friendship-&gt;initiator_user_id ), &amp;$friendship );
</del><ins>+                $primary_link = apply_filters( 'friends_activity_friendship_accepted_primary_link', bp_core_get_user_domain( $friendship-&gt;initiator_user_id ), &amp;$friendship );
</ins><span class="cx"> 
</span><span class="cx">                 /* Record in activity streams for the initiator */
</span><span class="cx">                 friends_record_activity( array(
</span></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (2284 => 2285)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2010-01-09 16:16:51 UTC (rev 2284)
+++ trunk/bp-groups.php        2010-01-10 11:38:25 UTC (rev 2285)
</span><span class="lines">@@ -1510,7 +1510,7 @@
</span><span class="cx">                         $group_id = $item_id;
</span><span class="cx"> 
</span><span class="cx">                         $group = new BP_Groups_Group( $group_id, false, false );
</span><del>-                        $user_url = bp_core_get_userurl( $user_id );
</del><ins>+                        $user_url = bp_core_get_domain( $user_id );
</ins><span class="cx"> 
</span><span class="cx">                         if ( (int)$total_items &gt; 1 ) {
</span><span class="cx">                                 return apply_filters( 'bp_groups_multiple_group_invite_notification', '&lt;a href=&quot;' . $bp-&gt;loggedin_user-&gt;domain . $bp-&gt;groups-&gt;slug . '/invites&quot; title=&quot;' . __( 'Group Invites', 'buddypress' ) . '&quot;&gt;' . sprintf( __('You have %d new group invitations', 'buddypress' ), (int)$total_items ) . '&lt;/a&gt;', $total_items );
</span></span></pre>
</div>
</div>

</body>
</html>