【发布时间】:2021-10-08 16:08:03
【问题描述】:
我已经尝试了几个小时来让最小密码大小控制系统工作。它适用于注册,但对于个人资料修改我无法让它工作。我有一个函数 update_user 结束如下:
// The password is updated only if a new one has been filled in
if (isset($_POST['user_pass']) && !empty($_POST['user_pass'])) {
$userdata['user_pass'] = trim($_POST['user_pass']);
}
// We check that the password contains 8 characters
if ( strlen($_POST['user_pass']) < 8 ) {
$errors = 'Your password must be at least 8 characters long and have at least one capital letter and one number in it.';
}
// Update user
wp_update_user($userdata);
// Redirect
wp_redirect(site_url('/profile'));
exit();
}
}
我也尝试过单独执行一个函数,但也没有用。
【问题讨论】:
-
我不是 WordPress 开发人员,但我没有在您的代码中看到阻止用户更新的内容。您设置了一个
$errors变量,但我认为它不会做太多事情。但这能满足您的需求吗? wordpress.stackexchange.com/a/159883 -
确实我添加了一个else,如果满足条件,尝试保存密码修改。还是不行:
if ( strlen($_POST['user_pass']) < 8 ) { $error = 'Your password must be at least 8 characters long and have at least one capital letter and one number in it.'; } else { $user = wp_update_user(array( user_pass' => $d['user_pass'], )); if (is_wp_error($user)) { $error = $user->get_error_message(); } } }
标签: php wordpress passwords string-length