bp_update_user_last_activity( int $user_id, string $time = '' )

Update a user’s last activity.

Description

Parameters

$user_id

(Required) ID of the user being updated.

$time

(Optional) Time of last activity, in 'Y-m-d H:i:s' format.

Default value: ''

Return

(bool) True on success, false on failure.

Source

File: bp-members/bp-members-functions.php

function bp_update_user_last_activity( $user_id = 0, $time = '' ) {

	// Fall back on current user.
	if ( empty( $user_id ) ) {
		$user_id = bp_loggedin_user_id();
	}

	// Bail if the user id is 0, as there's nothing to update.
	if ( empty( $user_id ) ) {
		return false;
	}

	// Bail if this is switched user
	$old_user = bp_current_member_switched();
	if ( $old_user instanceof WP_User ) {
		return false;
	}

	// Fall back on current time.
	if ( empty( $time ) ) {
		$time = bp_core_current_time();
	}

	// As of BuddyPress 2.0, last_activity is no longer stored in usermeta.
	// However, we mirror it there for backward compatibility. Do not use!
	// Remove our warning and re-add.
	remove_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10 );
	remove_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10 );
	bp_update_user_meta( $user_id, 'last_activity', $time );
	add_filter( 'update_user_metadata', '_bp_update_user_meta_last_activity_warning', 10, 4 );
	add_filter( 'get_user_metadata', '_bp_get_user_meta_last_activity_warning', 10, 4 );

	return BP_Core_User::update_last_activity( $user_id, $time );
}

Changelog

Changelog
Version Description
BuddyPress 1.9.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.