繁体   English   中英

bp_core_signup_user挂钩不起作用(PHP,BuddyPress,Wordpress和Parse.com)

[英]bp_core_signup_user hook not working (PHP, BuddyPress, Wordpress, & Parse.com)

我一直在尝试进行WordPress注册操作,以便可以将新用户的帐户信息存储在我的Parse.com用户数据库中。 但是,由于我使用的是BuddyPress,因此WP钩子user_register似乎不起作用。

在进行了在线研究之后,似乎我应该使用BP钩子bp_core_signup_user ,但这似乎不起作用,并且有关应如何实施的所有在线信息都已经存在bp_core_signup_user ,并且可能已经过时了。 有问题的是,BuddyPress根本没有好的Codex,因此我有些困惑。 我已经在这里待了几个小时了,但无法弄清楚。

这是我创建的试图与注册过程挂钩的函数:

<?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);
}

我究竟做错了什么? 难道这还没有按照预期的方式钩住和运行吗?

我知道这是行不通的,因为我在注册帐户后检查了Parse User DB,并且未创建新行,并且放入WP帐户的元信息根本不显示。

有趣的是,当我包含一个exit;时,当我挂接到WP的user_register (带有适当的参数和postdata数组设置)时,此DID便可以工作exit; 函数的末尾调用,这实际上阻止了注册过程通过BuddyPress'及其激活过程,而是直接通过Wordpress直接进行注册。 这也使网页显示来自HTTP请求的输出响应-这是Parse所期望的JSON响应主体,因此我知道它确实起作用。 为什么避免BuddyPress会起作用? BuddyPress似乎是造成此问题的原因。 (如果您想查看我为此所做的不同操作的代码,则可以将其发布。)

感谢您的协助。

我找出了问题所在,并且觉得自己是个白痴,因为它应该很明显。

我的功能没有错-我只是没有意识到它所包含的自定义插件已被禁用! 显然,当我重命名PHP文件,在服务器上删除一个文件并放入新文件时,这种情况就发生了,而我的问题才成为问题。

我学到了教训。 现在,我知道更改插件的文件将使整个插件无效。

这样,我对user_registration钩子仍然可以正常工作,并且不必通过bp_core_signup_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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM