<!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>[50129] trunk/src: Users: enable admins to send users a reset password link.</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 { white-space: pre-line; 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/50129">50129</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/50129","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>adamsilverstein</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-02-01 22:11:46 +0000 (Mon, 01 Feb 2021)</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: enable admins to send users a reset password link.
Add a feature so Admins can send users a 'password reset' email. This doesn't change the password or force a password change. It only emails the user the password reset link.
The feature appears in several places:
* A "Send Reset Link" button on user profile screen.
* A "Send password reset" option in the user list bulk action dropdown.
* A "Send password reset" quick action when hovering over a username in the user list.
Props Ipstenu, DrewAPicture, eventualo, wonderboymusic, knutsp, ericlewis, afercia, JoshuaWold, johnbillion, paaljoachim, hedgefield.
Fixes <a href="https://core.trac.wordpress.org/ticket/34281">#34281</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcjs_enqueuesadminuserprofilejs">trunk/src/js/_enqueues/admin/user-profile.js</a></li>
<li><a href="#trunksrcwpadminadminajaxphp">trunk/src/wp-admin/admin-ajax.php</a></li>
<li><a href="#trunksrcwpadminincludesajaxactionsphp">trunk/src/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunksrcwpadminincludesclasswpuserslisttablephp">trunk/src/wp-admin/includes/class-wp-users-list-table.php</a></li>
<li><a href="#trunksrcwpadminusereditphp">trunk/src/wp-admin/user-edit.php</a></li>
<li><a href="#trunksrcwpadminusersphp">trunk/src/wp-admin/users.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
<li><a href="#trunksrcwpincludesscriptloaderphp">trunk/src/wp-includes/script-loader.php</a></li>
<li><a href="#trunksrcwploginphp">trunk/src/wp-login.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcjs_enqueuesadminuserprofilejs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/js/_enqueues/admin/user-profile.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/js/_enqueues/admin/user-profile.js 2021-02-01 22:01:19 UTC (rev 50128)
+++ trunk/src/js/_enqueues/admin/user-profile.js 2021-02-01 22:11:46 UTC (rev 50129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,7 +2,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @output wp-admin/js/user-profile.js
</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">-/* global ajaxurl, pwsL10n */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* global ajaxurl, pwsL10n, userProfileL10n */
</ins><span class="cx" style="display: block; padding: 0 10px"> (function($) {
</span><span class="cx" style="display: block; padding: 0 10px"> var updateLock = false,
</span><span class="cx" style="display: block; padding: 0 10px"> __ = wp.i18n.__,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -91,6 +91,68 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Handle the password reset button. Sets up an ajax callback to trigger sending
+ * a password reset email.
+ */
+ function bindPasswordRestLink() {
+ $( '#generate-reset-link' ).on( 'click', function() {
+ var $this = $(this),
+ data = {
+ 'user_id': userProfileL10n.user_id, // The user to send a reset to.
+ 'nonce': userProfileL10n.nonce // Nonce to validate the action.
+ };
+
+ // Remove any previous error messages.
+ $this.parent().find( '.notice-error' ).remove();
+
+ // Send the reset request.
+ var resetAction = wp.ajax.post( 'send-password-reset', data );
+
+ // Handle reset success.
+ resetAction.done( function( response ) {
+ addInlineNotice( $this, true, response );
+ } );
+
+ // Handle reset failure.
+ resetAction.fail( function( response ) {
+ addInlineNotice( $this, false, response );
+ } );
+
+ });
+
+ }
+
+ /**
+ * Helper function to insert an inline notice of success or failure.
+ *
+ * @param {jQuery Object} $this The button element: the message will be inserted
+ * above this button
+ * @param {bool} success Whether the message is a success message.
+ * @param {string} message The message to insert.
+ */
+ function addInlineNotice( $this, success, message ) {
+ var resultDiv = $( '<div />' );
+
+ // Set up the notice div.
+ resultDiv.addClass( 'notice inline' );
+
+ // Add a class indicating success or failure.
+ resultDiv.addClass( 'notice-' + ( success ? 'success' : 'error' ) );
+
+ // Add the message, wrapping in a p tag, with a fadein to highlight each message.
+ resultDiv.text( $( $.parseHTML( message ) ).text() ).wrapInner( '<p />');
+
+ // Disable the button when the callback has succeeded.
+ $this.prop( 'disabled', success );
+
+ // Remove any previous notices.
+ $this.siblings( '.notice' ).remove();
+
+ // Insert the notice.
+ $this.before( resultDiv );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> function bindPasswordForm() {
</span><span class="cx" style="display: block; padding: 0 10px"> var $generateButton,
</span><span class="cx" style="display: block; padding: 0 10px"> $cancelButton;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -369,6 +431,7 @@
</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"> bindPasswordForm();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ bindPasswordRestLink();
</ins><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"> $( '#destroy-sessions' ).on( 'click', function( e ) {
</span></span></pre></div>
<a id="trunksrcwpadminadminajaxphp"></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/admin-ajax.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/admin-ajax.php 2021-02-01 22:01:19 UTC (rev 50128)
+++ trunk/src/wp-admin/admin-ajax.php 2021-02-01 22:11:46 UTC (rev 50129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -140,6 +140,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'health-check-loopback-requests',
</span><span class="cx" style="display: block; padding: 0 10px"> 'health-check-get-sizes',
</span><span class="cx" style="display: block; padding: 0 10px"> 'toggle-auto-updates',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'send-password-reset',
</ins><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"> // Deprecated.
</span></span></pre></div>
<a id="trunksrcwpadminincludesajaxactionsphp"></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/ajax-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ajax-actions.php 2021-02-01 22:01:19 UTC (rev 50128)
+++ trunk/src/wp-admin/includes/ajax-actions.php 2021-02-01 22:11:46 UTC (rev 50129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5398,3 +5398,33 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_success();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Ajax handler sends a password reset link.
+ *
+ * @since 5.7.0
+ */
+function wp_ajax_send_password_reset() {
+
+ // Validate the nonce for this action.
+ $user_id = isset( $_POST['user_id'] ) ? (int) $_POST['user_id'] : 0;
+ check_ajax_referer( 'reset-password-for-' . $user_id, 'nonce' );
+
+ // Verify user capabilities.
+ if ( ! current_user_can( 'edit_user', $user_id ) ) {
+ wp_send_json_error( __( 'Cannot send password reset, permission denied.' ) );
+ }
+
+ // Send the password reset link.
+ $user = get_userdata( $user_id );
+ $results = retrieve_password( $user->user_login );
+
+ if ( true === $results ) {
+ wp_send_json_success(
+ /* translators: 1: User's display name. */
+ sprintf( __( 'A password reset link was emailed to %s.' ), $user->display_name )
+ );
+ } else {
+ wp_send_json_error( $results );
+ }
+}
</ins></span></pre></div>
<a id="trunksrcwpadminincludesclasswpuserslisttablephp"></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/class-wp-users-list-table.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/class-wp-users-list-table.php 2021-02-01 22:01:19 UTC (rev 50128)
+++ trunk/src/wp-admin/includes/class-wp-users-list-table.php 2021-02-01 22:11:46 UTC (rev 50129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -274,6 +274,11 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Add a password reset link to the bulk actions dropdown.
+ if ( current_user_can( 'edit_users' ) ) {
+ $actions['resetpassword'] = __( 'Send password reset' );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $actions;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -469,6 +474,11 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Add a link to send the user a reset password link by email.
+ if ( get_current_user_id() !== $user_object->ID && current_user_can( 'edit_user', $user_object->ID ) ) {
+ $actions['resetpassword'] = "<a class='resetpassword' href='" . wp_nonce_url( "users.php?action=resetpassword&users=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Send password reset' ) . '</a>';
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the action links displayed under each user in the Users list table.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</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 2021-02-01 22:01:19 UTC (rev 50128)
+++ trunk/src/wp-admin/user-edit.php 2021-02-01 22:11:46 UTC (rev 50129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -609,6 +609,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </td>
</span><span class="cx" style="display: block; padding: 0 10px"> </tr>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php
+ // Allow admins to send reset password link
+ if ( ! IS_PROFILE_PAGE ) :
+ ?>
+ <tr class="user-sessions-wrap hide-if-no-js">
+ <th><?php _e( 'Password Reset' ); ?></th>
+ <td>
+ <div class="generate-reset-link">
+ <button type="button" class="button button-secondary" id="generate-reset-link">
+ <?php _e( 'Send Reset Link' ); ?>
+ </button>
+ </div>
+ <p class="description">
+ <?php
+ /* translators: 1: User's display name. */
+ printf( __( 'Send %s a link to reset their password. This will not change their password, nor will it force a change.' ), esc_html( $profileuser->display_name ) );
+ ?>
+ </p>
+ </td>
+ </tr>
+ <?php endif; ?>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpadminusersphp"></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/users.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/users.php 2021-02-01 22:01:19 UTC (rev 50128)
+++ trunk/src/wp-admin/users.php 2021-02-01 22:11:46 UTC (rev 50129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -208,6 +208,46 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp_redirect( $redirect );
</span><span class="cx" style="display: block; padding: 0 10px"> exit;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'resetpassword':
+ check_admin_referer( 'bulk-users' );
+ if ( ! current_user_can( 'edit_users' ) ) {
+ $errors = new WP_Error( 'edit_users', __( 'You can’t edit users.' ) );
+ }
+ if ( empty( $_REQUEST['users'] ) ) {
+ wp_redirect( $redirect );
+ exit();
+ }
+ $userids = array_map( 'intval', (array) $_REQUEST['users'] );
+
+ $reset_count = 0;
+
+ foreach ( $userids as $id ) {
+ if ( ! current_user_can( 'edit_user', $id ) ) {
+ wp_die( __( 'You can’t edit that user.' ) );
+ }
+
+ if ( $id === $current_user->ID ) {
+ $update = 'err_admin_reset';
+ continue;
+ }
+
+ // Send the password reset link.
+ $user = get_userdata( $id );
+ if ( retrieve_password( $user->user_login ) ) {
+ ++$reset_count;
+ }
+ }
+
+ $redirect = add_query_arg(
+ array(
+ 'reset_count' => $reset_count,
+ 'update' => 'resetpassword',
+ ),
+ $redirect
+ );
+ wp_redirect( $redirect );
+ exit;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> case 'delete':
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_multisite() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_die( __( 'User deletion is not allowed from this screen.' ), 400 );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -506,6 +546,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . $message . '</p></div>';
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'resetpassword':
+ $reset_count = isset( $_GET['reset_count'] ) ? (int) $_GET['reset_count'] : 0;
+ if ( 1 === $reset_count ) {
+ $message = __( 'Password reset link sent.' );
+ } else {
+ /* translators: %s: Number of users. */
+ $message = sprintf( __( 'Password reset links sent to %s users.' ), $reset_count );
+ }
+ $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . $message . '</p></div>';
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px"> case 'promote':
</span><span class="cx" style="display: block; padding: 0 10px"> $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Changed roles.' ) . '</p></div>';
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></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/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/functions.php 2021-02-01 22:01:19 UTC (rev 50128)
+++ trunk/src/wp-includes/functions.php 2021-02-01 22:11:46 UTC (rev 50129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7781,3 +7781,172 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return abs( (float) $expected - (float) $actual ) <= $precision;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Handles sending a password retrieval email to a user.
+ *
+ * @since 2.5.0
+ * @since 5.7.0 Added `$user_login` parameter.
+ *
+ * Note: prior to 5.7.0 this function was in wp_login.php.
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ * @global PasswordHash $wp_hasher Portable PHP password hashing framework.
+ *
+ * @param string $user_login Optional user_login, default null. Uses
+ * `$_POST['user_login']` if `$user_login` not set.
+ * @return true|WP_Error True when finished, WP_Error object on error.
+ */
+function retrieve_password( $user_login = null ) {
+ $errors = new WP_Error();
+ $user_data = false;
+
+ // Use the passed $user_login if available, otherwise use $_POST['user_login'].
+ if ( ! $user_login && ! empty( $_POST['user_login'] ) ) {
+ $user_login = $_POST['user_login'];
+ }
+
+ if ( empty( $user_login ) ) {
+ $errors->add( 'empty_username', __( '<strong>Error</strong>: Please enter a username or email address.' ) );
+ } elseif ( strpos( $user_login, '@' ) ) {
+ $user_data = get_user_by( 'email', trim( wp_unslash( $user_login ) ) );
+ if ( empty( $user_data ) ) {
+ $errors->add( 'invalid_email', __( '<strong>Error</strong>: There is no account with that username or email address.' ) );
+ }
+ } else {
+ $user_data = get_user_by( 'login', trim( wp_unslash( $user_login ) ) );
+ }
+
+ /**
+ * Filters the user data during a password reset request.
+ *
+ * Allows, for example, custom validation using data other than username or email address.
+ *
+ * @since 5.7.0
+ *
+ * @param WP_User|false $user_data WP_User object if found, false if the user does not exist.
+ * @param WP_Error $errors A WP_Error object containing any errors generated
+ * by using invalid credentials.
+ */
+ $user_data = apply_filters( 'lostpassword_user_data', $user_data, $errors );
+
+ /**
+ * Fires before errors are returned from a password reset request.
+ *
+ * @since 2.1.0
+ * @since 4.4.0 Added the `$errors` parameter.
+ * @since 5.4.0 Added the `$user_data` parameter.
+ *
+ * @param WP_Error $errors A WP_Error object containing any errors generated
+ * by using invalid credentials.
+ * @param WP_User|false $user_data WP_User object if found, false if the user does not exist.
+ */
+ do_action( 'lostpassword_post', $errors, $user_data );
+
+ /**
+ * Filters the errors encountered on a password reset request.
+ *
+ * The filtered WP_Error object may, for example, contain errors for an invalid
+ * username or email address. A WP_Error object should always be returned,
+ * but may or may not contain errors.
+ *
+ * If any errors are present in $errors, this will abort the password reset request.
+ *
+ * @since 5.5.0
+ *
+ * @param WP_Error $errors A WP_Error object containing any errors generated
+ * by using invalid credentials.
+ * @param WP_User|false $user_data WP_User object if found, false if the user does not exist.
+ */
+ $errors = apply_filters( 'lostpassword_errors', $errors, $user_data );
+
+ if ( $errors->has_errors() ) {
+ return $errors;
+ }
+
+ if ( ! $user_data ) {
+ $errors->add( 'invalidcombo', __( '<strong>Error</strong>: There is no account with that username or email address.' ) );
+ return $errors;
+ }
+
+ // Redefining user_login ensures we return the right case in the email.
+ $user_login = $user_data->user_login;
+ $user_email = $user_data->user_email;
+ $key = get_password_reset_key( $user_data );
+
+ if ( is_wp_error( $key ) ) {
+ return $key;
+ }
+
+ if ( is_multisite() ) {
+ $site_name = get_network()->site_name;
+ } else {
+ /*
+ * The blogname option is escaped with esc_html on the way into the database
+ * in sanitize_option. We want to reverse this for the plain text arena of emails.
+ */
+ $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
+ }
+
+ $message = __( 'Someone has requested a password reset for the following account:' ) . "\r\n\r\n";
+ /* translators: %s: Site name. */
+ $message .= sprintf( __( 'Site Name: %s' ), $site_name ) . "\r\n\r\n";
+ /* translators: %s: User login. */
+ $message .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n\r\n";
+ $message .= __( 'If this was a mistake, ignore this email and nothing will happen.' ) . "\r\n\r\n";
+ $message .= __( 'To reset your password, visit the following address:' ) . "\r\n\r\n";
+ $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "\r\n\r\n";
+
+ $requester_ip = $_SERVER['REMOTE_ADDR'];
+ if ( $requester_ip ) {
+ $message .= sprintf(
+ /* translators: %s: IP address of password reset requester. */
+ __( 'This password reset request originated from the IP address %s.' ),
+ $requester_ip
+ ) . "\r\n";
+ }
+
+ /* translators: Password reset notification email subject. %s: Site title. */
+ $title = sprintf( __( '[%s] Password Reset' ), $site_name );
+
+ /**
+ * Filters the subject of the password reset email.
+ *
+ * @since 2.8.0
+ * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
+ *
+ * @param string $title Email subject.
+ * @param string $user_login The username for the user.
+ * @param WP_User $user_data WP_User object.
+ */
+ $title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
+
+ /**
+ * Filters the message body of the password reset mail.
+ *
+ * If the filtered message is empty, the password reset email will not be sent.
+ *
+ * @since 2.8.0
+ * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
+ *
+ * @param string $message Email message.
+ * @param string $key The activation key.
+ * @param string $user_login The username for the user.
+ * @param WP_User $user_data WP_User object.
+ */
+ $message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
+
+ if ( $message && ! wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) ) {
+ $errors->add(
+ 'retrieve_password_email_failure',
+ sprintf(
+ /* translators: %s: Documentation URL. */
+ __( '<strong>Error</strong>: The email could not be sent. Your site may not be correctly configured to send emails. <a href="%s">Get support for resetting your password</a>.' ),
+ esc_url( __( 'https://wordpress.org/support/article/resetting-your-password/' ) )
+ )
+ );
+ return $errors;
+ }
+
+ return true;
+}
</ins></span></pre></div>
<a id="trunksrcwpincludesscriptloaderphp"></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/script-loader.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/script-loader.php 2021-02-01 22:01:19 UTC (rev 50128)
+++ trunk/src/wp-includes/script-loader.php 2021-02-01 22:11:46 UTC (rev 50129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1078,6 +1078,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> $scripts->set_translations( 'user-profile' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user_id = isset( $_GET['user_id'] ) ? (int) $_GET['user_id'] : 0;
+ did_action( 'init' ) && $scripts->localize(
+ 'user-profile',
+ 'userProfileL10n',
+ array(
+ 'user_id' => $user_id,
+ 'nonce' => wp_create_nonce( 'reset-password-for-' . $user_id ),
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $scripts->add( 'language-chooser', "/wp-admin/js/language-chooser$suffix.js", array( 'jquery' ), false, 1 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwploginphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-login.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-login.php 2021-02-01 22:01:19 UTC (rev 50128)
+++ trunk/src/wp-login.php 2021-02-01 22:11:46 UTC (rev 50129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -360,163 +360,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</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">-/**
- * Handles sending a password retrieval email to a user.
- *
- * @since 2.5.0
- *
- * @return true|WP_Error True when finished, WP_Error object on error.
- */
-function retrieve_password() {
- $errors = new WP_Error();
- $user_data = false;
-
- if ( empty( $_POST['user_login'] ) || ! is_string( $_POST['user_login'] ) ) {
- $errors->add( 'empty_username', __( '<strong>Error</strong>: Please enter a username or email address.' ) );
- } elseif ( strpos( $_POST['user_login'], '@' ) ) {
- $user_data = get_user_by( 'email', trim( wp_unslash( $_POST['user_login'] ) ) );
- if ( empty( $user_data ) ) {
- $errors->add( 'invalid_email', __( '<strong>Error</strong>: There is no account with that username or email address.' ) );
- }
- } else {
- $login = trim( wp_unslash( $_POST['user_login'] ) );
- $user_data = get_user_by( 'login', $login );
- }
-
- /**
- * Filters the user data during a password reset request.
- *
- * Allows, for example, custom validation using data other than username or email address.
- *
- * @since 5.7.0
- *
- * @param WP_User|false $user_data WP_User object if found, false if the user does not exist.
- * @param WP_Error $errors A WP_Error object containing any errors generated
- * by using invalid credentials.
- */
- $user_data = apply_filters( 'lostpassword_user_data', $user_data, $errors );
-
- /**
- * Fires before errors are returned from a password reset request.
- *
- * @since 2.1.0
- * @since 4.4.0 Added the `$errors` parameter.
- * @since 5.4.0 Added the `$user_data` parameter.
- *
- * @param WP_Error $errors A WP_Error object containing any errors generated
- * by using invalid credentials.
- * @param WP_User|false $user_data WP_User object if found, false if the user does not exist.
- */
- do_action( 'lostpassword_post', $errors, $user_data );
-
- /**
- * Filters the errors encountered on a password reset request.
- *
- * The filtered WP_Error object may, for example, contain errors for an invalid
- * username or email address. A WP_Error object should always be returned,
- * but may or may not contain errors.
- *
- * If any errors are present in $errors, this will abort the password reset request.
- *
- * @since 5.5.0
- *
- * @param WP_Error $errors A WP_Error object containing any errors generated
- * by using invalid credentials.
- * @param WP_User|false $user_data WP_User object if found, false if the user does not exist.
- */
- $errors = apply_filters( 'lostpassword_errors', $errors, $user_data );
-
- if ( $errors->has_errors() ) {
- return $errors;
- }
-
- if ( ! $user_data ) {
- $errors->add( 'invalidcombo', __( '<strong>Error</strong>: There is no account with that username or email address.' ) );
- return $errors;
- }
-
- // Redefining user_login ensures we return the right case in the email.
- $user_login = $user_data->user_login;
- $user_email = $user_data->user_email;
- $key = get_password_reset_key( $user_data );
-
- if ( is_wp_error( $key ) ) {
- return $key;
- }
-
- if ( is_multisite() ) {
- $site_name = get_network()->site_name;
- } else {
- /*
- * The blogname option is escaped with esc_html on the way into the database
- * in sanitize_option. We want to reverse this for the plain text arena of emails.
- */
- $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
- }
-
- $message = __( 'Someone has requested a password reset for the following account:' ) . "\r\n\r\n";
- /* translators: %s: Site name. */
- $message .= sprintf( __( 'Site Name: %s' ), $site_name ) . "\r\n\r\n";
- /* translators: %s: User login. */
- $message .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n\r\n";
- $message .= __( 'If this was a mistake, ignore this email and nothing will happen.' ) . "\r\n\r\n";
- $message .= __( 'To reset your password, visit the following address:' ) . "\r\n\r\n";
- $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "\r\n\r\n";
-
- $requester_ip = $_SERVER['REMOTE_ADDR'];
- if ( $requester_ip ) {
- $message .= sprintf(
- /* translators: %s: IP address of password reset requester. */
- __( 'This password reset request originated from the IP address %s.' ),
- $requester_ip
- ) . "\r\n";
- }
-
- /* translators: Password reset notification email subject. %s: Site title. */
- $title = sprintf( __( '[%s] Password Reset' ), $site_name );
-
- /**
- * Filters the subject of the password reset email.
- *
- * @since 2.8.0
- * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
- *
- * @param string $title Email subject.
- * @param string $user_login The username for the user.
- * @param WP_User $user_data WP_User object.
- */
- $title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
-
- /**
- * Filters the message body of the password reset mail.
- *
- * If the filtered message is empty, the password reset email will not be sent.
- *
- * @since 2.8.0
- * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
- *
- * @param string $message Email message.
- * @param string $key The activation key.
- * @param string $user_login The username for the user.
- * @param WP_User $user_data WP_User object.
- */
- $message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
-
- if ( $message && ! wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) ) {
- $errors->add(
- 'retrieve_password_email_failure',
- sprintf(
- /* translators: %s: Documentation URL. */
- __( '<strong>Error</strong>: The email could not be sent. Your site may not be correctly configured to send emails. <a href="%s">Get support for resetting your password</a>.' ),
- esc_url( __( 'https://wordpress.org/support/article/resetting-your-password/' ) )
- )
- );
- return $errors;
- }
-
- return true;
-}
-
</del><span class="cx" style="display: block; padding: 0 10px"> //
</span><span class="cx" style="display: block; padding: 0 10px"> // Main.
</span><span class="cx" style="display: block; padding: 0 10px"> //
</span></span></pre>
</div>
</div>
</body>
</html>