Skip to:
Content
Pages
Categories
Search
Top
Bottom

Checking if member is online


  • Alex4red
    Participant

    @alex4red

    I’m getting an error all of a sudden to my code

    
    function is_member_online($user_id, $time=5){
        global $wp, $wpdb;
    
        $user_login = $wpdb->get_var( $wpdb->prepare( "
            SELECT u.user_login FROM $wpdb->users u JOIN $wpdb->usermeta um ON um.user_id = u.ID
            WHERE     u.ID = $user_id
            AND um.meta_key = 'last_activity'
            AND DATE_ADD( um.meta_value, INTERVAL $time MINUTE ) >= UTC_TIMESTAMP()
            "
        ));
        if(isset($user_login) && $user_login !=""){
            return true;
        }
        else {return false;}
    }
    

    This checks if bbpress members are online. This is the error that is being resulted

    
    Warning: Missing argument 2 for wpdb::prepare(), called in /hermes/bosweb/web172/b1721/ipg.dnbrawlercom/lsheroes/wp-content/themes/SaveLSHoooo/custom-functions.php on line 15 and defined in /hermes/bosweb/web172/b1721/ipg.dnbrawlercom/lsheroes/wp-includes/wp-db.php on line 992

    It has been happening working until recently.

Viewing 1 replies (of 1 total)

  • Lynqoid
    Participant

    @lynqoid

    The wpdb prepare uses a placeholder like %s and then replaces it with the first variable in the arguments after the query itself.

    For example:

    $user_login = $wpdb->get_var( $wpdb->prepare( 
    	"SELECT u.user_login FROM $wpdb->users u JOIN $wpdb->usermeta um ON um.user_id = u.ID
            WHERE     u.ID = %s
            AND um.meta_key = 'last_activity'
            AND DATE_ADD( um.meta_value, INTERVAL %s MINUTE ) >= UTC_TIMESTAMP()
    	", 
    	$user_id, $time
    ) );

    Good luck!

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar