您好,我正在尝试从桌面应用程序检索任何给定用户的成员级别,在进行一些研究后,我发现了以下代码:
/*
Call to http://yoursite.com/[email protected]&secret=CHECK to
check the membership level of a user.
*/
function my_init_pmpro_mini_api()
{
if(function_exists(\'pmpro_getMembershipLevelForUser\') &&
!empty($_REQUEST[\'verify\']) &&
!empty($_REQUEST[\'secret\']))
{
if($_REQUEST[\'secret\'] != "CHECK")
wp_die("Invalid secret.");
$user = get_user_by("email", str_replace(" ", "+",
($_REQUEST[\'verify\'])));
if(empty($user))
wp_die("User not found.");
$membership_level = pmpro_getMembershipLevelForUser();
if(empty($membership_level))
die("0");
//user and membership level found, output json encoded membership level
info
echo json_encode($membership_level);
exit;
}
}
add_action(\'init\', \'my_init_pmpro_mini_api\');
我的问题是:为了让我的网站开始响应这些请求,我应该在witch文件中添加这个片段吗?
最合适的回答,由SO网友:Nuno Sarmento 整理而成
首先,您需要安装插件(paidmembershipspro),否则您将无法调用函数“pmpro\\u getMembershipLevelForUser”,然后只需将下面的代码复制到您的函数中。位于WordPress主题内的php文件。
/*
Call to http://yoursite.com/[email protected]&secret=CHECK to
check the membership level of a user.
*/
function my_init_pmpro_mini_api()
{
if(function_exists(\'pmpro_getMembershipLevelForUser\') &&
!empty($_REQUEST[\'verify\']) &&
!empty($_REQUEST[\'secret\']))
{
if($_REQUEST[\'secret\'] != "CHECK")
wp_die("Invalid secret.");
$user = get_user_by("email", str_replace(" ", "+",
($_REQUEST[\'verify\'])));
if(empty($user))
wp_die("User not found.");
$membership_level = pmpro_getMembershipLevelForUser();
if(empty($membership_level))
die("0");
//user and membership level found, output json encoded membership level
info
echo json_encode($membership_level);
exit;
}
}
add_action(\'init\', \'my_init_pmpro_mini_api\');