reset – Jak ustawić hasło z frontendu, jeśli masz klucz aktywacyjny i login użytkownika w adresie URL w wordpress?
![reset – Jak ustawić hasło z frontendu, jeśli masz klucz aktywacyjny i login użytkownika w adresie URL w wordpress?](https://oen.pl/wp-content/uploads/2023/01/apple-touch-icon@2.png)
Chcę zapewnić funkcjonalność użytkownikowi, podczas gdy jego konto jest tworzone w wordpress przez administratora w tym czasie do użytkownika wysyłana jest wiadomość e-mail z ustawionym hasłem, która zawiera niestandardowy link do strony z kluczem aktywacyjnym, loginem i akcją. Stworzyłem jeden krótki kod, który był używany na stronie do ustawiania hasła z interfejsu użytkownika. Udało mi się uzyskać dane z adresu URL i udało mi się sprawdzić, czy hasło jest zgodne, a nie puste, ale jak mogę ustawić to hasło dla nowych użytkowników. Każda pomoc/sugestia jest doceniana.
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
}