/**
  * Updates an existing Group
  *
  * @param int $groupID - Group identifier
  * @param string $name - Name of the group
  * @param string $description - Group description (optional)
  * @return boolean True on successful update
  **/
 function updateGroup($group_id, $name, $description = '')
 {
     global $wpdb;
     $description = strip_tags($description);
     if ($prev = scoper_get_row("SELECT * FROM {$wpdb->groups_rs} WHERE {$wpdb->groups_id_col}='{$group_id}';")) {
         if ($prev->{$wpdb->groups_name_col} != $name && !UserGroups_tp::isValidName($name)) {
             return false;
         }
         // don't allow updating of metagroup name / descript
         if (!empty($prev->meta_id)) {
             return false;
         }
     }
     do_action('update_group_rs', $group_id);
     $query = "UPDATE {$wpdb->groups_rs} SET {$wpdb->groups_name_col} = '{$name}', {$wpdb->groups_descript_col}='{$description}' WHERE {$wpdb->groups_id_col}='{$group_id}';";
     scoper_query($query);
     wpp_cache_flush_group('all_usergroups');
     wpp_cache_flush_group('group_members');
     wpp_cache_flush_group('usergroups_for_user');
     wpp_cache_flush_group('usergroups_for_groups');
     wpp_cache_flush_group('usergroups_for_ug');
     return true;
 }
 if ($can_manage_all_groups || current_user_can('manage_groups', $_POST['groupID'])) {
     if (!empty($_POST['groupName'])) {
         $_POST['groupName'] = str_replace('[', '', $_POST['groupName']);
         $_POST['groupName'] = str_replace(']', '', $_POST['groupName']);
     }
     //to continue edit
     $group->display_name = $_POST['groupName'];
     $group->prev_name = $_POST['prevName'];
     $group->descript = $_POST['groupDesc'];
     if ($get_group = ScoperAdminLib::get_group($group->ID)) {
         $group->meta_id = $get_group->meta_id;
     }
     check_admin_referer('scoper-edit-group_' . $group->ID);
     if (!$group->meta_id) {
         // editable metagroups can have users edited but not group name\
         if (!UserGroups_tp::isValidName($_POST['groupName']) && $_POST['groupName'] != $_POST['prevName']) {
             if ($_POST['groupName'] == "") {
                 $errorMessage = __("Please specify a name for the group.", 'scoper');
                 $mode = "edit";
             } else {
                 $errorMessage = sprintf(__("A group with the name <strong>%s</strong> already exists.", 'scoper'), $_POST['groupName']);
                 $mode = "edit";
             }
         } else {
             if (UserGroups_tp::updateGroup($_POST['groupID'], $_POST['groupName'], $_POST['groupDesc'])) {
                 $success_msg = sprintf(__("Group <strong>%s</strong> updated successfuly.", 'scoper'), $_POST['groupName']);
             } else {
                 $errorMessage = sprintf(__("Group <strong>%s</strong> was not updated successfuly.", 'scoper'), $_POST['prevName']);
                 $mode = "edit";
             }
         }
Beispiel #3
0
 $group->ID = (int) $_POST['groupID'];
 if ($can_manage_all_groups || current_user_can('manage_groups', $group->ID)) {
     $groupName = sanitize_text_field($_POST['groupName'], '', 'query');
     $groupName = str_replace('[', '', $groupName);
     $groupName = str_replace(']', '', $groupName);
     //to continue edit
     $group->display_name = $groupName;
     $group->prev_name = sanitize_text_field($_POST['prevName'], '', 'query');
     $group->descript = sanitize_text_field($_POST['groupDesc'], '', 'query');
     if ($get_group = ScoperAdminLib::get_group($group->ID)) {
         $group->meta_id = $get_group->meta_id;
     }
     check_admin_referer('scoper-edit-group_' . $group->ID);
     if (!$group->meta_id) {
         // editable metagroups can have users edited but not group name\
         if (!UserGroups_tp::isValidName($groupName) && $groupName != $group->prev_name) {
             if ($groupName == "") {
                 $errorMessage = __("Please specify a name for the group.", 'scoper');
                 $mode = "edit";
             } else {
                 $errorMessage = sprintf(__("A group with the name <strong>%s</strong> already exists.", 'scoper'), $groupName);
                 $mode = "edit";
             }
         } else {
             if (UserGroups_tp::updateGroup($group->ID, $groupName, $group->descript)) {
                 $success_msg = sprintf(__("Group <strong>%s</strong> updated successfuly.", 'scoper'), $groupName);
             } else {
                 $errorMessage = sprintf(__("Group <strong>%s</strong> was not updated successfuly.", 'scoper'), $group->prev_name);
                 $mode = "edit";
             }
         }