Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/11/2012 04:39:44 PM (13 years ago)
Author:
boonebgorges
Message:

Reworks some functions around the querying of friendship requests:

  • Refactors bp_get_friendship_requests() so that it accepts a manual user_id parameter, and so that it falls back on the displayed_user rather than the loggedin_user (for future administrative tasks)
  • Reconfigures the return value of bp_get_friendship_requests() so that a 0 is returned when there are no pending requests, to ensure that a non-false value is passed to bp_has_members() when viewing the Requests page of a user with no pending requests
  • Removes the hardcoded 'return false' from bp_has_members() that would occur when an empty 'include' parameter was passed on the Requests page, so that sidebar widgets using bp_has_members() would work properly
  • Reconfigures the 'include' logic in BP_Core_User::get_users() so that a value of 0 or '0' results in a false result, while continuing to respect legacy behavior of the default false value
  • Fixes #4066
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-friends/bp-friends-template.php

    r5729 r5906  
    379379    return implode( ',', friends_get_friend_user_ids( $user_id ) );
    380380}
    381 function bp_get_friendship_requests() {
    382     return apply_filters( 'bp_get_friendship_requests', implode( ',', (array) friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) ) );
     381
     382/**
     383 * Get a user's friendship requests
     384 *
     385 * Note that we return a 0 if no pending requests are found. This is necessary because of the
     386 * structure of the $include parameter in bp_has_members().
     387 *
     388 * @param int $user_id Defaults to displayed user
     389 * @return mixed Returns an array of users if found, or a 0 if none are found
     390 */
     391function bp_get_friendship_requests( $user_id = 0 ) {
     392    if ( !$user_id ) {
     393        $user_id = bp_displayed_user_id();
     394    }
     395   
     396    if ( !$user_id ) {
     397        return 0;   
     398    }
     399   
     400    $requests = friends_get_friendship_request_user_ids( $user_id );
     401   
     402    if ( !empty( $requests ) ) {
     403        $requests = implode( ',', (array) $requests );
     404    } else {
     405        $requests = 0;
     406    }
     407   
     408    return apply_filters( 'bp_get_friendship_requests', $requests );
    383409}
    384410
Note: See TracChangeset for help on using the changeset viewer.