Halloween Sale 15% off Ends in See the plans
PHP

BuddyPress: Last Active Column on the Users Screen

Adds a "Last active" column to the WordPress Users screen using BuddyPress's activity tracking, so you can see who is actually using the community.

Don’t have WPIDE yet? Install it on your site

Code

if ( ! function_exists( 'buddypress' ) ) {
    return;
}

add_filter( 'manage_users_columns', function ( $columns ) {
    $columns['wpide_bp_active'] = 'Last active';

    return $columns;
} );

add_filter( 'manage_users_custom_column', function ( $output, $column, $user_id ) {
    if ( 'wpide_bp_active' !== $column ) {
        return $output;
    }

    $last = bp_get_user_last_activity( $user_id );

    return $last ? esc_html( sprintf( '%s ago', human_time_diff( strtotime( $last . ' UTC' ) ) ) ) : 'Never';
}, 10, 3 );

Notes

Shows "Never" for members who have not been active since BuddyPress was installed.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.