<!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][7556] trunk/bp-friends: Improve inline docs in bp-friends.</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">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/7556">7556</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2013-11-10 02:43:45 +0000 (Sun, 10 Nov 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Improve inline docs in bp-friends. See <a href="http://buddypress.trac.wordpress.org/ticket/5022">#5022</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpfriendsbpfriendsactionsphp">trunk/bp-friends/bp-friends-actions.php</a></li>
<li><a href="#trunkbpfriendsbpfriendsactivityphp">trunk/bp-friends/bp-friends-activity.php</a></li>
<li><a href="#trunkbpfriendsbpfriendscachephp">trunk/bp-friends/bp-friends-cache.php</a></li>
<li><a href="#trunkbpfriendsbpfriendsclassesphp">trunk/bp-friends/bp-friends-classes.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpfriendsbpfriendsactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-actions.php (7555 => 7556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-actions.php 2013-11-10 02:04:14 UTC (rev 7555)
+++ trunk/bp-friends/bp-friends-actions.php 2013-11-10 02:43:45 UTC (rev 7556)
</span><span class="lines">@@ -3,9 +3,9 @@
</span><span class="cx"> /**
</span><span class="cx"> * BuddyPress Friends Actions
</span><span class="cx"> *
</span><del>- * Action functions are exactly the same as screen functions, however they do not
- * have a template screen associated with them. Usually they will send the user
- * back to the default screen after execution.
</del><ins>+ * Action functions are exactly the same as screen functions, however they do
+ * not have a template screen associated with them. Usually they will send the
+ * user back to the default screen after execution.
</ins><span class="cx"> *
</span><span class="cx"> * @package BuddyPress
</span><span class="cx"> * @subpackage FriendsActions
</span><span class="lines">@@ -14,6 +14,9 @@
</span><span class="cx"> // Exit if accessed directly
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx">
</span><ins>+/**
+ * Catch and process friendship requests.
+ */
</ins><span class="cx"> function friends_action_add_friend() {
</span><span class="cx"> if ( !bp_is_friends_component() || !bp_is_current_action( 'add-friend' ) )
</span><span class="cx"> return false;
</span><span class="lines">@@ -49,6 +52,9 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'bp_init', 'friends_action_add_friend' );
</span><span class="cx">
</span><ins>+/**
+ * Catch and process Remove Friendship requests.
+ */
</ins><span class="cx"> function friends_action_remove_friend() {
</span><span class="cx"> if ( !bp_is_friends_component() || !bp_is_current_action( 'remove-friend' ) )
</span><span class="cx"> return false;
</span></span></pre></div>
<a id="trunkbpfriendsbpfriendsactivityphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-activity.php (7555 => 7556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-activity.php 2013-11-10 02:04:14 UTC (rev 7555)
+++ trunk/bp-friends/bp-friends-activity.php 2013-11-10 02:43:45 UTC (rev 7556)
</span><span class="lines">@@ -13,6 +13,24 @@
</span><span class="cx"> // Exit if accessed directly
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx">
</span><ins>+/**
+ * Record an activity item related to the Friends component.
+ *
+ * A wrapper for {@link bp_activity_add()} that provides some Friends-specific
+ * defaults.
+ *
+ * @see bp_activity_add() for more detailed description of parameters and
+ * return values.
+ *
+ * @param array $args {
+ * An array of arguments for the new activity item. Accepts all parameters
+ * of {@link bp_activity_add()}. The one difference is the following
+ * argument, which has a different default here:
+ * @type string $component Default: the id of your Friends component
+ * (usually 'friends').
+ * }
+ * @return bool See {@link bp_activity_add()}.
+ */
</ins><span class="cx"> function friends_record_activity( $args = '' ) {
</span><span class="cx"> global $bp;
</span><span class="cx">
</span><span class="lines">@@ -38,6 +56,20 @@
</span><span class="cx"> return bp_activity_add( array( 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Delete an activity item related to the Friends component.
+ *
+ * @param array $args {
+ * An array of arguments for the item to delete.
+ * @type int $item_id ID of the 'item' associated with the activity item.
+ * For Friends activity items, this is usually the user ID of one
+ * of the friends.
+ * @type string $type The 'type' of the activity item (eg
+ * 'friendship_accepted').
+ * @type int $user_id ID of the user associated with the activity item.
+ * }
+ * @return bool True on success, false on failure.
+ */
</ins><span class="cx"> function friends_delete_activity( $args ) {
</span><span class="cx"> global $bp;
</span><span class="cx">
</span><span class="lines">@@ -47,6 +79,9 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Register the activity actions for bp-friends.
+ */
</ins><span class="cx"> function friends_register_activity_actions() {
</span><span class="cx"> global $bp;
</span><span class="cx">
</span><span class="lines">@@ -65,15 +100,16 @@
</span><span class="cx"> add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' );
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Format the BuddyBar/Toolbar notifications for the Friends component
</del><ins>+ * Notification formatting callback for bp-friends notifications.
</ins><span class="cx"> *
</span><del>- * @package BuddyPress
- *
- * @param string $action The kind of notification being rendered
- * @param int $item_id The primary item id
- * @param int $secondary_item_id The secondary item id
- * @param int $total_items The total number of messaging-related notifications waiting for the user
- * @param string $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar
</del><ins>+ * @param string $action The kind of notification being rendered.
+ * @param int $item_id The primary item ID.
+ * @param int $secondary_item_id The secondary item ID.
+ * @param int $total_items The total number of messaging-related notifications
+ * waiting for the user.
+ * @param string $format 'string' for BuddyBar-compatible notifications;
+ * 'array' for WP Toolbar. Default: 'string'.
+ * @return array|string
</ins><span class="cx"> */
</span><span class="cx"> function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpfriendsbpfriendscachephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-cache.php (7555 => 7556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-cache.php 2013-11-10 02:04:14 UTC (rev 7555)
+++ trunk/bp-friends/bp-friends-cache.php 2013-11-10 02:43:45 UTC (rev 7556)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * BuddyPress Friends Caching
</del><ins>+ * BuddyPress Friends Caching.
</ins><span class="cx"> *
</span><span class="cx"> * Caching functions handle the clearing of cached objects and pages on specific
</span><span class="cx"> * actions throughout BuddyPress.
</span><span class="lines">@@ -14,6 +14,12 @@
</span><span class="cx"> // Exit if accessed directly
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx">
</span><ins>+/**
+ * Clear friends-related cache for members of a specific friendship.
+ *
+ * @param int $friendship_id ID of the friendship whose two members should
+ * have their friends cache busted.
+ */
</ins><span class="cx"> function friends_clear_friend_object_cache( $friendship_id ) {
</span><span class="cx"> if ( !$friendship = new BP_Friends_Friendship( $friendship_id ) )
</span><span class="cx"> return false;
</span><span class="lines">@@ -22,6 +28,9 @@
</span><span class="cx"> wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Clear friend-related notifications when ?new=1.
+ */
</ins><span class="cx"> function friends_clear_friend_notifications() {
</span><span class="cx"> if ( isset( $_GET['new'] ) ) {
</span><span class="cx"> bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
</span></span></pre></div>
<a id="trunkbpfriendsbpfriendsclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-classes.php (7555 => 7556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-classes.php 2013-11-10 02:04:14 UTC (rev 7555)
+++ trunk/bp-friends/bp-friends-classes.php 2013-11-10 02:43:45 UTC (rev 7556)
</span><span class="lines">@@ -9,19 +9,95 @@
</span><span class="cx"> // Exit if accessed directly
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx">
</span><ins>+/**
+ * BuddyPress Friendship object.
+ */
</ins><span class="cx"> class BP_Friends_Friendship {
</span><ins>+
+ /**
+ * ID of the friendship.
+ *
+ * @access public
+ * @var int
+ */
</ins><span class="cx"> public $id;
</span><ins>+
+ /**
+ * User ID of the friendship initiator.
+ *
+ * @access public
+ * @var int
+ */
</ins><span class="cx"> public $initiator_user_id;
</span><ins>+
+ /**
+ * User ID of the 'friend' - the one invited to the friendship.
+ *
+ * @access public
+ * @var int
+ */
</ins><span class="cx"> public $friend_user_id;
</span><ins>+
+ /**
+ * Has the friendship been confirmed/accepted?
+ *
+ * @access public
+ * @var int
+ */
</ins><span class="cx"> public $is_confirmed;
</span><ins>+
+ /**
+ * Is this a "limited" friendship?
+ *
+ * Not currently used by BuddyPress.
+ *
+ * @access public
+ * @var int
+ */
</ins><span class="cx"> public $is_limited;
</span><ins>+
+ /**
+ * Date the friendship was created.
+ *
+ * @access public
+ * @var string
+ */
</ins><span class="cx"> public $date_created;
</span><span class="cx">
</span><ins>+ /**
+ * Is this a request?
+ *
+ * Not currently used in BuddyPress.
+ *
+ * @access public
+ * @var unknown
+ */
</ins><span class="cx"> public $is_request;
</span><ins>+
+ /**
+ * Should additional friend details be queried?
+ *
+ * @access public
+ * @var bool
+ */
</ins><span class="cx"> public $populate_friend_details;
</span><span class="cx">
</span><ins>+ /**
+ * Details about the friend.
+ *
+ * @access public
+ * @var BP_Core_User
+ */
</ins><span class="cx"> public $friend;
</span><span class="cx">
</span><ins>+ /**
+ * Constructor method.
+ *
+ * @param int $id Optional. The ID of an existing friendship.
+ * @param bool $is_request Deprecated.
+ * @param bool $populate_friend_details True if friend details should
+ * be queried.
+ */
</ins><span class="cx"> public function __construct( $id = null, $is_request = false, $populate_friend_details = true ) {
</span><span class="cx"> $this->is_request = $is_request;
</span><span class="cx">
</span><span class="lines">@@ -32,6 +108,9 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Set up data about the current friendship.
+ */
</ins><span class="cx"> public function populate() {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -52,6 +131,11 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Save the current friendship to the database.
+ *
+ * @return bool True on success, false on failure.
+ */
</ins><span class="cx"> public function save() {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -85,6 +169,16 @@
</span><span class="cx">
</span><span class="cx"> /** Static Methods ********************************************************/
</span><span class="cx">
</span><ins>+ /**
+ * Get the IDs of a given user's friends.
+ *
+ * @param int $user_id ID of the user whose friends are being retreived.
+ * @param bool $friend_requests_only Optional. Whether to fetch
+ * unaccepted requests only. Default: false.
+ * @param bool $assoc_arr Optional. True to receive an array of arrays
+ * keyed as 'user_id' => $user_id; false to get a one-dimensional
+ * array of user IDs. Default: false.
+ */
</ins><span class="cx"> public static function get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -110,18 +204,41 @@
</span><span class="cx"> return $fids;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get the ID of the friendship object, if any, between a pair of users.
+ *
+ * @param int $user_id The ID of the first user.
+ * @param int $friend_id The ID of the second user.
+ * @return int|bool The ID of the friendship object if found, otherwise
+ * false.
+ */
</ins><span class="cx"> public static function get_friendship_id( $user_id, $friend_id ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="cx"> return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->friends->table_name} WHERE ( initiator_user_id = %d AND friend_user_id = %d ) OR ( initiator_user_id = %d AND friend_user_id = %d ) AND is_confirmed = 1", $user_id, $friend_id, $friend_id, $user_id ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get a list of IDs of users who have requested friendship of a given user.
+ *
+ * @param int $user_id The ID of the user who has received the
+ * friendship requests.
+ * @return array|bool An array of user IDs, or false if none are found.
+ */
</ins><span class="cx"> public static function get_friendship_request_user_ids( $user_id ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="cx"> return $wpdb->get_col( $wpdb->prepare( "SELECT initiator_user_id FROM {$bp->friends->table_name} WHERE friend_user_id = %d AND is_confirmed = 0", $user_id ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get a total friend count for a given user.
+ *
+ * @param int $user_id Optional. ID of the user whose friendships you
+ * are counting. Default: displayed user (if any), otherwise
+ * logged-in user.
+ * @return int Friend count for the user.
+ */
</ins><span class="cx"> public static function total_friend_count( $user_id = 0 ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -142,6 +259,21 @@
</span><span class="cx"> return absint( $count );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Search the friends of a user by a search string.
+ *
+ * @param string $filter The search string, matched against xprofile
+ * fields (if available), or usermeta 'nickname' field.
+ * @param int $user_id ID of the user whose friends are being searched.
+ * @param int $limit Optional. Max number of friends to return.
+ * @param int $page Optional. The page of results to return. Default:
+ * null (no pagination - return all results).
+ * @return array|bool On success, an array: {
+ * @type array $friends IDs of friends returned by the query.
+ * @type int $count Total number of friends (disregarding
+ * pagination) who match the search.
+ * }. Returns false on failure.
+ */
</ins><span class="cx"> public static function search_friends( $filter, $user_id, $limit = null, $page = null ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -184,19 +316,19 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Check friendship status between two users
</del><ins>+ * Check friendship status between two users.
</ins><span class="cx"> *
</span><span class="cx"> * Note that 'pending' means that $initiator_userid has sent a friend
</span><span class="cx"> * request to $possible_friend_userid that has not yet been approved,
</span><span class="cx"> * while 'awaiting_response' is the other way around ($possible_friend_userid
</span><span class="cx"> * sent the initial request)
</span><span class="cx"> *
</span><del>- * @param int $initiator_userid The id of the user who is the initiator
- * of the potential friendship/request.
- * @param int $possible_friend_userid The id of the user who is the
- * recipient of the potential friendship/request.
</del><ins>+ * @param int $initiator_userid The ID of the user who is the initiator
+ * of the potential friendship/request.
+ * @param int $possible_friend_userid The ID of the user who is the
+ * recipient of the potential friendship/request.
</ins><span class="cx"> * @return string The friendship status, from among 'not_friends',
</span><del>- * 'is_friend', 'pending', and 'awaiting_response'
</del><ins>+ * 'is_friend', 'pending', and 'awaiting_response'.
</ins><span class="cx"> */
</span><span class="cx"> public static function check_is_friend( $initiator_userid, $possible_friend_userid ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="lines">@@ -220,6 +352,15 @@
</span><span class="cx"> return $status;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get the last active date of many users at once.
+ *
+ * @todo Why is this in the Friends component?
+ *
+ * @param array $user_ids IDs of users whose last_active meta is
+ * being queried.
+ * @return array Array of last_active values + user_ids.
+ */
</ins><span class="cx"> public static function get_bulk_last_active( $user_ids ) {
</span><span class="cx"> global $wpdb;
</span><span class="cx">
</span><span class="lines">@@ -228,21 +369,51 @@
</span><span class="cx"> return $wpdb->get_results( $wpdb->prepare( "SELECT meta_value as last_activity, user_id FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} ) ORDER BY meta_value DESC", bp_get_user_meta_key( 'last_activity' ) ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Mark a friendship as accepted.
+ *
+ * @param int $friendship_id ID of the friendship to be accepted.
+ * @return int Number of database rows updated.
+ */
</ins><span class="cx"> public static function accept($friendship_id) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx"> return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, bp_loggedin_user_id() ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Remove a friendship or a friendship request INITIATED BY the logged-in user.
+ *
+ * @param int $friendship_id ID of the friendship to be withdrawn.
+ * @return int Number of database rows deleted.
+ */
</ins><span class="cx"> public static function withdraw($friendship_id) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx"> return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND initiator_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Remove a friendship or a friendship request MADE OF the logged-in user.
+ *
+ * @param int $friendship_id ID of the friendship to be rejected.
+ * @return int Number of database rows deleted.
+ */
</ins><span class="cx"> public static function reject($friendship_id) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx"> return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND friend_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Search users.
+ *
+ * @todo Why does this exist, and why is it in bp-friends?
+ *
+ * @param string $filter String to search by.
+ * @param int $user_id A user ID param that is unused.
+ * @param int $limit Optional. Max number of records to return.
+ * @param int $page Optional. Number of the page to return. Default:
+ * false (no pagination - return all results).
+ * @return array $filtered_ids IDs of users who match the query.
+ */
</ins><span class="cx"> public static function search_users( $filter, $user_id, $limit = null, $page = null ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -270,6 +441,14 @@
</span><span class="cx"> return $filtered_fids;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get a count of users who match a search term.
+ *
+ * @todo Why does this exist, and why is it in bp-friends?
+ *
+ * @param string $filter Search term.
+ * @return int Count of users matching the search term.
+ */
</ins><span class="cx"> public static function search_users_count( $filter ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -293,6 +472,14 @@
</span><span class="cx"> return $user_count[0];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Sort a list of user IDs by their display names.
+ *
+ * @todo Why does this exist, and why is it in bp-friends?
+ *
+ * @param array $user_ids Array of user IDs.
+ * @return array User IDs, sorted by the associated display names.
+ */
</ins><span class="cx"> public static function sort_by_name( $user_ids ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -304,6 +491,15 @@
</span><span class="cx"> return $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$bp->profile->table_name_data} pd, {$bp->profile->table_name_fields} pf WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} ) ORDER BY pd.value ASC", bp_xprofile_fullname_field_name() ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get a list of random friend IDs.
+ *
+ * @param int $user_id ID of the user whose friends are being retrieved.
+ * @param int $total_friends Optional. Number of random friends to get.
+ * Default: 5.
+ * @return array|bool An array of random friend user IDs on success;
+ * false if none are found.
+ */
</ins><span class="cx"> public static function get_random_friends( $user_id, $total_friends = 5 ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -322,6 +518,19 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get a count of a user's friends who can be invited to a given group.
+ *
+ * Users can invite any of their friends except:
+ *
+ * - users who are already in the group
+ * - users who have a pending invite to the group
+ * - users who have been banned from the group
+ *
+ * @param int $user_id ID of the user whose friends are being counted.
+ * @param int $group_id ID of the group friends are being invited to.
+ * @return int $invitable_count Eligible friend count.
+ */
</ins><span class="cx"> public static function get_invitable_friend_count( $user_id, $group_id ) {
</span><span class="cx">
</span><span class="cx"> // Setup some data we'll use below
</span><span class="lines">@@ -349,11 +558,22 @@
</span><span class="cx"> return $invitable_count;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get the friend user IDs for a given friendship.
+ *
+ * @param int $friendship_id ID of the friendship.
+ * @return object friend_user_id and initiator_user_id.
+ */
</ins><span class="cx"> public static function get_user_ids_for_friendship( $friendship_id ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx"> return $wpdb->get_row( $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE id = %d", $friendship_id ) );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Delete all friendships and friend notifications related to a user.
+ *
+ * @param int $user_id ID of the user being expunged.
+ */
</ins><span class="cx"> public static function delete_all_for_user( $user_id ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>