Deleting a user in multisite

时间:2013-09-20 作者:phoenixlaef

我试图在支付网关请求时删除用户,我有以下代码:

(编辑代码以显示与支付网关通信的完整功能,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也不起作用(但我认为不需要它)。

1 个回复
最合适的回答,由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;
    }
  }

结束

相关推荐

在许多外观相似的网站上使用MultiSite有什么缺点吗?

我正在为一位摄影师开发多个网站。大多数时候,我都会围绕摄影师拍摄的这些精彩图片进行定制设计,但在很多情况下,公司没有预算让我们创建定制设计的WP网站。因此,我正在寻找一种简单的方法,为我的客户提供一个“模板”。一个基本的网站,我设置,自定义一点,作为我们客户的服务。我的想法是:我创建了一个主题,每个新网站都有自己的子主题,只需稍作修改。所有网站在结构上都是相同的,但我会调整徽标、颜色、字体和总体外观。每个网站都有自己的域名,因此不涉及子域。它们都共享一些插件,比如GravityForms。这似乎是我的一个

Deleting a user in multisite - 小码农CODE - 行之有效找到问题解决它

Deleting a user in multisite

时间:2013-09-20 作者:phoenixlaef

我试图在支付网关请求时删除用户,我有以下代码:

(编辑代码以显示与支付网关通信的完整功能,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也不起作用(但我认为不需要它)。

1 个回复
最合适的回答,由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;
    }
  }