我想给用户提供功能,而他们的帐户是由管理员在wordpress中创建的,此时设置密码的电子邮件会发送给用户,其中包含带有激活密钥、登录和操作的自定义页面链接。我已经创建了一个短代码,用于在页面中从前端设置密码。我能够从url获取数据,并设法检查密码是否匹配且不为空,但如何为新用户设置此密码。欢迎提供任何帮助/建议。
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
}