Make WordPress Core

Ticket #39119: 39119.diff

File 39119.diff, 7.3 KB (added by johnbillion, 7 years ago)
  • src/wp-admin/includes/ms-admin-filters.php

    diff --git src/wp-admin/includes/ms-admin-filters.php src/wp-admin/includes/ms-admin-filters.php
    index e8952e15b3..02fbf68b3c 100644
    add_action( 'network_admin_notices', 'site_admin_notice' ); 
    3838// Update Hooks
    3939add_action( 'network_admin_notices', 'update_nag',      3  );
    4040add_action( 'network_admin_notices', 'maintenance_nag', 10 );
     41
     42// Network Admin Hooks
     43add_action( 'add_site_option_new_admin_email',    'update_network_option_new_admin_email', 10, 2 );
     44add_action( 'update_site_option_new_admin_email', 'update_network_option_new_admin_email', 10, 2 );
  • src/wp-admin/network/settings.php

    diff --git src/wp-admin/network/settings.php src/wp-admin/network/settings.php
    index af37fbcbed..f66acef03a 100644
    if ( ! current_user_can( 'manage_network_options' ) ) 
    1919$title = __( 'Network Settings' );
    2020$parent_file = 'settings.php';
    2121
     22// Handle admin email change requests
     23if ( ! empty( $_GET[ 'network_admin_hash' ] ) ) {
     24        $new_admin_details = get_site_option( 'network_admin_hash' );
     25        $redirect = 'settings.php?updated=false';
     26        if ( is_array( $new_admin_details ) && hash_equals( $new_admin_details[ 'hash' ], $_GET[ 'network_admin_hash' ] ) && ! empty( $new_admin_details[ 'newemail' ] ) ) {
     27                update_site_option( 'admin_email', $new_admin_details[ 'newemail' ] );
     28                delete_site_option( 'network_admin_hash' );
     29                delete_site_option( 'new_admin_email' );
     30                $redirect = 'settings.php?updated=true';
     31        }
     32        wp_redirect( network_admin_url( $redirect ) );
     33        exit;
     34} elseif ( ! empty( $_GET['dismiss'] ) && 'new_network_admin_email' == $_GET['dismiss'] ) {
     35        check_admin_referer( 'dismiss_new_network_admin_email' );
     36        delete_site_option( 'network_admin_hash' );
     37        delete_site_option( 'new_admin_email' );
     38        wp_redirect( network_admin_url( 'settings.php?updated=true' ) );
     39        exit;
     40}
     41
    2242add_action( 'admin_head', 'network_settings_add_js' );
    2343
    2444get_current_screen()->add_help_tab( array(
    if ( $_POST ) { 
    5878                'upload_space_check_disabled', 'blog_upload_space', 'upload_filetypes', 'site_name',
    5979                'first_post', 'first_page', 'first_comment', 'first_comment_url', 'first_comment_author',
    6080                'welcome_email', 'welcome_user_email', 'fileupload_maxk', 'global_terms_enabled',
    61                 'illegal_names', 'limited_email_domains', 'banned_email_domains', 'WPLANG', 'admin_email',
     81                'illegal_names', 'limited_email_domains', 'banned_email_domains', 'WPLANG', 'new_admin_email',
    6282                'first_comment_email',
    6383        );
    6484
    if ( isset( $_GET['updated'] ) ) { 
    111131                        <tr>
    112132                                <th scope="row"><label for="admin_email"><?php _e( 'Network Admin Email' ) ?></label></th>
    113133                                <td>
    114                                         <input name="admin_email" type="email" id="admin_email" aria-describedby="admin-email-desc" class="regular-text" value="<?php echo esc_attr( get_site_option( 'admin_email' ) ) ?>" />
     134                                        <input name="new_admin_email" type="email" id="admin_email" aria-describedby="admin-email-desc" class="regular-text" value="<?php echo esc_attr( get_site_option( 'admin_email' ) ) ?>" />
    115135                                        <p class="description" id="admin-email-desc">
    116136                                                <?php _e( 'This email address will receive notifications. Registration and support emails will also come from this address.' ); ?>
    117137                                        </p>
     138                                        <?php
     139                                        $new_admin_email = get_site_option( 'new_admin_email' );
     140                                        if ( $new_admin_email && $new_admin_email != get_site_option( 'admin_email' ) ) : ?>
     141                                                <div class="updated inline">
     142                                                <p><?php
     143                                                        printf(
     144                                                                /* translators: %s: new network admin email */
     145                                                                __( 'There is a pending change of the network admin email to %s.' ),
     146                                                                '<code>' . esc_html( $new_admin_email ) . '</code>'
     147                                                        );
     148                                                        printf(
     149                                                                ' <a href="%1$s">%2$s</a>',
     150                                                                esc_url( wp_nonce_url( network_admin_url( 'settings.php?dismiss=new_network_admin_email' ), 'dismiss_new_network_admin_email' ) ),
     151                                                                __( 'Cancel' )
     152                                                        );
     153                                                ?></p>
     154                                                </div>
     155                                        <?php endif; ?>
    118156                                </td>
    119157                        </tr>
    120158                </table>
  • src/wp-includes/ms-functions.php

    diff --git src/wp-includes/ms-functions.php src/wp-includes/ms-functions.php
    index 7c28844e0c..b51dd00c71 100644
    function get_subdirectory_reserved_names() { 
    25952595}
    25962596
    25972597/**
     2598 * Send a confirmation request email when a change of network admin email address is attempted.
     2599 *
     2600 * The new network admin address will not become active until confirmed.
     2601 *
     2602 * @since 4.9.0
     2603 *
     2604 * @param string $old_value The old network admin email address.
     2605 * @param string $value     The proposed new network admin email address.
     2606 */
     2607function update_network_option_new_admin_email( $old_value, $value ) {
     2608        if ( $value == get_site_option( 'admin_email' ) || ! is_email( $value ) ) {
     2609                return;
     2610        }
     2611
     2612        $hash = md5( $value . time() . mt_rand() );
     2613        $new_admin_email = array(
     2614                'hash'     => $hash,
     2615                'newemail' => $value,
     2616        );
     2617        update_site_option( 'network_admin_hash', $new_admin_email );
     2618
     2619        $switched_locale = switch_to_locale( get_user_locale() );
     2620
     2621        /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
     2622        $email_text = __( 'Howdy ###USERNAME###,
     2623
     2624You recently requested to have the network admin email address on
     2625your network changed.
     2626
     2627If this is correct, please click on the following link to change it:
     2628###ADMIN_URL###
     2629
     2630You can safely ignore and delete this email if you do not want to
     2631take this action.
     2632
     2633This email has been sent to ###EMAIL###
     2634
     2635Regards,
     2636All at ###SITENAME###
     2637###SITEURL###' );
     2638
     2639        /**
     2640         * Filters the text of the email sent when a change of network admin email address is attempted.
     2641         *
     2642         * The following strings have a special meaning and will get replaced dynamically:
     2643         * ###USERNAME###  The current user's username.
     2644         * ###ADMIN_URL### The link to click on to confirm the email change.
     2645         * ###EMAIL###     The proposed new network admin email address.
     2646         * ###SITENAME###  The name of the network.
     2647         * ###SITEURL###   The URL to the network.
     2648         *
     2649         * @since 4.9.0
     2650         *
     2651         * @param string $email_text      Text in the email.
     2652         * @param array  $new_admin_email {
     2653         *     Data relating to the new network admin email address.
     2654         *
     2655         *     @type string $hash     The secure hash used in the confirmation link URL.
     2656         *     @type string $newemail The proposed new network admin email address.
     2657         * }
     2658         */
     2659        $content = apply_filters( 'new_network_admin_email_content', $email_text, $new_admin_email );
     2660
     2661        $current_user = wp_get_current_user();
     2662        $content = str_replace( '###USERNAME###', $current_user->user_login, $content );
     2663        $content = str_replace( '###ADMIN_URL###', esc_url( network_admin_url( 'settings.php?network_admin_hash=' . $hash ) ), $content );
     2664        $content = str_replace( '###EMAIL###', $value, $content );
     2665        $content = str_replace( '###SITENAME###', wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ), $content );
     2666        $content = str_replace( '###SITEURL###', home_url(), $content );
     2667
     2668        wp_mail( $value, sprintf( __( '[%s] New Network Admin Email Address' ), wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ) ), $content );
     2669
     2670        if ( $switched_locale ) {
     2671                restore_previous_locale();
     2672        }
     2673}
     2674
     2675/**
    25982676 * Send an email to the old network admin email address when the network admin email address changes.
    25992677 *
    26002678 * @since 4.9.0