I have a function in my custom plugin that will be called after the user do the fisrt login. The function, after a check will give to the user the ability to change it's assigned password with a custom one. This is the code
public function change_user_password( WP_REST_Request $request )
{
$user = wp_get_current_user();
if( !wp_verify_nonce( $request->get_header('X-WP-Nonce'), 'wp_rest' ) || !is_user_logged_in() && is_array($user->roles) & !in_array('customer', $user->roles) ){
return false;
} else {
$old_password_hash = $user->user_pass;
$password = sanitize_text_field( $request->get_param('new_password') );
if( !wp_check_password($password, $old_password_hash, $user->ID) ){
$updated_user = wp_update_user(
array(
'ID' => $user->ID,
'user_pass' => $password,
'meta_input' => array(
'last_password_reset' => time()
)
)
);
if( is_wp_error( $updated_user ) ){
return array(
'status' => 'error',
'message' => $updated_user->get_error_message()
);
} else {
return array(
'status' => 'success',
'message' => 'Password changed with success'
);
}
} else {
return array(
'status' => 'error',
'message' => 'Previous password is equal to the old one.'
);
}
}
}
I need to disable or modify the email that will be sent to the users after password chenge. In another part of the code I've used this filter and seems to work.
add_filter('send_password_change_email', '__return_false');
What is the correct way to modify the email sent to the user after a password change?