WordPress.org

Make WordPress Core

Changeset 34251


Ignore:
Timestamp:
09/16/2015 10:18:33 PM (5 years ago)
Author:
boonebgorges
Message:

Move new user notification emails to add_action() callbacks.

When a new user is created in various places throughout the interface,
notifications are sent to the site admin and the new user. Previously, these
notifications were fired through direct calls to wp_new_user_notification(),
making it difficult to stop or modify the messages.

This changeset introduces a number of new action hooks in place of direct calls
to wp_new_user_notification(), and hooks the new wrapper function
wp_send_new_user_notifications() to these hooks.

Props dshanske, thomaswm, boonebgorges.
Fixes #33587.

Location:
trunk/src
Files:
7 edited

Legend:

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

    r34116 r34251  
    177177    } else {
    178178        $user_id = wp_insert_user( $user );
    179         wp_new_user_notification( $user_id, null, 'both' );
     179        /**
     180          * Fires after a new user has been created.
     181          *
     182          * @since 4.4.0
     183          *
     184          * @param int $user_id ID of the newly created user.
     185          */
     186        do_action( 'edit_user_created_user', $user_id );
    180187    }
    181188    return $user_id;
  • trunk/src/wp-admin/network/site-new.php

    r34116 r34251  
    9292        $password = wp_generate_password( 12, false );
    9393        $user_id = wpmu_create_user( $domain, $password, $email );
    94         if ( false === $user_id )
     94        if ( false === $user_id ) {
    9595            wp_die( __( 'There was an error creating the user.' ) );
    96         else
    97             wp_new_user_notification( $user_id, null, 'both' );
     96        }
     97
     98        /**
     99          * Fires after a new user has been created via the network site-new.php page.
     100          *
     101          * @since 4.4.0
     102          *
     103          * @param int $user_id ID of the newly created user.
     104          */
     105        do_action( 'network_site_new_created_user', $user_id );
    98106    }
    99107
  • trunk/src/wp-admin/network/site-users.php

    r34116 r34251  
    7878                    $update = 'err_new_dup';
    7979                } else {
    80                     wp_new_user_notification( $user_id, null, 'both' );
    8180                    add_user_to_blog( $id, $user_id, $_POST['new_role'] );
    8281                    $update = 'newuser';
     82                    /**
     83                      * Fires after a user has been created via the network site-users.php page.
     84                      *
     85                      * @since 4.4.0
     86                      *
     87                      * @param int $user_id ID of the newly created user.
     88                      */
     89                    do_action( 'network_site_users_created_user', $user_id );
    8390                }
    8491            }
  • trunk/src/wp-admin/network/user-new.php

    r34218 r34251  
    5252            $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
    5353        } else {
    54             wp_new_user_notification( $user_id, null, 'both' );
     54            /**
     55              * Fires after a new user has been created via the network user-new.php page.
     56              *
     57              * @since 4.4.0
     58              *
     59              * @param int $user_id ID of the newly created user.
     60              */
     61            do_action( 'network_user_new_created_user', $user_id );
    5562            wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) );
    5663            exit;
  • trunk/src/wp-includes/default-filters.php

    r34124 r34251  
    340340add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
    341341add_action( 'after_password_reset', 'wp_password_change_notification' );
     342add_action( 'register_new_user',      'wp_send_new_user_notifications' );
     343add_action( 'edit_user_created_user', 'wp_send_new_user_notifications' );
    342344
    343345/**
  • trunk/src/wp-includes/ms-default-filters.php

    r34112 r34251  
    2828add_action( 'wpmu_activate_user', 'wpmu_welcome_user_notification', 10, 3 );
    2929add_action( 'after_signup_user', 'wpmu_signup_user_notification', 10, 4 );
     30add_action( 'network_site_new_created_user',   'wp_send_new_user_notifications' );
     31add_action( 'network_site_users_created_user', 'wp_send_new_user_notifications' );
     32add_action( 'network_user_new_created_user',   'wp_send_new_user_notifications' );
    3033add_filter( 'sanitize_user', 'strtolower' );
    3134
  • trunk/src/wp-includes/user-functions.php

    r34218 r34251  
    20242024    update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
    20252025
     2026    /**
     2027     * Fires after a new user registration has been recorded.
     2028     *
     2029     * @since 4.4.0
     2030     *
     2031     * @param int $user_id ID of the newly registered user.
     2032     */
     2033    do_action( 'register_new_user', $user_id );
     2034
     2035    return $user_id;
     2036}
     2037
     2038/**
     2039 * Initiate email notifications related to the creation of new users.
     2040 *
     2041 * Notifications are sent both to the site admin and to the newly created user.
     2042 *
     2043 * @since 4.4.0
     2044 *
     2045 * @param int $user_id ID of the newly created user.
     2046 */
     2047function wp_send_new_user_notifications( $user_id ) {
    20262048    wp_new_user_notification( $user_id, null, 'both' );
    2027 
    2028     return $user_id;
    20292049}
    20302050
Note: See TracChangeset for help on using the changeset viewer.