Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/11/2012 04:39:44 PM (12 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-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        }
Note: See TracChangeset for help on using the changeset viewer.