Skip to content

Instantly share code, notes, and snippets.

@maplerock
Created July 19, 2021 11:37
Show Gist options
  • Save maplerock/8aca49a855899e82fc43bb5def586cab to your computer and use it in GitHub Desktop.
Save maplerock/8aca49a855899e82fc43bb5def586cab to your computer and use it in GitHub Desktop.
Huh πŸ€·πŸ»β€β™‚οΈ
<?php
include './wp-load.php';
$username = $_REQUEST['username'];
$user = get_user_by('login',$username);
$userId = $user->data->ID;
$password = $_REQUEST['password'];
$new_password = $_REQUEST['new_password'];
if(empty($username)){
$json = array('status'=>false,'msg'=>'Please enter user name');
echo json_encode($json);
exit;
}
if(empty($password)){
$json = array('status'=>false,'msg'=>'Please enter old password');
echo json_encode($json);
exit;
}
if(empty($new_password)){
$json = array('status'=>false,'msg'=>'Please enter new password');
echo json_encode($json);
exit;
}
$hash = $user->data->user_pass;
$code = 500; $status = false;
if (wp_check_password( $password, $hash ) ){
$msg = 'Password updated successfully';
$code = 200; $status = true;
wp_set_password($new_password , $userId);
}else{
$msg = 'Current password does not match.';
}
$json = array('code'=>$code,'status'=>$status,'msg'=>$msg);
echo json_encode($json);
exit;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment