我试图在支付网关请求时删除用户,我有以下代码:
(编辑代码以显示与支付网关通信的完整功能,echo向支付网关提供响应,退出是因为它在支付网关示例代码中使用。)
function handle_gateway_return() {
$GWPass = get_option( $this->gateway . "_gateway_gwpass" );
if ($_GET["GWPass"] != $GWPass ) {
header("HTTP/1.0 401 Unauthorized");
echo "<h1>Gateway 1.1</h1><h3>Authentication failed.</h3>";
exit;
}
//==================================================
// Action: user.add
//==================================================
if ($_GET["Action"] == "user.add") {
// Load variables
$ZFirstName = trim($_GET[\'FIRSTNAME\']);
$ZLastName = trim($_GET[\'LASTNAME\']);
$ZFullName = $ZFirstName." ".$ZLastName;
$ZUserName = trim($_GET[\'username\']);
$ZEmail = trim($_GET[\'EMAIL\']);
$ZPassword = trim($_GET[\'password\']);
$ZPassword = md5($ZPassword); //md5
if ( username_exists( $ZUserName ) ) {
echo "OK|User Added!";
exit;
}
if ( !username_exists( $ZUserName ) ) {
wp_create_user( $ZUserName, $ZPassword, $ZEmail );
echo "OK|User Added!";
exit;
}
}
//==================================================
// Action: user.delete
//==================================================
else if ($_GET["Action"] == "user.delete") {
$ZUserName = trim($_GET[\'username\']);
// Grab user_id
$user = get_user_by(\'login\', $ZUserName);
if (!$user) {
echo \'USER_DOES_NOT_EXIST\';
exit;
}
$url = network_site_url(\'/wp-admin/includes/ms.php\');
if ($user) {
include($url);
wpmu_delete_user($user->ID);
echo "OK|User Deleted!";
exit;
}
} else {
echo "UNKNOWN_ACTION|UNKNOWN_ACTION";
exit;
}
}
但是,用户不会被删除!我做错了什么?
提前感谢您的帮助!
编辑:这发生在wpmudevs成员插件中使用的支付网关加载项文件中。在插件文件中,我有一个处理网关返回和创建用户的函数,使用wp\\u create\\u user可以很好地工作,是的,不需要在那里包含。我在这里添加include仅仅是因为我在某处看到了它,我想我会尝试一下,因为没有include也不起作用(但我认为不需要它)。
最合适的回答,由SO网友:phoenixlaef 整理而成
我不久前就知道了。。。完全忘了把它贴在这里。
一旦我正确添加了include,它就可以正常工作了:
require_once(\'./wp-admin/includes/ms.php\');
if ( $user ) {
wpmu_delete_user( $user->ID );
}
为了将来的读者,这里是最后的代码:
function handle_gateway_return() {
$GWPass = get_option( $this->gateway . "_gateway_gwpass" );
if ($_GET["GWPass"] != $GWPass) {
header("HTTP/1.0 401 Unauthorized");
echo "<h1>Gateway 1.1</h1><h3>Authentication failed.</h3>";
exit;
}
if ($_GET["Action"] == "user.add") {
// Load variables.
$ZFirstName = trim($_GET[\'FIRSTNAME\']);
$ZLastName = trim($_GET[\'LASTNAME\']);
$ZFullName = $ZFirstName." ".$ZLastName;
$ZUserName = trim($_GET[\'username\']);
$ZEmail = trim($_GET[\'EMAIL\']);
$ZPassword = trim($_GET[\'password\']);
$ZPassword = md5($ZPassword); //md5
if ( !username_exists( $ZUserName ) ) {
wp_create_user( $ZUserName, $ZPassword, $ZEmail );
}
// Tell server that user was added
echo "OK|User added!";
exit;
}
else if ($_GET["Action"] == "user.delete") {
$ZUserName = trim($_GET[\'username\']);
$user = get_user_by( \'login\', $ZUserName );
require_once(\'./wp-admin/includes/ms.php\');
if ( $user ) {
wpmu_delete_user( $user->ID );
} else {
echo "User Not Deleted!";
exit;
}
// Tell server user deleted
echo "OK|User deleted!";
exit;
}
else {
echo "UNKNOW_ACTION|UNKNOW_ACTION";
exit;
}
}