1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

User Groups and PHP

Discussion in 'XenForo Development Discussions' started by LandNetwork, Jul 21, 2016.

  1. LandNetwork

    LandNetwork Member

    Hey all,

    I've found a few threads on this and they seem to recommend the use of:

    $visitor->removeUserGroupChange($visitor["user_id"], $randKey);
    $visitor->addUserGroupChange($visitor["user_id"], $randKeygetIDFromRank($data["rank"]));
    But why is a random key needed and what does it do? I've implemented my code and the user groups are simply not updated with this code.

    I've got a $visitor object ($visitor = XenForo_Visitor::getInstance()->toArray();) and a DataWriter that updates custom field values.

                    if (strtolower($data["link_id"] == strtolower($linkingkey))) {
    $customFields unserialize($visitor["custom_fields"]);
    $customFields["minecraft"] = $data["name"];
    $customFields["mcuuid"] = $data["uuid"];
    $dw XenForo_DataWriter::create('XenForo_DataWriter_User');
    $randKey "cYNh7Z2MABLLMQMhjTHfBaJK";
    $visitor->removeUserGroupChange($visitor["user_id"], $randKey);
    $visitor->addUserGroupChange($visitor["user_id"], $randKey2);
                        if (
    $dw->save()) {
    $data["forum_linked"] = true// Sets to true in memory
    $couchBucket->upsert("playerdata:".$data["uuid"], $data); // Overwrite stored data to say forum_linked=true (upsert is replace)
    $success "Successfully linked website account <i>" $visitor["username"] . "</i> to Minecraft account <i>" $data["name"] . "</i>.";
                    } else {
    $error "The supplied linking key is invalid.";
    Custom fields are successfully updated whilst removeUserGroupChange throws:
    Fatal error: Call to a member function removeUserGroupChange() on a non-object in link.php.
    I tried to apply it on a User_Model instead of a $visitor object ($user_Model = XenForo_Model::create('XenForo_Model_User'); but whilst there's no immediate error, nothing changes.

    What is it that I'm missing?
    Last edited: Jul 21, 2016
  2. LandNetwork

    LandNetwork Member

Share This Page