salesforce - Add wordpress custom post type data to an external db -
this function adds custom post 'event' data salesforce db. i've tested function outside of wordpress , works flawlessly. when test inside wordpress adding new event, no error generated , data not inserted sf db. i've tested printing out $_post , saw data being collected. how can display errors can trouble shoot this?
function add_campaign_to_sf( $post_id) { global $sf_username; global $sf_password; if ('event' == $_post['post-type']) { 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->name = get_the_title( $post_id ); $sobject->startdate = date("y-m-d", strtotime($_post["events_startdate"])); $sobject->enddate = date("y-m-d", strtotime($_post["events_enddate"])); $sobject->isactive = '1'; $createresponse = $mysforceconnection->create(array($sobject), 'campaign'); $ids = array(); foreach ($createresponse $createresult) { error_log($createresult); array_push($ids, $createresult->id); } } catch (exception $e) { error_log($mysforceconnection->getlastrequest()); error_log($e->faultstring); die; } } } add_action( 'save_post', 'add_campaign_to_sf');
i use get_post_type()
check "event" posts. use error_log()
write php error log additional debugging - check status of salesforce login, etc.
keep in mind save_post
run every time post saved - created or updated - might want additional checking (like setting meta value) before creating new campaign
in salesforce, otherwise end duplicates.
function add_campaign_to_sf( $post_id ) { $debug = true; if ($debug) error_log("running save_post function add_campaign_to_sf( $post_id )"); if ( 'event' == get_post_type( $post_id ) ){ if ($debug) error_log("the post type 'event'"); if ( false === get_post_meta( $post_id, 'sfdc_id', true ) ){ if ($debug) error_log("there no meta value 'sfdc_id'"); // add salesforce, id of new campaign object if ($debug) error_log("the new object id $sfdc_id"); update_post_meta( $post_id, 'sfdc_id', $sfdc_id ); } } } add_action( 'save_post', 'add_campaign_to_sf' );
Comments
Post a Comment