Skip to:
Content

BuddyPress.org

Changeset 5906


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
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-classes.php

    r5729 r5906  
    256256        }
    257257
    258         if ( !empty( $include ) ) {
    259             if ( is_array( $include ) ) {
    260                 $uids = $wpdb->escape( implode( ',', (array) $include ) );
    261             } else {
    262                 $uids = $wpdb->escape( $include );
    263             }
    264 
    265             if ( !empty( $uids ) ) {
    266                 $sql['where_users'] = "AND u.ID IN ({$uids})";
    267             }
    268         } elseif ( !empty( $user_id ) && bp_is_active( 'friends' ) ) {
    269             $friend_ids = friends_get_friend_user_ids( $user_id );
    270             $friend_ids = $wpdb->escape( implode( ',', (array) $friend_ids ) );
    271 
    272             if ( !empty( $friend_ids ) ) {
    273                 $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
    274 
    275             // User has no friends, return false since there will be no users to fetch.
    276             } else {
    277                 return false;
     258        // Passing an $include value of 0 or '0' will necessarily result in an empty set
     259        // returned. The default value of false will hit the 'else' clause.
     260        if ( 0 === $include || '0' === $include ) {
     261            $sql['where_users'] = "AND 0 = 1";
     262        } else {
     263            if ( !empty( $include ) ) {
     264                if ( is_array( $include ) ) {
     265                    $uids = $wpdb->escape( implode( ',', (array) $include ) );
     266                } else {
     267                    $uids = $wpdb->escape( $include );
     268                }
     269   
     270                if ( !empty( $uids ) ) {
     271                    $sql['where_users'] = "AND u.ID IN ({$uids})";
     272                }
     273            } elseif ( !empty( $user_id ) && bp_is_active( 'friends' ) ) {
     274                $friend_ids = friends_get_friend_user_ids( $user_id );
     275                $friend_ids = $wpdb->escape( implode( ',', (array) $friend_ids ) );
     276   
     277                if ( !empty( $friend_ids ) ) {
     278                    $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
     279   
     280                // User has no friends, return false since there will be no users to fetch.
     281                } else {
     282                    return false;
     283                }
    278284            }
    279285        }
  • 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
  • trunk/bp-members/bp-members-template.php

    r5891 r5906  
    314314    if ( !empty( $max ) && ( $per_page > $max ) )
    315315        $per_page = $max;
    316 
    317     // Make sure we return no members if we looking at friendship requests and there are none.
    318     if ( empty( $include ) && bp_is_friends_component() && bp_is_current_action( 'requests' ) )
    319         return false;
    320316
    321317    $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras, $exclude, $meta_key, $meta_value, $page_arg );
Note: See TracChangeset for help on using the changeset viewer.