我忘记密码表格,一旦用户点击保存按钮需要在wordpress数据库用户表中保存更改的密码。如何实现呢?
function wp_login_form_alter(&$form, &$form_state, $form_id) {
//echo "hi";
if($form_id=="user_profile_form"){
print '<pre>';
//print_r($form);
print_r($form_state['user']);
echo $form_state['user']->uid;
echo $form_state['user']->name;
echo $form_state['user']->mail;
echo $form_state['user']->pass;
echo $form_state['user']->login;
exit;
//UPDATE wp_users SET user_pass = md5($new_password) WHERE ID = $user_id
}
}
答案 0 :(得分:0)
不确定您是否可以直接从hook_form_alter()读取提交的值。相反,我认为您应该从那里添加(注册)自定义提交表单处理程序:
$form['#submit'][] = 'my_custom_submit_handler';
然后创建另一个以这种方式调用的函数(&#34; my_custom_submit_handler()&#34;),因此当表单是提交者时,您的自定义提交表单处理程序也将被调用,您可以收集密码数据并保存它。 / p>
答案 1 :(得分:0)
What you can do is:
Setting the password to a random value, using user_hash_password()
Show a message to the users telling them they need to reset their password
The right way to call user_hash_password() is the following one.
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$hash = user_hash_password($password);