Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- register_rest_route( $namespace, '/' . $base . '/reset', array(
- array(
- 'methods' => 'POST',
- 'callback' => array( $this, 'myplugin_reset_user_pass' ),
- ),
- ));
- public function myplugin_reset_user_pass( $request ) {
- $params = $request->get_params();
- $userdata = array(
- 'user_email' => $params['user_email']
- );
- $user = get_user_by( 'email', $userdata['user_email'] );
- // check if username / email exist
- $username = username_exists( $user->user_login );
- if ( $username and email_exists($user->user_email) == true ) {
- if ( function_exists( 'wp_set_password') ) {
- // generate new password
- $password = wp_generate_password( 8, true );
- $resetPass = wp_set_password( $password, $user->id );
- if($resetPass){
- return new WP_REST_Response(true, 200);
- }
- }
- }
- return new WP_Error( 'cant-reset', __( 'message', 'text-domain'), array( 'status' => 500 ) );
- }
Add Comment
Please, Sign In to add comment