function prepare_items() { global $groupsearch; $groupsearch = isset($_REQUEST['s']) ? sanitize_text_field($_REQUEST['s']) : ''; $groups_per_page = $this->get_items_per_page('groups_per_page'); $paged = $this->get_pagenum(); $args = array('number' => $groups_per_page, 'offset' => ($paged - 1) * $groups_per_page, 'search' => $groupsearch); $args['search'] = '*' . $args['search'] . '*'; if (isset($_REQUEST['orderby'])) { $args['orderby'] = pp_sanitize_word($_REQUEST['orderby']); } if (isset($_REQUEST['order'])) { $args['order'] = pp_sanitize_word($_REQUEST['order']); } // Query the user IDs for this page $args['agent_type'] = $this->agent_type; $pp_group_search = new PP_Group_Query($args); $this->items = $pp_group_search->get_results(); $this->listed_ids = array(); foreach ($this->items as $group) { $this->listed_ids[] = $group->ID; } $this->role_info = ppc_count_assigned_roles($this->agent_type, array('query_agent_ids' => $this->listed_ids)); $this->exception_info = ppc_count_assigned_exceptions($this->agent_type, array('query_agent_ids' => $this->listed_ids)); $this->set_pagination_args(array('total_items' => $pp_group_search->get_total(), 'per_page' => $groups_per_page)); }
function _ppc_list_agent_exceptions($agent_type, $id, $args = array()) { global $wp_list_table; static $exception_info; $defaults = array('query_agent_ids' => array(), 'show_link' => true, 'join_groups' => true, 'force_refresh' => false, 'display_limit' => 3); $args = array_merge($defaults, $args); extract($args, EXTR_SKIP); if (empty($args['query_agent_ids'])) { $args['query_agent_ids'] = (array) $id; } if (!isset($exception_info) || $force_refresh) { $exception_info = ppc_count_assigned_exceptions($agent_type, $args); } $exc_str = ''; if (isset($exception_info[$id])) { if (isset($exception_info[$id]['exceptions'])) { $exc_titles = array(); $i = 0; foreach ($exception_info[$id]['exceptions'] as $exc_title => $exc_count) { $i++; $exc_titles[] = sprintf(__('%1$s (%2$s)', 'pp'), $exc_title, $exc_count); if ($i >= $display_limit) { break; } } $exc_str = '<span class="pp-group-site-roles">' . implode(', ', $exc_titles) . '</span>'; if (count($exception_info[$id]['exceptions']) > $display_limit) { $exc_str = sprintf(__('%s, more...', 'pp'), $exc_str); } if ($show_link && current_user_can('edit_user', $id) && current_user_can('pp_assign_roles')) { $edit_link = "admin.php?page=pp-edit-permissions&action=edit&agent_id={$id}&agent_type=user"; $exc_str = "<a href=\"{$edit_link}\">{$exc_str}</a><br />"; } } } return $exc_str; }