"New Sign-Ups" View on the Users Screen
Adds a "New this week" link next to All / Administrator / Subscriber on the Users screen that lists only people who registered in the last 7 days.
Opens WPIDE on
Code
// How many days count as "new".
$wpide_recent_days = 7;
add_filter( 'views_users', function ( $views ) use ( $wpide_recent_days ) {
$query = new WP_User_Query( array(
'fields' => 'ID',
'number' => 1,
'count_total' => true,
'date_query' => array( array( 'after' => $wpide_recent_days . ' days ago', 'inclusive' => true ) ),
) );
$current = ! empty( $_GET['wpide_recent'] );
$views['wpide_recent'] = sprintf(
'<a href="%1$s"%2$s>New this week <span class="count">(%3$s)</span></a>',
esc_url( add_query_arg( 'wpide_recent', 1, admin_url( 'users.php' ) ) ),
$current ? ' class="current" aria-current="page"' : '',
number_format_i18n( $query->get_total() )
);
return $views;
} );
add_action( 'pre_get_users', function ( $query ) use ( $wpide_recent_days ) {
global $pagenow;
if ( 'users.php' !== $pagenow || empty( $_GET['wpide_recent'] ) || $query->get( 'fields' ) === 'ID' ) {
return;
}
$query->set( 'date_query', array( array( 'after' => $wpide_recent_days . ' days ago', 'inclusive' => true ) ) );
} );
Notes
Change $wpide_recent_days to show a different period.
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.