Ticket #16470: 16470.patch
File 16470.patch, 11.0 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/admin-filters.php
diff --git a/src/wp-admin/includes/admin-filters.php b/src/wp-admin/includes/admin-filters.php index 141e8aa..97768dd 100644
a b add_action( 'admin_notices', 'default_password_nag' ); 102 102 103 103 add_action( 'profile_update', 'default_password_nag_edit_user', 10, 2 ); 104 104 105 add_action( 'personal_options_update', 'send_confirmation_on_profile_email' ); 106 105 107 // Update hooks. 106 108 add_action( 'load-plugins.php', 'wp_plugin_update_rows', 20 ); // After wp_update_plugins() is called. 107 109 add_action( 'load-themes.php', 'wp_theme_update_rows', 20 ); // After wp_update_themes() is called. -
src/wp-admin/includes/ms-admin-filters.php
diff --git a/src/wp-admin/includes/ms-admin-filters.php b/src/wp-admin/includes/ms-admin-filters.php index fb4f678..3c6cc00 100644
a b add_action( 'admin_page_access_denied', '_access_denied_splash', 99 ); 18 18 19 19 add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); 20 20 21 add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );22 23 21 add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); 24 22 25 23 // Site Hooks. -
src/wp-admin/includes/ms.php
diff --git a/src/wp-admin/includes/ms.php b/src/wp-admin/includes/ms.php index c88123a..cff8f61 100644
a b All at ###SITENAME### 318 318 } 319 319 320 320 /** 321 * Sends an email when an email address change is requested.322 *323 * @since 3.0.0324 *325 * @global WP_Error $errors WP_Error object.326 * @global wpdb $wpdb WordPress database object.327 */328 function send_confirmation_on_profile_email() {329 global $errors, $wpdb;330 $current_user = wp_get_current_user();331 if ( ! is_object($errors) )332 $errors = new WP_Error();333 334 if ( $current_user->ID != $_POST['user_id'] )335 return false;336 337 if ( $current_user->user_email != $_POST['email'] ) {338 if ( !is_email( $_POST['email'] ) ) {339 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn’t correct." ), array( 'form-field' => 'email' ) );340 return;341 }342 343 if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {344 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array( 'form-field' => 'email' ) );345 delete_user_meta( $current_user->ID, '_new_email' );346 return;347 }348 349 $hash = md5( $_POST['email'] . time() . mt_rand() );350 $new_user_email = array(351 'hash' => $hash,352 'newemail' => $_POST['email']353 );354 update_user_meta( $current_user->ID, '_new_email', $new_user_email );355 356 /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */357 $email_text = __( 'Howdy ###USERNAME###,358 359 You recently requested to have the email address on your account changed.360 361 If this is correct, please click on the following link to change it:362 ###ADMIN_URL###363 364 You can safely ignore and delete this email if you do not want to365 take this action.366 367 This email has been sent to ###EMAIL###368 369 Regards,370 All at ###SITENAME###371 ###SITEURL###' );372 373 /**374 * Filters the email text sent when a user changes emails.375 *376 * The following strings have a special meaning and will get replaced dynamically:377 * ###USERNAME### The current user's username.378 * ###ADMIN_URL### The link to click on to confirm the email change.379 * ###EMAIL### The new email.380 * ###SITENAME### The name of the site.381 * ###SITEURL### The URL to the site.382 *383 * @since MU384 *385 * @param string $email_text Text in the email.386 * @param string $new_user_email New user email that the current user has changed to.387 */388 $content = apply_filters( 'new_user_email_content', $email_text, $new_user_email );389 390 $content = str_replace( '###USERNAME###', $current_user->user_login, $content );391 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content );392 $content = str_replace( '###EMAIL###', $_POST['email'], $content);393 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );394 $content = str_replace( '###SITEURL###', network_home_url(), $content );395 396 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content );397 $_POST['email'] = $current_user->user_email;398 }399 }400 401 /**402 * Adds an admin notice alerting the user to check for confirmation email403 * after email address change.404 *405 * @since 3.0.0406 *407 * @global string $pagenow408 */409 function new_user_email_admin_notice() {410 global $pagenow;411 if ( 'profile.php' === $pagenow && isset( $_GET['updated'] ) && $email = get_user_meta( get_current_user_id(), '_new_email', true ) ) {412 /* translators: %s: New email address */413 echo '<div class="notice notice-info"><p>' . sprintf( __( 'Your email address has not been updated yet. Please check your inbox at %s for a confirmation email.' ), '<code>' . esc_html( $email['newemail'] ) . '</code>' ) . '</p></div>';414 }415 }416 417 /**418 321 * Check whether a site has used its allotted upload space. 419 322 * 420 323 * @since MU -
src/wp-admin/user-edit.php
diff --git a/src/wp-admin/user-edit.php b/src/wp-admin/user-edit.php index aa6ed7f..10847d8 100644
a b if ( is_multisite() 81 81 } 82 82 83 83 // Execute confirmed email change. See send_confirmation_on_profile_email(). 84 if ( is_multisite() &&IS_PROFILE_PAGE && isset( $_GET[ 'newuseremail' ] ) && $current_user->ID ) {84 if ( IS_PROFILE_PAGE && isset( $_GET[ 'newuseremail' ] ) && $current_user->ID ) { 85 85 $new_email = get_user_meta( $current_user->ID, '_new_email', true ); 86 86 if ( $new_email && hash_equals( $new_email[ 'hash' ], $_GET[ 'newuseremail' ] ) ) { 87 87 $user = new stdClass; 88 88 $user->ID = $current_user->ID; 89 89 $user->user_email = esc_html( trim( $new_email[ 'newemail' ] ) ); 90 if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) {90 if ( is_multisite() && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) { 91 91 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $current_user->user_login ) ); 92 92 } 93 93 wp_update_user( $user ); … … if ( is_multisite() && IS_PROFILE_PAGE && isset( $_GET[ 'newuseremail' ] ) && $c 97 97 } else { 98 98 wp_redirect( add_query_arg( array( 'error' => 'new-email' ), self_admin_url( 'profile.php' ) ) ); 99 99 } 100 } elseif ( is_multisite() &&IS_PROFILE_PAGE && !empty( $_GET['dismiss'] ) && $current_user->ID . '_new_email' === $_GET['dismiss'] ) {100 } elseif ( IS_PROFILE_PAGE && !empty( $_GET['dismiss'] ) && $current_user->ID . '_new_email' === $_GET['dismiss'] ) { 101 101 check_admin_referer( 'dismiss-' . $current_user->ID . '_new_email' ); 102 102 delete_user_meta( $current_user->ID, '_new_email' ); 103 103 wp_redirect( add_query_arg( array('updated' => 'true'), self_admin_url( 'profile.php' ) ) ); -
src/wp-includes/user.php
diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 6d473ef..d520cce 100644
a b function _wp_get_current_user() { 2507 2507 2508 2508 return $current_user; 2509 2509 } 2510 2511 /** 2512 * Sends an email when an email address change is requested. 2513 * 2514 * @since 3.0.0 2515 * 2516 * @global WP_Error $errors WP_Error object. 2517 * @global wpdb $wpdb WordPress database object. 2518 */ 2519 function send_confirmation_on_profile_email() { 2520 global $errors, $wpdb; 2521 2522 $current_user = wp_get_current_user(); 2523 if ( ! is_object( $errors ) ) { 2524 $errors = new WP_Error(); 2525 } 2526 2527 if ( $current_user->ID != $_POST['user_id'] ) { 2528 return false; 2529 } 2530 2531 if ( $current_user->user_email != $_POST['email'] ) { 2532 if ( ! is_email( $_POST['email'] ) ) { 2533 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn’t correct." ), array( 'form-field' => 'email' ) ); 2534 2535 return; 2536 } 2537 2538 if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) { 2539 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array( 'form-field' => 'email' ) ); 2540 delete_user_meta( $current_user->ID, '_new_email' ); 2541 2542 return; 2543 } 2544 2545 $hash = md5( $_POST['email'] . time() . mt_rand() ); 2546 $new_user_email = array( 2547 'hash' => $hash, 2548 'newemail' => $_POST['email'] 2549 ); 2550 update_user_meta( $current_user->ID, '_new_email', $new_user_email ); 2551 2552 /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ 2553 $email_text = __( 'Howdy ###USERNAME###, 2554 2555 You recently requested to have the email address on your account changed. 2556 2557 If this is correct, please click on the following link to change it: 2558 ###ADMIN_URL### 2559 2560 You can safely ignore and delete this email if you do not want to 2561 take this action. 2562 2563 This email has been sent to ###EMAIL### 2564 2565 Regards, 2566 All at ###SITENAME### 2567 ###SITEURL###' ); 2568 2569 /** 2570 * Filters the email text sent when a user changes emails. 2571 * 2572 * The following strings have a special meaning and will get replaced dynamically: 2573 * ###USERNAME### The current user's username. 2574 * ###ADMIN_URL### The link to click on to confirm the email change. 2575 * ###EMAIL### The new email. 2576 * ###SITENAME### The name of the site. 2577 * ###SITEURL### The URL to the site. 2578 * 2579 * @since MU 2580 * 2581 * @param string $email_text Text in the email. 2582 * @param string $new_user_email New user email that the current user has changed to. 2583 */ 2584 $content = apply_filters( 'new_user_email_content', $email_text, $new_user_email ); 2585 2586 $content = str_replace( '###USERNAME###', $current_user->user_login, $content ); 2587 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail=' . $hash ) ), $content ); 2588 $content = str_replace( '###EMAIL###', $_POST['email'], $content ); 2589 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); 2590 $content = str_replace( '###SITEURL###', network_home_url(), $content ); 2591 2592 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); 2593 $_POST['email'] = $current_user->user_email; 2594 } 2595 } 2596 2597 /** 2598 * Adds an admin notice alerting the user to check for confirmation email 2599 * after email address change. 2600 * 2601 * @since 3.0.0 2602 * 2603 * @global string $pagenow 2604 */ 2605 function new_user_email_admin_notice() { 2606 global $pagenow; 2607 if ( 'profile.php' === $pagenow && isset( $_GET['updated'] ) && $email = get_user_meta( get_current_user_id(), '_new_email', true ) ) { 2608 /* translators: %s: New email address */ 2609 echo '<div class="notice notice-info"><p>' . sprintf( __( 'Your email address has not been updated yet. Please check your inbox at %s for a confirmation email.' ), '<code>' . esc_html( $email['newemail'] ) . '</code>' ) . '</p></div>'; 2610 } 2611 }