How to set password from frontend if have activation key and user login in url in wordpress?
Question
I want to give functionality to user, while their account is created in wordpress by administrator at that time set password email is sent to user, which contains custom page link with activation key, login, and action. I have created one shortcode which used in page for set password from front end. I was able to get data from url, and managed to check whether password is match and not empty, but how can i set this password for new users. Any help/suggestion is appreciated.
add_shortcode( 'RESET_PASSWORD' , 'reset_password_function' );
function reset_password_function() {
global $wpdb, $user_ID;
if(isset($_GET['key']) && $_GET['action'] == "rp") {
$reset_key = $_GET['key'];
$action = $_GET['action'];
$user_login = $_GET['login'];
print_r($reset_key);
echo '<br/>';
print_r($action);
echo '<br/>';
print_r($user_login);
// Print output like
// Kdfd3434Kdfrewfpd
// rp
// demo.test@abc.com
}
if($_POST['action'] == "agent_pwd_reset"){
$error = array();
if(empty($_POST['new_password'])) {
$error[] = __('Can not set blank new password field','AA');
} else {
$agent_new_pass = $_POST['new_password'];
}
if(empty($_POST['confirm_password'])) {
$error[] = __('Can not set blank confirm password field','AA');
} elseif ($_POST['new_password'] !== $_POST['confirm_password']) {
$error[] = __('Password not match.','AA');
} else {
$agent_confrim_pass = $_POST['confirm_password'];
$success = __('Password match.','AA');
}
if ( count($error) == 0 ) {
echo '<div class="col-md-6 col-md-offset-4 alert alert-success">'.$success. '</div>';
// here i want to set new password for user
} elseif ( count($error) > 0 ) {
echo '<div class="col-md-6 col-md-offset-4 alert alert-danger error">' . implode("<br />", $error) . '</div>';
}
}
?>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<form class="form-horizontal password_reset_form" method="post" action="">
<div class="form-group">
<label class="control-label col-sm-4" for="new_password">
<?php _e('New Password', 'AA'); ?>
</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="new_password" id="new_password" required value="" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4" for="confirm_password">
<?php _e('Confirm Password', 'AA'); ?>
</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="confirm_password" required id="confirm_password" value="" />
</div>
</div>
<input type="hidden" name="action" value="agent_pwd_reset" />
<input type="hidden" name="reset_pass_nonce" value="<?php echo wp_create_nonce("reset_pass_nonce"); ?>" />
<div class="form-group">
<div class="col-sm-8 col-sm-offset-4">
<input name="resetbtn" type="submit" id="resetbtn" class="resetbtn btn btn-primary" value="<?php _e('Reset Password', 'AA'); ?>" />
</div>
</div>
</form>
</div>
</div>
<?php
}
0
password, reset
3 years
2020-03-25T00:53:48-05:00
2020-03-25T00:53:48-05:00 0 Answers
120 views
0
Leave an answer