Make WordPress Core

Ticket #42134: 42134.patch

File 42134.patch, 6.3 KB (added by Dhruvin, 7 years ago)

Added a filter for filtering the contents of the email sent when a new site is created.

  • wp-admin/network/site-new.php

    diff --git a/wp-admin/network/site-new.php b/wp-admin/network/site-new.php
    index 0b404ea7c4..7c21ac9f3d 100644
    a b if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) { 
    136136                        update_user_option( $user_id, 'primary_blog', $id, true );
    137137                }
    138138
    139                 wp_mail(
    140                         get_site_option( 'admin_email' ),
    141                         sprintf(
    142                                 /* translators: %s: network name */
    143                                 __( '[%s] New Site Created' ),
    144                                 get_network()->site_name
    145                         ),
    146                         sprintf(
    147                                 /* translators: 1: user login, 2: site url, 3: site name/title */
    148                                 __( 'New site created by %1$s
     139                /* translators: %s: network name */
     140                $new_site_subject = sprintf( __( '[%s] New Site Created' ), get_network()->site_name );
    149141
     142                /* translators: 1: user login, 2: site url, 3: site name/title */
     143                $new_site_message = sprintf(
     144                        __( 'New site created by %1$s
    150145Address: %2$s
    151146Name: %3$s' ),
    152                                 $current_user->user_login,
    153                                 get_site_url( $id ),
    154                                 wp_unslash( $title )
    155                         ),
    156                         sprintf(
    157                                 'From: "%1$s" <%2$s>',
    158                                 _x( 'Site Admin', 'email "From" field' ),
    159                                 get_site_option( 'admin_email' )
    160                         )
     147                        $current_user->user_login,
     148                        get_site_url( $id ),
     149                        wp_unslash( $title )
     150                );
     151
     152                $headers = sprintf(
     153                        'From: "%1$s" <%2$s>',
     154                        _x( 'Site Admin', 'email "From" field' ),
     155                        get_site_option( 'admin_email' )
     156                );
     157
     158                $new_site_created_email = array(
     159                        'admin_email'   => get_site_option( 'admin_email' ),
     160                        'subject'               => $new_site_subject,
     161                        'message'               => $new_site_message,
     162                        'headers'               => $headers
     163                );
     164
     165                /**
     166                 * Filters the contents of the email sent when a new site is created.
     167                 *
     168                 * @since 4.9
     169                 *
     170                 * @param array $new_site_created_email {
     171                 *            Used to build wp_mail().
     172                 *            @type string $admin_email Email of the newly created site user.
     173                 *            @type string $subject The subject of the email.
     174                 *            @type string $message The content of the email.
     175                 *                The following strings have a special meaning and will get replaced dynamically:
     176                 *                - ###SITENAME###    The name of the site.
     177                 *                - ###SITEURL###     The URL to the site.
     178                 *            @type string $headers Headers. Add headers in a newline (\r\n) separated string.
     179                 *        }
     180                 * @param int $user_id ID of the newly created user.
     181                 *
     182                 */
     183
     184                $new_site_created_email = apply_filters( 'new_site_created', $new_site_created_email, $user_id );
     185
     186                $new_site_created_email['message'] = str_replace( '###SITENAME###', wp_unslash( $title ), $new_site_created_email['message'] );
     187                $new_site_created_email['message'] = str_replace( '###SITEURL###', get_site_url( $id ), $new_site_created_email['message'] );
     188
     189                wp_mail(
     190                        $new_site_created_email['admin_email'],
     191                        $new_site_created_email['subject'],
     192                        $new_site_created_email['message'],
     193                        $new_site_created_email['headers']
    161194                );
    162195                wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
    163196                wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) );