Halloween Sale 15% off Ends in See the plans
PHP

Daily Digest of New User Registrations

Replaces the "New user registration" email WordPress sends for every sign-up with one daily email listing all new users, their role and email address.

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

Code

$wpide_users_digest_hour = 8;

add_filter( 'wp_send_new_user_notification_to_admin', '__return_false' );

add_action( 'init', function () use ( $wpide_users_digest_hour ) {
    if ( wp_next_scheduled( 'wpide_new_users_digest' ) ) {
        return;
    }
    $next = new DateTime( 'today ' . $wpide_users_digest_hour . ':00', wp_timezone() );
    if ( $next->getTimestamp() <= time() ) {
        $next->modify( '+1 day' );
    }
    wp_schedule_event( $next->getTimestamp(), 'daily', 'wpide_new_users_digest' );
} );

add_action( 'wpide_new_users_digest', function () {
    $users = get_users( array(
        'date_query' => array( array( 'after' => gmdate( 'Y-m-d H:i:s', time() - DAY_IN_SECONDS ), 'column' => 'user_registered' ) ),
        'number'     => 200,
        'orderby'    => 'registered',
        'order'      => 'DESC',
    ) );

    if ( ! $users ) {
        return;
    }

    $lines = array( sprintf( '%d new user(s) registered in the last 24 hours:', count( $users ) ), '' );
    foreach ( $users as $user ) {
        $lines[] = sprintf( '• %s <%s> – %s', $user->user_login, $user->user_email, implode( ', ', (array) $user->roles ) );
    }
    $lines[] = '';
    $lines[] = 'All users: ' . admin_url( 'users.php' );

    wp_mail( get_option( 'admin_email' ), sprintf( '[%s] %d new user(s)', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), count( $users ) ), implode( "\n", $lines ) );
} );

Notes

Needs WordPress 6.1 or later, users still get their own welcome email, and nothing is sent on days without new registrations.

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.