Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am getting the following error when with the code that I wrote for my plugin:

Error: Fatal error: Call to a member function get_error_code() on a non-object in .../wp-login.php on line 335

I've tried to do a var_dump($errors) inside wp-login.php and it returns NULL.

My Plugin: (Adds registered users to an external db)

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

Additionally, when I test the process with this function, everything works smoothly.

  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 );
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Your function must return the variable $errors – even when there is no new error in your logic.

'registration_errors' is a filter, and filters always expect a return value. Without that your function returns NULL, and that is what var_dump() found.

So the basic function body should be:

function add_user_to_SF($errors, $sanitized_user_login, $user_email ) {
    try {
    } catch (Exception $e) {
        return $errors;
    }
    return $errors; // important!
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.