Make WordPress Core

Ticket #40477: 40477.diff

File 40477.diff, 1.2 KB (added by nikunj8866, 10 months ago)

ADD: Hook to manage Email Notifications on user creation by WP REST API

  • src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
    index c2e0db83c5..355f04fa1a 100644
    a b class WP_REST_Users_Controller extends WP_REST_Controller { 
    605605                        if ( is_wp_error( $user_id ) ) {
    606606                                return $user_id;
    607607                        }
     608
     609                        /**
     610                         * Filters whether the notified of a new user registration.
     611                         *
     612                         * @param string $notify     Type of notification that should happen. Accepts 'admin' or an empty
     613                         *                           string (admin only), 'user', or 'both' (admin and user). Default 'admin'.
     614                         *                           You can set 'false' to stop notification for both.
     615                         * @param int    $user_id    User ID.
     616                         *
     617                         */
     618                        $notify = apply_filters( 'rest_wp_user_created_notification', $notify = 'admin', $user_id );
     619
     620                        if ( $notify && $notify != 'false' ) {
     621                                wp_new_user_notification( $user_id, null, $notify );
     622                        }
    608623                }
    609624
    610625                $user = get_user_by( 'id', $user_id );