Created
November 29, 2012 22:38
-
-
Save jperona/4172390 to your computer and use it in GitHub Desktop.
SalesLogix WordPress to Lead - Test Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function submit_form($post, $options) { | |
global $wp_version; | |
if (!isset($options['sdata_url']) || empty($options['sdata_url'])) | |
return false; | |
//spam honeypot | |
if( !empty($_POST['message']) ) | |
return false; | |
$url = 'https://timesharesonly.sagesaleslogixcloud.com/sdata/slx/dynamic/-/leads'; | |
$post = '<?xml version="1.0"?>'; | |
$post .= '<entry xmlns:sdata="http://schemas.sage.com/sdata/2008/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:slx="http://schemas.sage.com/dynamic/2007">'; | |
$post .= '<sdata:payload><slx:Lead>'; | |
$post .= '<slx:FirstName>'.'Jimmy'.'</slx:FirstName>'; | |
$post .= '<slx:LastName>'.'WordPressman'.'</slx:LastName>'; | |
$post .= '<slx:Title>'.'President'.'</slx:Title>'; | |
$post .= '<slx:Company>'.'companywp'.'</slx:Company>'; | |
$post .= '<slx:BusinessDescription>'.'bdwp'.'</slx:BusinessDescription>'; | |
$post .= '<slx:WorkPhone>'.'workphonewp'.'</slx:WorkPhone>'; | |
$post .= '<slx:Email>'.'[email protected]'.'</slx:Email>'; | |
$post .= '<slx:Interests>'.'interestswp'.'</slx:Interests>'; | |
$post .= '<slx:LeadSource sdata:key="LDEMOA000017" />'; | |
$post .= '<slx:Notes>'.'wpnotes'.'</slx:Notes>'; //notes is actually comments! | |
if(false) { | |
$post .= '<slx:DoNotSolicit>true</slx:DoNotSolicit>'; | |
} | |
else { | |
$post .= '<slx:DoNotSolicit>false</slx:DoNotSolicit>'; | |
} | |
$post .= '<slx:Address>'; | |
$post .= '<slx:Address1>'.'address3'.'</slx:Address1>'; | |
$post .= '<slx:City>'.'citywp2'.'</slx:City>'; | |
$post .= '<slx:State>'.'statewp'.'</slx:State>'; | |
$post .= '<slx:PostalCode>'.'postalwp'.'</slx:PostalCode>'; | |
$post .= '</slx:Address>'; | |
$post .= '<slx:AccountManager sdata:key="UDEMOA00000I"/>'; | |
$post .= '<slx:Owner sdata:key="SYST00000001"/>'; | |
$post .= '<slx:CreateSource>WordPress</slx:CreateSource>'; | |
$post .= '</slx:Lead></sdata:payload></entry>'; | |
// Set SSL verify to false because of server issues. | |
$args = array( | |
'method' => 'POST', | |
'redirection' => 0, | |
'body' => $post, | |
'headers' => array( | |
'user-agent' => 'SLX from WordPress/'.$wp_version.'; '.get_bloginfo('url'), | |
'Content-Type' => 'application/atom+xml; type=entry', | |
'Authorization' => 'Basic ' . base64_encode($options['sdata_username']. ":" . $options['sdata_password'] ) | |
), | |
'sslverify' => false | |
); | |
error_log('Url: '.$url); | |
error_log('Args'.print_r($args, true)); | |
$result = wp_remote_post($url, $args); | |
error_log('Result: '. print_r($result, true)); | |
if( is_wp_error($result) ){ | |
return false; | |
} | |
if ($result['response']['code'] == 201){ // Created | |
// | |
// if( $_POST['w2lcc'] == 1 ) | |
// slx_cc_user($post, $options); | |
// | |
// if( $options['ccadmin'] ) | |
// slx_cc_admin($post, $options); | |
return true; | |
}else{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment