Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在另一页上显示WP_Error()错误?_Php_Wordpress_Error Handling - Fatal编程技术网

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&#8217;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。