Skip to:
Content

BuddyPress.org

Changeset 11025


Ignore:
Timestamp:
08/22/2016 09:37:39 PM (4 years ago)
Author:
r-a-y
Message:

Friends: Cast properties as integers where appropriate.

See #6977.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/classes/class-bp-friends-friendship.php

    r10820 r11025  
    242242        }
    243243
    244         return $fids;
     244        return array_map( 'intval', $fids );
    245245    }
    246246
     
    252252     * @param int $user_id   The ID of the first user.
    253253     * @param int $friend_id The ID of the second user.
    254      * @return int|bool The ID of the friendship object if found, otherwise false.
     254     * @return int|null The ID of the friendship object if found, otherwise null.
    255255     */
    256256    public static function get_friendship_id( $user_id, $friend_id ) {
     
    259259        $bp = buddypress();
    260260
    261         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 ) );
     261        $query = $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 ) );
     262
     263        return is_numeric( $query ) ? (int) $query : $query;
    262264    }
    263265
     
    282284
    283285            wp_cache_set( $user_id, $friend_requests, 'bp_friends_requests' );
     286        }
     287
     288        // Integer casting.
     289        if ( ! empty( $friend_requests ) ) {
     290            $friend_requests = array_map( 'intval', $friend_requests );
    284291        }
    285292
     
    382389            return false;
    383390
    384         return array( 'friends' => $filtered_friend_ids, 'total' => (int) $total_friend_ids );
     391        return array( 'friends' => array_map( 'intval', $filtered_friend_ids ), 'total' => (int) $total_friend_ids );
    385392    }
    386393
Note: See TracChangeset for help on using the changeset viewer.