0

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

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!
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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