我正在尝试更新$\\u POST收到的用户邮件,并立即使用它。它会改变,但会输出旧的。怎么做呢?
global $current_user;
get_currentuserinfo();
if (isset($_POST[\'email\'])) {
wp_update_user( array(\'ID\' => $current_user->ID, \'user_email\' => $_POST[\'email\']) );
get_currentuserinfo(); //just in case
}
echo \'<p>You\'ll recieve a mail here: \' . $current_user->user_email . \'</p>\'; //outputs old mail
可能必须使用全局$current\\u用户变量?
编辑:
Chuncky修复,
global $current_user;
get_currentuserinfo();
$email = $current_user->user_email;
if (isset($_POST[\'email\'])) {
wp_update_user( array(\'ID\' => $current_user->ID, \'user_email\' => $_POST[\'email\']) );
$email = $_POST[\'email\'];
}
echo \'<p>You\'ll recieve a mail here: \' . $email . \'</p>\';
最合适的回答,由SO网友:Tomás Cot 整理而成
global $current_user;
get_currentuserinfo();
if (isset($_POST[\'email\'])) {
wp_update_user( array(\'ID\' => $current_user->ID, \'user_email\' => $_POST[\'email\']) );
unset($current_user);
get_currentuserinfo(); //just in case
}
echo \'<p>You\'ll recieve a mail here: \' . $current_user->user_email . \'</p>\';
现在应该可以了,问题出在
get_currentuserinfo()
作用
because it checks if the variable is already set and is an instace of WP_User
, 如果是,则函数“中止”(返回)并且不更新变量。