I’m having a serious issue with the Remote Operations API. I have a mu_plugin that I’m using to save data from submitted via a Gravity Forms form to s2Member fields in the database. The code works fine on my Dev site, but doesn’t run appear to be firing on the Production site.
The only difference in the code is the API key (and I have verified that the key on the Production site is correct).
There were several plugins running on the Production site that aren’t on the Dev site, but I deactivated them all and nothing changed.
I’ve checked for errors in the Developer Console, the WordPress debug.log and on the server. Both sites are on SiteGround (although on different accounts they are the same TYPE of account). I’m at my wit’s end here because I can’t find a logical explanation for this. I’m hoping I’ve forgotten something stupid and someone can point it out for me. The code (minus the API key) is below:
<?php
add_action( 'gform_user_registered', 'sg_add_s2data', 10, 4 );
/*******************************************************
Notes on the $entry Values in the following function
All $entry values are retrieved using the Field ID except the Stripe Transaction ID (which is not a field entry. Ths function works for ALL forms which have a
User Registration and Stripe feed. BUT the Field IDs
must remain the same. You can delete fields but if you
add fields to a form based on the template form, you
must be sure that the field IDs of the added fields are
greater than 40 (to be safe).
******************************************************/
function sg_add_s2data( $user_id, $feed, $entry, $user_pass ) {
$sg_user = $user_id;
$sg_company = rgar( $entry, '7');
$sg_address = rgar( $entry, '8');
$sg_address2 = rgar( $entry, '9');
$sg_city = rgar( $entry, '10');
$sg_state = rgar( $entry, '11');
$sg_zip = rgar( $entry, '12');
$sg_country = rgar( $entry, '13');
$sg_profession = rgar( $entry, '15');
$sg_profession_providers = rgar( $entry, '16');
$sg_profession_other = rgar( $entry, '17');
$sg_ibclc = rgar( $entry, '18');
$sg_nlnum = rgar( $entry, '19');
$sg_contactsrc = rgar( $entry, '20');
$sg_ccaps = rgar( $entry, '21');
$sg_eot = rgar( $entry, '23' );
$sg_txnid = rgar( $entry, 'transaction_id');
// Troubleshooting: Echo Field Values
// echo "<p><strong>User ID: </strong>". $user_id."</p>";
// echo "<p><strong>Company: </strong>". $sg_company."</p>";
// echo "<p><strong>Address: </strong>". $sg_address."</p>";
//echo "<p><strong>Address2: </strong>". $sg_address2."</p>";
// echo "<p><strong>City: </strong>". $sg_city."</p>";
// echo "<p><strong>State: </strong>". $sg_state."</p>";
// echo "<p><strong>Zip: </strong>". $sg_zip."</p>";
// echo "<p><strong>Country: </strong>". $sg_country."</p>";
// echo "<p><strong>Profession: </strong>". $sg_profession."</p>";
// echo "<p><strong>Provider Profession: </strong>". $sg_profession_providers."</p>";
// echo "<p><strong>Profession - Other: </strong>". $sg_profession_other."</p>";
// echo "<p><strong>IBCLC: </strong>". $sg_ibclc."</p>";
// echo "<p><strong>Nursing License: </strong>". $sg_nlnum."</p>";
// echo "<p><strong>Where Did You Hear About Us?: </strong>". $sg_contactsrc."</p>";
// echo "<p><strong>CCAPs: </strong>". $sg_ccaps."</p>";
// echo "<p><strong>EOT: </strong>". $sg_eot."</p>";
// echo "<p><strong>Transaction ID: </strong>". $sg_txnid."</p>";
$op['op'] = 'modify_user'; // The Remote Operation.
$op['api_key'] = 'removed'; // Check your Dashboard for this value.
// Save Data
$op['data'] = array(
'user_id' => $sg_user, // A WordPress® User ID.
's2member_ccaps' => $sg_ccaps, // Optional—if updating.
// Any Custom Capabilities you supply here will be added to any that a User already has.
// If you want to remove all Custom Capabilities, start your list with "-all". Ex: "-all,music,videos" (removes all, then adds: music,videos).
// If you simply want to remove all Custom Capabilities, set this to "-all" (removes all Custom Capabilities, adds none).
's2member_subscr_gateway' => 'stripe',
's2member_subscr_id' => $sg_txnid,
's2member_custom' => 'tmmgf.sitegeeks.com',
's2member_auto_eot_time' => $sg_eot,
'custom_fields' => array('company' => $sg_company,
'address' => $sg_address,
'address2' => $sg_address2,
'city' => $sg_city,
'state' => $sg_state,
'zip' => $sg_zip,
'country' => $sg_country,
'profession' => $sg_profession,
'profession_providers' => $sg_profession_providers,
'profession_other' => $sg_profession_other,
'ibclc' => $sg_ibclc,
'nurse_license_number' => $sg_nlnum,
'contact_source' => $sg_contactsrc,
),
's2member_notes' => 'Modified this User via API call from Gravity Forms.',
);
$post_data = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => 's2member_pro_remote_op='.urlencode(json_encode($op)))));
$result = json_decode(trim(file_get_contents('https://tmmgf.sitegeeks.com/?s2member_pro_remote_op=1', false, $post_data)), true);
if ($result && empty($result['error']) && !empty($result['ID'])) {
echo 'Success. Modified user ID: '.$result['ID'];
} elseif (!empty($result['error'])) {
echo 'API error reads: '.$result['error'];
}
}
There’s still a lot of troubleshooting code because I still haven’t got this working on the Production site.
Any ideas, anyone?
Thanks in advance.