Newest Users Dashboard Widget
Shows the most recent registrations on the dashboard with their role and sign-up date.
Opens WPIDE on
Code
add_action( 'wp_dashboard_setup', function () {
if ( ! current_user_can( 'list_users' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_new_users', 'Newest Users', function () {
$users = get_users( array(
'number' => 8,
'orderby' => 'registered',
'order' => 'DESC',
) );
$names = wp_roles()->get_names();
echo '<ul>';
foreach ( $users as $user ) {
$role = $user->roles ? reset( $user->roles ) : '';
printf(
'<li>%1$s <a href="%2$s">%3$s</a> <span style="color:#646970">%4$s · %5$s ago</span></li>',
get_avatar( $user->ID, 20, '', '', array( 'extra_attr' => 'style="vertical-align:middle;border-radius:50%"' ) ),
esc_url( get_edit_user_link( $user->ID ) ),
esc_html( $user->display_name ),
esc_html( $role && isset( $names[ $role ] ) ? translate_user_role( $names[ $role ] ) : 'No role' ),
esc_html( human_time_diff( strtotime( $user->user_registered ), time() ) )
);
}
echo '</ul>';
} );
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.