WordPress中的注册表验证

时间:2013-08-22 作者:Vignesh Pichamani

我已经验证了注册表中的自定义字段,我读取了wordpress的codex,所以我自己也是这样做的。但我发现它会抛出像这样的错误

Call to a member function add() on a non-object  I don\'t know why this should happen. How can i overcome this. 

Code:

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);

1 个回复
SO网友:Stephen Harris

似乎这可能是插件或主题中的错误。从Codex:

如果返回任何错误,表单将不会创建新用户。注意事项:The function must return the variable $errors in any case (即使您的逻辑没有错误),otherwise the function may cause this problem: Fatal error: Call to a member function get_error_code() on a non-object.

停用所有其他插件以查找导致它的原因。如果它仍然存在,请将主题切换到TwentyEeven。一旦确定了罪魁祸首,就需要在代码中搜索错误-在某个地方他们会做一些与您类似的事情,但不会返回$errors.

结束

相关推荐

Display All Non-Used Plugins

我的公司目前拥有大约20个多站点,并且每天都在增长。我们正在尝试通过插件并制定标准。IE,表单使用插件X。然而,我们还没有找到一种单一的方法来检查和系统地显示哪些插件甚至没有被使用。是否有一个功能可以向我们显示已使用或未使用的插件?我试着寻找我能想到的一切,但我一生都找不到答案。