/** * Handle add group form submission. * @return int new group's id or false if unsuccessful */ function groups_admin_groups_add_submit() { global $wpdb; if (!current_user_can(GROUPS_ADMINISTER_GROUPS)) { wp_die(__('Access denied.', GROUPS_PLUGIN_DOMAIN)); } if (!wp_verify_nonce($_POST[GROUPS_ADMIN_GROUPS_NONCE], 'groups-add')) { wp_die(__('Access denied.', GROUPS_PLUGIN_DOMAIN)); } $creator_id = get_current_user_id(); $datetime = date('Y-m-d H:i:s', time()); $parent_id = isset($_POST['parent-id-field']) ? $_POST['parent-id-field'] : null; $description = isset($_POST['description-field']) ? $_POST['description-field'] : ''; $name = isset($_POST['name-field']) ? $_POST['name-field'] : null; $group_id = Groups_Group::create(compact("creator_id", "datetime", "parent_id", "description", "name")); if ($group_id) { if (!empty($_POST['capability_ids'])) { $caps = $_POST['capability_ids']; foreach ($caps as $cap) { Groups_Group_Capability::create(array('group_id' => $group_id, 'capability_id' => $cap)); } } do_action('groups_admin_groups_add_submit_success', $group_id); } else { if (!$name) { Groups_Admin::add_message(__('The name must not be empty.', GROUPS_PLUGIN_DOMAIN), 'error'); } else { if (Groups_Group::read_by_name($name)) { Groups_Admin::add_message(sprintf(__('The <em>%s</em> group already exists.', GROUPS_PLUGIN_DOMAIN), stripslashes(wp_filter_nohtml_kses($name))), 'error'); } } } return $group_id; }
return $result; } /** * Remove group-capability relation. * * @param int $group_id * @param int $capability_id * @return true if successful, false otherwise */ public static function delete($group_id, $capability_id) { global $wpdb; $result = false; // avoid nonsense requests if (!empty($group_id) && !empty($capability_id)) { // we can omit checking if the group and capability exist, to // allow resolving the relationship after they have been deleted $group_capability_table = _groups_get_tablename('group_capability'); // get rid of it $rows = $wpdb->query($wpdb->prepare("DELETE FROM {$group_capability_table} WHERE group_id = %d AND capability_id = %d", Groups_Utility::id($group_id), Groups_Utility::id($capability_id))); // must have affected a row, otherwise no great success $result = $rows !== false && $rows > 0; if ($result) { do_action("groups_deleted_group_capability", $group_id, $capability_id); } } return $result; } } Groups_Group_Capability::init();
/** * (non-PHPdoc) * @see I_Capable::can() */ public function can($capability) { global $wpdb; $result = false; if ($this->group !== null) { $group_table = _groups_get_tablename("group"); $capability_table = _groups_get_tablename("capability"); $group_capability_table = _groups_get_tablename("group_capability"); // determine capability id $capability_id = null; if (is_numeric($capability)) { $capability_id = Groups_Utility::id($capability); } else { if (is_string($capability)) { $capability_id = $wpdb->get_var($wpdb->prepare("SELECT capability_id FROM {$capability_table} WHERE capability = %s", $capability)); } } if ($capability_id !== null) { // check if the group itself can $result = Groups_Group_Capability::read($this->group->group_id, $capability_id) !== false; if (!$result) { // find all parent groups and include in the group's // upward hierarchy to see if any of these can $group_ids = array($this->group->group_id); $iterations = 0; $old_group_ids_count = 0; $all_groups = $wpdb->get_var("SELECT COUNT(*) FROM {$group_table}"); while ($iterations < $all_groups && count($group_ids) !== $old_group_ids_count) { $iterations++; $old_group_ids_count = count($group_ids); $id_list = implode(",", $group_ids); $parent_group_ids = $wpdb->get_results("SELECT parent_id FROM {$group_table} WHERE parent_id IS NOT NULL AND group_id IN ({$id_list})"); if ($parent_group_ids) { foreach ($parent_group_ids as $parent_group_id) { $parent_group_id = Groups_Utility::id($parent_group_id->parent_id); if (!in_array($parent_group_id, $group_ids)) { $group_ids[] = $parent_group_id; } } } } if (count($group_ids) > 0) { $id_list = implode(",", $group_ids); $rows = $wpdb->get_results($wpdb->prepare("SELECT capability_id FROM {$group_capability_table} WHERE capability_id = %d AND group_id IN ({$id_list})", Groups_Utility::id($capability_id))); if (count($rows) > 0) { $result = true; } } } } } $result = apply_filters_ref_array("groups_group_can", array($result, &$this, $capability)); return $result; }
/** * Handle edit form submission. */ function groups_admin_groups_edit_submit() { global $wpdb; if (!current_user_can(GROUPS_ADMINISTER_GROUPS)) { wp_die(__('Access denied.', GROUPS_PLUGIN_DOMAIN)); } if (!wp_verify_nonce($_POST[GROUPS_ADMIN_GROUPS_NONCE], 'groups-edit')) { wp_die(__('Access denied.', GROUPS_PLUGIN_DOMAIN)); } $group_id = isset($_POST['group-id-field']) ? $_POST['group-id-field'] : null; $group = Groups_Group::read($group_id); if ($group) { $group_id = $group->group_id; if ($group->name !== Groups_Registered::REGISTERED_GROUP_NAME) { $name = isset($_POST['name-field']) ? $_POST['name-field'] : null; } else { $name = Groups_Registered::REGISTERED_GROUP_NAME; } $parent_id = isset($_POST['parent-id-field']) ? $_POST['parent-id-field'] : null; $description = isset($_POST['description-field']) ? $_POST['description-field'] : ''; if (empty($name)) { Groups_Admin::add_message(__('The <em>Name</em> must not be empty.', GROUPS_PLUGIN_DOMAIN), 'error'); return false; } if ($other_group = Groups_Group::read_by_name($name)) { if ($other_group->group_id != $group_id) { Groups_Admin::add_message(sprintf(__('The <em>%s</em> group already exists and cannot be used to name this one.', GROUPS_PLUGIN_DOMAIN), stripslashes(wp_filter_nohtml_kses($other_group->name))), 'error'); return false; } } $group_id = Groups_Group::update(compact("group_id", "name", "parent_id", "description")); if ($group_id) { $capability_table = _groups_get_tablename("capability"); $group_capability_table = _groups_get_tablename("group_capability"); $group_capabilities = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$capability_table} WHERE capability_id IN ( SELECT capability_id FROM {$group_capability_table} WHERE group_id = %d )", Groups_Utility::id($group_id))); $group_capabilities_array = array(); foreach ($group_capabilities as $group_capability) { $group_capabilities_array[] = $group_capability->capability_id; } $caps = array(); if (isset($_POST['capability_ids'])) { $caps = $_POST['capability_ids']; } // delete foreach ($group_capabilities_array as $group_cap) { if (!in_array($group_cap, $caps)) { Groups_Group_Capability::delete($group_id, $group_cap); } } // add foreach ($caps as $cap) { if (!in_array($cap, $group_capabilities_array)) { Groups_Group_Capability::create(array('group_id' => $group_id, 'capability_id' => $cap)); } } } return $group_id; } else { return false; } }
/** * Save capability options. * * @param int $post_id * @param mixed $post post data (not used here) */ public static function save_post($post_id = null, $post = null) { if (defined("DOING_AUTOSAVE") && DOING_AUTOSAVE) { } else { $post_type = get_post_type($post_id); $post_type_object = get_post_type_object($post_type); if ($post_type_object && $post_type != 'attachment') { $post_types_option = Groups_Options::get_option(Groups_Post_Access::POST_TYPES, array()); if (!isset($post_types_option[$post_type]['add_meta_box']) || $post_types_option[$post_type]['add_meta_box']) { if (isset($_POST[self::NONCE]) && wp_verify_nonce($_POST[self::NONCE], self::SET_CAPABILITY)) { $post_type = isset($_POST["post_type"]) ? $_POST["post_type"] : null; if ($post_type !== null) { // See http://codex.wordpress.org/Function_Reference/current_user_can 20130119 WP 3.5 // "... Some capability checks (like 'edit_post' or 'delete_page') require this [the post ID] be provided." // If the post ID is not provided, it will throw: // PHP Notice: Undefined offset: 0 in /var/www/groups-forums/wp-includes/capabilities.php on line 1067 $edit_post_type = 'edit_' . $post_type; if ($post_type_object = get_post_type_object($post_type)) { if (!isset($post_type_object->capabilities)) { // get_post_type_capabilities() (WP 3.8) will throw a warning // when trying to merge the missing property otherwise. It's either a // bug or the function's documentation should make it clear that you // have to provide that. $post_type_object->capabilities = array(); } $caps_object = get_post_type_capabilities($post_type_object); if (isset($caps_object->edit_post)) { $edit_post_type = $caps_object->edit_post; } } if (current_user_can($edit_post_type, $post_id)) { // quick-create ? if (current_user_can(GROUPS_ADMINISTER_GROUPS)) { if (!empty($_POST['quick-group-capability'])) { $creator_id = get_current_user_id(); $datetime = date('Y-m-d H:i:s', time()); $name = ucfirst(strtolower(trim($_POST['quick-group-capability']))); if (strlen($name) > 0) { // create or obtain the group if ($group = Groups_Group::read_by_name($name)) { } else { if ($group_id = Groups_Group::create(compact('creator_id', 'datetime', 'name'))) { $group = Groups_Group::read($group_id); } } // create or obtain the capability $name = strtolower($name); if ($capability = Groups_Capability::read_by_capability($name)) { } else { if ($capability_id = Groups_Capability::create(array('capability' => $name))) { $capability = Groups_Capability::read($capability_id); } } if ($group && $capability) { // add the capability to the group if (!Groups_Group_Capability::read($group->group_id, $capability->capability_id)) { Groups_Group_Capability::create(array('group_id' => $group->group_id, 'capability_id' => $capability->capability_id)); } // enable the capability for access restriction $valid_read_caps = Groups_Options::get_option(Groups_Post_Access::READ_POST_CAPABILITIES, array(Groups_Post_Access::READ_POST_CAPABILITY)); if (!in_array($capability->capability, $valid_read_caps)) { $valid_read_caps[] = $capability->capability; } Groups_Options::update_option(Groups_Post_Access::READ_POST_CAPABILITIES, $valid_read_caps); // add the current user to the group Groups_User_Group::create(array('user_id' => get_current_user_id(), 'group_id' => $group->group_id)); // put the capability ID in $_POST[self::CAPABILITY] so it is treated below if (empty($_POST[self::CAPABILITY])) { $_POST[self::CAPABILITY] = array(); } if (!in_array($capability->capability_id, $_POST[self::CAPABILITY])) { $_POST[self::CAPABILITY][] = $capability->capability_id; } } } } } // set if (self::user_can_restrict()) { $valid_read_caps = self::get_valid_read_caps_for_user(); foreach ($valid_read_caps as $valid_read_cap) { if ($capability = Groups_Capability::read_by_capability($valid_read_cap)) { if (!empty($_POST[self::CAPABILITY]) && is_array($_POST[self::CAPABILITY]) && in_array($capability->capability_id, $_POST[self::CAPABILITY])) { Groups_Post_Access::create(array('post_id' => $post_id, 'capability' => $capability->capability)); } else { Groups_Post_Access::delete($post_id, $capability->capability); } } } } // show groups Groups_Options::update_user_option(self::SHOW_GROUPS, !empty($_POST[self::SHOW_GROUPS])); } } } } } } }
/** * Manage Groups: table of groups and add, edit, remove actions. */ function groups_admin_groups() { global $wpdb; $output = ''; $today = date('Y-m-d', time()); if (!current_user_can(GROUPS_ADMINISTER_GROUPS)) { wp_die(__('Access denied.', GROUPS_PLUGIN_DOMAIN)); } // // handle actions // if (isset($_POST['action'])) { // handle action submit - do it switch ($_POST['action']) { case 'add': if (!($group_id = groups_admin_groups_add_submit())) { return groups_admin_groups_add(); } else { $group = Groups_Group::read($group_id); Groups_Admin::add_message(sprintf(__("The <em>%s</em> group has been created.", GROUPS_PLUGIN_DOMAIN), stripslashes(wp_filter_nohtml_kses($group->name)))); } break; case 'edit': if (!($group_id = groups_admin_groups_edit_submit())) { return groups_admin_groups_edit($_POST['group-id-field']); } else { $group = Groups_Group::read($group_id); Groups_Admin::add_message(sprintf(__('The <em>%s</em> group has been updated.', GROUPS_PLUGIN_DOMAIN), stripslashes(wp_filter_nohtml_kses($group->name)))); } break; case 'remove': if ($group_id = groups_admin_groups_remove_submit()) { Groups_Admin::add_message(__('The group has been deleted.', GROUPS_PLUGIN_DOMAIN)); } break; // bulk actions on groups: add capabilities, remove capabilities, remove groups // bulk actions on groups: add capabilities, remove capabilities, remove groups case 'groups-action': if (wp_verify_nonce($_POST[GROUPS_ADMIN_GROUPS_ACTION_NONCE], 'admin')) { $group_ids = isset($_POST['group_ids']) ? $_POST['group_ids'] : null; $bulk_action = null; if (isset($_POST['bulk'])) { $bulk_action = $_POST['bulk-action']; } if (is_array($group_ids) && $bulk_action !== null) { foreach ($group_ids as $group_id) { switch ($bulk_action) { case 'add-capability': $capabilities_id = isset($_POST['capability_id']) ? $_POST['capability_id'] : null; if ($capabilities_id !== null) { foreach ($capabilities_id as $capability_id) { Groups_Group_Capability::create(array('group_id' => $group_id, 'capability_id' => $capability_id)); } } break; case 'remove-capability': $capabilities_id = isset($_POST['capability_id']) ? $_POST['capability_id'] : null; if ($capabilities_id !== null) { foreach ($capabilities_id as $capability_id) { Groups_Group_Capability::delete($group_id, $capability_id); } } break; case 'remove-group': $bulk_confirm = isset($_POST['confirm']) ? true : false; if ($bulk_confirm) { groups_admin_groups_bulk_remove_submit(); } else { return groups_admin_groups_bulk_remove(); } break; } } } } break; } } else { if (isset($_GET['action'])) { // handle action request - show form switch ($_GET['action']) { case 'add': return groups_admin_groups_add(); break; case 'edit': if (isset($_GET['group_id'])) { return groups_admin_groups_edit($_GET['group_id']); } break; case 'remove': if (isset($_GET['group_id'])) { return groups_admin_groups_remove($_GET['group_id']); } break; } } } // // group table // if (isset($_POST['clear_filters']) || isset($_POST['group_id']) || isset($_POST['group_name'])) { if (!wp_verify_nonce($_POST[GROUPS_ADMIN_GROUPS_FILTER_NONCE], 'admin')) { wp_die(__('Access denied.', GROUPS_PLUGIN_DOMAIN)); } } // filters $group_id = Groups_Options::get_user_option('groups_group_id', null); $group_name = Groups_Options::get_user_option('groups_group_name', null); if (isset($_POST['clear_filters'])) { Groups_Options::delete_user_option('groups_group_id'); Groups_Options::delete_user_option('groups_group_name'); $group_id = null; $group_name = null; } else { if (isset($_POST['submitted'])) { // filter by name if (!empty($_POST['group_name'])) { $group_name = $_POST['group_name']; Groups_Options::update_user_option('groups_group_name', $group_name); } // filter by group id if (!empty($_POST['group_id'])) { $group_id = intval($_POST['group_id']); Groups_Options::update_user_option('groups_group_id', $group_id); } else { if (isset($_POST['group_id'])) { // empty && isset => '' => all $group_id = null; Groups_Options::delete_user_option('groups_group_id'); } } } } if (isset($_POST['row_count'])) { if (!wp_verify_nonce($_POST[GROUPS_ADMIN_GROUPS_NONCE_1], 'admin')) { wp_die(__('Access denied.', GROUPS_PLUGIN_DOMAIN)); } } if (isset($_POST['paged'])) { if (!wp_verify_nonce($_POST[GROUPS_ADMIN_GROUPS_NONCE_2], 'admin')) { wp_die(__('Access denied.', GROUPS_PLUGIN_DOMAIN)); } } $current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $current_url = remove_query_arg('paged', $current_url); $current_url = remove_query_arg('action', $current_url); $current_url = remove_query_arg('group_id', $current_url); $group_table = _groups_get_tablename('group'); $output .= '<div class="manage-groups">' . '<div>' . '<h2>' . _x('Groups', 'page-title', GROUPS_PLUGIN_DOMAIN) . '</h2>' . '</div>'; $output .= Groups_Admin::render_messages(); $output .= '<div class="manage">' . "<a title='" . __('Click to add a new group', GROUPS_PLUGIN_DOMAIN) . "' class='add button' href='" . esc_url($current_url) . "&action=add'><img class='icon' alt='" . __('Add', GROUPS_PLUGIN_DOMAIN) . "' src='" . GROUPS_PLUGIN_URL . "images/add.png'/><span class='label'>" . __('New Group', GROUPS_PLUGIN_DOMAIN) . "</span></a>" . '</div>'; $row_count = isset($_POST['row_count']) ? intval($_POST['row_count']) : 0; if ($row_count <= 0) { $row_count = Groups_Options::get_user_option('groups_per_page', GROUPS_GROUPS_PER_PAGE); } else { Groups_Options::update_user_option('groups_per_page', $row_count); } $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; if ($offset < 0) { $offset = 0; } $paged = isset($_REQUEST['paged']) ? intval($_REQUEST['paged']) : 0; if ($paged < 0) { $paged = 0; } $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : null; switch ($orderby) { case 'group_id': case 'name': break; default: $orderby = 'name'; } $order = isset($_GET['order']) ? $_GET['order'] : null; switch ($order) { case 'asc': case 'ASC': $switch_order = 'DESC'; break; case 'desc': case 'DESC': $switch_order = 'ASC'; break; default: $order = 'ASC'; $switch_order = 'DESC'; } $filters = array(" 1=%d "); $filter_params = array(1); if ($group_id) { $filters[] = " {$group_table}.group_id = %d "; $filter_params[] = $group_id; } if ($group_name) { $filters[] = " {$group_table}.name LIKE '%%%s%%' "; $filter_params[] = $group_name; } if (!empty($filters)) { $filters = " WHERE " . implode(" AND ", $filters); } else { $filters = ''; } $count_query = $wpdb->prepare("SELECT COUNT(*) FROM {$group_table} {$filters}", $filter_params); $count = $wpdb->get_var($count_query); if ($count > $row_count) { $paginate = true; } else { $paginate = false; } $pages = ceil($count / $row_count); if ($paged > $pages) { $paged = $pages; } if ($paged != 0) { $offset = ($paged - 1) * $row_count; } $query = $wpdb->prepare("SELECT * FROM {$group_table}\n\t\t{$filters}\n\t\tORDER BY {$orderby} {$order}\n\t\tLIMIT {$row_count} OFFSET {$offset}", $filter_params); $results = $wpdb->get_results($query, OBJECT); $column_display_names = array('group_id' => __('Id', GROUPS_PLUGIN_DOMAIN), 'name' => __('Group', GROUPS_PLUGIN_DOMAIN), 'description' => __('Description', GROUPS_PLUGIN_DOMAIN), 'capabilities' => __('Capabilities', GROUPS_PLUGIN_DOMAIN), 'edit' => __('Edit', GROUPS_PLUGIN_DOMAIN), 'remove' => __('Remove', GROUPS_PLUGIN_DOMAIN)); $output .= '<div class="groups-overview">'; $output .= '<div class="filters">' . '<label class="description" for="setfilters">' . __('Filters', GROUPS_PLUGIN_DOMAIN) . '</label>' . '<form id="setfilters" action="" method="post">' . '<p>' . '<label class="group-id-filter" for="group_id">' . __('Group Id', GROUPS_PLUGIN_DOMAIN) . '</label>' . '<input class="group-id-filter" name="group_id" type="text" value="' . esc_attr($group_id) . '"/>' . '<label class="group-name-filter" for="group_name">' . __('Group Name', GROUPS_PLUGIN_DOMAIN) . '</label>' . '<input class="group-name-filter" name="group_name" type="text" value="' . $group_name . '"/>' . '</p>' . '<p>' . wp_nonce_field('admin', GROUPS_ADMIN_GROUPS_FILTER_NONCE, true, false) . '<input class="button" type="submit" value="' . __('Apply', GROUPS_PLUGIN_DOMAIN) . '"/>' . '<input class="button" type="submit" name="clear_filters" value="' . __('Clear', GROUPS_PLUGIN_DOMAIN) . '"/>' . '<input type="hidden" value="submitted" name="submitted"/>' . '</p>' . '</form>' . '</div>'; if ($paginate) { require_once GROUPS_CORE_LIB . '/class-groups-pagination.php'; $pagination = new Groups_Pagination($count, null, $row_count); $output .= '<form id="posts-filter" method="post" action="">'; $output .= '<div>'; $output .= wp_nonce_field('admin', GROUPS_ADMIN_GROUPS_NONCE_2, true, false); $output .= '</div>'; $output .= '<div class="tablenav top">'; $output .= $pagination->pagination('top'); $output .= '</div>'; $output .= '</form>'; } $output .= '<div class="page-options right">'; $output .= '<form id="setrowcount" action="" method="post">'; $output .= '<div>'; $output .= '<label for="row_count">' . __('Results per page', GROUPS_PLUGIN_DOMAIN) . '</label>'; $output .= '<input name="row_count" type="text" size="2" value="' . esc_attr($row_count) . '" />'; $output .= wp_nonce_field('admin', GROUPS_ADMIN_GROUPS_NONCE_1, true, false); $output .= '<input class="button" type="submit" value="' . __('Apply', GROUPS_PLUGIN_DOMAIN) . '"/>'; $output .= '</div>'; $output .= '</form>'; $output .= '</div>'; $capability_table = _groups_get_tablename("capability"); $group_capability_table = _groups_get_tablename("group_capability"); // capabilities select $capabilities = $wpdb->get_results("SELECT * FROM {$capability_table} ORDER BY capability"); $capabilities_select = sprintf('<select class="select capability" name="capability_id[]" multiple="multiple" placeholder="%s" data-placeholder="%s">', esc_attr(__('Capabilities …', GROUPS_PLUGIN_DOMAIN)), esc_attr(__('Capabilities …', GROUPS_PLUGIN_DOMAIN))); foreach ($capabilities as $capability) { $capabilities_select .= sprintf('<option value="%s">%s</option>', esc_attr($capability->capability_id), wp_filter_nohtml_kses($capability->capability)); } $capabilities_select .= '</select>'; $capabilities_select .= Groups_UIE::render_select('.select.capability'); $output .= '<form id="groups-action" method="post" action="">'; $output .= '<div class="tablenav top">'; $output .= '<div class="groups-bulk-container">'; $output .= '<div class="capabilities-select-container">'; $output .= $capabilities_select; $output .= wp_nonce_field('admin', GROUPS_ADMIN_GROUPS_ACTION_NONCE, true, false); $output .= '</div>'; $output .= '<select class="bulk-action" name="bulk-action">'; $output .= '<option selected="selected" value="-1">' . __('Bulk Actions', GROUPS_PLUGIN_DOMAIN) . '</option>'; $output .= '<option value="remove-group">' . __('Remove group', GROUPS_PLUGIN_DOMAIN) . '</option>'; $output .= '<option value="add-capability">' . __('Add capability', GROUPS_PLUGIN_DOMAIN) . '</option>'; $output .= '<option value="remove-capability">' . __('Remove capability', GROUPS_PLUGIN_DOMAIN) . '</option>'; $output .= '</select>'; $output .= sprintf('<input class="button" type="submit" name="bulk" value="%s" />', __('Apply', GROUPS_PLUGIN_DOMAIN)); $output .= '<input type="hidden" name="action" value="groups-action"/>'; $output .= '</div>'; $output .= '</div>'; $output .= '<table id="" class="wp-list-table widefat fixed" cellspacing="0">'; $output .= '<thead>'; $output .= '<tr>'; $output .= '<th id="cb" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th>'; foreach ($column_display_names as $key => $column_display_name) { $options = array('orderby' => $key, 'order' => $switch_order); $class = $key; if (!in_array($key, array('capabilities', 'edit', 'remove'))) { if (strcmp($key, $orderby) == 0) { $lorder = strtolower($order); $class = "{$key} manage-column sorted {$lorder}"; } else { $class = "{$key} manage-column sortable"; } $column_display_name = '<a href="' . esc_url(add_query_arg($options, $current_url)) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>'; } $output .= "<th scope='col' class='{$class}'>{$column_display_name}</th>"; } $output .= '</tr>'; $output .= '</thead>'; $output .= '<tbody>'; if (count($results) > 0) { for ($i = 0; $i < count($results); $i++) { $result = $results[$i]; $output .= '<tr class="' . ($i % 2 == 0 ? 'even' : 'odd') . '">'; $output .= '<th class="check-column">'; $output .= '<input type="checkbox" value="' . esc_attr($result->group_id) . '" name="group_ids[]"/>'; $output .= '</th>'; $output .= "<td class='group-id'>"; $output .= $result->group_id; $output .= "</td>"; $output .= "<td class='group-name'>" . stripslashes(wp_filter_nohtml_kses($result->name)) . "</td>"; $output .= "<td class='group-description'>" . stripslashes(wp_filter_nohtml_kses($result->description)) . "</td>"; $output .= '<td class="capabilities">'; $group = new Groups_Group($result->group_id); $group_capabilities = $group->capabilities; $group_capabilities_deep = $group->capabilities_deep; usort($group_capabilities_deep, array('Groups_Utility', 'cmp')); if (count($group_capabilities_deep) > 0) { $output .= '<ul>'; foreach ($group_capabilities_deep as $group_capability) { $output .= '<li>'; $class = ''; if (empty($group_capabilities) || !in_array($group_capability, $group_capabilities)) { $class = 'inherited'; } $output .= sprintf('<span class="%s">', $class); if (isset($group_capability->capability) && isset($group_capability->capability->capability)) { $output .= wp_filter_nohtml_kses($group_capability->capability->capability); } $output .= '</span>'; $output .= '</li>'; } $output .= '</ul>'; } else { $output .= __('This group has no capabilities.', GROUPS_PLUGIN_DOMAIN); } $output .= '</td>'; $output .= "<td class='edit'>"; $output .= "<a href='" . esc_url(add_query_arg('paged', $paged, $current_url)) . "&action=edit&group_id=" . $result->group_id . "' alt='" . __('Edit', GROUPS_PLUGIN_DOMAIN) . "'><img src='" . GROUPS_PLUGIN_URL . "images/edit.png'/></a>"; $output .= "</td>"; $output .= "<td class='remove'>"; if ($result->name !== Groups_Registered::REGISTERED_GROUP_NAME) { $output .= "<a href='" . esc_url($current_url) . "&action=remove&group_id=" . $result->group_id . "' alt='" . __('Remove', GROUPS_PLUGIN_DOMAIN) . "'><img src='" . GROUPS_PLUGIN_URL . "images/remove.png'/></a>"; } $output .= "</td>"; $output .= '</tr>'; } } else { $output .= '<tr><td colspan="7">' . __('There are no results.', GROUPS_PLUGIN_DOMAIN) . '</td></tr>'; } $output .= '</tbody>'; $output .= '</table>'; $output .= Groups_UIE::render_add_titles('.groups-overview table td'); $output .= '</form>'; // #groups-action if ($paginate) { require_once GROUPS_CORE_LIB . '/class-groups-pagination.php'; $pagination = new Groups_Pagination($count, null, $row_count); $output .= '<div class="tablenav bottom">'; $output .= $pagination->pagination('bottom'); $output .= '</div>'; } $output .= '</div>'; // .groups-overview $output .= '</div>'; // .manage-groups echo $output; Groups_Help::footer(); }