I have been trying to hook into the WordPress registration action so that I can store the new user's account info on my Parse.com User database. However, since I am using BuddyPress, the WP hook user_register
does not seem to work.
After doing research online, it seems like I am supposed to use the BP hook bp_core_signup_user
, but that does not seem to be working, and all the info online on how it should be implemented are years old and may be outdated. Problematically, BuddyPress does not have a good Codex at all, so I am kind of stuck. I've been at this for hours, but cannot figure it out.
This is the function I created in an attempt to hook into the registration process:
<?php
// Saves the newly registered BP user account to the Parse DB.
add_action('bp_core_signup_user', 'saveNewParseUser', 10, 5);
function saveNewParseUser($userId, $userLogin, $userPass, $userEmail, $userMeta) {
//Commit new user data to an HTTP POST request to Parse.
$url = 'https://api.parse.com/1/users';
$postdata = array(
"wpUserId" => $userId,
"username" => $userLogin,
"password" => $userPass,
"email" => $userEmail,
"fullName" => $userMeta[display_name],
"firstName" => $userMeta[first_name],
"lastName" => $userMeta[last_name]
);
$appID = "a5TtlVG52JKTC************************";
$restAPIKey = "Qc86jA8dy1FpcB**************************";
$options = array();
$options[] = "Content-type: application/json";
$options[] = "X-Parse-Application-Id: $appID";
$options[] = "X-Parse-REST-API-Key: $restAPIKey";
$options[] = "X-Parse-Revocable-Session: 1";
//open connection
$ch = curl_init($url);
//sets the number of POST vars & POST data
curl_setopt_array($ch, array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($postdata),
CURLOPT_HTTPHEADER => $options,
CURLOPT_RETURNTRANSFER => true
));
//execute post
$result = curl_exec($ch);
$resultArray = json_decode($result, true);
//Error check
if (curl_errno($ch)) {
echo "Error Code " . curl_errno() . ": " . curl_error($ch);
}
//Retrieve and place Parse user session token & ID into WP DB user account.
add_user_meta($userId, 'parseSessionToken', $resultArray[sessionToken]);
add_user_meta($userId, 'parseObjId', $resultArray[objectId]);
curl_close($ch);
}
What am I doing wrong? Is this not even being hooked and run as it is meant to?
I know it does not work because I check the Parse User DB after registering an account and a new row is not created, and the meta info I put into the WP account do not show there at all.
Interestingly, this DID work when I hooked into WP's user_register
(with the appropriate parameter and postdata
array setup) when I included an exit;
call at the end of the function, which essentially prevented the registration process from going through BuddyPress' and its activation procedure, and instead went straight to registering through Wordpress directly. That also left the web page displaying the output response from the HTTP request - it was the JSON response body as expected from Parse, so I know it did in fact work. Why would it be working when avoiding BuddyPress? BuddyPress seems to be causing the problem here. (If you would like to see the code for what I had done differently for this, then I can post it.)
Thank you for any assistance.