/**
  * Removes a given group
  *
  * @param int $id - Identifier of the group to delete
  * @param boolean True if the deletion is successful
  **/
 function deleteGroup($group_id)
 {
     global $wpdb;
     if (!$group_id || !UserGroups_tp::getGroup($group_id)) {
         return false;
     }
     do_action('delete_group_rs', $group_id);
     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');
     // first delete all cache entries related to this group
     if ($group_members = ScoperAdminLib::get_group_members($group_id, COL_ID_RS)) {
         $id_in = "'" . implode("', '", $group_members) . "'";
         $any_user_roles = scoper_get_var("SELECT assignment_id FROM {$wpdb->user2role2object_rs} WHERE role_type = 'rs' AND user_id IN ({$id_in}) LIMIT 1");
         foreach ($group_members as $user_id) {
             wpp_cache_delete($user_id, 'group_membership_for_user');
         }
     }
     //if ( $got_blogrole = scoper_get_var("SELECT assignment_id FROM $wpdb->user2role2object_rs WHERE scope = 'blog' AND role_type = 'rs' AND group_id = '$group_id' LIMIT 1") ) {
     scoper_query("DELETE FROM {$wpdb->user2role2object_rs} WHERE scope = 'blog' AND role_type = 'rs' AND group_id = '{$group_id}'");
     scoper_flush_roles_cache(BLOG_SCOPE_RS, ROLE_BASIS_GROUPS);
     if ($any_user_roles) {
         scoper_flush_roles_cache(BLOG_SCOPE_RS, ROLE_BASIS_USER_AND_GROUPS, $group_members);
     }
     //}
     //if ( $got_taxonomyrole = scoper_get_var("SELECT assignment_id FROM $wpdb->user2role2object_rs WHERE scope = 'term' AND role_type = 'rs' AND group_id = '$group_id' LIMIT 1") ) {
     scoper_query("DELETE FROM {$wpdb->user2role2object_rs} WHERE scope = 'term' AND role_type = 'rs' AND group_id = '{$group_id}'");
     scoper_flush_roles_cache(TERM_SCOPE_RS, ROLE_BASIS_GROUPS);
     if ($any_user_roles) {
         scoper_flush_roles_cache(TERM_SCOPE_RS, ROLE_BASIS_USER_AND_GROUPS, $group_members);
     }
     //}
     //if ( $got_objectrole = scoper_get_var("SELECT assignment_id FROM $wpdb->user2role2object_rs WHERE scope = 'object' AND role_type = 'rs' AND group_id = '$group_id' LIMIT 1") ) {
     scoper_query("DELETE FROM {$wpdb->user2role2object_rs} WHERE scope = 'object' AND role_type = 'rs' AND group_id = '{$group_id}'");
     scoper_flush_roles_cache(OBJECT_SCOPE_RS, ROLE_BASIS_GROUPS);
     if ($any_user_roles) {
         scoper_flush_roles_cache(OBJECT_SCOPE_RS, ROLE_BASIS_USER_AND_GROUPS, $group_members);
     }
     //}
     //if ( $got_blogrole || $got_taxonomyrole || $got_objectrole ) {
     scoper_flush_results_cache(ROLE_BASIS_GROUPS);
     if ($any_user_roles) {
         scoper_flush_results_cache(ROLE_BASIS_USER_AND_GROUPS, $group_members);
     }
     //}
     $delete = "DELETE FROM {$wpdb->groups_rs} WHERE {$wpdb->groups_id_col}='{$group_id}'";
     scoper_query($delete);
     $delete = "DELETE FROM {$wpdb->user2group_rs} WHERE {$wpdb->user2group_gid_col}='{$group_id}'";
     scoper_query($delete);
     return true;
 }
 function flush_user_cache($user_ids)
 {
     $user_ids = (array) $user_ids;
     scoper_flush_results_cache(ROLE_BASIS_USER, $user_ids);
     scoper_flush_roles_cache(OBJECT_SCOPE_RS, ROLE_BASIS_USER, $user_ids);
     scoper_flush_roles_cache(TERM_SCOPE_RS, ROLE_BASIS_USER, $user_ids);
     scoper_flush_roles_cache(BLOG_SCOPE_RS, ROLE_BASIS_USER, $user_ids);
 }
 function mnt_delete_term($deprecated_taxonomy, $args, $term_id, $unused_tt_id = '', $taxonomy = '')
 {
     global $wpdb;
     if (!$term_id) {
         return;
     }
     if (!$taxonomy) {
         $taxonomy = $deprecated_taxonomy;
     }
     // could defer role/cache maint to speed potential bulk deletion, but script may be interrupted before admin_footer
     $this->item_deletion_aftermath(TERM_SCOPE_RS, $taxonomy, $term_id);
     delete_option("{$taxonomy}_children_rs");
     scoper_term_cache_flush();
     scoper_flush_roles_cache(TERM_SCOPE_RS, '', '', $taxonomy);
     scoper_flush_cache_flag_once("rs_{$taxonomy}");
 }
function scoper_mnt_save_term($deprecated_taxonomy, $args, $term_id, $unused_tt_id = '', $taxonomy = '')
{
    if (!$taxonomy) {
        $taxonomy = $deprecated_taxonomy;
    }
    static $saved_terms;
    if (!isset($saved_terms)) {
        $saved_terms = array();
    }
    // so this filter doesn't get called by hook AND internally
    if (isset($saved_terms[$taxonomy][$term_id])) {
        return;
    }
    global $scoper;
    // parent settings can affect the auto-assignment of propagating roles/restrictions
    $set_parent = 0;
    if ($col_parent = $scoper->taxonomies->member_property($taxonomy, 'source', 'cols', 'parent')) {
        $tx_src_name = $scoper->taxonomies->member_property($taxonomy, 'source', 'name');
        $set_parent = (int) $scoper->data_sources->get_from_http_post('parent', $tx_src_name);
    }
    if (empty($term_id)) {
        $term_id = (int) $scoper->data_sources->get_from_http_post('id', $tx_src_name);
    }
    $saved_terms[$taxonomy][$term_id] = 1;
    // Determine whether this object is new (first time this RS filter has run for it, though the object may already be inserted into db)
    $last_parent = 0;
    $last_parents = get_option("scoper_last_{$taxonomy}_parents");
    if (!is_array($last_parents)) {
        $last_parents = array();
    }
    if (!isset($last_parents[$term_id])) {
        $is_new_term = true;
        $last_parents = array();
    } else {
        $is_new_term = false;
    }
    if (isset($last_parents[$term_id])) {
        $last_parent = $last_parents[$term_id];
    }
    if ($set_parent != $last_parent && ($set_parent || $last_parent)) {
        $last_parents[$term_id] = $set_parent;
        update_option("scoper_last_{$taxonomy}_parents", $last_parents);
    }
    $roles_customized = false;
    if (!$is_new_term) {
        if ($custom_role_objects = get_option("scoper_custom_{$taxonomy}")) {
            $roles_customized = isset($custom_role_objects[$term_id]);
        }
    }
    // Inherit parent roles / restrictions, but only for new terms,
    // or if a new parent is set and no roles have been manually assigned to this term
    if ($is_new_term || !$roles_customized && $set_parent != $last_parent) {
        // apply default roles for new term
        if ($is_new_term) {
            scoper_inherit_parent_roles($term_id, TERM_SCOPE_RS, $taxonomy, 0);
        } else {
            $args = array('inherited_only' => true, 'clear_propagated' => true);
            ScoperAdminLib::clear_restrictions(TERM_SCOPE_RS, $taxonomy, $term_id, $args);
            ScoperAdminLib::clear_roles(TERM_SCOPE_RS, $taxonomy, $term_id, $args);
        }
        // apply propagating roles,restrictions from specific parent
        if ($set_parent) {
            scoper_inherit_parent_roles($term_id, TERM_SCOPE_RS, $taxonomy, $set_parent);
            scoper_inherit_parent_restrictions($term_id, TERM_SCOPE_RS, $taxonomy, $set_parent);
        }
    }
    // endif new parent selection (or new object)
    scoper_term_cache_flush();
    scoper_flush_roles_cache(TERM_SCOPE_RS, '', '', $taxonomy);
    delete_option("{$taxonomy}_children");
    delete_option("{$taxonomy}_children_rs");
    delete_option("{$taxonomy}_ancestors_rs");
}