Make WordPress Core

Ticket #39117: 39117.4.diff

File 39117.4.diff, 4.1 KB (added by MatheusGimenez, 6 years ago)

Update email message

  • wp-admin/includes/admin-filters.php

     
    5555add_action( 'update_option_siteurl',       'update_home_siteurl', 10, 2 );
    5656add_action( 'update_option_page_on_front', 'update_home_siteurl', 10, 2 );
    5757
     58// Send email to old email address on change site admin email
     59add_action( 'update_option_admin_email', 'send_email_on_admin_email_change', 10, 3 );
    5860add_filter( 'heartbeat_received', 'wp_check_locked_posts',  10,  3 );
    5961add_filter( 'heartbeat_received', 'wp_refresh_post_lock',   10,  3 );
    6062add_filter( 'wp_refresh_nonces', 'wp_refresh_post_nonces', 10,  3 );
  • wp-admin/includes/options.php

     
    139139        echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />';
    140140        echo '<p class="description">' . __( 'The <a href="https://codex.wordpress.org/Glossary#Character_set">character encoding</a> of your site (UTF-8 is recommended)' ) . '</p>';
    141141}
     142
     143/**
     144 * Send email to old email address on change site admin email
     145 * @param type $old_email
     146 * @param type $new_email
     147 * @param type $option_name
     148 */
     149function send_email_on_admin_email_change( $old_email, $new_email, $option_name ) {
     150
     151        /**
     152        * Filters whether to send the admin email change.
     153        *
     154        * @since 4.8.0
     155        *
     156        *
     157        * @param bool  $send     Whether to send the email.
     158        * @param array $old_email     The original admin email.
     159        * @param array $new_email The updated admin email.
     160        *
     161        */
     162        $send_admin_email_change_email = apply_filters( 'send_admin_email_change_email', true, $old_email, $new_email );
     163        if ( $send_admin_email_change_email ) {
     164        /* translators: Do not translate ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
     165                $email_change_text = __( 'Hi,
     166
     167                                This notice confirms your site admin e-mail has been changed on ###SITENAME###.
     168                                Your new site admin e-mail is now "###NEWEMAIL###"
     169
     170                                Regards,
     171                                All at ###SITENAME###
     172                                ###SITEURL###' );
     173
     174                $email_change_email = array(
     175                        'to'      => $old_email,
     176                        /* translators: Site admin email change notification email subject. 1: Site name */
     177                        'subject' => __( '[%s] Notice of Admin Email Change' ),
     178                        'message' => $email_change_text,
     179                        'headers' => '',
     180                );
     181                // get blog name
     182                $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     183
     184                /**
     185                * Filters the contents of the email sent when the site admin email is change
     186                *
     187                *
     188                * @since 4.8.0
     189                *
     190                * @param array $email_change_email {
     191                *            Used to build wp_mail().
     192                *            @type string $to      The intended recipients.
     193                *            @type string $subject The subject of the email.
     194                *            @type string $message The content of the email.
     195                *                The following strings have a special meaning and will get replaced dynamically:
     196                *                - ###NEWEMAIL### The admin email in case this was unexpected.
     197                *                - ###SITENAME###    The name of the site.
     198                *                - ###SITEURL###     The URL to the site.
     199                *            @type string $headers Headers.
     200                *        }
     201                * @param array $old_email The original email
     202                * @param array $new_email The updated email.
     203                 */
     204                $email_change_email = apply_filters( 'admin_email_change_email', $email_change_email, $old_email, $new_email );
     205
     206                $email_change_email['message'] = str_replace( '###NEWEMAIL###', $new_email,  $email_change_email[ 'message' ] );
     207                $email_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $email_change_email['message'] );
     208                $email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] );
     209
     210                wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] );
     211        }
     212}