Make WordPress Core


Ignore:
Timestamp:
07/12/2022 09:03:39 PM (3 years ago)
Author:
johnbillion
Message:

Users: Allow conditional supression of the email notifications that are sent when a new user account is registered.

This introduces the following new filters:

  • wp_send_new_user_notification_to_admin
  • wp_send_new_user_notification_to_user

Props janthiel, costdev, audrasjb, peterwilsoncc

Fixes #54874

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r53483 r53698  
    21112111        $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    21122112
    2113         if ( 'user' !== $notify ) {
     2113        /**
     2114         * Filters whether the admin is notified of a new user registration.
     2115         *
     2116         * @since 6.1.0
     2117         *
     2118         * @param bool    $send Whether to send the email. Default true.
     2119         * @param WP_User $user User object for new user.
     2120         */
     2121        $send_notification_to_admin = apply_filters( 'wp_send_new_user_notification_to_admin', true, $user );
     2122
     2123        if ( 'user' !== $notify && true === $send_notification_to_admin ) {
    21142124            $switched_locale = switch_to_locale( get_locale() );
    21152125
     
    21592169        }
    21602170
     2171        /**
     2172         * Filters whether the user is notified of their new user registration.
     2173         *
     2174         * @since 6.1.0
     2175         *
     2176         * @param bool    $send Whether to send the email. Default true.
     2177         * @param WP_User $user User object for new user.
     2178         */
     2179        $send_notification_to_user = apply_filters( 'wp_send_new_user_notification_to_user', true, $user );
     2180
    21612181        // `$deprecated` was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification.
    2162         if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) {
     2182        if ( 'admin' === $notify || true !== $send_notification_to_user || ( empty( $deprecated ) && empty( $notify ) ) ) {
    21632183            return;
    21642184        }
Note: See TracChangeset for help on using the changeset viewer.