<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41163] trunk: Users: Require a confirmation link in an email to be clicked when a user attempts to change their email address.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41163">41163</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41163","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>johnbillion</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-07-27 02:09:51 +0000 (Thu, 27 Jul 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Users: Require a confirmation link in an email to be clicked when a user attempts to change their email address.
This adds this previously Multisite-only functionality to single site installations too. This change prevents accidental or erroneous email address changes from potentially locking users out of their account.
Props rodrigosprimo, tharsheblows, johnbillion
Fixes <a href="https://core.trac.wordpress.org/ticket/16470">#16470</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesadminfiltersphp">trunk/src/wp-admin/includes/admin-filters.php</a></li>
<li><a href="#trunksrcwpadminincludesmsadminfiltersphp">trunk/src/wp-admin/includes/ms-admin-filters.php</a></li>
<li><a href="#trunksrcwpadminincludesmsphp">trunk/src/wp-admin/includes/ms.php</a></li>
<li><a href="#trunksrcwpadminusereditphp">trunk/src/wp-admin/user-edit.php</a></li>
<li><a href="#trunksrcwpincludesuserphp">trunk/src/wp-includes/user.php</a></li>
<li><a href="#trunktestsphpunittestsuserphp">trunk/tests/phpunit/tests/user.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesadminfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/admin-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/admin-filters.php 2017-07-27 00:40:27 UTC (rev 41162)
+++ trunk/src/wp-admin/includes/admin-filters.php 2017-07-27 02:09:51 UTC (rev 41163)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -99,9 +99,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_init', 'default_password_nag_handler' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_notices', 'default_password_nag' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_action( 'admin_notices', 'new_user_email_admin_notice' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'profile_update', 'default_password_nag_edit_user', 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Update hooks.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'load-plugins.php', 'wp_plugin_update_rows', 20 ); // After wp_update_plugins() is called.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'load-themes.php', 'wp_theme_update_rows', 20 ); // After wp_update_themes() is called.
</span></span></pre></div>
<a id="trunksrcwpadminincludesmsadminfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ms-admin-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ms-admin-filters.php 2017-07-27 00:40:27 UTC (rev 41162)
+++ trunk/src/wp-admin/includes/ms-admin-filters.php 2017-07-27 02:09:51 UTC (rev 41163)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,15 +11,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // User Hooks
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_action( 'admin_notices', 'new_user_email_admin_notice' );
</del><span class="cx" style="display: block; padding: 0 10px"> add_action( 'user_admin_notices', 'new_user_email_admin_notice' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
-
</del><span class="cx" style="display: block; padding: 0 10px"> add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Site Hooks.
</span></span></pre></div>
<a id="trunksrcwpadminincludesmsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ms.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ms.php 2017-07-27 00:40:27 UTC (rev 41162)
+++ trunk/src/wp-admin/includes/ms.php 2017-07-27 02:09:51 UTC (rev 41163)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -336,109 +336,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Sends an email when an email address change is requested.
- *
- * @since 3.0.0
- *
- * @global WP_Error $errors WP_Error object.
- * @global wpdb $wpdb WordPress database object.
- */
-function send_confirmation_on_profile_email() {
- global $errors, $wpdb;
- $current_user = wp_get_current_user();
- if ( ! is_object($errors) )
- $errors = new WP_Error();
-
- if ( $current_user->ID != $_POST['user_id'] )
- return false;
-
- if ( $current_user->user_email != $_POST['email'] ) {
- if ( !is_email( $_POST['email'] ) ) {
- $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn’t correct." ), array( 'form-field' => 'email' ) );
- return;
- }
-
- if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {
- $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array( 'form-field' => 'email' ) );
- delete_user_meta( $current_user->ID, '_new_email' );
- return;
- }
-
- $hash = md5( $_POST['email'] . time() . mt_rand() );
- $new_user_email = array(
- 'hash' => $hash,
- 'newemail' => $_POST['email']
- );
- update_user_meta( $current_user->ID, '_new_email', $new_user_email );
-
- $switched_locale = switch_to_locale( get_user_locale() );
-
- /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
- $email_text = __( 'Howdy ###USERNAME###,
-
-You recently requested to have the email address on your account changed.
-
-If this is correct, please click on the following link to change it:
-###ADMIN_URL###
-
-You can safely ignore and delete this email if you do not want to
-take this action.
-
-This email has been sent to ###EMAIL###
-
-Regards,
-All at ###SITENAME###
-###SITEURL###' );
-
- /**
- * Filters the email text sent when a user changes emails.
- *
- * The following strings have a special meaning and will get replaced dynamically:
- * ###USERNAME### The current user's username.
- * ###ADMIN_URL### The link to click on to confirm the email change.
- * ###EMAIL### The new email.
- * ###SITENAME### The name of the site.
- * ###SITEURL### The URL to the site.
- *
- * @since MU
- *
- * @param string $email_text Text in the email.
- * @param string $new_user_email New user email that the current user has changed to.
- */
- $content = apply_filters( 'new_user_email_content', $email_text, $new_user_email );
-
- $content = str_replace( '###USERNAME###', $current_user->user_login, $content );
- $content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'profile.php?newuseremail=' . $hash ) ), $content );
- $content = str_replace( '###EMAIL###', $_POST['email'], $content);
- $content = str_replace( '###SITENAME###', wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ), $content );
- $content = str_replace( '###SITEURL###', network_home_url(), $content );
-
- wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ), $content );
- $_POST['email'] = $current_user->user_email;
-
- if ( $switched_locale ) {
- restore_previous_locale();
- }
- }
-}
-
-/**
- * Adds an admin notice alerting the user to check for confirmation email
- * after email address change.
- *
- * @since 3.0.0
- *
- * @global string $pagenow
- */
-function new_user_email_admin_notice() {
- global $pagenow;
- if ( 'profile.php' === $pagenow && isset( $_GET['updated'] ) && $email = get_user_meta( get_current_user_id(), '_new_email', true ) ) {
- /* translators: %s: New email address */
- 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>';
- }
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * Check whether a site has used its allotted upload space.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since MU
</span></span></pre></div>
<a id="trunksrcwpadminusereditphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/user-edit.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/user-edit.php 2017-07-27 00:40:27 UTC (rev 41162)
+++ trunk/src/wp-admin/user-edit.php 2017-07-27 02:09:51 UTC (rev 41163)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -88,13 +88,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Execute confirmed email change. See send_confirmation_on_profile_email().
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( is_multisite() && IS_PROFILE_PAGE && isset( $_GET[ 'newuseremail' ] ) && $current_user->ID ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( IS_PROFILE_PAGE && isset( $_GET[ 'newuseremail' ] ) && $current_user->ID ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $new_email = get_user_meta( $current_user->ID, '_new_email', true );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $new_email && hash_equals( $new_email[ 'hash' ], $_GET[ 'newuseremail' ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $user = new stdClass;
</span><span class="cx" style="display: block; padding: 0 10px"> $user->ID = $current_user->ID;
</span><span class="cx" style="display: block; padding: 0 10px"> $user->user_email = esc_html( trim( $new_email[ 'newemail' ] ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_multisite() && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $current_user->user_login ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> wp_update_user( $user );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -104,7 +104,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_redirect( add_query_arg( array( 'error' => 'new-email' ), self_admin_url( 'profile.php' ) ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-} elseif ( is_multisite() && IS_PROFILE_PAGE && !empty( $_GET['dismiss'] ) && $current_user->ID . '_new_email' === $_GET['dismiss'] ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+} elseif ( IS_PROFILE_PAGE && ! empty( $_GET['dismiss'] ) && $current_user->ID . '_new_email' === $_GET['dismiss'] ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> check_admin_referer( 'dismiss-' . $current_user->ID . '_new_email' );
</span><span class="cx" style="display: block; padding: 0 10px"> delete_user_meta( $current_user->ID, '_new_email' );
</span><span class="cx" style="display: block; padding: 0 10px"> wp_redirect( add_query_arg( array('updated' => 'true'), self_admin_url( 'profile.php' ) ) );
</span></span></pre></div>
<a id="trunksrcwpincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/user.php 2017-07-27 00:40:27 UTC (rev 41162)
+++ trunk/src/wp-includes/user.php 2017-07-27 02:09:51 UTC (rev 41163)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2590,3 +2590,113 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $current_user;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Sends an email when an email address change is requested.
+ *
+ * @since 3.0.0
+ * @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific.
+ *
+ * @global WP_Error $errors WP_Error object.
+ * @global wpdb $wpdb WordPress database object.
+ */
+function send_confirmation_on_profile_email() {
+ global $errors, $wpdb;
+
+ $current_user = wp_get_current_user();
+ if ( ! is_object( $errors ) ) {
+ $errors = new WP_Error();
+ }
+
+ if ( $current_user->ID != $_POST['user_id'] ) {
+ return false;
+ }
+
+ if ( $current_user->user_email != $_POST['email'] ) {
+ if ( ! is_email( $_POST['email'] ) ) {
+ $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn’t correct." ), array(
+ 'form-field' => 'email',
+ ) );
+
+ return;
+ }
+
+ if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {
+ $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array(
+ 'form-field' => 'email',
+ ) );
+ delete_user_meta( $current_user->ID, '_new_email' );
+
+ return;
+ }
+
+ $hash = md5( $_POST['email'] . time() . mt_rand() );
+ $new_user_email = array(
+ 'hash' => $hash,
+ 'newemail' => $_POST['email'],
+ );
+ update_user_meta( $current_user->ID, '_new_email', $new_user_email );
+
+ /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
+ $email_text = __( 'Howdy ###USERNAME###,
+
+You recently requested to have the email address on your account changed.
+
+If this is correct, please click on the following link to change it:
+###ADMIN_URL###
+
+You can safely ignore and delete this email if you do not want to
+take this action.
+
+This email has been sent to ###EMAIL###
+
+Regards,
+All at ###SITENAME###
+###SITEURL###' );
+
+ /**
+ * Filters the email text sent when a user changes emails.
+ *
+ * The following strings have a special meaning and will get replaced dynamically:
+ * ###USERNAME### The current user's username.
+ * ###ADMIN_URL### The link to click on to confirm the email change.
+ * ###EMAIL### The new email.
+ * ###SITENAME### The name of the site.
+ * ###SITEURL### The URL to the site.
+ *
+ * @since MU
+ * @since 4.9.0 This filter is no longer Multisite specific.
+ *
+ * @param string $email_text Text in the email.
+ * @param string $new_user_email New user email that the current user has changed to.
+ */
+ $content = apply_filters( 'new_user_email_content', $email_text, $new_user_email );
+
+ $content = str_replace( '###USERNAME###', $current_user->user_login, $content );
+ $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail=' . $hash ) ), $content );
+ $content = str_replace( '###EMAIL###', $_POST['email'], $content );
+ $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
+ $content = str_replace( '###SITEURL###', network_home_url(), $content );
+
+ wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content );
+
+ $_POST['email'] = $current_user->user_email;
+ }
+}
+
+/**
+ * Adds an admin notice alerting the user to check for confirmation email
+ * after email address change.
+ *
+ * @since 3.0.0
+ * @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific.
+ *
+ * @global string $pagenow
+ */
+function new_user_email_admin_notice() {
+ global $pagenow;
+ if ( 'profile.php' === $pagenow && isset( $_GET['updated'] ) && $email = get_user_meta( get_current_user_id(), '_new_email', true ) ) {
+ /* translators: %s: New email address */
+ 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>';
+ }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/user.php 2017-07-27 00:40:27 UTC (rev 41162)
+++ trunk/tests/phpunit/tests/user.php 2017-07-27 02:09:51 UTC (rev 41163)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1204,4 +1204,72 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function action_check_passwords_blank_pw( $user_login, &$pass1 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $pass1 = '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 16470
+ */
+ function test_send_confirmation_on_profile_email() {
+ reset_phpmailer_instance();
+ $was_confirmation_email_sent = false;
+
+ $user = $this->factory()->user->create_and_get( array(
+ 'user_email' => 'before@example.com',
+ ) );
+
+ $_POST['email'] = 'after@example.com';
+ $_POST['user_id'] = $user->ID;
+
+ wp_set_current_user( $user->ID );
+
+ do_action( 'personal_options_update' );
+
+ if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
+ $was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
+ }
+
+ // A confirmation email is sent.
+ $this->assertTrue( $was_confirmation_email_sent );
+
+ // The new email address gets put into user_meta.
+ $new_email_meta = get_user_meta( $user->ID, '_new_email', true );
+ $this->assertEquals( 'after@example.com', $new_email_meta['newemail'] );
+
+ // The email address of the user doesn't change. $_POST['email'] should be the email address pre-update.
+ $this->assertEquals( $_POST['email'], $user->user_email );
+ }
+
+ /**
+ * @ticket 16470
+ */
+ function test_remove_send_confirmation_on_profile_email() {
+ remove_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
+
+ reset_phpmailer_instance();
+ $was_confirmation_email_sent = false;
+
+ $user = $this->factory()->user->create_and_get( array(
+ 'user_email' => 'before@example.com',
+ ) );
+
+ $_POST['email'] = 'after@example.com';
+ $_POST['user_id'] = $user->ID;
+
+ wp_set_current_user( $user->ID );
+
+ do_action( 'personal_options_update' );
+
+ if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
+ $was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
+ }
+
+ // No confirmation email is sent.
+ $this->assertFalse( $was_confirmation_email_sent );
+
+ // No usermeta is created.
+ $new_email_meta = get_user_meta( $user->ID, '_new_email', true );
+ $this->assertEmpty( $new_email_meta );
+
+ // $_POST['email'] should be the email address posted from the form.
+ $this->assertEquals( $_POST['email'], 'after@example.com' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>