BP_REST_Members_Endpoint::bp_rest_get_member_last_active( int $user_id, array $args = array() )

Return the current member’s last active time.

Description

— from bp_get_member_last_active().

Parameters

$user_id

(Required) User ID.

$args

(Optional) Array of optional arguments.

Default value: array()

Return

(string)

Source

File: bp-members/classes/class-bp-rest-members-endpoint.php

1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
public function bp_rest_get_member_last_active( $user_id, $args = array() ) {
 
    // Parse the activity format.
    $r = bp_parse_args(
        $args,
        array(
            'active_format' => true,
            'relative'      => true,
        )
    );
 
    $last_active = bp_get_user_last_activity( $user_id );
 
    // Backwards compatibility for anyone forcing a 'true' active_format.
    if ( true === $r['active_format'] ) {
        /* translators: last active format. */
        $r['active_format'] = __( 'active %s', 'buddyboss' );
    }
 
    // Member has logged in at least one time.
    if ( isset( $last_active ) ) {
        // We do not want relative time, so return now.
        // @todo Should the 'bp_member_last_active' filter be applied here?
        if ( ! $r['relative'] ) {
            return ( empty( $last_active ) ? __( 'Not recently active', 'buddyboss' ) : bp_rest_prepare_date_response( $last_active ) );
        }
 
        // Backwards compatibility for pre 1.5 'ago' strings.
        $last_activity = ! empty( $r['active_format'] )
            ? bp_core_get_last_activity( $last_active, $r['active_format'] )
            : bp_core_time_since( $last_active );
 
        // Member has never logged in or been active.
    } else {
        $last_activity = __( 'Never active', 'buddyboss' );
    }
 
    /**
     * Filters the current members last active time.
     *
     * @param string $last_activity Formatted time since last activity.
     * @param array  $r             Array of parsed arguments for query.
     */
    return apply_filters( 'bp_member_last_active', $last_activity, $r );
}

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.