bp_core_signup_用户钩子不工作(PHP、BuddyPress、Wordpress和Parse.com)
我一直在尝试挂接WordPress注册操作,以便将新用户的帐户信息存储在Parse.com用户数据库中。但是,由于我使用BuddyPress,WP hookbp_core_signup_用户钩子不工作(PHP、BuddyPress、Wordpress和Parse.com),php,wordpress,parse-platform,hook,buddypress,Php,Wordpress,Parse Platform,Hook,Buddypress,我一直在尝试挂接WordPress注册操作,以便将新用户的帐户信息存储在Parse.com用户数据库中。但是,由于我使用BuddyPress,WP hookuser\u register似乎不起作用 在网上做了研究之后,我似乎应该使用BP hookBP_core\u signup\u user,但这似乎不起作用,所有关于如何实现它的在线信息都已经过时多年了。问题是,BuddyPress根本没有一本好的法典,所以我有点被卡住了。我已经做了好几个小时了,但还是想不出来 这是我创建的函数,旨在与注册过
user\u register
似乎不起作用
在网上做了研究之后,我似乎应该使用BP hookBP_core\u signup\u user
,但这似乎不起作用,所有关于如何实现它的在线信息都已经过时多年了。问题是,BuddyPress根本没有一本好的法典,所以我有点被卡住了。我已经做了好几个小时了,但还是想不出来
这是我创建的函数,旨在与注册过程挂钩:
<?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);
}
我发现了问题所在,我觉得自己像个十足的白痴,因为这应该是显而易见的
我的函数没有问题——我只是没有意识到它包含的自定义插件被禁用了!显然,在我的问题成为问题之前,当我重命名PHP文件、删除服务器上的文件并放入新文件时,就发生了这种情况
我吸取了教训。现在我知道更改插件的文件将使整个插件失效
因此,我对user\u registration
的钩子仍然可以正常工作,并且不需要通过bp\u core\u signup\u user
钩子,因此我回到了前者。为了将来有人想知道,这是我使用的最后一个函数:
<?php
// Saves the newly registered WP user account to the Parse DB.
add_action('user_register', 'saveNewParseUser');
function saveNewParseUser($newUserId) {
//Retrieve the new User object from WP's DB.
$newUser = get_userdata($newUserId);
//Commit new user data to an HTTP POST request to Parse.
$url = 'https://api.parse.com/1/users';
$postdata = array(
"wpUserId" => $newUserId,
"username" => $newUser->user_login,
"password" => $newUser->user_pass,
"email" => $newUser->user_email,
"fullName" => $newUser->display_name,
"firstName" => $newUser->first_name,
"lastName" => $newUser->last_name
);
$appID = "a5TtlVG52JKTCbc*******************";
$restAPIKey = "Qc86jA8dy1F************************";
$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($newUserId, 'parseSessionToken', $resultArray[sessionToken]);
add_user_meta($newUserId, 'parseObjId', $resultArray[objectId]);
curl_close($ch);
}
谢谢,伙计,这真的帮了我大忙!