我正在创建一个具有前端配置文件更新部分的插件。
如果我有这段代码......
$userdata = array(
'user_login' => $username,
'user_email' => $email,
'user_url' => $website,
'first_name' => $first_name,
'last_name' => $last_name,
'nickname' => $nickname,
'description' => $bio,
);
global $current_user; get_currentuserinfo();
$ID=$current_user->ID;
$ID_array = array('ID' => $ID);
$userdata = $ID_array + $userdata;
$user = wp_update_user( $userdata );
......一切都很好;但是,如果我还通过添加'user_pass' => $password
来更新密码,从而将代码更改为...
$userdata = array(
'user_login' => $username,
'user_email' => $email,
'user_pass' => $password,
'user_url' => $website,
'first_name' => $first_name,
'last_name' => $last_name,
'nickname' => $nickname,
'description' => $bio,
);
global $current_user; get_currentuserinfo();
$ID=$current_user->ID;
$ID_array = array('ID' => $ID);
$userdata = $ID_array + $userdata;
$user = wp_update_user( $userdata );
...我在前端得到以下错误......
警告:无法修改标头信息 - 已在/ home / sdglandl / public_html / home中发送的标头(输出从/home/sdglandl/public_html/home/wp-content/themes/converio/header.php:2开始)第942行/wp-includes/pluggable.php
多条线路反复出现同样的错误
答案 0 :(得分:1)
当您更新当前用户的密码时,将清除当前用户的cookie。这类似于已经讨论过的issue。您需要在呈现任何HTML之前运行此代码,以防止标题已设置问题。
add_action( 'wp', 'set_current_users_password' );
function set_current_users_password() {
// Get current logged-in user.
$user = wp_get_current_user();
// Change password.
wp_set_password($new_password, wp_get_current_user()->ID);
// Log-in again.
wp_set_auth_cookie($user->ID);
wp_set_current_user($user->ID);
do_action('wp_login', $user->user_login, $user);
}