我試圖通過掛鉤Wordpress註冊並添加註冊到Salesforce數據庫的用戶來完成一個相對簡單的任務。當我在Wordpress外部運行Salesforce db代碼時,它的工作原理完美無瑕,但是當我在我的wordpress網站上註冊時進行測試時,出現以下錯誤消息:INVALID_LOGIN:無效的用戶名,密碼,安全令牌;或用戶鎖定。添加一個wordpress用戶到Salesforce聯繫人
此外,我從Wordpress收到此錯誤「無法修改標頭信息 - 標頭已發送」,它不允許我查看發送到Salesforce的整個對象數據。
這是我的代碼:
$SF_USERNAME = 'test';
$SF_PASSWORD = 'test';
define('CD_PLUGIN_PATH', plugin_dir_path(__FILE__));
require_once (CD_PLUGIN_PATH . 'Toolkit/soapclient/SforceEnterpriseClient.php');
require_once (CD_PLUGIN_PATH . 'Toolkit/soapclient/SforceHeaderOptions.php');
function add_user_to_SF($user_id) {
$user = get_userdata($user_id);
try {
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(CD_PLUGIN_PATH . 'Toolkit/soapclient/enterprise.wsdl.xml');
$mylogin = $mySforceConnection->login($SF_USERNAME, $SF_PASSWORD);
print '<pre>';
print_r($mylogin);
print '</pre>';
print '<br/><br/>';
$sObject = new stdclass();
$sObject->FirstName = $user->first_name;
$sObject->LastName = $user->last_name;
$sObject->Email = $user->user_email;
//echo "**** Creating the following:\r\n";
$createResponse = $mySforceConnection->create(array($sObject), 'Contact');
$ids = array();
foreach ($createResponse as $createResult) {
print_r($createResult);
array_push($ids, $createResult->id);
}
} catch (Exception $e) {
$errors->add('demo_error', __(print_r($_POST),'mydomain'));
$errors->add('demo_error', __($mySforceConnection->getLastRequest(),'mydomain'));
$errors->add('demo_error', __($e->faultstring,'mydomain'));
return $errors;
}
}
add_filter('registration_errors', 'add_user_to_SF', 10, 3);
謝謝,但我解決了使用添加全局問題。 – MG1