Index: og_user_roles.module
===================================================================
--- og_user_roles.module	(revision 3312)
+++ og_user_roles.module	(working copy)
@@ -77,19 +77,19 @@
       '#type' => 'checkboxes',
       '#title' => t('Assignable roles'),
       '#options' => $roles,
-      '#default_value' => variable_get("og_user_roles_roles_$type", array()),
+      '#default_value' => og_user_roles_variable_get("og_user_roles_roles_$type", array()),
     );
     $form["og_user_roles_$type"]["og_user_roles_assign_typegrouprole_$type"] = array(
       '#type' => 'checkbox',
       '#title' => t('<strong>Set default basic group (group limited) role for users who join groups of this type: %type_name?</strong>', array('%type_name' => $name)),
-      '#default_value' => variable_get("og_user_roles_assign_typegrouprole_$type", 0),
+      '#default_value' => og_user_roles_variable_get("og_user_roles_assign_typegrouprole_$type", 0),
       '#description' => t('Do you wish to automatically assign a specific "basic group role" to <b>every new group subscriber</b> at the time he subscribes to a group of this type: %type_name? The role is limited to the group that he is subscribed to. This role assignment can be removed by the groups\' admins', array('%type_name' => $name)),
     );
     $form["og_user_roles_$type"]["og_user_roles_typegrouprole_value_$type"] = array(
       '#type' => 'select',
       '#title' => t('Role to use as a group type %type_name role', array('%type_name' => $name)),
       '#options' => $roles,
-      '#default_value' => variable_get("og_user_roles_typegrouprole_value_$type", 0),
+      '#default_value' => og_user_roles_variable_get("og_user_roles_typegrouprole_value_$type", 0),
       '#description' => t('Select the role you wish to use as the "group role" for every new groupmember to groups of this type: %type_name.', array('%type_name' => $name)),
     );
   }
@@ -104,7 +104,7 @@
   $form['og_user_roles_regcode_gid_default']['og_user_roles_assign_regcode_gid'] = array(
     '#type' => 'checkbox',
     '#title' => t('Allow Group Admins to set Registration Codes for users to join their moderated groups without admin approval?'),
-    '#default_value' => variable_get('og_user_roles_assign_regcode_gid', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_assign_regcode_gid', 0),
     '#description' => t('Do you wish to allow Group Admins to define "Registration Codes" to allow users to subscribe to their groups without admin approval? The Group Admin will be able to define the Registration Codes on <b>edit</b> (not creation) of the group node.  Group Admin must have <b>manage registration codes</b> permission.'),
   );
 
@@ -118,7 +118,7 @@
   $form['og_user_roles_approval']['og_user_roles_approval_default'] = array(
     '#type' => 'checkbox',
     '#title' => t('Allow group admins to approve new signups?'),
-    '#default_value' => variable_get('og_user_roles_approval_default', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_approval_default', 0),
     '#description' => t('<strong>If your site requires administrator approval for signups</strong>: When a user registers and elects to subscribe to a group (group is on registration form), then the admin of the group will receive an email notification of the pending signup and be allowed to approve it.  Note that this requires that the group admin have a group role which includes the <strong>administer users</strong> permission.'),
   );
 
@@ -132,14 +132,14 @@
   $form['og_user_roles_default']['og_user_roles_assign_default'] = array(
     '#type' => 'checkbox',
     '#title' => t('Set default global (site-wide) role for new signups?'),
-    '#default_value' => variable_get('og_user_roles_assign_default', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_assign_default', 0),
     '#description' => t('Do you wish to automatically assign all new signups to your web site to a specific role (that is NOT group specific) upon registration?'),
   );
   $form['og_user_roles_default']['og_user_roles_default_value'] = array(
     '#type' => 'select',
     '#title' => t('Selectable roles'),
     '#options' => $roles,
-    '#default_value' => variable_get('og_user_roles_default_value', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_default_value', 0),
   );
 
   $form['og_user_roles_basicgrouprole'] = array(
@@ -152,14 +152,14 @@
   $form['og_user_roles_basicgrouprole']['og_user_roles_assign_basicgrouprole'] = array(
     '#type' => 'checkbox',
     '#title' => t('Set default basic group (group limited) role for users who join groups?'),
-    '#default_value' => variable_get('og_user_roles_assign_basicgrouprole', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_assign_basicgrouprole', 0),
     '#description' => t('Do you wish to automatically assign a specific "basic group role" to <b>every new group subscriber</b> at the time he subscribes to the group? The role is limited to the group that he is subscribed to. This role assignment can be removed by the groups\' admins'),
   );
   $form['og_user_roles_basicgrouprole']['og_user_roles_basicgrouprole_value'] = array(
     '#type' => 'select',
     '#title' => t('Role to use as a basic group role'),
     '#options' => $roles,
-    '#default_value' => variable_get('og_user_roles_basicgrouprole_value', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_basicgrouprole_value', 0),
     '#description' => t('Select the role you wish to use as the "basic group role" for every new groupmember.'),
   );
 
@@ -173,7 +173,7 @@
   $form['og_user_roles_basicgrouprole_gid_default']['og_user_roles_assign_basicgrouprole_gid'] = array(
     '#type' => 'checkbox',
     '#title' => t('Allow Group Admins to set default basic group (group limited) role for users who join their groups?'),
-    '#default_value' => variable_get('og_user_roles_assign_basicgrouprole_gid', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_assign_basicgrouprole_gid', 0),
     '#description' => t('Do you wish to allow Group Admins to define a specific "basic group role" for <b>every new subscriber to their group</b> at the time he subscribes to the group? The role is limited to the group that he is subscribed to. This role assignment can be be removed by the groups\' admin(s).  The Group Admin will be able to define the default group role on <b>edit</b> (not creation) of the group node.  Group Admin must have <b>configure member roles</b> permission.'),
   );
 
@@ -187,14 +187,14 @@
   $form['og_user_roles_founder']['og_user_roles_assign_founder'] = array(
     '#type' => 'checkbox',
     '#title' => t('Set default group founder (group limited) role for users who create groups?'),
-    '#default_value' => variable_get('og_user_roles_assign_founder', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_assign_founder', 0),
     '#description' => t('Do you wish to automatically assign a user who creates a group (e.g. "founder") to a group specific role that is limited to the group that he creates?'),
   );
   $form['og_user_roles_founder']['og_user_roles_founder_value'] = array(
     '#type' => 'select',
     '#title' => t('Role to use as founder role'),
     '#options' => $roles,
-    '#default_value' => variable_get('og_user_roles_founder_value', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_founder_value', 0),
     '#description' => t('Select the role you wish to use as the "founder" role.'),
   );
 
@@ -208,14 +208,14 @@
   $form['og_user_roles_admingrouprole']['og_user_roles_assign_admingrouprole'] = array(
     '#type' => 'checkbox',
     '#title' => t('Set default group (group limited) administrator role for users who are elevated to group administrator?'),
-    '#default_value' => variable_get('og_user_roles_assign_admingrouprole', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_assign_admingrouprole', 0),
     '#description' => t('Do you wish to automatically assign a specific "administrator group role" to <b>every new group administrator</b> at the time he is elevated to group administrator status? The role is limited to the group that he is the administrator for. This role assignment can only be removed by removing the user as a group administrator.'),
   );
   $form['og_user_roles_admingrouprole']['og_user_roles_admingrouprole_value'] = array(
     '#type' => 'select',
     '#title' => t('Role to use as group administrator role'),
     '#options' => $roles,
-    '#default_value' => variable_get('og_user_roles_admingrouprole_value', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_admingrouprole_value', 0),
     '#description' => t('Select the role you wish to use as the "group administrator role" for every new group administrator.'),
   );
 
@@ -228,7 +228,7 @@
   $form['og_user_roles_notify']['og_user_roles_notify_default'] = array(
     '#type' => 'checkbox',
     '#title' => t('Send email notification to group admin when new subscriber is added to group?'),
-    '#default_value' => variable_get('og_user_roles_notify_default', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_notify_default', 0),
     '#description' => t('Do you wish to automatically send an email notification to the group administrator when a new subscriber is added to a group? (Note that this feature requires ' . l("mimemail.module", "http://www.drupal.org/project/mimemail") . ' to be installed)'),
   );
 
@@ -241,7 +241,7 @@
   $form['og_user_roles_all_groups']['og_user_roles_all_groups_nodes'] = array(
     '#type' => 'textarea',
     '#title' => t('Nodes to automatically place into all available groups'),
-    '#default_value' => variable_get('og_user_roles_all_groups_nodes', ''),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_all_groups_nodes', ''),
     '#cols' => 50,
     '#rows' => 2,
     '#description' => t('Specify here the node IDs of nodes which you want placed into all groups, each separated by a comma. Structure your entries like this:
@@ -265,7 +265,7 @@
   $form['og_user_roles_tac_og_default']['og_user_roles_tac_og_value'] = array(
     '#type' => 'checkbox',
     '#title' => t('Integrate TAC and OG Access Control?'),
-    '#default_value' => variable_get('og_user_roles_tac_og_value', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_tac_og_value', 0),
     '#description' => t('Do you have Taxonomy Access installed and do you wish to make its access control work with Organic Groups?  Note that this feature requires that you install the ' . l("Taxonomy Access Control Module", "http://www.drupal.org/project/taxonomy_access") . '.  The <b>taxonomy_access.module</b> is currently <b>' . $taxonomy_access . '</b>.  Details here: ' . l("How to Make OG and TAC Work Together: Step 2", "http://groups.drupal.org/node/3700")),
     '#disabled' => $disabled,
   );
@@ -281,14 +281,14 @@
     $form['og_user_roles_subgroup']['og_user_roles_create_subgroup'] = array(
       '#type' => 'checkbox',
       '#title' => t('Create link to "Create Subgroup" in group menu?'),
-      '#default_value' => variable_get('og_user_roles_create_subgroup', 0),
+      '#default_value' => og_user_roles_variable_get('og_user_roles_create_subgroup', 0),
       '#description' => t('Do you wish to have a "Create Subgroup" link appear on the group menu (if the user has the appropriate permissions)?'),
     );
     $form['og_user_roles_subgroup']['og_user_roles_create_subgroup_value'] = array(
       '#type' => 'select',
       '#title' => t('Group type to use for subgroup creation'),
       '#options' => $types,
-      '#default_value' => variable_get('og_user_roles_create_subgroup_value', ''),
+      '#default_value' => og_user_roles_variable_get('og_user_roles_create_subgroup_value', ''),
       '#description' => t('Select the group type you wish to use for subgroup creation.'),
     );
   }
@@ -304,7 +304,7 @@
   $form['og_user_roles_clear_cache']['og_user_roles_clear_cache_value'] = array(
     '#type' => 'checkbox',
     '#title' => t('Clear the user_access() and cache_menu caches for user?'),
-    '#default_value' => variable_get('og_user_roles_clear_cache_value', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_clear_cache_value', 0),
     '#description' => t($description),
   );						 
 
@@ -317,7 +317,7 @@
   $form['og_user_roles_test']['og_user_roles_test_default'] = array(
     '#type' => 'checkbox',
     '#title' => t('Output debug data to og_user_test table?'),
-    '#default_value' => variable_get('og_user_roles_test_default', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_test_default', 0),
     '#description' => t('Every time user_access() is called, it will call og_user_all_roles() which adds group roles to $user->roles.  Do you wish to see the output from this function? (Note that this feature is for testing/debug purposes, and could create a very large output file.  This feature also requires that the table og_user_test already exist. Details here: ' . l("OG User Roles: Test", "http://drupal.org/node/164038")),
   );
 
@@ -332,7 +332,7 @@
   $form['og_user_roles_menu_options']['og_user_roles_menu_options_enabled'] = array(
     '#type' => 'checkbox',
     '#title' => t('Enable menu control?'),
-    '#default_value' => variable_get('og_user_roles_menu_options_enabled', 1),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_menu_options_enabled', 1),
     '#description' => t("This will add two form elements, inside a field set, to the OG node's edit page, enabling this feature."),
    );
 
@@ -346,21 +346,21 @@
   $form['og_user_roles_logo']['og_user_roles_logo_enabled'] = array(
     '#type' => 'checkbox',
     '#title' => t('Enable group logo?'),
-    '#default_value' => variable_get('og_user_roles_logo_enabled', 1),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_logo_enabled', 1),
     '#description' => t("This will add a text box onto the OG node's edit page, enabling this feature."),
    );
   $form['og_user_roles_logo']['og_user_roles_logo_width'] = array(
     '#type' => 'textfield',
     '#size' => 10,
     '#title' => t('Maximum width for display of group logo?'),
-    '#default_value' => variable_get('og_user_roles_logo_width', '135'),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_logo_width', '135'),
     '#description' => t('Enter the maximim pixel (px) width at which group logos will be displayed'),
     );
   $form['og_user_roles_logo']['og_user_roles_logo_height'] = array(
     '#type' => 'textfield',
     '#size' => 10,
     '#title' => t('Maximimum height for display of group logo?'),
-    '#default_value' => variable_get('og_user_roles_logo_height', '113'),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_logo_height', '113'),
     '#description' => t('Enter the maximum pixel (px) height at which group logos will be displayed'),
     );
 
@@ -368,13 +368,43 @@
     '#type' => 'textfield',
     '#size' => 10,
     '#title' => t('Counter for <b>og_users_roles</b> table'),
-    '#default_value' => variable_get('og_user_roles_counter', 0),
+    '#default_value' => og_user_roles_variable_get('og_user_roles_counter', 0),
     '#description' => t('This is the counter for the <b>og_users_roles</b> table. You do not need to set this.  It will update itself.  It should NOT be set lower than the number of records currently in the table.'),
   );
 
-  return system_settings_form($form);
+  $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
+  $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
+
+  return $form;
 }
 
+function og_user_roles_admin_settings_submit($form_id, $form_values) {
+  $op = isset($form_values['op']) ? $form_values['op'] : '';
+
+  // Exclude unnecessary elements.
+  unset($form_values['submit'], $form_values['reset'], $form_values['form_id'], $form_values['op'], $form_values['form_token']);
+
+  foreach ($form_values as $key => $value) {
+    if ($op == t('Reset to defaults')) {
+      og_user_roles_variable_del($key);
+    }
+    else {
+      if (is_array($value) && isset($form_values['array_filter'])) {
+        $value = array_keys(array_filter($value));
+      }
+      og_user_roles_variable_set($key, $value);
+    }
+  }
+  if ($op == t('Reset to defaults')) {
+    drupal_set_message(t('The configuration options have been reset to their default values.'));
+  }
+  else {
+    drupal_set_message(t('The configuration options have been saved.'));
+  }
+
+}
+
+
 /**
  * Generate multinode access UI form.
  */
@@ -446,7 +476,7 @@
 
   // This is an OGUR restriction: Do not show "submit" button if 
   // TAC/OG Integration not turned on.
-  if (variable_get('og_user_roles_tac_og_value', 0) == 1) {
+  if (og_user_roles_variable_get('og_user_roles_tac_og_value', 0) == 1) {
     $output .= drupal_render($form['submit']);
   } else {
     $output .= '<div id="comments">'. t('<strong>TAC/OG Integration is OFF</strong>.') ."</div>\n";
@@ -621,7 +651,7 @@
   $node = node_load($gid);
   // Get roles associated with this group. We rebuild the associative
   // array because the settings form only passes RID and we need the name.
-  $role_ids = variable_get("og_user_roles_roles_{$node->type}", array());
+  $role_ids = og_user_roles_variable_get("og_user_roles_roles_{$node->type}", array());
   $all_roles = user_roles();
   foreach ($role_ids as $rid => $checked) {
     if ($checked != 0) {
@@ -717,8 +747,8 @@
     foreach ($roles as $rid => $checked) {
       $exists = db_result(db_query("SELECT * FROM {og_users_roles} WHERE uid = %d AND rid = %d AND gid = %d", $uid, $rid, $gid));
       if ($checked && !$exists) {
-	    $ogr_id = variable_get('og_user_roles_counter', 0) + 1;
-        variable_set('og_user_roles_counter', $ogr_id);
+	    $ogr_id = og_user_roles_variable_get('og_user_roles_counter', 0) + 1;
+        og_user_roles_variable_set('og_user_roles_counter', $ogr_id);
         db_query("INSERT INTO {og_users_roles} (uid, rid, gid, ogr_id) VALUES (%d, %d, %d, %d)", $uid, $rid, $gid, $ogr_id);
         $args['rid'] = $rid;
         $args['ogr_id'] = $ogr_id;
@@ -795,7 +825,7 @@
  */
 function og_user_roles_is_allowed($nid) {
   $node = node_load($nid);
-  if (in_array($node->type, og_get_types('group')) && variable_get("og_user_roles_roles_$node->type", NULL)) {
+  if (in_array($node->type, og_get_types('group')) && og_user_roles_variable_get("og_user_roles_roles_$node->type", NULL)) {
     return TRUE;
   }
   else {
@@ -822,8 +852,8 @@
   $output = (db_result($result));
 
   if ($output == 0) {
-    $ogr_id = variable_get('og_user_roles_counter', 0) + 1;
-    variable_set('og_user_roles_counter', $ogr_id);
+    $ogr_id = og_user_roles_variable_get('og_user_roles_counter', 0) + 1;
+    og_user_roles_variable_set('og_user_roles_counter', $ogr_id);
     db_query("INSERT INTO {og_users_roles} (rid, uid, gid, ogr_id) VALUES ('%d','%d','%d', %d)", $rid, $uid, $gid, $ogr_id);
     $args['rid'] = $rid;
     $args['ogr_id'] = $ogr_id;
@@ -856,8 +886,8 @@
  * Remove og_user_roles variables for a group node that has been deleted.
  */
 function og_user_roles_variable_remove($gid) {
-  if (variable_get('og_user_roles_basicgrouprole_value_' . $gid, 0)) variable_del('og_user_roles_basicgrouprole_value_' . $gid);  
-  if (variable_get('og_user_roles_assign_basicgrouprole_' . $gid, 0)) variable_del('og_user_roles_assign_basicgrouprole_' . $gid);  
+  if (og_user_roles_variable_get('og_user_roles_basicgrouprole_value_' . $gid, 0)) og_user_roles_variable_del('og_user_roles_basicgrouprole_value_' . $gid);  
+  if (og_user_roles_variable_get('og_user_roles_assign_basicgrouprole_' . $gid, 0)) og_user_roles_variable_del('og_user_roles_assign_basicgrouprole_' . $gid);  
 }
 
 /**
@@ -1063,7 +1093,7 @@
   }
   // Get roles associated with this group. We rebuild the associative
   // array because the settings form only passes RID and we need the name.
-  $role_ids = variable_get("og_user_roles_roles_{$group}", array());
+  $role_ids = og_user_roles_variable_get("og_user_roles_roles_{$group}", array());
   $all_roles = user_roles();
   foreach ($role_ids as $rid => $checked) {
     if ($checked != 0) {
@@ -1088,7 +1118,7 @@
   if ($user->uid > 0) {
     $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
     $user->roles = $roles;
-    if (variable_get('og_user_roles_clear_cache_value', 0) == 1) {
+    if (og_user_roles_variable_get('og_user_roles_clear_cache_value', 0) == 1) {
 	  cache_clear_all($user->uid, 'cache_menu', TRUE);
 	  // Clear the user_access $perm cache
 	  user_access('', NULL, TRUE);
@@ -1148,7 +1178,7 @@
       $path = 'node/ognodeadd';
 
       if ($type == 'og_user_roles_subgroup') {
-        $type = variable_get('og_user_roles_create_subgroup_value', ''); // change OG Subgroups type to 'group'
+        $type = og_user_roles_variable_get('og_user_roles_create_subgroup_value', ''); // change OG Subgroups type to 'group'
       }
 
       $query = 'type='. $type .'&gids[]='. $gid;
@@ -1221,7 +1251,7 @@
 	  $og_permitted = og_is_group_post_type($type);
       if ($og_permitted && $og_audience_required && (!in_array($type, $og_omitted)) ) {
         if ($type == 'og_user_roles_subgroup') {
-          $type = variable_get('og_user_roles_create_subgroup_value', ''); // change OG Subgroups type to 'group'
+          $type = og_user_roles_variable_get('og_user_roles_create_subgroup_value', ''); // change OG Subgroups type to 'group'
         }
 
         $query = 'type='. $type .'&gids[]='. $gid;
@@ -1360,7 +1390,7 @@
     // Then redirect back to referrer.
 	// As a result of http://drupal.org/node/176662 this can only be done if the
 	// "Allow group admins to approve users" setting is checked on.
-    if (variable_get('og_user_roles_approval_default', 0) == 1 && ((!user_access('access administration pages')) && (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) != 1 && arg(2) == '') || (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'user'))) {
+    if (og_user_roles_variable_get('og_user_roles_approval_default', 0) == 1 && ((!user_access('access administration pages')) && (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) != 1 && arg(2) == '') || (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'user'))) {
       $ref = $_SERVER["HTTP_REFERER"];
       $ref_url = parse_url($ref);
       $ref_path = $ref_url[path];
@@ -1443,7 +1473,7 @@
 
   if ($op == 'insert') {
     // Registration Code 
-    if (isset($edit['og_user_roles_regcode']) && variable_get('og_user_roles_assign_regcode_gid', 0) == 1) { //only present during registration
+    if (isset($edit['og_user_roles_regcode']) && og_user_roles_variable_get('og_user_roles_assign_regcode_gid', 0) == 1) { //only present during registration
       $gid = og_user_roles_gid_from_regcode($edit['og_user_roles_regcode']);
       if ($gid > 0) {
         $node = node_load($gid);
@@ -1451,11 +1481,11 @@
         $return = og_save_subscription($gid, $user->uid, array('is_active' => 1)); // as per http://drupal.org/node/156224
         drupal_set_message(t('Subscription request to ' . l($title, 'node/'. $gid) . ' approved.'));	
         // Delete this registration code if 'delete_regcode' is set
-        if (variable_get('og_user_roles_delete_regcode_' . $gid, 0) == 1) og_user_roles_delete_regcode($gid, $edit['og_user_roles_regcode']);
+        if (og_user_roles_variable_get('og_user_roles_delete_regcode_' . $gid, 0) == 1) og_user_roles_delete_regcode($gid, $edit['og_user_roles_regcode']);
         // Places all new registration code group subscribers into default regcode role.
-        if (variable_get('og_user_roles_assign_regcoderole_' . $gid, 0)) { // check to see if this variable exists
-          if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && variable_get('og_user_roles_assign_regcoderole_' . $gid, 0) == 1 ) {
-            $rid = variable_get('og_user_roles_regcoderole_value_' . $gid, 0);
+        if (og_user_roles_variable_get('og_user_roles_assign_regcoderole_' . $gid, 0)) { // check to see if this variable exists
+          if (og_user_roles_variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && og_user_roles_variable_get('og_user_roles_assign_regcoderole_' . $gid, 0) == 1 ) {
+            $rid = og_user_roles_variable_get('og_user_roles_regcoderole_value_' . $gid, 0);
             og_user_roles_role_join($user->uid, $rid, $gid); // assign user to group role in that group
           }
         }
@@ -1464,7 +1494,7 @@
 
     // If site requires admin approval and group admins are allowed to approve users
 	// Variable "user_register" values: 0 = Admin Only, 1 = No Admin Approval, 2 = Admin Approval
-    if (variable_get('og_user_roles_approval_default', 0) == 1 && (variable_get('user_register', 1) == 2 || ($user->status == 0))) {
+    if (og_user_roles_variable_get('og_user_roles_approval_default', 0) == 1 && (variable_get('user_register', 1) == 2 || ($user->status == 0))) {
        watchdog('new_user: status', 'user->status = ' . $user->status, WATCHDOG_NOTICE);
       if (is_array($edit['og_register'])) {
         $sender = variable_get('site_mail', '');
@@ -1474,7 +1504,7 @@
           $node = node_load($gid);
           $group = check_plain($node->title);
           $subject = t('User @user pending account approval. Subscription request to : @group', array('@user' => $user->name, '@group' => $group));
-		  if (variable_get('og_user_roles_approval_default', 0) == 1) {
+		  if (og_user_roles_variable_get('og_user_roles_approval_default', 0) == 1) {
             $view_user = "oguseredit/$user->uid";
 		  }else{
             $view_user = "user/$user->uid";
@@ -1493,10 +1523,10 @@
 	}
 
     // If site admin opted to create a default role
-    if (variable_get('og_user_roles_assign_default', 0) == 1) {
+    if (og_user_roles_variable_get('og_user_roles_assign_default', 0) == 1) {
       // Check to see if this user doesn't already have this role;
       // If not, then assign it.
-      $rid = variable_get('og_user_roles_default_value', 0);
+      $rid = og_user_roles_variable_get('og_user_roles_default_value', 0);
       $sql = "SELECT COUNT(*) FROM {users_roles} WHERE uid = %d AND rid = %d";
       $result = db_query($sql, $user->uid, $rid);
       $output = (db_result($result));
@@ -1510,7 +1540,7 @@
   if ($op == 'validate') {
     // Registration Code
     if (isset($edit['og_user_roles_regcode'])) { //only present during registration
-      if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && $edit['og_user_roles_regcode'] != '') {
+      if (og_user_roles_variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && $edit['og_user_roles_regcode'] != '') {
         $gid = og_user_roles_gid_from_regcode($edit['og_user_roles_regcode']);
         if ($gid == 0) {
           form_set_error('og_user_roles_regcode', "Not a valid group registration code.  If you do not have a registration code, please make sure the Group registration code box is empty.");
@@ -1551,8 +1581,8 @@
       // I don't know a better way, so I'll do it like this. This is based on the creating of a founder role,
       // just that every user in the group should automagically get this role.
       // -Bibo
-      if (variable_get('og_user_roles_assign_basicgrouprole', 0) == 1) {
-        $rid = variable_get('og_user_roles_basicgrouprole_value', 0);
+      if (og_user_roles_variable_get('og_user_roles_assign_basicgrouprole', 0) == 1) {
+        $rid = og_user_roles_variable_get('og_user_roles_basicgrouprole_value', 0);
         og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
       }
 
@@ -1560,9 +1590,9 @@
       // Places all new group subscribers into default role.
       // Same as above, except these settings are set by Group Admin in the
       // group node.  So, the variables are set by group.
-	  if (variable_get('og_user_roles_assign_basicgrouprole_' . $nid, 0)) { // check to see if this variable exists
-        if (variable_get('og_user_roles_assign_basicgrouprole_gid', 0) == 1 && variable_get('og_user_roles_assign_basicgrouprole_' . $nid, 0) == 1 ) {
-          $rid = variable_get('og_user_roles_basicgrouprole_value_' . $nid, 0);
+	  if (og_user_roles_variable_get('og_user_roles_assign_basicgrouprole_' . $nid, 0)) { // check to see if this variable exists
+        if (og_user_roles_variable_get('og_user_roles_assign_basicgrouprole_gid', 0) == 1 && og_user_roles_variable_get('og_user_roles_assign_basicgrouprole_' . $nid, 0) == 1 ) {
+          $rid = og_user_roles_variable_get('og_user_roles_basicgrouprole_value_' . $nid, 0);
           og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
         }
       }
@@ -1570,8 +1600,8 @@
       // --- Modification - 2008-01-10 - as per: http://drupal.org/node/197489
       // Places all new group administrators into default group administrator role.
       $admin = $args['is_admin'];
-      if (variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin == 1) {
-        $rid = variable_get('og_user_roles_admingrouprole_value', 0);
+      if (og_user_roles_variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin == 1) {
+        $rid = og_user_roles_variable_get('og_user_roles_admingrouprole_value', 0);
         og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
       }
 
@@ -1582,19 +1612,19 @@
       // --- Modification - 2008-03-10 - as per: http://drupal.org/node/229715
       // Places all new group subscribers into default role per group type.
       $type = $node->type;
-	  if (variable_get('og_user_roles_assign_typegrouprole_' . $type, 0)) {
-	    if (variable_get('og_user_roles_assign_typegrouprole_' . $type, 0) == 1) {
-          $rid = variable_get('og_user_roles_typegrouprole_value_' . $type, 0);
+	  if (og_user_roles_variable_get('og_user_roles_assign_typegrouprole_' . $type, 0)) {
+	    if (og_user_roles_variable_get('og_user_roles_assign_typegrouprole_' . $type, 0) == 1) {
+          $rid = og_user_roles_variable_get('og_user_roles_typegrouprole_value_' . $type, 0);
           og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
         }
       }
 
       // Send notification of new og subscription to administrators of group;
-      if (variable_get('og_user_roles_notify_default', 0) == 1 && module_exists('mimemail')) {
+      if (og_user_roles_variable_get('og_user_roles_notify_default', 0) == 1 && module_exists('mimemail')) {
         $group = check_plain($node->title);
         $sender = variable_get('site_mail', '');
         $subject = t('User @user added to group: @group', array('@user' => $user->name, '@group' => $group));
-        if (variable_get('og_user_roles_approval_default', 0) == 1) {
+        if (og_user_roles_variable_get('og_user_roles_approval_default', 0) == 1) {
           $view_user = "oguseredit/$user->uid";
 		}else{
           $view_user = "user/$user->uid";
@@ -1617,12 +1647,12 @@
       // --- Modification - 2008-01-10 - as per: http://drupal.org/node/197489
       // Places all new group administrators into default group administrator role.
       $admin = $args['is_admin'];
-      if (variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin === 0) {
-        $rid = variable_get('og_user_roles_admingrouprole_value', 0);
+      if (og_user_roles_variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin === 0) {
+        $rid = og_user_roles_variable_get('og_user_roles_admingrouprole_value', 0);
         og_user_roles_role_delete($uid, $rid, $nid); // delete this admin role for this user in this group (if it exists)
       }
-      if (variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin === 1) {
-        $rid = variable_get('og_user_roles_admingrouprole_value', 0);
+      if (og_user_roles_variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin === 1) {
+        $rid = og_user_roles_variable_get('og_user_roles_admingrouprole_value', 0);
         og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
       }
       break;
@@ -1639,7 +1669,7 @@
  */
 function og_user_roles_node_info() {
   // If og_subgroups is installed AND og_user_roles_create_subgroup checkbox is checked;
-  if (module_exists('og_subgroups') && variable_get('og_user_roles_create_subgroup', 0) == 1) {
+  if (module_exists('og_subgroups') && og_user_roles_variable_get('og_user_roles_create_subgroup', 0) == 1) {
 
     return array(
       'og_user_roles_subgroup' => array(
@@ -1669,12 +1699,12 @@
     case 'insert':
 
       // If this is a group node, put the group creator into a group role upon creation;
-      if (variable_get('og_user_roles_assign_founder', 0) == 1) {
+      if (og_user_roles_variable_get('og_user_roles_assign_founder', 0) == 1) {
         // If this is a group node
         if (og_is_group_type($node->type)) {
           // Get the requisite data
           $uid = $node->uid; // user ID
-          $rid = variable_get('og_user_roles_founder_value', 0);
+          $rid = og_user_roles_variable_get('og_user_roles_founder_value', 0);
           $gid = $node->nid; // group ID
           og_user_roles_role_join($uid, $rid, $gid); // assign user to group role in that group
         }
@@ -1682,7 +1712,7 @@
       // Create a subgroup record for this group
       // 'ognodeadd' is my node add callback, so I know if this node is a group and
       // here, then we need to process it node as a subgroup
-      if ($node->type == variable_get('og_user_roles_create_subgroup_value', '') && arg(1) == 'ognodeadd') {
+      if ($node->type == og_user_roles_variable_get('og_user_roles_create_subgroup_value', '') && arg(1) == 'ognodeadd') {
         $gids = $_GET['gids'];
         $gid = $gids[0];
         $subgroup = $node->nid;
@@ -1699,12 +1729,12 @@
       // If this is a group node, put the group creator into a group role upon creation
 	  // OR when the group node is updated.  If user already is in that role in the group,
 	  // the og_user_roles_role_join command will ignore the request.
-      if (variable_get('og_user_roles_assign_founder', 0) == 1) {
+      if (og_user_roles_variable_get('og_user_roles_assign_founder', 0) == 1) {
         // If this is a group node
         if (og_is_group_type($node->type)) {
           // Get the requisite data
           $uid = $node->uid; // user ID
-          $rid = variable_get('og_user_roles_founder_value', 0);
+          $rid = og_user_roles_variable_get('og_user_roles_founder_value', 0);
           $gid = $node->nid; // group ID
           og_user_roles_role_join($uid, $rid, $gid); // assign user to group role in that group
         }
@@ -1785,7 +1815,7 @@
 	   }
 
 	   // Check the nopublic variable for this group
-        if (variable_get('og_user_roles_assign_nopublic_' . $gid, 0) == 1) { 
+        if (og_user_roles_variable_get('og_user_roles_assign_nopublic_' . $gid, 0) == 1) { 
 	      // Check public status of this post
 	      if ($node->og_public) { 
 	        form_set_error('og_public', t('No public posts allowed in this group.  You may NOT check the <strong>Public</strong> box on this post.'));
@@ -2491,7 +2521,7 @@
   }
 
   // Write the test data: http://drupal.org/node/164038
-  if (variable_get('og_user_roles_test_default', 0) == 1) {
+  if (og_user_roles_variable_get('og_user_roles_test_default', 0) == 1) {
     if (is_array($d)) {
       $d1 = 'Roles Returned: ('. implode(',', $d) .')';
 	} else {
@@ -2934,36 +2964,36 @@
   if ($group_node = og_get_group_context()) {
     $location .= "A";
     $gid = $group_node->nid;
-    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+    $logo = og_user_roles_variable_get('og_user_roles_logo_' . $gid, '');
     $_SESSION['oglogo'] = $logo;
-    variable_set('oglogo_' . $addr, $logo);
+    og_user_roles_variable_set('oglogo_' . $addr, $logo);
   }
 
   if ($ref_arg[1] == 'print' && is_numeric($ref_arg[2])) {
     $location .= "B";
     $nid = (int)$ref_arg[2];
     $gid = og_user_roles_getgid($nid, $uid);
-    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+    $logo = og_user_roles_variable_get('og_user_roles_logo_' . $gid, '');
     $_SESSION['oglogo'] = $logo;
-    variable_set('oglogo_' . $addr, $logo);
+    og_user_roles_variable_set('oglogo_' . $addr, $logo);
   }
 
   if (arg(0) == 'print' && arg(2) == 'og' && is_numeric(arg(3))) {
     $location .= "C";
     $nid = (int)arg(3);
     $gid = og_user_roles_getgid($nid, $uid);
-    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+    $logo = og_user_roles_variable_get('og_user_roles_logo_' . $gid, '');
     $_SESSION['oglogo'] = $logo;
-    variable_set('oglogo_' . $addr, $logo);
+    og_user_roles_variable_set('oglogo_' . $addr, $logo);
   }
 
   if ($ref_arg[1] == 'print' && is_numeric($ref_arg[4])) {
     $location .= "D";
     $nid = (int)$ref_arg[4];
     $gid = og_user_roles_getgid($nid, $uid);
-    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+    $logo = og_user_roles_variable_get('og_user_roles_logo_' . $gid, '');
     $_SESSION['oglogo'] = $logo;
-    variable_set('oglogo_' . $addr, $logo);
+    og_user_roles_variable_set('oglogo_' . $addr, $logo);
   }
 
 
@@ -2976,7 +3006,7 @@
 //    $location .= "F";
 //    $nid = $_SESSION['og_last'];
 //    $gid = og_user_roles_getgid($nid, $uid);
-//    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+//    $logo = og_user_roles_variable_get('og_user_roles_logo_' . $gid, '');
 //  }
 
 // IE Print Problem: If we found $logo above, use this to locate it.
@@ -2987,7 +3017,7 @@
 
   if (empty($logo) && empty($ref) && empty($gid) && $user->uid == 0) {
     $location .= "G";
-    $logo = variable_get('oglogo_' . $addr, '');
+    $logo = og_user_roles_variable_get('oglogo_' . $addr, '');
   }
 
   $d = 'Session variables: (';
@@ -3005,7 +3035,7 @@
   }
 
   // Write the test data: http://drupal.org/node/164038
-  if (variable_get('og_user_roles_test_default', 0) == 1) {
+  if (og_user_roles_variable_get('og_user_roles_test_default', 0) == 1) {
     og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $ref, $test_function);
   }
 
@@ -3038,7 +3068,7 @@
  */
 function og_user_roles_oglogo_gid($gid) {
 
-  $logo = variable_get('og_user_roles_logo_' . $gid, '');
+  $logo = og_user_roles_variable_get('og_user_roles_logo_' . $gid, '');
 
   return $logo;
 }
@@ -3131,9 +3161,9 @@
   $groups = og_all_groups_options();
   foreach ($groups as $group => $title) {
     // Only process groups that are allowed to have registration codes
-    if (variable_get('og_user_roles_assign_regcode_' . $group, 0) == 1) {
+    if (og_user_roles_variable_get('og_user_roles_assign_regcode_' . $group, 0) == 1) {
       // Get the array of codes for this group.
-      $group_array = explode(',', variable_get('og_user_roles_regcode_value_' . $group, ''));
+      $group_array = explode(',', og_user_roles_variable_get('og_user_roles_regcode_value_' . $group, ''));
       if (in_array($regcode, $group_array)) {
         $gid = $group;
       }
@@ -3184,14 +3214,14 @@
   // the user has the 'configure member roles' permission, and we allow group admins
   // to set default group roles, then print the 'basicgrouprole' form on the
   // group edit form.
-  if (arg(0) == 'node' && ($_SESSION['og_last'] == arg(1)) && arg(2) == 'edit' && user_access('configure member roles') && variable_get('og_user_roles_assign_basicgrouprole_gid', 0) == 1) {
+  if (arg(0) == 'node' && ($_SESSION['og_last'] == arg(1)) && arg(2) == 'edit' && user_access('configure member roles') && og_user_roles_variable_get('og_user_roles_assign_basicgrouprole_gid', 0) == 1) {
     $gid = arg(1);
 
     // First, we need to get a list of all og-enabled node types
     $group_types = og_get_types('group');
     foreach ($group_types as $type) {
       // Get list of assignable group roles for this group type
-      $role_ids = variable_get("og_user_roles_roles_{$type}", array());
+      $role_ids = og_user_roles_variable_get("og_user_roles_roles_{$type}", array());
       $all_roles = user_roles();
       foreach ($role_ids as $rid => $checked) {
         if ($checked != 0) {
@@ -3210,14 +3240,14 @@
         $form['og_user_roles_basicgrouprole_gid']['og_user_roles_assign_basicgrouprole_' . $gid] = array(
           '#type' => 'checkbox',
           '#title' => t('Set default basic group (group limited) role for users who join this group?'),
-          '#default_value' => variable_get('og_user_roles_assign_basicgrouprole_' . $gid, 0),
+          '#default_value' => og_user_roles_variable_get('og_user_roles_assign_basicgrouprole_' . $gid, 0),
           '#description' => t('Do you wish to automatically assign a specific "basic group role" to <b>every new subscriber to this group</b> at the time he subscribes to this group? The role is limited to this group. This role assignment can be be removed by the groups\' admin(s)'),
           );
         $form['og_user_roles_basicgrouprole_gid']['og_user_roles_basicgrouprole_value_' . $gid] = array(
           '#type' => 'select',
           '#title' => t('Role to use as a basic group role'),
           '#options' => $roles,
-          '#default_value' => variable_get('og_user_roles_basicgrouprole_value_' . $gid, 0),
+          '#default_value' => og_user_roles_variable_get('og_user_roles_basicgrouprole_value_' . $gid, 0),
           '#description' => t('Select the role you wish to use as the "basic group role" for every new subscriber to this group.'),
           );      
          $form['#submit'] += array('og_user_roles_basicgrouprole_form_submit' => array($form_id, &$form));          
@@ -3233,7 +3263,7 @@
     $group_types = og_get_types('group');
     foreach ($group_types as $type) {
       // Get list of assignable group roles for this group type
-      $role_ids = variable_get("og_user_roles_roles_{$type}", array());
+      $role_ids = og_user_roles_variable_get("og_user_roles_roles_{$type}", array());
       $all_roles = user_roles();
       foreach ($role_ids as $rid => $checked) {
         if ($checked != 0) {
@@ -3246,7 +3276,7 @@
 
         // Group Logo Location
 
-        if(variable_get('og_user_roles_logo_enabled', '1') ) {
+        if(og_user_roles_variable_get('og_user_roles_logo_enabled', '1') ) {
           $form['og_user_roles_logo'] = array(
             '#type' => 'fieldset',
             '#title' => t('Group Logo location.'),
@@ -3257,8 +3287,8 @@
           $form['og_user_roles_logo']['og_user_roles_logo_' . $gid] = array(
             '#type' => 'textfield',
             '#title' => t('Location of group logo?'),
-            '#default_value' => variable_get('og_user_roles_logo_' . $gid, ''),
-            '#description' => t('Enter either the local file path or the remote URL for the image to be used as the logo for this group. Enter one of the following formats: <strong>http://www.yoursite.com/yourlogo.gif</strong> (for remote file) or <strong>files/yourlogo.gif</strong> (for local file). You can attach the file you wish to use to this group using <strong>File attachments</strong> section below, then supply local path here once the file is uploaded (attached).  Your logo image must not exceed these size dimensions: Width (in pixels): <strong>' . variable_get('og_user_roles_logo_width', '135') . 'px</strong> Height (in pixels): <strong>' . variable_get('og_user_roles_logo_height', '113') . 'px</strong>'),
+            '#default_value' => og_user_roles_variable_get('og_user_roles_logo_' . $gid, ''),
+            '#description' => t('Enter either the local file path or the remote URL for the image to be used as the logo for this group. Enter one of the following formats: <strong>http://www.yoursite.com/yourlogo.gif</strong> (for remote file) or <strong>files/yourlogo.gif</strong> (for local file). You can attach the file you wish to use to this group using <strong>File attachments</strong> section below, then supply local path here once the file is uploaded (attached).  Your logo image must not exceed these size dimensions: Width (in pixels): <strong>' . og_user_roles_variable_get('og_user_roles_logo_width', '135') . 'px</strong> Height (in pixels): <strong>' . og_user_roles_variable_get('og_user_roles_logo_height', '113') . 'px</strong>'),
             );
           $form['#validate'] += array('og_user_roles_logo_form_validate' => array($form_id, &$form));          
           $form['#submit'] += array('og_user_roles_logo_form_submit' => array($form_id, &$form));          
@@ -3266,7 +3296,7 @@
 
         // Add the code to display 'Create content' link and/or remove 'create_' links.
 
-        if (variable_get('og_user_roles_menu_options_enabled', 1)) {
+        if (og_user_roles_variable_get('og_user_roles_menu_options_enabled', 1)) {
           $form['og_user_roles_links_gid'] = array(
             '#type' => 'fieldset',
             '#title' => t('Control group menu content links.'),
@@ -3276,13 +3306,13 @@
           $form['og_user_roles_links_gid']['og_user_roles_links_content_' . $gid] = array(
             '#type' => 'checkbox',
             '#title' => t('Display the <strong>Create content</strong> link?'),
-            '#default_value' => variable_get('og_user_roles_links_content_' . $gid, 0),
+            '#default_value' => og_user_roles_variable_get('og_user_roles_links_content_' . $gid, 0),
             '#description' => t('Do you wish to display the OGUR <strong>Create content</strong> link on this group\'s menu?'),
             );
           $form['og_user_roles_links_gid']['og_user_roles_links_remove_' . $gid] = array(
             '#type' => 'checkbox',
             '#title' => t('Remove the default <strong>Create</strong> links?'),
-            '#default_value' => variable_get('og_user_roles_links_remove_' . $gid, 0),
+            '#default_value' => og_user_roles_variable_get('og_user_roles_links_remove_' . $gid, 0),
             '#description' => t('Do you wish to remove the default OG <strong>Create</strong> content links on this group\'s menu?'),
             );
           $form['#submit'] += array('og_user_roles_links_form_submit' => array($form_id, &$form));          
@@ -3301,7 +3331,7 @@
           $form['og_user_roles_nopublic_gid']['og_user_roles_assign_nopublic_' . $gid] = array(
             '#type' => 'checkbox',
             '#title' => t('Do not allow public posts in this group?'),
-            '#default_value' => variable_get('og_user_roles_assign_nopublic_' . $gid, 0),
+            '#default_value' => og_user_roles_variable_get('og_user_roles_assign_nopublic_' . $gid, 0),
             '#description' => t('Do you wish to disallow public postings from this group?'),
             );
           $form['#submit'] += array('og_user_roles_nopublic_form_submit' => array($form_id, &$form));          
@@ -3309,7 +3339,7 @@
         // If the user has the 'manage registration codes' permission, and we allow group admins
         // to set registration codes, then print the 'regcode' form on the
         // group edit form.
-        if (user_access('manage registration codes') && variable_get('og_user_roles_assign_regcode_gid', 0) == 1) {
+        if (user_access('manage registration codes') && og_user_roles_variable_get('og_user_roles_assign_regcode_gid', 0) == 1) {
 
           $form['og_user_roles_regcode_gid'] = array(
             '#type' => 'fieldset',
@@ -3321,19 +3351,19 @@
           $form['og_user_roles_regcode_gid']['og_user_roles_assign_regcode_' . $gid] = array(
             '#type' => 'checkbox',
             '#title' => t('Set registration codes to allow users to join this group?'),
-            '#default_value' => variable_get('og_user_roles_assign_regcode_' . $gid, 0),
+            '#default_value' => og_user_roles_variable_get('og_user_roles_assign_regcode_' . $gid, 0),
             '#description' => t('Do you wish to enter registration codes that will allow new subscribers to bypass admin approval and join this group?'),
             );
           $form['og_user_roles_regcode_gid']['og_user_roles_delete_regcode_' . $gid] = array(
             '#type' => 'checkbox',
             '#title' => t('Delete registration code after it is used?'),
-            '#default_value' => variable_get('og_user_roles_delete_regcode_' . $gid, 0),
+            '#default_value' => og_user_roles_variable_get('og_user_roles_delete_regcode_' . $gid, 0),
             '#description' => t('Do you want to delete each individual registration code after it is used to successfully subscribe a user to the group?'),
             );
           $form['og_user_roles_regcode_gid']['og_user_roles_regcode_value_' . $gid] = array(
             '#type' => 'textarea',
             '#title' => t('Registration codes for allowing users to subscribe to this group without admin approval'),
-            '#default_value' => variable_get('og_user_roles_regcode_value_' . $gid, ''),
+            '#default_value' => og_user_roles_variable_get('og_user_roles_regcode_value_' . $gid, ''),
             '#cols' => 50,
             '#rows' => 2,
             '#description' => t('Specify here the registration codes which will allow users who enter them to subscribe to this moderated group without being manually approved by the group administrator. Structure your entries like this:
@@ -3345,14 +3375,14 @@
             $form['og_user_roles_regcode_gid']['og_user_roles_assign_regcoderole_' . $gid] = array(
               '#type' => 'checkbox',
               '#title' => t('Set default basic group (group limited) role for users who join this group using this registration code?'),
-              '#default_value' => variable_get('og_user_roles_assign_regcoderole_' . $gid, 0),
+              '#default_value' => og_user_roles_variable_get('og_user_roles_assign_regcoderole_' . $gid, 0),
               '#description' => t('Do you wish to automatically assign a specific "registration code group role" to new subscribers to this group <b>who use this registration code to subscribe</b> to this group? The role is limited to this group. This role assignment can be be removed by the groups\' admin(s)'),
               );
             $form['og_user_roles_regcode_gid']['og_user_roles_regcoderole_value_' . $gid] = array(
               '#type' => 'select',
               '#title' => t('Role to assign'),
               '#options' => $roles,
-              '#default_value' => variable_get('og_user_roles_regcoderole_value_' . $gid, 0),
+              '#default_value' => og_user_roles_variable_get('og_user_roles_regcoderole_value_' . $gid, 0),
               '#description' => t('Select the role you wish to use as the "registration code group role" for every new subscriber who subscribes to this group using one of the registration codes above.'),
               );      
           }
@@ -3377,12 +3407,12 @@
 
 function og_user_roles_basicgrouprole_form_submit($form_id, $form_values) {
   $gid = arg(1);
-  variable_set('og_user_roles_assign_basicgrouprole_' . $gid, $form_values['og_user_roles_assign_basicgrouprole_' . $gid]);
-  variable_set('og_user_roles_basicgrouprole_value_' . $gid, $form_values['og_user_roles_basicgrouprole_value_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_assign_basicgrouprole_' . $gid, $form_values['og_user_roles_assign_basicgrouprole_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_basicgrouprole_value_' . $gid, $form_values['og_user_roles_basicgrouprole_value_' . $gid]);
 }
 function og_user_roles_logo_form_submit($form_id, $form_values) {
   $gid = arg(1);
-  variable_set('og_user_roles_logo_' . $gid, $form_values['og_user_roles_logo_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_logo_' . $gid, $form_values['og_user_roles_logo_' . $gid]);
 }
 /*
  * Here we want to make sure that the submitted logo does not exceed size restrictions.
@@ -3390,8 +3420,8 @@
 function og_user_roles_logo_form_validate($form_id, $form_values) {
   $gid = arg(1);
   if ($form_values['og_user_roles_logo_' . $gid]) {
-    $width = variable_get('og_user_roles_logo_width', '135');
-    $height = variable_get('og_user_roles_logo_height', '113');
+    $width = og_user_roles_variable_get('og_user_roles_logo_width', '135');
+    $height = og_user_roles_variable_get('og_user_roles_logo_height', '113');
     $image = image_get_info($form_values['og_user_roles_logo_' . $gid]);
 	$img_width = $image['width'];
 	$img_height = $image['height'];
@@ -3402,20 +3432,20 @@
 }
 function og_user_roles_links_form_submit($form_id, $form_values) {
   $gid = arg(1);
-  variable_set('og_user_roles_links_content_' . $gid, $form_values['og_user_roles_links_content_' . $gid]);
-  variable_set('og_user_roles_links_remove_' . $gid, $form_values['og_user_roles_links_remove_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_links_content_' . $gid, $form_values['og_user_roles_links_content_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_links_remove_' . $gid, $form_values['og_user_roles_links_remove_' . $gid]);
 }
 function og_user_roles_nopublic_form_submit($form_id, $form_values) {
   $gid = arg(1);
-  variable_set('og_user_roles_assign_nopublic_' . $gid, $form_values['og_user_roles_assign_nopublic_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_assign_nopublic_' . $gid, $form_values['og_user_roles_assign_nopublic_' . $gid]);
 }
 function og_user_roles_regcode_form_submit($form_id, $form_values) {
   $gid = arg(1);
-  variable_set('og_user_roles_assign_regcode_' . $gid, $form_values['og_user_roles_assign_regcode_' . $gid]);
-  variable_set('og_user_roles_delete_regcode_' . $gid, $form_values['og_user_roles_delete_regcode_' . $gid]);
-  variable_set('og_user_roles_regcode_value_' . $gid, $form_values['og_user_roles_regcode_value_' . $gid]);
-  variable_set('og_user_roles_assign_regcoderole_' . $gid, $form_values['og_user_roles_assign_regcoderole_' . $gid]);
-  variable_set('og_user_roles_regcoderole_value_' . $gid, $form_values['og_user_roles_regcoderole_value_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_assign_regcode_' . $gid, $form_values['og_user_roles_assign_regcode_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_delete_regcode_' . $gid, $form_values['og_user_roles_delete_regcode_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_regcode_value_' . $gid, $form_values['og_user_roles_regcode_value_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_assign_regcoderole_' . $gid, $form_values['og_user_roles_assign_regcoderole_' . $gid]);
+  og_user_roles_variable_set('og_user_roles_regcoderole_value_' . $gid, $form_values['og_user_roles_regcoderole_value_' . $gid]);
 }
 /*
  * Here we want to make sure that the submitted regcode value is not duplicated in another group.
@@ -3423,7 +3453,7 @@
 function og_user_roles_regcode_form_validate($form_id, $form_values) {
   $gid = arg(1);
   // No need to go through any of this if the 'Allow Group Admins to set Registration Codes' is not set
-  if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1) {
+  if (og_user_roles_variable_get('og_user_roles_assign_regcode_gid', 0) == 1) {
     // If this group allows for registration codes to be set
     if ($form_values['og_user_roles_assign_regcode_' . $gid] == 1) {
       // If this value is blank, return error
@@ -3437,9 +3467,9 @@
 	    // Get all groups except current one.
         if ($group != $gid) {
           // Only process groups that are allowed to have registration codes
-          if (variable_get('og_user_roles_assign_regcode_' . $group, 0) == 1) {
+          if (og_user_roles_variable_get('og_user_roles_assign_regcode_' . $group, 0) == 1) {
 	   	    // Get the array of codes for this group.
-            $group_array = explode(',', variable_get('og_user_roles_regcode_value_' . $group, ''));
+            $group_array = explode(',', og_user_roles_variable_get('og_user_roles_regcode_value_' . $group, ''));
             // Check to see this array as any elements which are duplicated
             if ($duplicated = array_intersect($regcode_array, $group_array)) {
               // If there are duplicates, then display the group in which they are duplicated ONLY if this is a site admin
@@ -3534,7 +3564,7 @@
  * $group is an object containing the group node
  */
 function og_user_roles_og_create_links($group) {
-  if (variable_get('og_user_roles_links_content_' . $group->nid, 0) == 1) {
+  if (og_user_roles_variable_get('og_user_roles_links_content_' . $group->nid, 0) == 1) {
     $links[] = l(t('Create content'), "node/ognodeadd", array('title' => t('Add new content in this group.')), "gids[]=$group->nid");
     return $links;
   }
@@ -3547,7 +3577,7 @@
  * Optionally remove create_ links.
  */
 function og_user_roles_og_link_alter(&$links, $group_node) {
-  if (variable_get('og_user_roles_links_remove_' . $group_node->nid, 0) == 1) {
+  if (og_user_roles_variable_get('og_user_roles_links_remove_' . $group_node->nid, 0) == 1) {
     foreach($links as $key => $value) {
       if(substr($key,0,7) == 'create_') {
         unset($links["$key"]);
@@ -3578,7 +3608,7 @@
           $subscription = og_user_roles_og_status($node);
           if ($subscription == 'none') {
             if ($user->uid) {
-              if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && variable_get('og_user_roles_assign_regcode_' . $node->nid, 0) == 1 ) {
+              if (og_user_roles_variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && og_user_roles_variable_get('og_user_roles_assign_regcode_' . $node->nid, 0) == 1 ) {
                 $block = array('subject' => t('Register Codes'), 'content' => l('Enter your registration code', 'og/regcode'));
               }
             }
@@ -3587,9 +3617,9 @@
         break;
       case 1:
         if ($node = og_get_group_context()) {
-          if ($logo = variable_get('og_user_roles_logo_' . $node->nid, '')) {
-//		    $width = variable_get('og_user_roles_logo_width', '135');
-//		    $height = variable_get('og_user_roles_logo_height', '113');
+          if ($logo = og_user_roles_variable_get('og_user_roles_logo_' . $node->nid, '')) {
+//		    $width = og_user_roles_variable_get('og_user_roles_logo_width', '135');
+//		    $height = og_user_roles_variable_get('og_user_roles_logo_height', '113');
 //		    $attributes = array('width' => $width, 'height' => $height);
 		    $attributes = array();
             $imglink = theme_image($logo, $alt = $node->title, $title = $node->title, $attributes, $getsize = FALSE);
@@ -3612,7 +3642,7 @@
  * if in moderation.
  */
 function og_user_roles_og_block_details($group) {
-  if ($group->og_selective == OG_MODERATED && variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && variable_get('og_user_roles_assign_regcode_' . $group->nid, '') == 1) {
+  if ($group->og_selective == OG_MODERATED && og_user_roles_variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && og_user_roles_variable_get('og_user_roles_assign_regcode_' . $group->nid, '') == 1) {
     $links[] = l(t('Enter registration code'), "og/regcode", array('title' => t('Subscribe to this group using a registration code.')));
   }  
   $oldblock = og_og_block_details($group);
@@ -3673,11 +3703,11 @@
       $return = og_save_subscription($gid, $user->uid, array('is_active' => 1)); // as per http://drupal.org/node/156224
       drupal_set_message(t('Subscription request to ' . l($title, 'node/'. $gid) . ' approved.'));	
       // Delete this registration code if 'delete_regcode' is set
-      if (variable_get('og_user_roles_delete_regcode_' . $gid, 0) == 1) og_user_roles_delete_regcode($gid, $form_values['og_user_roles_regcode']);
+      if (og_user_roles_variable_get('og_user_roles_delete_regcode_' . $gid, 0) == 1) og_user_roles_delete_regcode($gid, $form_values['og_user_roles_regcode']);
       // Places all new registration code group subscribers into default regcode role.
-      if (variable_get('og_user_roles_assign_regcoderole_' . $gid, 0)) { // check to see if this variable exists
-        if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && variable_get('og_user_roles_assign_regcoderole_' . $gid, 0) == 1 ) {
-          $rid = variable_get('og_user_roles_regcoderole_value_' . $gid, 0);
+      if (og_user_roles_variable_get('og_user_roles_assign_regcoderole_' . $gid, 0)) { // check to see if this variable exists
+        if (og_user_roles_variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && og_user_roles_variable_get('og_user_roles_assign_regcoderole_' . $gid, 0) == 1 ) {
+          $rid = og_user_roles_variable_get('og_user_roles_regcoderole_value_' . $gid, 0);
           og_user_roles_role_join($user->uid, $rid, $gid); // assign user to group role in that group
         }
       }
@@ -3690,7 +3720,7 @@
 
 function og_user_roles_delete_regcode($gid, $regcode) {
   // Get the array of registration codes for this $gid
-  $group_array = explode(',', variable_get('og_user_roles_regcode_value_' . $gid, ''));
+  $group_array = explode(',', og_user_roles_variable_get('og_user_roles_regcode_value_' . $gid, ''));
   // Create new array that contains all codes for this one.
   foreach ($group_array as $item) {
     if ($item != $regcode) {
@@ -3700,7 +3730,7 @@
   // Implode the new array
   $new = implode(",", $new_array);
   // Write the new value.
-  variable_set('og_user_roles_regcode_value_' . $gid, $new);  
+  og_user_roles_variable_set('og_user_roles_regcode_value_' . $gid, $new);  
 }
 
 /**
@@ -3746,7 +3776,7 @@
 
   $grants = array();
 
-  if (variable_get('og_user_roles_tac_og_value', 0) == 1) {
+  if (og_user_roles_variable_get('og_user_roles_tac_og_value', 0) == 1) {
 
     // we need to explicitly label public nodes it seems. OG doesn't label nodes
     // of types it doesn't apply to, or the "implicitly public" nodes created by
@@ -3854,7 +3884,7 @@
 function og_user_roles_cron() {
 
   // Insert nodes into all groups.
-  $nodelist = variable_get('og_user_roles_all_groups_nodes', '');
+  $nodelist = og_user_roles_variable_get('og_user_roles_all_groups_nodes', '');
 
   if (!empty($nodelist)) {
     $nodelist_array = explode(',', $nodelist);
@@ -3916,5 +3946,17 @@
   }
 
 }
-
-?>
+
+function og_user_roles_variable_get($name, $default) {
+  $value = db_result(db_query("SELECT value FROM {og_user_roles_variable} WHERE name = '%s'", $name));
+  return isset($value) ? unserialize($value) : $default;
+}
+
+function og_user_roles_variable_set($name, $value) {
+  og_user_roles_variable_del($name);
+  db_query("INSERT INTO {og_user_roles_variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
+}
+
+function og_user_roles_variable_del($name) {
+  db_query("DELETE FROM {og_user_roles_variable} WHERE name = '%s'", $name);
+}
Index: og_user_roles.install
===================================================================
--- og_user_roles.install	(revision 3312)
+++ og_user_roles.install	(working copy)
@@ -24,6 +24,12 @@
         PRIMARY KEY  (realm)
       ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
 
+      db_query("CREATE TABLE {og_user_roles_variable} (
+        name varchar(128) NOT NULL DEFAULT '',
+        value longtext NOT NULL,
+        PRIMARY KEY  (name)
+      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+
       break;
 
     case 'pgsql':
@@ -46,6 +52,12 @@
         PRIMARY KEY  (realm)
       );");
 
+      db_query("CREATE TABLE {og_user_roles_variable} (
+        name varchar(128) NOT NULL DEFAULT '',
+        value longtext NOT NULL,
+        PRIMARY KEY  (name)
+      );");
+
       break;
   }
 
@@ -129,5 +141,35 @@
       ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
   return $items;
 }
-
-?>
\ No newline at end of file
+
+function og_user_roles_update_5292() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {og_user_roles_variable} (
+          name varchar(128) NOT NULL DEFAULT '',
+          value longtext NOT NULL,
+          PRIMARY KEY  (name)
+        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+      break;
+
+    case 'pgsql':
+      $ret[] = update_sql("CREATE TABLE {og_user_roles_variable} (
+          name varchar(128) NOT NULL DEFAULT '',
+          value longtext NOT NULL,
+          PRIMARY KEY  (name)
+        );");
+      break;
+  }
+
+  // Move existing variable settings from the variable table to the new
+  // og_user_roles_variable table.
+  $result = db_query("SELECT name, value FROM {variable} WHERE name LIKE 'og_user_roles%' OR name LIKE 'oglogo%'");
+  while ($row = db_fetch_object($result)) {
+    db_query("INSERT INTO {og_user_roles_variable} (name, value) VALUES('%s', '%s')", $row->name, $row->value);
+    variable_del($row->name);
+  }
+
+  return $ret;
+}
