/** * CONFIG PACKAGE for groups attached to taxonomy terms */ public function package_taxonomy_term_groups() { $this->table_conf = array('form_id' => '', 'form_method' => '', 'list_id' => 'ctxps-relationships', 'record_slug' => 'term_group_rec', 'bulk' => 'false', 'no_records' => __('No groups have been added yet.', 'contexture-page-security'), 'actions_col' => 'name'); $this->bulk_conf = array(); // Indexed array. Each entry is an assoc array. All values required. $this->column_conf = array(array('title' => 'id', 'slug' => 'id', 'class' => 'col-first', 'width' => '30px'), array('title' => __('Name', 'contexture-page-security'), 'slug' => 'name', 'class' => '', 'width' => '300px'), array('title' => __('Description', 'contexture-page-security'), 'slug' => 'description', 'class' => '', 'width' => ''), array('title' => __('Users', 'contexture-page-security'), 'slug' => 'users', 'class' => 'col-last', 'width' => '60px')); // Indexed array. Each entry is an associative array. All values required. $this->actions_conf = array(array('title' => __('Edit', 'contexture-page-security'), 'tip' => __('Edit this content.', 'contexture-page-security'), 'slug' => 'edit', 'color' => ''), array('title' => __('Remove', 'contexture-page-security'), 'tip' => __('Detach this group from the content.', 'contexture-page-security'), 'slug' => 'trash', 'color' => 'red')); //Try to get a tag id (can be called different things in different places) $term_id = 0; if (isset($_REQUEST['tag_ID'])) { $term_id = $_REQUEST['tag_ID']; } else { if (isset($_REQUEST['content_id'])) { $term_id = $_REQUEST['content_id']; } else { if (isset($_REQUEST['object_id'])) { $term_id = $_REQUEST['object_id']; } } } //Get a list of all the groups attached to this term $list = CTXPS_Queries::get_groups_by_object('term', $term_id); foreach ($list as $record) { //Get edit URL $edit_url = admin_url("users.php?page=ps_groups_edit&groupid={$record->ID}"); //Build records $this->list_data[] = array('id' => $record->ID, 'columns' => array('id' => $record->ID, 'name' => sprintf('<strong><a href="%s">%s</a></strong>', $edit_url, $record->group_title), 'description' => $record->group_description, 'users' => CTXPS_Queries::count_members($record->ID)), 'actions' => array('edit' => $edit_url, 'trash' => array('onclick' => 'CTXPS_Ajax.removeGroupFromTerm(' . $record->ID . ',jQuery(this))'))); //End array add } //End foreach }
/** * Used to generate <tbody> inner html for group lists. If a user_id is provided, the list * will only include groups attached to that specified user. * * @global wpdb $wpdb * * @param string $user_id If set, only shows groups that have a specific user as a member * @param string $view Specify which view the list is being generated for (there are some differences). Supports 'groups' (default) or 'users' * @param bool $show_actions If set to false, will not show the actions (default true) * * @return string Returns the html */ public static function render_group_list($user_id = '', $view = 'groups', $show_actions = true, $profile = true) { global $wpdb; $linkBack = admin_url('users.php'); $groups = CTXPS_Queries::get_groups($user_id); //If there are no groups, stop right here if (count($groups) === 0) { if ($profile) { return sprintf('<td colspan="4">%s</td>', sprintf(__('You are not currently a member of any groups.', 'contexture-page-security'), admin_url('users.php?page=ps_groups'))); } else { return sprintf('<td colspan="4">%s</td>', sprintf(__('This user has not been added to any custom groups. Select a group above or visit any <a href="%s">group detail page</a>.', 'contexture-page-security'), admin_url('users.php?page=ps_groups'))); } } $html = ''; $htmlactions = ''; $countmembers = ''; $alternatecss = ' class="alternate" '; $countusers = count_users(); if (empty($user_id) && !empty($_REQUEST['user_id'])) { $user_id = esc_attr($_REQUEST['user_id']); } //Loop through all groups and output... foreach ($groups as $group) { //Escape output $group->ID = esc_attr($group->ID); $group->group_title = esc_attr($group->group_title); $group->group_description = esc_attr($group->group_description); //Count the number of members in the group $countmembers = !isset($group->group_system_id) ? CTXPS_Queries::count_members($group->ID) : $countusers['total_users']; //Only create the actions if $showactions is true if ($show_actions && current_user_can('promote_users')) { switch ($view) { case 'users': //Button for "Remove" takes user out of group (ajax) $htmlactions = sprintf('<div class="row-actions"><span class="edit"><a href="%1$s?page=ps_groups_edit&groupid=%2$s">Edit</a> | </span><span class="delete"><a class="submitdelete" id="unenroll-%2$s" onclick="CTXPS_Ajax.removeGroupFromUser(%2$s,%3$s,jQuery(this))">Unenroll</a></span></div>', $linkBack, $group->ID, $user_id); break; case 'groups': //Button for "Delete" removes group from db (postback) //If $showactions is false, we dont show the actions row at all $htmlactions = sprintf('<div class="row-actions"><span class="edit"><a href="%1$s?page=ps_groups_edit&groupid=%2$s">Edit</a> | </span><span class="delete"><a class="submitdelete" href="?page=ps_groups_delete&groupid=%2$s">Delete</a></span></div>', $linkBack, $group->ID); break; default: break; } } //If user isnt admin, we wont even link to group edit page (useful for profile pages) if (current_user_can('promote_users')) { //User is admin - determined if link is system or not $grouplink = !isset($group->group_system_id) ? sprintf('<a href="%1$s?page=ps_groups_edit&groupid=%2$s"><strong>%3$s</strong></a>%4$s', $linkBack, $group->ID, $group->group_title, $htmlactions) : sprintf('<a id="%s" class="ctx-ps-sysgroup"><strong>%s</strong></a>', $group->group_system_id, $group->group_title); } else { //User is not admin - no links $grouplink = sprintf('<a id="%s"><strong>%s</strong></a>', $group->group_system_id, esc_attr($group->group_title)); } $html .= sprintf('<tr %1$s> <td class="id">%2$s</td> <td class="name">%3$s</td> <td class="description">%4$s</td> <td class="user-count">%5$s</td> </tr>', $alternatecss, $group->ID, $grouplink, $group->group_description, $countmembers); //Alternate css style for odd-numbered rows $alternatecss = $alternatecss != '' ? '' : ' class="alternate" '; } return $html; }
echo '<div id="message" class="error below-h2"><p>' . __('System groups cannot be deleted.', 'contexture-page-security') . ' <a href="' . admin_url() . 'users.php?page=ps_groups">' . __('View all groups', 'contexture-page-security') . ' >></a></p></div>'; } else { ?> <form id="deletegroup" name="deletegroup" method="get" action=""> <input type="hidden" name="page" value="ps_groups_delete"/> <input type="hidden" name="groupid" value="<?php echo $_GET['groupid']; ?> " /> <input type="hidden" name="action" value="delete" /> <p>You are about to delete the group <strong><?php echo $groupInfo->group_title; ?> </strong>.</p> <p>Deleting this group will affect <strong><?php echo CTXPS_Queries::count_members($groupInfo->ID); ?> </strong> users and <strong><?php echo $groupPageCount; ?> </strong> pages/posts. Are you sure you want to continue?</p> <?php wp_nonce_field('delete-group'); ?> <p class="submit"> <input class="button-secondary" type="submit" value="<?php _e('Confirm Deletion', 'contexture-page-security'); ?> " name="submit"/> </p> </form>