Title: Using Code to change Member Group
Last modified: August 21, 2016

---

# Using Code to change Member Group

 *  [gld](https://wordpress.org/support/users/gld/)
 * (@gld)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/using-code-to-change-member-group/)
 * Hello, how do I use code (HP specifically) to change a user’s group, add a user
   to a group or remove them from a group?
 * [https://wordpress.org/plugins/user-access-manager/](https://wordpress.org/plugins/user-access-manager/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [gld](https://wordpress.org/support/users/gld/)
 * (@gld)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/using-code-to-change-member-group/#post-4815163)
 * HP specifically -> ie PHP
 *  Thread Starter [gld](https://wordpress.org/support/users/gld/)
 * (@gld)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/using-code-to-change-member-group/#post-4815357)
 * Not a lot of support for the plug-in!
 * Anyway, if anyone else needs help, I’ve add the following function to my functions.
   php file in order to change the group the individual belongs too based upon a
   variable ‘record-status’ that is posted.
 * function UserUAgroupAccess() {
 *  $record_status = $_POST[‘record_status’];
 *  // grab the values we need
    $email = $_POST[’email’];
 *  // Now obtain the User’s User ID
    $the_user = get_user_by(’email’, $email); 
   $wp_uid = $the_user->ID; $userGroupId=2; // Group ID to be updated
 *  // Now set the user’s permissions to have access to the pages
    global $oUserAccessManager;
 *  if (isset($oUserAccessManager)) {
    $oUamAccessHandler = $oUserAccessManager-
   >getAccessHandler(); $uamUserGroup = $oUamAccessHandler->getUserGroups($userGroupId);
   if ($record_status == “Archived” OR $record_status == “Pending” OR $record_status
   == “Rejected”) { $uamUserGroup->removeObject(‘user’, $wp_uid); } else { $uamUserGroup-
   >addObject(‘user’, $wp_uid); } $uamUserGroup->save(); }
 *  // make sure we return the posted values to ensure the plugin that we have hooked
   in front of will continue to function properly
    return ($_POST);
 * }
 *  [nwoetzel](https://wordpress.org/support/users/nwoetzel/)
 * (@nwoetzel)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-code-to-change-member-group/#post-4815414)
 * I actually had the same problem, but needed it for all sorts of types:
    user,
   role, post, term So I implemented a plugin for the wp-cli: [http://wp-cli.org/](http://wp-cli.org/)
   by extending the current plugin. Since I am not not clear about how to contribute
   directly to the project, I made a “fork” based on the current svn trunk at [https://github.com/nwoetzel/user-access-manager/](https://github.com/nwoetzel/user-access-manager/)
   and created a branch that adds wp-cli functionality: [https://github.com/nwoetzel/user-access-manager/tree/wp-cli](https://github.com/nwoetzel/user-access-manager/tree/wp-cli)
 * I hope this helps more then just me.
    When wp-cli is installed, and the plugin
   from the branch, you should have ‘wp uam’ as a new command in case you have just
   the svn version installed, you can apply a patch: [https://github.com/nwoetzel/user-access-manager/compare/master…wp-cli.patch](https://github.com/nwoetzel/user-access-manager/compare/master…wp-cli.patch)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Using Code to change Member Group’ is closed to new replies.

 * ![](https://ps.w.org/user-access-manager/assets/icon.svg?rev=1563783)
 * [User Access Manager](https://wordpress.org/plugins/user-access-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/user-access-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/user-access-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/user-access-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/user-access-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/user-access-manager/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [nwoetzel](https://wordpress.org/support/users/nwoetzel/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/using-code-to-change-member-group/#post-4815414)
 * Status: not resolved