<!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][11818] trunk: Use WP functions to retrieve user data.</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/11818">11818</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/11818","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dcavins</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-01-25 19:44:54 +0000 (Thu, 25 Jan 2018)</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'>Use WP functions to retrieve user data.
Use WP functions to retrieve user name, display name, nicename, and email.
Switch functions like `bp_core_get_username()` to use native WordPress functions. This also removes the need for maintaining redundant cached items, like caching individual usernames, and instead relies upon WP's userdata cache.
Props dcavins, djpaul.
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/7661">#7661</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpcoreclassesclassbpcoreuserphp">trunk/src/bp-core/classes/class-bp-core-user.php</a></li>
<li><a href="#trunksrcbpmembersbpmembersfunctionsphp">trunk/src/bp-members/bp-members-functions.php</a></li>
<li><a href="#trunksrcbpxprofilebpxprofilecachephp">trunk/src/bp-xprofile/bp-xprofile-cache.php</a></li>
<li><a href="#trunktestsphpunittestcasesmembersfunctionsphp">trunk/tests/phpunit/testcases/members/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpcoreclassesclassbpcoreuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/classes/class-bp-core-user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/classes/class-bp-core-user.php 2018-01-25 19:44:49 UTC (rev 11817)
+++ trunk/src/bp-core/classes/class-bp-core-user.php 2018-01-25 19:44:54 UTC (rev 11818)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -166,11 +166,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->email = esc_attr( bp_core_get_user_email( $this->id ) );
</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">- // Cache a few things that are fetched often.
- wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' );
- wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' );
- wp_cache_set( 'bp_user_url_' . $this->id, $this->user_url, 'bp' );
-
</del><span class="cx" style="display: block; padding: 0 10px"> $this->avatar = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'full', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->fullname ) ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->fullname ) ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->fullname ), 'width' => 30, 'height' => 30 ) );
</span></span></pre></div>
<a id="trunksrcbpmembersbpmembersfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-members/bp-members-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-members/bp-members-functions.php 2018-01-25 19:44:49 UTC (rev 11817)
+++ trunk/src/bp-members/bp-members-functions.php 2018-01-25 19:44:54 UTC (rev 11818)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -304,68 +304,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $user_id User ID to check.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string|bool $user_nicename Optional. user_nicename of user being checked.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string|bool $user_login Optional. user_login of user being checked.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string|bool The username of the matched user, or false.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string The username of the matched user or an empty string if no user is found.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_core_get_username( $user_id = 0, $user_nicename = false, $user_login = false ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $bp = buddypress();
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Check cache for user nicename.
- $username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' );
- if ( false === $username ) {
-
- // Cache not found so prepare to update it.
- $update_cache = true;
-
- // Nicename and login were not passed.
- if ( empty( $user_nicename ) && empty( $user_login ) ) {
-
- // User ID matches logged in user.
- if ( bp_loggedin_user_id() == $user_id ) {
- $userdata = &$bp->loggedin_user->userdata;
-
- // User ID matches displayed in user.
- } elseif ( bp_displayed_user_id() == $user_id ) {
- $userdata = &$bp->displayed_user->userdata;
-
- // No user ID match.
- } else {
- $userdata = false;
- }
-
- // No match so go dig.
- if ( empty( $userdata ) ) {
-
- // User not found so return false.
- if ( !$userdata = bp_core_get_core_userdata( $user_id ) ) {
- return false;
- }
- }
-
- // Update the $user_id for later.
- $user_id = $userdata->ID;
-
- // Two possible options.
- $user_nicename = $userdata->user_nicename;
- $user_login = $userdata->user_login;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $user_nicename && ! $user_login ) {
+ // Pull an audible and maybe use the login over the nicename.
+ if ( bp_is_username_compatibility_mode() ) {
+ $username = get_the_author_meta( 'login', $user_id );
+ } else {
+ $username = get_the_author_meta( 'nicename', $user_id );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- // Pull an audible and maybe use the login over the nicename.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } else {
</ins><span class="cx" style="display: block; padding: 0 10px"> $username = bp_is_username_compatibility_mode() ? $user_login : $user_nicename;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- // Username found in cache so don't update it again.
- } else {
- $update_cache = false;
</del><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">- // Add this to cache.
- if ( ( true === $update_cache ) && !empty( $username ) ) {
- wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );
-
- // @todo bust this cache if no $username found?
- // } else {
- // wp_cache_delete( 'bp_user_username_' . $user_id );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the username based on originally provided user ID.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -384,52 +337,10 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @todo Refactor to use a WP core function, if possible.
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @param int $user_id User ID to check.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string|bool The username of the matched user, or false.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string The username of the matched user or an empty string if no user is found.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_members_get_user_nicename( $user_id ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $bp = buddypress();
-
- if ( !$user_nicename = wp_cache_get( 'bp_members_user_nicename_' . $user_id, 'bp' ) ) {
- $update_cache = true;
-
- // User ID matches logged in user.
- if ( bp_loggedin_user_id() == $user_id ) {
- $userdata = &$bp->loggedin_user->userdata;
-
- // User ID matches displayed in user.
- } elseif ( bp_displayed_user_id() == $user_id ) {
- $userdata = &$bp->displayed_user->userdata;
-
- // No user ID match.
- } else {
- $userdata = false;
- }
-
- // No match so go dig.
- if ( empty( $userdata ) ) {
-
- // User not found so return false.
- if ( !$userdata = bp_core_get_core_userdata( $user_id ) ) {
- return false;
- }
- }
-
- // User nicename found.
- $user_nicename = $userdata->user_nicename;
-
- // Nicename found in cache so don't update it again.
- } else {
- $update_cache = false;
- }
-
- // Add this to cache.
- if ( true == $update_cache && !empty( $user_nicename ) ) {
- wp_cache_set( 'bp_members_user_nicename_' . $user_id, $user_nicename, 'bp' );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the user_nicename based on originally provided user ID.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -437,7 +348,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $username User nice name determined by user ID.
</span><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_members_get_user_nicename', $user_nicename );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( 'bp_members_get_user_nicename', get_the_author_meta( 'nicename', $user_id ) );
</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">@@ -447,25 +358,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $uid User ID to check.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string The email for the matched user. Empty string if no user
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * matched the $uid.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * matches the $user_id.
</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_core_get_user_email( $uid ) {
-
- if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {
-
- // User exists.
- $ud = bp_core_get_core_userdata( $uid );
- if ( ! empty( $ud ) ) {
- $email = $ud->user_email;
-
- // User was deleted.
- } else {
- $email = '';
- }
-
- wp_cache_set( 'bp_user_email_' . $uid, $email, 'bp' );
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function bp_core_get_user_email( $user_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the user email for user based on user ID.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -473,7 +368,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $email Email determined for the user.
</span><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_core_get_user_email', $email );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( 'bp_core_get_user_email', get_the_author_meta( 'email', $user_id ) );
</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">@@ -532,7 +427,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $user_ids Array of user IDs to get display names for.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return array
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return array Associative array of the format "id" => "displayname".
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_core_get_user_displaynames( $user_ids ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -546,62 +441,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return array();
</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">- $uncached_ids = array();
- foreach ( $user_ids as $user_id ) {
- if ( false === wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {
- $uncached_ids[] = $user_id;
- }
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Warm the WP users cache with a targeted bulk update.
+ cache_users( $user_ids );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Prime caches.
- if ( ! empty( $uncached_ids ) ) {
- if ( bp_is_active( 'xprofile' ) ) {
- $fullname_data = BP_XProfile_ProfileData::get_value_byid( 1, $uncached_ids );
-
- // Key by user_id.
- $fullnames = array();
- foreach ( $fullname_data as $fd ) {
- if ( ! empty( $fd->value ) ) {
- $fullnames[ intval( $fd->user_id ) ] = $fd->value;
- }
- }
-
- // If xprofiledata is not found for any users, we'll look
- // them up separately.
- $no_xprofile_ids = array_diff( $uncached_ids, array_keys( $fullnames ) );
- } else {
- $fullnames = array();
- $no_xprofile_ids = $user_ids;
- }
-
- if ( ! empty( $no_xprofile_ids ) ) {
- // Use WP_User_Query because we don't need BP information.
- $query = new WP_User_Query( array(
- 'include' => $no_xprofile_ids,
- 'fields' => array( 'ID', 'user_nicename', 'display_name', ),
- 'count_total' => false,
- 'blog_id' => 0,
- ) );
-
- foreach ( $query->results as $qr ) {
- $fullnames[ $qr->ID ] = ! empty( $qr->display_name ) ? $qr->display_name : $qr->user_nicename;
-
- // If xprofile is active, set this value as the
- // xprofile display name as well.
- if ( bp_is_active( 'xprofile' ) ) {
- xprofile_set_field_data( 1, $qr->ID, $fullnames[ $qr->ID ] );
- }
- }
- }
-
- foreach ( $fullnames as $fuser_id => $fname ) {
- wp_cache_set( 'bp_user_fullname_' . $fuser_id, $fname, 'bp' );
- }
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $retval = array();
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $user_ids as $user_id ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $retval[ $user_id ] = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $retval[ $user_id ] = bp_core_get_user_displayname( $user_id );
</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"> return $retval;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -631,14 +476,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</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">- $display_names = bp_core_get_user_displaynames( array( $user_id ) );
-
- if ( ! isset( $display_names[ $user_id ] ) ) {
- $fullname = false;
- } else {
- $fullname = $display_names[ $user_id ];
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the display name for the passed in user.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -647,7 +484,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $fullname Display name for the user.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $user_id ID of the user to check.
</span><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_core_get_user_displayname', $fullname, $user_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( 'bp_core_get_user_displayname', get_the_author_meta( 'display_name', $user_id ), $user_id );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_core_get_user_displayname', 'trim' );
</span></span></pre></div>
<a id="trunksrcbpxprofilebpxprofilecachephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/bp-xprofile-cache.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/bp-xprofile-cache.php 2018-01-25 19:44:49 UTC (rev 11817)
+++ trunk/src/bp-xprofile/bp-xprofile-cache.php 2018-01-25 19:44:54 UTC (rev 11818)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -190,35 +190,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'xprofile_group_after_save', 'xprofile_clear_profile_groups_object_cache' );
</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">- * Clear cached XProfile fullname data for user.
- *
- * @since 2.1.0
- *
- * @param int $user_id ID of user whose fullname cache to delete.
- */
-function xprofile_clear_profile_data_object_cache( $user_id = 0 ) {
- wp_cache_delete( 'bp_user_fullname_' . $user_id, 'bp' );
-}
-add_action( 'xprofile_updated_profile', 'xprofile_clear_profile_data_object_cache' );
-
-/**
- * Clear the fullname cache when field 1 is updated.
- *
- * The xprofile_clear_profile_data_object_cache() will make this redundant in most
- * cases, except where the field is updated directly with xprofile_set_field_data().
- *
- * @since 2.0.0
- *
- * @param object $data Data object to clear.
- */
-function xprofile_clear_fullname_cache_on_profile_field_edit( $data ) {
- if ( 1 == $data->field_id ) {
- wp_cache_delete( 'bp_user_fullname_' . $data->user_id, 'bp' );
- }
-}
-add_action( 'xprofile_data_after_save', 'xprofile_clear_fullname_cache_on_profile_field_edit' );
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * Clear caches when a field object is modified.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.0
</span></span></pre></div>
<a id="trunktestsphpunittestcasesmembersfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/members/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/members/functions.php 2018-01-25 19:44:49 UTC (rev 11817)
+++ trunk/tests/phpunit/testcases/members/functions.php 2018-01-25 19:44:54 UTC (rev 11818)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -101,45 +101,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"> * @group bp_core_get_user_displayname
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @group cache
</del><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_bp_core_get_user_displayname_xprofile_populate_cache() {
- $xprofile_is_active = bp_is_active( 'xprofile' );
- buddypress()->active_components['xprofile'] = '1';
-
- $u = self::factory()->user->create( array(
- 'display_name' => 'Foo',
- ) );
- bp_core_get_user_displayname( $u );
-
- $this->assertSame( 'Foo', wp_cache_get( 'bp_user_fullname_' . $u, 'bp' ) );
-
- if ( ! $xprofile_is_active ) {
- unset( buddypress()->active_components['xprofile'] );
- }
- }
-
- /**
- * @group bp_core_get_user_displayname
- * @group cache
- */
- public function test_bp_core_get_user_displayname_xprofile_bust_cache_after_xprofile_update() {
- $xprofile_is_active = bp_is_active( 'xprofile' );
- buddypress()->active_components['xprofile'] = '1';
-
- $u = self::factory()->user->create();
- xprofile_set_field_data( 1, $u, 'Foo Foo' );
-
- $this->assertFalse( wp_cache_get( 'bp_user_fullname_' . $u, 'bp' ) );
-
- if ( ! $xprofile_is_active ) {
- unset( buddypress()->active_components['xprofile'] );
- }
- }
-
- /**
- * @group bp_core_get_user_displayname
- */
</del><span class="cx" style="display: block; padding: 0 10px"> public function test_bp_core_get_user_displayname_xprofile_exists() {
</span><span class="cx" style="display: block; padding: 0 10px"> $xprofile_is_active = bp_is_active( 'xprofile' );
</span><span class="cx" style="display: block; padding: 0 10px"> buddypress()->active_components['xprofile'] = '1';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -155,34 +117,6 @@
</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">- * @group bp_core_get_user_displayname
- */
- public function test_bp_core_get_user_displayname_xprofile_does_not_exist() {
- $bp = buddypress();
- $xprofile_is_active = bp_is_active( 'xprofile' );
- $bp->active_components['xprofile'] = '1';
-
- $u = self::factory()->user->create( array(
- 'display_name' => 'Foo Foo',
- ) );
-
- // Delete directly because BP won't let you delete a required
- // field through the API
- global $wpdb;
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = 1", $u ) );
- wp_cache_delete( 'bp_user_fullname_' . $u, 'bp' );
- wp_cache_delete( "{$u}:1", 'bp_xprofile_data' );
-
- $this->assertSame( '', xprofile_get_field_data( 1, $u ) );
- $this->assertSame( 'Foo Foo', bp_core_get_user_displayname( $u ) );
- $this->assertSame( 'Foo Foo', xprofile_get_field_data( 1, $u ) );
-
- if ( ! $xprofile_is_active ) {
- unset( $bp->active_components['xprofile'] );
- }
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * @group bp_core_get_user_displaynames
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_bp_core_get_user_displayname_arrays_all_bad_entries() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -195,7 +129,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_bp_core_get_user_displaynames_all_uncached() {
</span><span class="cx" style="display: block; padding: 0 10px"> $u1 = self::factory()->user->create();
</span><span class="cx" style="display: block; padding: 0 10px"> $u2 = self::factory()->user->create();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> xprofile_set_field_data( 1, $u1, 'Foo' );
</span><span class="cx" style="display: block; padding: 0 10px"> xprofile_set_field_data( 1, $u2, 'Bar' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -215,17 +148,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $u2 = self::factory()->user->create( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'display_name' => 'Bar',
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> xprofile_set_field_data( 1, $u1, 'Foo' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Delete directly because BP won't let you delete a required
- // field through the API
- global $wpdb;
- $bp = buddypress();
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = 1", $u2 ) );
- wp_cache_delete( 'bp_user_fullname_' . $u2, 'bp' );
- wp_cache_delete( "{$u2}:1", 'bp_xprofile_data' );
-
</del><span class="cx" style="display: block; padding: 0 10px"> $expected = array(
</span><span class="cx" style="display: block; padding: 0 10px"> $u1 => 'Foo',
</span><span class="cx" style="display: block; padding: 0 10px"> $u2 => 'Bar',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -235,25 +159,6 @@
</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">- * @group bp_core_get_user_displaynames
- */
- public function test_bp_core_get_user_displaynames_one_in_cache() {
- $u1 = self::factory()->user->create();
- xprofile_set_field_data( 1, $u1, 'Foo' );
-
- // Fake the cache for $u2
- $u2 = 123;
- wp_cache_set( 'bp_user_fullname_' . $u2, 'Bar', 'bp' );
-
- $expected = array(
- $u1 => 'Foo',
- $u2 => 'Bar',
- );
-
- $this->assertSame( $expected, bp_core_get_user_displaynames( array( $u1, $u2, ) ) );
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * @group bp_members_migrate_signups
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_bp_members_migrate_signups_standard() {
</span></span></pre>
</div>
</div>
</body>
</html>