0

我已经验证了注册表单中的自定义字段,我读出了 wordpress 的法典,以便我自己这样做。但我发现它会引发像这样的错误

Call to a member function add() on a non-object 

我不知道为什么会发生这种情况。我怎样才能解决这个问题?任何建议都会很棒。

代码:

function myplugin_check_fields($errors, $sanitized_user_login, $user_email) {

        $errors->add( 'demo_error', __('<strong>ERROR</strong>: This is a demo error. Registration halted.','mydomain') );

        return $errors;

    }

    add_filter('registration_errors', 'myplugin_check_fields', 10, 3);
4

1 回答 1

1

Make Global 或获取对负责实例的对象的全局权限add() global $wp_object_responsible;

    function myplugin_check_fields($errors, $sanitized_user_login, $user_email) {
        global $wp_object_responsible;  //edit here

$errors->add( 'demo_error', __('<strong>ERROR</strong>: This is a demo error. Registration halted.','mydomain') );

            return $errors;
于 2013-08-22T05:37:36.193 回答