如何在另一页上显示WP_Error()
错误?WordPress:如何在另一页上显示WP_Error()错误?
在functions.php
,我有以下代码的形式处理器:
global $current_user, $errors; get_currentuserinfo();
$errors = new WP_Error();
if(isset($_POST['user_email'])) {
if(!is_email($_POST['user_email'])) {
$errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.'));
} elseif(email_exists($_POST['user_email'])) {
$errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'));
} elseif($_POST['user_email'] <> $current_user->{user_email}) {
wp_update_user(array('ID' => $uid, 'user_email' => esc_attr($_POST['user_email'])));
}
}
if($errors->get_error_code()) { return $errors; }
在account.php
,它显示的形式,我有以下代码:
<?php
$return = update_account();
if(is_wp_error($return)) { echo $return->get_error_message(); }
?>
无论是invalid_email
也不在测试过程中报告了email_exist
错误。但是,错误是阻止。我只是不明白他们为什么没有被展示。我究竟做错了什么?
您是否在account.php中包含了wp_blog_header.php? – Jerry
@Jerry包括wp-blog-header.php既不帮助也不阻碍。 – fireundubh
好的,account.php的确切位置在哪里?你能否发布更完整的代码版本? – Jerry