Php 如何在另一页上显示WP_Error()错误?
如何在另一页上显示Php 如何在另一页上显示WP_Error()错误?,php,wordpress,error-handling,Php,Wordpress,Error Handling,如何在另一页上显示WP\u 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('in
WP\u 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; }
<?php
$return = update_account();
if(is_wp_error($return)) { echo $return->get_error_message(); }
?>
在测试过程中,既不报告
无效电子邮件
也不报告电子邮件
错误。但是,错误是可以避免的。我只是不明白为什么它们没有被展示出来。我做错了什么?您需要在您的帐户页面上添加全局$errors。@Jerry包括wp-blog-header.php既没有帮助也没有阻碍。好的,account.php确切位于哪里?你能发布一个更完整的代码版本吗?account.php和functions.php在主题的目录中。提交表单时,将调用一个处理页面,其中执行update_account()函数,并将用户返回account.php。