Make WordPress Core


Ignore:
Timestamp:
02/01/2021 10:11:46 PM (3 years ago)
Author:
adamsilverstein
Message:

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 #34281.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r49193 r50129  
    53995399    wp_send_json_success();
    54005400}
     5401
     5402/**
     5403 * Ajax handler sends a password reset link.
     5404 *
     5405 * @since 5.7.0
     5406 */
     5407function wp_ajax_send_password_reset() {
     5408
     5409    // Validate the nonce for this action.
     5410    $user_id = isset( $_POST['user_id'] ) ? (int) $_POST['user_id'] : 0;
     5411    check_ajax_referer( 'reset-password-for-' . $user_id, 'nonce' );
     5412
     5413    // Verify user capabilities.
     5414    if ( ! current_user_can( 'edit_user', $user_id ) ) {
     5415        wp_send_json_error( __( 'Cannot send password reset, permission denied.' ) );
     5416    }
     5417
     5418    // Send the password reset link.
     5419    $user    = get_userdata( $user_id );
     5420    $results = retrieve_password( $user->user_login );
     5421
     5422    if ( true === $results ) {
     5423        wp_send_json_success(
     5424            /* translators: 1: User's display name. */
     5425            sprintf( __( 'A password reset link was emailed to %s.' ), $user->display_name )
     5426        );
     5427    } else {
     5428        wp_send_json_error( $results );
     5429    }
     5430}
Note: See TracChangeset for help on using the changeset viewer.