使用为插件编写的代码时出现以下错误:
错误:致命错误:在第 335 行的 .../wp-login.php 中对非对象调用成员函数 get_error_code()
我尝试在 wp-login.php 中执行 var_dump($errors) 并返回 NULL。
我的插件:(将注册用户添加到外部数据库)
function add_user_to_SF($errors, $sanitized_user_login, $user_email ) {
global $SF_USERNAME;
global $SF_PASSWORD;
global $errors;
try {
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(CD_PLUGIN_PATH . 'Toolkit/soapclient/enterprise.wsdl.xml');
$mySFlogin = $mySforceConnection->login($SF_USERNAME, $SF_PASSWORD);
$sObject = new stdclass();
$sObject->FirstName = $_POST['user_login'];
$sObject->LastName = $_POST['user_login'];
$sObject->Email = $_POST['user_email'];
$createResponse = $mySforceConnection->create(array($sObject), 'Contact');
$ids = array();
foreach ($createResponse as $createResult) {
array_push($ids, $createResult->id);
}
} catch (Exception $e) {
$errors->add( 'demo_error', __('<strong>ERROR</strong>: There is a Salesforce problem.','mydomain') );
return $errors;
}
}
add_filter( 'registration_errors', 'add_user_to_SF', 10, 3 );
此外,当我使用此功能测试该过程时,一切正常。
function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
if ( empty( $_POST['first_name'] ) )
$errors->add( 'first_name_error', __('<strong>ERROR</strong>: You must include a first name.','mydomain') );
return $errors;
}
add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );