Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/02/2013 06:29:06 PM (11 years ago)
Author:
boonebgorges
Message:

Introduces bp_*_user_last_activity() functions

User last activity data is currently stored as usermeta, with BuddyPress
making multiple calls directly to the usermeta table to get that data. These
new functions provide a central, standardized way to update and fetch
last_activity information. This makes it easier for plugins to update user
activity programatically in a future-compatible way.

Having this set of functions will facilitate any changes associated with #5128,
whose goal is to move last_activity data out of usermeta altogether.

File:
1 edited

Legend:

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

    r7228 r7334  
    806806    // Return the inverse of active
    807807    return !bp_is_user_active( $user_id );
     808}
     809
     810/**
     811 * Update a user's last activity
     812 *
     813 * @since BuddyPress (1.9)
     814 * @param int $user_id ID of the user being updated
     815 * @param string $time Time of last activity, in 'Y-m-d H:i:s' format
     816 * @return bool True on success
     817 */
     818function bp_update_user_last_activity( $user_id = 0, $time = '' ) {
     819    // Fall back on current user
     820    if ( empty( $user_id ) ) {
     821        $user_id = bp_loggedin_user_id();
     822    }
     823
     824    // Bail if the user id is 0, as there's nothing to update
     825    if ( empty( $user_id ) ) {
     826        return false;
     827    }
     828
     829    // Fall back on current time
     830    if ( empty( $time ) ) {
     831        $time = bp_core_current_time();
     832    }
     833
     834    return bp_update_user_meta( $user_id, 'last_activity', $time );
     835}
     836
     837/**
     838 * Get the last activity for a given user
     839 *
     840 * @param int $user_id The ID of the user
     841 * @return string Time of last activity, in 'Y-m-d H:i:s' format, or an empty
     842 *   string if none is found
     843 */
     844function bp_get_user_last_activity( $user_id = 0 ) {
     845    // Fall back on current user
     846    if ( empty( $user_id ) ) {
     847        $user_id = bp_loggedin_user_id();
     848    }
     849
     850    $activity = bp_get_user_meta( $user_id, 'last_activity', true );
     851
     852    return apply_filters( 'bp_get_user_last_activity', $activity, $user_id );
    808853}
    809854
     
    15141559    add_action( 'login_head', 'wp_shake_js', 12 );
    15151560}
    1516 add_action( 'login_form_bp-spam', 'bp_live_spammer_login_error' ); 
     1561add_action( 'login_form_bp-spam', 'bp_live_spammer_login_error' );
Note: See TracChangeset for help on using the changeset viewer.