_e('Delete Groups'); ?> </h2> <p><?php echo _n('You have specified this group for deletion:', 'You have specified these groups for deletion:', count($groupids), 'pp'); ?> </p> <ul> <?php $go_delete = 0; if (!($agent_type = apply_filters('pp_query_group_type', ''))) { $agent_type = 'pp_group'; } foreach ($groupids as $id) { $id = (int) $id; if ($group = pp_get_group($id, $agent_type)) { echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1s: %2s'), $id, $group->name) . "</li>\n"; $go_delete++; } } ?> </ul> <?php if ($go_delete) { ?> <input type="hidden" name="action" value="dodelete" /> <?php submit_button(__('Confirm Deletion'), 'secondary'); } else { ?> <p><?php
public static function delete_group($group_id, $agent_type = 'pp_group') { global $wpdb; if (!$group_id || !pp_get_group($group_id, $agent_type)) { return false; } $groups_table = apply_filters('pp_use_groups_table', $wpdb->pp_groups, $agent_type); $members_table = apply_filters('pp_use_group_members_table', $wpdb->pp_group_members, $agent_type); do_action('pp_delete_group', $group_id, $agent_type); $wpdb->delete($wpdb->ppc_roles, array('agent_type' => $agent_type, 'agent_id' => $group_id)); $wpdb->delete($groups_table, array('ID' => $group_id)); $wpdb->delete($members_table, compact('group_id')); do_action('pp_deleted_group', $group_id, $agent_type); return true; }
/** * Edit group settings based on contents of $_POST * * @param int $group_id Optional. Group ID. * @return int group id of the updated group */ function _pp_edit_group($group_id = 0, $agent_type = 'pp_group', $members_only = false) { global $wpdb; if ($group_id) { $update = true; $group = pp_get_group($group_id, $agent_type); } else { $update = false; $group = (object) array(); } if (!$members_only) { if (isset($_REQUEST['group_name'])) { $group->group_name = sanitize_text_field($_REQUEST['group_name']); } if (isset($_REQUEST['description'])) { $group->group_description = sanitize_text_field($_REQUEST['description']); } $errors = new WP_Error(); /* checking that username has been typed */ if (!$group->group_name) { $errors->add('group_name', __('<strong>ERROR</strong>: Please enter a group name.', 'pp')); } elseif (!$update && !PP_GroupsUpdate::group_name_available($group->group_name, $agent_type)) { $errors->add('user_login', __('<strong>ERROR</strong>: This group name is already registered. Please choose another one.', 'pp')); } // Allow plugins to return their own errors. do_action_ref_array('pp_group_profile_update_errors', array(&$errors, $update, &$group)); if ($errors->get_error_codes()) { return $errors; } if ($update) { PP_GroupsUpdate::update_group($group_id, $group, $agent_type); } else { $group_id = PP_GroupsUpdate::create_group($group, $agent_type); } } if ($group_id) { $member_types = array(); if (pp_has_group_cap('pp_manage_members', $group_id, $agent_type)) { $member_types[] = 'member'; } foreach ($member_types as $member_type) { if (isset($_REQUEST["{$member_type}_csv"]) && $_REQUEST["{$member_type}_csv"] != -1) { // handle member changes $current = pp_get_group_members($group_id, $agent_type, 'id', compact('member_type')); $selected = isset($_REQUEST["{$member_type}_csv"]) ? explode(",", pp_sanitize_csv($_REQUEST["{$member_type}_csv"])) : array(); if ('member' != $member_type || !apply_filters('pp_custom_agent_update', false, $agent_type, $group_id, $selected)) { if ($add_users = array_diff($selected, $current)) { pp_add_group_user($group_id, $add_users, compact('agent_type', 'member_type')); } if ($remove_users = array_diff($current, $selected)) { pp_remove_group_user($group_id, $remove_users, compact('agent_type', 'member_type')); } } } } // end foreach member_types do_action('pp_edited_group', $agent_type, $group_id, $update); } return $group_id; }
} if (count($ops) > 1) { $html .= "<option class='pp-opt-none' value=''>" . __('select...', 'pp') . "</option>"; } foreach ($ops as $val => $title) { $html .= "<option value='{$val}'>{$title}</option>"; } break; case 'get_mod_options': if (!is_user_logged_in()) { echo '<option>' . __('(login timed out)', 'pp') . '</option>'; exit; } // TODO: deal with login timeout in JS to avoid multiple messages if ($agent_id && 'pp_group' == $agent_type) { $group = pp_get_group($agent_id); $is_wp_role = 'wp_role' == $group->metagroup_type; } else { $is_wp_role = false; } if (!$is_wp_role || !in_array($group->metagroup_id, array('wp_anon', 'wp_all')) || defined('PP_ALL_ANON_FULL_EXCEPTIONS')) { $modes['additional'] = __('Also these:', 'pp'); } if ('user' == $agent_type || $is_wp_role || 'assign' == $operation || defined('PP_GROUP_RESTRICTIONS')) { $modes['exclude'] = __('Not these:', 'pp'); } $modes['include'] = __('Only these:', 'pp'); $modes = apply_filters('pp_exception_modes', $modes, $for_src_name, $for_type, $operation); foreach ($modes as $val => $title) { $html .= "<option value='{$val}'>{$title}</option>"; }
public static function clone_permissions($agent_type, $agent_id, $source_agent) { global $wpdb, $current_user; if ('pp_group' != $agent_type) { return false; } $current_user_id = $current_user->ID; $agent_id = (int) $agent_id; $agent = pp_get_group($agent_id); if (is_string($source_agent)) { $source_agent = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->pp_groups} WHERE metagroup_type = 'wp_role' AND metagroup_id = %s", $source_agent)); } else { $source_agent = pp_get_group($source_agent); } if (!$source_agent || $source_agent->metagroup_type != 'wp_role') { return false; } $source_agent_id = $source_agent->ID; // =========== Roles Import ============= $exc_query = "SELECT role_name FROM {$wpdb->ppc_roles} WHERE agent_type = %s AND agent_id = %d"; $target_roles = $wpdb->get_col($wpdb->prepare($exc_query, $agent_type, $agent_id)); $source_roles = $wpdb->get_col($wpdb->prepare($exc_query, $agent_type, $source_agent_id)); foreach ($source_roles as $role_name) { $wpdb->insert_id = 0; $sql = "INSERT INTO {$wpdb->ppc_roles} (agent_id, agent_type, role_name, assigner_id) SELECT * FROM ( SELECT '{$agent_id}' AS a, '{$agent_type}' AS b, '{$role_name}' AS c, '{$current_user_id}' AS d ) AS tmp WHERE NOT EXISTS (SELECT 1 FROM {$wpdb->ppc_roles} WHERE agent_type = '{$agent_type}' AND agent_id = '{$agent_id}' AND role_name = '{$role_name}') LIMIT 1"; $wpdb->query($sql); //if ( $wpdb->insert_id ) { //$assignment_id = (int) $wpdb->insert_id; //} } // =========== Exceptions Import =========== $old_inherited_from = array(); $log_eitem_ids = array(); $target_agent_data = compact('agent_type', 'agent_id'); $exc_query = "SELECT exception_id, for_item_source, for_item_type, for_item_status, operation, mod_type, via_item_source, via_item_type FROM {$wpdb->ppc_exceptions} WHERE agent_type = %s AND agent_id = %d"; $target_exceptions = $wpdb->get_results($wpdb->prepare($exc_query, $agent_type, $agent_id), OBJECT_K); $source_exceptions = $wpdb->get_results($wpdb->prepare($exc_query, $agent_type, $source_agent_id), OBJECT_K); $source_eitems = $wpdb->get_results("SELECT eitem_id, exception_id, item_id, assign_for, inherited_from FROM {$wpdb->ppc_exception_items} WHERE exception_id IN ('" . implode("','", array_keys($source_exceptions)) . "')"); foreach ($source_eitems as $row) { $target_exception_data = (array) $source_exceptions[$row->exception_id]; unset($target_exception_data['exception_id']); $target_exception_id = self::get_exception_id($target_exceptions, $target_exception_data, $target_agent_data); $wpdb->insert_id = 0; $sql = "INSERT INTO {$wpdb->ppc_exception_items} (assign_for, exception_id, assigner_id, item_id) SELECT * FROM ( SELECT '{$row->assign_for}' AS a, '{$target_exception_id}' AS b, '{$current_user_id}' AS c, '{$row->item_id}' AS d ) AS tmp WHERE NOT EXISTS (SELECT 1 FROM {$wpdb->ppc_exception_items} WHERE assign_for = '{$row->assign_for}' AND exception_id = '{$target_exception_id}' AND item_id = '{$row->item_id}') LIMIT 1"; $wpdb->query($sql); if ($wpdb->insert_id) { $target_eitem_id = (int) $wpdb->insert_id; $log_eitem_ids[$row->eitem_id] = $target_eitem_id; if ($row->inherited_from) { $old_inherited_from[$target_eitem_id] = $row->inherited_from; } } } // convert inherited_from values from source to target exception items foreach ($old_inherited_from as $target_eitem_id => $source_inherited_from) { if (isset($log_eitem_ids[$source_inherited_from])) { $data = array('inherited_from' => $log_eitem_ids[$source_inherited_from]); $where = array('eitem_id' => $target_eitem_id); $wpdb->update($wpdb->ppc_exception_items, $data, $where); } } return true; }
public static function handle_request() { global $pp_admin; $url = $referer = $redirect = $update = ''; PP_Permits_Helper::get_url_properties($url, $referer, $redirect); if (!($agent_type = apply_filters('pp_query_group_type', ''))) { $agent_type = 'pp_group'; } if (!empty($_REQUEST['action2']) && !is_numeric($_REQUEST['action2'])) { $action = $_REQUEST['action2']; } elseif (!empty($_REQUEST['action']) && !is_numeric($_REQUEST['action'])) { $action = $_REQUEST['action']; } elseif (!empty($_REQUEST['pp_action'])) { $action = $_REQUEST['pp_action']; } else { $action = ''; } switch ($action) { case 'dodelete': check_admin_referer('delete-groups'); if (!current_user_can('pp_delete_groups')) { wp_die(__('You are not permitted to do that.', 'pp')); } if (empty($_REQUEST['groups']) && empty($_REQUEST['group'])) { wp_redirect($redirect); exit; } if (empty($_REQUEST['groups'])) { $groupids = array(intval($_REQUEST['group'])); } else { $groupids = (array) $_REQUEST['groups']; } $update = 'del'; $delete_ids = array(); foreach ((array) $groupids as $id) { $id = (int) $id; if ($group_obj = pp_get_group($id, $agent_type)) { if (!empty($group->obj->metagroup_id)) { continue; } } //if ( ! current_user_can( 'pp_delete_groups', $id ) ) // continue; pp_delete_group($id, $agent_type); $delete_ids[] = $id; } if (!$delete_ids) { wp_die(__('You can’t delete that group.', 'pp')); } $redirect = add_query_arg(array('delete_count' => count($delete_ids), 'update' => $update), $redirect); wp_redirect($redirect); exit; break; case 'delete': check_admin_referer('bulk-groups'); if (!current_user_can('pp_delete_groups')) { wp_die(__('You are not permitted to do that.', 'pp')); } if (!empty($_REQUEST['groups'])) { $redirect = esc_url_raw(add_query_arg(array('pp_action' => 'bulkdelete', 'agent_type' => $agent_type, 'wp_http_referer' => isset($_REQUEST['wp_http_referer']) ? $_REQUEST['wp_http_referer'] : '', 'groups' => $_REQUEST['groups']), $redirect)); wp_redirect($redirect); exit; } if (empty($_REQUEST['group'])) { // && empty($_REQUEST['user']) ) { wp_redirect($redirect); exit; } break; default: } // end switch }
public static function _draw_group_permissions($agent_id, $agent_type, $url, $wp_http_referer = '', $args = array()) { global $current_user; //$defaults = array( 'agent' => (object) array() ); $post_types = _pp_order_types(pp_get_enabled_post_types(array(), 'object')); $taxonomies = _pp_order_types(pp_get_enabled_taxonomies(array('object_type' => false), 'object')); //$taxonomies ['link_category'] = (object) array( 'name' => 'link_category', 'labels' => (object) array( 'name' => __ppw('Link Categories'), 'singular_name' => __ppw('Link Categories') ) ); $perms = array(); if ('pp_group' == $agent_type && ($group = pp_get_group($agent_id))) { $is_wp_role = 'wp_role' == $group->metagroup_type; } if (empty($group) || !in_array($group->metagroup_id, array('wp_anon', 'wp_all')) || defined('PP_ALL_ANON_ROLES')) { $perms['roles'] = __('Add Supplemental Roles', 'pp'); } $perms['exceptions'] = __('Add Exceptions', 'pp'); if (!isset($perms['roles'])) { $current_tab = 'pp-add-exceptions'; } elseif (!isset($perms['roles'])) { $current_tab = 'pp-add-roles'; } elseif (!($current_tab = get_user_option('pp-permissions-tab'))) { $current_tab = isset($perms['roles']) ? 'pp-add-roles' : 'pp-add-exceptions'; } if ($args['agent']->metagroup_type == 'wp_role' && !in_array($args['agent']->metagroup_id, array('wp_anon', 'wp_all'))) { $perms['clone'] = __('Clone', 'pp'); } // --- add permission tabs --- echo "<ul id='pp_add_permission_tabs' class='pp-list_horiz' style='margin-bottom:-3px'>"; foreach ($perms as $perm_type => $_caption) { $class = "pp-add-{$perm_type}" == $current_tab ? 'agp-selected_agent' : 'agp-unselected_agent'; echo "<li class='agp-agent pp-add-{$perm_type} pp-add-permissions {$class}'><a class='pp-add-{$perm_type}' href='javascript:void(0)'>" . $_caption . '</a></li>'; } echo '</ul>'; // --- divs for add Roles / Exceptions --- $arr = array_keys($perms); $first_perm_type = reset($arr); foreach (array_keys($perms) as $perm_type) { $display_style = "pp-add-{$perm_type}" == $current_tab ? '' : ';display:none'; echo "<div class='pp-group-box pp-add-permissions pp-add-{$perm_type}' style='clear:both{$display_style}'>"; echo '<div>'; if ('roles' == $perm_type) { // temp workaround for bbPress self::_select_roles_ui(array_diff_key($post_types, array_fill_keys(array('topic', 'reply'), true)), $taxonomies); } elseif ('exceptions' == $perm_type) { if (!isset($args['external'])) { $args['external'] = array(); } self::_select_exceptions_ui(array_diff_key($post_types, array_fill_keys(array('topic', 'reply'), true)), $taxonomies, $args); } ?> <form id="group-<?php echo $perm_type; ?> -selections" action="<?php echo esc_url($url); ?> " method="post"<?php do_action('pp_group_edit_form_tag'); ?> > <?php wp_nonce_field("pp-update-{$perm_type}_" . $agent_id, "_pp_nonce_{$perm_type}"); ?> <?php if ('clone' == $perm_type) { self::_select_clone_ui($args['agent']); } ?> <?php if ($wp_http_referer) { ?> <input type="hidden" name="wp_http_referer" value="<?php echo esc_url($wp_http_referer); ?> " /> <?php } ?> <input type="hidden" name="action" value="pp_update<?php echo $perm_type; ?> " /> <input type="hidden" name="agent_id" value="<?php echo esc_attr($agent_id); ?> " /> <input type="hidden" name="agent_type" value="<?php echo esc_attr($agent_type); ?> " /> <input type="hidden" name="member_csv" value="-1" /> <input type="hidden" name="group_name" value="-1" /> <input type="hidden" name="description" value="-1" /> <?php if ('roles' == $perm_type) { self::_selected_roles_ui(); } elseif ('exceptions' == $perm_type) { self::_selected_exceptions_ui(); } ?> </form> <?php echo '</div></div>'; } // end foreach perm_type (roles, exceptions) $args['agent_type'] = $agent_type; $roles = ppc_get_roles($agent_type, $agent_id, compact($post_types, $taxonomies)); $args['class'] = 'user' == $agent_type ? 'pp-user-roles' : 'pp-group-roles'; $args['agent_type'] = $agent_type; self::_current_roles_ui($roles, $args); $post_types[''] = ''; // also retrieve exceptions for (all) post type $_args = array('assign_for' => '', 'extra_cols' => array('i.assign_for', 'i.eitem_id'), 'agent_type' => $agent_type, 'agent_id' => $agent_id, 'post_types' => array_keys($post_types), 'taxonomies' => array_keys($taxonomies), 'return_raw_results' => true); if (empty($_REQUEST['show_propagated'])) { $_args['inherited_from'] = 0; } else { $_args['extra_cols'][] = 'i.inherited_from'; } $exc = ppc_get_exceptions($_args); $args['class'] = 'user' == $agent_type ? 'pp-user-roles' : 'pp-group-roles'; self::_current_exceptions_ui($exc, $args); do_action('pp_group_roles_ui', $agent_type, $agent_id); }