Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/04/2011 06:54:19 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Update bp_core_is_user_spammer() and bp_core_is_user_deleted() functions to use get_userdata() to take advantage of WP object cache.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-members/bp-members-functions.php

    r4559 r4592  
    482482    global $wpdb;
    483483
    484     if ( is_multisite() )
    485         $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM $wpdb->users WHERE ID = %d", $user_id ) );
    486     else
    487         $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) );
    488 
    489     return apply_filters( 'bp_core_is_user_spammer', $is_spammer );
     484    // Assume user is not spam
     485    $is_spammer = false;
     486
     487    // Get user data
     488    $user = get_userdata( $user_id );
     489
     490    // No user found
     491    if ( empty( $user ) ) {
     492        $is_spammer = false;
     493       
     494    // User found
     495    } else {
     496
     497        // Check if spam
     498        if ( !empty( $user->spam ) )
     499            $is_spammer = true;
     500
     501        if ( 'spam' == $user->user_status )
     502            $is_spammer = true;
     503    }
     504
     505    return apply_filters( 'bp_core_is_user_spammer', (bool) $is_spammer );
    490506}
    491507
     
    500516    global $wpdb;
    501517
    502     return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM $wpdb->users WHERE ID = %d", $user_id ) ) );
     518    // Assume user is not deleted
     519    $is_deleted = false;
     520
     521    // Get user data
     522    $user = get_userdata( $user_id );
     523
     524    // No user found
     525    if ( empty( $user ) ) {
     526        $is_deleted = true;
     527       
     528    // User found
     529    } else {
     530
     531        // Check if deleted
     532        if ( !empty( $user->deleted ) )
     533            $is_deleted = true;
     534
     535        if ( 'deleted' == $user->user_status )
     536            $is_deleted = true;
     537
     538    }
     539
     540    return apply_filters( 'bp_core_is_user_deleted', (bool) $is_deleted );
    503541}
    504542
Note: See TracChangeset for help on using the changeset viewer.