<td> <div class="pp-submit" style="text-align:right"> <?php if (pp_group_type_editable($agent_type) && (empty($agent->metagroup_type) || !in_array($agent->metagroup_type, array('wp_role', 'meta_role')) || apply_filters('pp_metagroup_editable', false, $agent->metagroup_type, $agent_id))) { submit_button(__('Update Group', 'pp')); } ?> </div> </td> </tr> </table> <?php do_action('pp_group_edit_form', $agent_type, $agent_id); if ($agent_id) { if (pp_group_type_editable($agent_type) && !in_array($agent->metagroup_type, array('wp_role', 'meta_role'))) { $member_types = array(); if (pp_has_group_cap('pp_manage_members', $agent_id, $agent_type)) { $member_types[] = 'member'; } if ($member_types) { PP_GroupsUI::_draw_member_checklists($agent_id, $agent_type, compact('member_types')); } } } elseif ('user' == $agent_type) { echo '<br />'; PP_GroupsUI::_draw_member_checklists(0, 'pp_group', array('suppress_caption' => true)); } do_action('pp_edit_group_profile', $agent_type, $agent_id); ?>
$groups_caption = defined('PP_GROUPS_CAPTION') ? PP_GROUPS_CAPTION : __('Permission Groups', 'pp'); } else { $groups_caption = $group_type_obj->labels->name; } echo esc_html($groups_caption); /* if ( current_user_can( 'pp_edit_groups' ) ) { if ( PP_MULTISITE && pp_get_option('ms_netwide_groups') ) $url = 'users.php'; else $url = 'admin.php'; } */ $url = 'admin.php'; $group_variant = isset($_REQUEST['group_variant']) ? pp_sanitize_key($_REQUEST['group_variant']) : 'pp_group'; if (pp_group_type_editable($group_variant) && current_user_can('pp_create_groups')) { ?> <a href="<?php echo add_query_arg(array('agent_type' => $agent_type, 'page' => 'pp-group-new'), $url); ?> " class="add-new-h2"><?php echo esc_html(__ppw('Add New')); ?> </a> <?php } echo '</h2>'; if (pp_get_option('display_hints')) { echo '<div class="pp-hint">'; if (defined('PP_GROUPS_HINT')) { echo esc_html(PP_GROUPS_HINT);
if (!empty($pp_admin->errors) && is_wp_error($pp_admin->errors)) { ?> <div class="error"><p><?php echo implode("</p>\n<p>", $pp_admin->errors->get_error_messages()); ?> </p></div> <?php } ?> <div class="wrap" id="group-profile-page"> <?php pp_icon(); ?> <h2><?php $agent_type = isset($_REQUEST['agent_type']) && pp_group_type_editable($_REQUEST['agent_type']) ? pp_sanitize_key($_REQUEST['agent_type']) : 'pp_group'; if ('pp_group' == $agent_type || !($group_type_obj = pp_get_group_type_object($agent_type))) { _e('Create New Permission Group', 'pp'); } else { printf(__('Create New %s', 'pp'), $group_type_obj->labels->singular_name); } ?> </h2> <form action="" method="post" id="creategroup" name="creategroup" class="pp-admin"> <input name="action" type="hidden" value="creategroup" /> <input name="agent_type" type="hidden" value="<?php echo $agent_type; ?> " /> <?php
// cludged update of group members on role selection, due to inability to put them in the same form if ($agent_id && pp_group_type_editable($agent_type) && pp_has_group_cap('pp_edit_groups', $agent_id, $agent_type)) { _pp_trigger_group_edit($agent_id, $agent_type); } global $current_user; update_user_option($current_user->ID, 'pp-permissions-tab', 'pp-add-roles'); $redirect = "{$url}?page=pp-edit-permissions&agent_id={$agent_id}&agent_type={$agent_type}&updated=1&pp_roles=1"; break; case 'pp_updateexceptions': $agent_id = (int) $_REQUEST['agent_id']; check_admin_referer('pp-update-exceptions_' . $agent_id, '_pp_nonce_exceptions'); if (current_user_can('pp_assign_roles') && pp_bulk_roles_enabled()) { _pp_edit_agent_exceptions($agent_id, $agent_type); } // cludged update of group members on role selection, due to inability to put them in the same form if (pp_group_type_editable($agent_type) && pp_has_group_cap('pp_edit_groups', $agent_id, $agent_type)) { _pp_trigger_group_edit($agent_id, $agent_type); } global $current_user; update_user_option($current_user->ID, 'pp-permissions-tab', 'pp-add-exceptions'); $redirect = "{$url}?page=pp-edit-permissions&agent_id={$agent_id}&agent_type={$agent_type}&updated=1&pp_exc=1"; break; case 'creategroup': if (!current_user_can('pp_create_groups')) { wp_die(__('You are not permitted to do that.', 'pp')); } check_admin_referer('pp-create-group', '_wpnonce_pp-create-group'); $agent_type = isset($_REQUEST['agent_type']) ? pp_sanitize_key($_REQUEST['agent_type']) : ''; if (!($agent_type = apply_filters('pp_query_group_type', $agent_type))) { $agent_type = 'pp_group'; }
function draw_exceptions_ui($box, $args) { if (!isset($box['args'])) { return; } extract($box['args'], EXTR_SKIP); // $op extract($args, EXTR_SKIP); // $for_item_source, for_item_type, via_item_source global $wp_roles, $pp_current_user; $is_draft_post = false; if ('post' == $via_item_source) { if ('read' == $op) { global $post; $status_obj = get_post_status_object($post->post_status); if (!$status_obj || !$status_obj->public && !$status_obj->private) { $is_draft_post = true; } } $hierarchical = is_post_type_hierarchical($via_item_type); } else { $hierarchical = is_taxonomy_hierarchical($via_item_type); } if ($hierarchical = apply_filters('pp_do_assign_for_children_ui', $hierarchical, $via_item_type, $args)) { $type_obj = 'post' == $via_item_source ? get_post_type_object($via_item_type) : get_taxonomy($via_item_type); } $agent_types['wp_role'] = (object) array('labels' => (object) array('name' => __('WP Roles', 'pp'), 'singular_name' => __('WP Role', 'pp'))); $agent_types = apply_filters('pp_list_group_types', array_merge($agent_types, pp_get_group_types(array(), 'object'))); $agent_types['user'] = (object) array('labels' => (object) array('name' => __('Users'), 'singular_name' => __('User'))); //if ( ! $skip_user_validation && ! $pp_admin->user_can_admin_role($role_name, $item_id, $src_name, $object_type) ) // return; static $drew_itemroles_marker; if (empty($drew_itemroles_marker)) { echo "<input type='hidden' name='pp_post_exceptions' value='true' />"; $drew_itemroles_marker = true; } $current_exceptions = isset($this->data->current_exceptions[$for_item_type]) ? $this->data->current_exceptions[$for_item_type] : array(); // ========== OBJECT / TERM EXCEPTION DROPDOWNS ============ $toggle_agents = count($agent_types) > 1; if ($toggle_agents) { global $is_ID; $class_selected = 'agp-selected_agent agp-agent'; $class_unselected = 'agp-unselected_agent agp-agent'; $bottom_margin = !empty($is_IE) ? '-0.7em' : 0; $default_agent_type = 'wp_role'; echo "<div class='hide-if-not-js' style='margin:0 0 {$bottom_margin} 0'>" . "<ul class='pp-list_horiz' style='margin-bottom:-0.1em'>"; foreach ($agent_types as $agent_type => $gtype_obj) { $label = !empty($current_exceptions[$op][$agent_type]) ? sprintf(__('%1$s (%2$s)', 'pp'), $gtype_obj->labels->name, count($current_exceptions[$op][$agent_type])) : $gtype_obj->labels->name; $class = $default_agent_type == $agent_type ? "class='{$class_selected}'" : "class='{$class_unselected}'"; echo "<li {$class}><a href='javascript:void(0)' class='{$op}-{$for_item_type}-{$agent_type}'>" . $label . '</a></li>'; } echo '</ul></div>'; } $class = "class='pp-agents pp-exceptions'"; //need effective line break here if not IE echo "<div style='clear:both;margin:0 0 0.3em 0' {$class}>"; $pp_agents_ui = pp_init_agents_ui(); foreach (array_keys($agent_types) as $agent_type) { $hide_class = $toggle_agents && $agent_type != $default_agent_type ? ' class="hide-if-js"' : ''; echo "\r\n<div id='{$op}-{$for_item_type}-{$agent_type}' {$hide_class} style='overflow-x:auto'>"; $this->render->set_options($agent_type); // list all WP roles if ('wp_role' == $agent_type) { if (!isset($current_exceptions[$op][$agent_type])) { $current_exceptions[$op][$agent_type] = array(); } foreach ($this->data->agent_info['wp_role'] as $agent_id => $role) { if (in_array($role->metagroup_id, array('wp_anon', 'wp_all')) && !defined('PP_ALL_ANON_FULL_EXCEPTIONS') && ('read' != $op || pp_get_option('anonymous_unfiltered'))) { continue; } if (!isset($current_exceptions[$op][$agent_type][$agent_id])) { $current_exceptions[$op][$agent_type][$agent_id] = array(); } } if (!$is_draft_post && 'post' == $via_item_source && 'attachment' != $via_item_type && in_array($op, array('read', 'edit', 'delete'))) { $reqd_caps = map_meta_cap("{$op}_post", 0, $item_id); } else { $reqd_caps = false; } } global $wp_roles; ?> <table class="pp-item-exceptions-ui pp-exc-<?php echo $agent_type; ?> " style="width:100%"><tr> <?php if ('wp_role' != $agent_type) { ?> <td class="pp-select-exception-agents" style="display:none;"> <?php // Select Groups / Users UI echo '<div>'; echo '<div class="pp-agent-select">'; $args = array_merge($args, array('suppress_extra_prefix' => true, 'ajax_selection' => true, 'display_stored_selections' => false, 'create_dropdowns' => true, 'op' => $op, 'via_item_type' => $via_item_type)); $pp_agents_ui = pp_init_agents_ui(); $pp_agents_ui->agents_ui($agent_type, array(), "{$op}:{$for_item_type}:{$agent_type}", array(), $args); echo '</div>'; echo '</div>'; $colspan = 'colspan="2"'; ?> </td> <?php } else { $colspan = ''; // for html5 compliance } ?> <?php $any_stored = empty($current_exceptions[$op][$agent_type]) ? 0 : count($current_exceptions[$op][$agent_type]); ?> <td class="pp-current-item-exceptions" style="width:100%"> <div style="overflow:auto;max-height:325px"> <table <?php if (!$any_stored) { echo 'style="display:none"'; } ?> > <?php if ($hierarchical) { ?> <thead> <tr> <th></th> <th><?php printf(__('This %s', 'pp'), $type_obj->labels->singular_name); ?> </th> <th><?php if ($caption = apply_filters('pp_item_assign_for_children_caption', '', $via_item_type)) { printf($caption); } else { printf(__('Sub-%s', 'pp'), $type_obj->labels->name); } ?> </th> </tr> </thead> <?php } ?> <tbody> <?php // @todo: why is agent_id=0 in current_exceptions array? if ($any_stored) { if ('wp_role' == $agent_type) { foreach ($current_exceptions[$op][$agent_type] as $agent_id => $agent_exceptions) { if ($agent_id && isset($this->data->agent_info[$agent_type][$agent_id])) { $this->render->draw_row($agent_type, $agent_id, $current_exceptions[$op][$agent_type][$agent_id], $this->data->inclusions_active, $this->data->agent_info[$agent_type][$agent_id], compact('for_item_type', 'op', 'reqd_caps', 'hierarchical')); } } } else { foreach (array_keys($this->data->agent_info[$agent_type]) as $agent_id) { // order by agent name if ($agent_id && isset($current_exceptions[$op][$agent_type][$agent_id])) { $this->render->draw_row($agent_type, $agent_id, $current_exceptions[$op][$agent_type][$agent_id], $this->data->inclusions_active, $this->data->agent_info[$agent_type][$agent_id], compact('for_item_type', 'op', 'reqd_caps', 'hierarchical')); } } } } ?> </tbody> <tfoot<?php if ($any_stored < 2) { echo ' style="display:none;"'; } ?> > <?php $link_caption = 'wp_role' == $agent_type ? __('default all', 'pp') : __('clear all', 'pp'); ?> <tr> <td></td><td style="text-align:center"><a href="#clear-item-exc"><?php echo $link_caption; ?> </a></td> <?php if ($hierarchical) { ?> <td style="text-align:center"><a href="#clear-sub-exc"><?php echo $link_caption; ?> </a></td> <?php } ?> </tr> </tfoot> </table> </div> <?php if (!$any_stored) { ?> <div class="pp-no-exceptions"><?php _e('No access customizations stored.', 'pp'); ?> </div> <?php } ?> </td> </tr> <tr> <td class="pp-exception-actions" <?php echo $colspan; ?> > <?php if ('wp_role' != $agent_type) { ?> <a class="pp-select-exception-agents" href="#"><?php 'user' == $agent_type ? _e('select users', 'pp') : _e('select groups', 'pp'); ?> </a> <a class="pp-close-select-exception-agents" href="#" style="display:none;"><?php _e('close', 'pp'); ?> </a> <?php } if (pp_group_type_editable($agent_type) && pp_has_group_cap('pp_create_groups', 0, $agent_type)) { ?> • <a class="pp-create-exception-agent" href="admin.php?page=pp-group-new" target="_blank"><?php _e('create group', 'pp'); ?> </a> <?php } ?> </td> </tr> </table> </div> <?php } // end foreach group type caption echo '</div>'; // class pp-agents if ('read' == $op && pp_get_option('display_extension_hints') && ('attachment' == $for_item_type && !defined('PPFF_VERSION') || !defined('PPCE_VERSION'))) { require_once dirname(__FILE__) . '/item-exceptions-ui-hints_pp.php'; _ppc_item_ui_hints($for_item_type); } if ('term' == $via_item_source && in_array($op, array('read', 'edit'))) { $msg = __('To customize <strong>for a specific post status</strong>, edit the desired role / group / user permissions directly (Permissions > Groups or Users)', 'pp'); echo "<div class='pp-exc-notes'>{$msg}</div>"; } }
<td> <div class="pp-submit" style="text-align:right"> <?php if (pp_group_type_editable($agent_type) && (empty($agent->metagroup_type) || !in_array($agent->metagroup_type, array('wp_role', 'meta_role')) || apply_filters('pp_metagroup_editable', false, $agent->metagroup_type, $agent_id))) { submit_button(__('Update Group', 'pp')); } ?> </div> </td> </tr> </table> <?php do_action('pp_group_edit_form', $agent_type, $agent_id); if ($agent_id) { if (pp_group_type_editable($agent_type) && !in_array($agent->metagroup_type, array('wp_role', 'meta_role')) && !in_array($agent_type, apply_filters('pp_automember_group_types', array('bp_group')))) { $member_types = array(); if (pp_has_group_cap('pp_manage_members', $agent_id, $agent_type)) { $member_types[] = 'member'; } if ($member_types) { PP_GroupsUI::_draw_member_checklists($agent_id, $agent_type, compact('member_types')); } } } elseif ('user' == $agent_type) { echo '<br />'; PP_GroupsUI::_draw_member_checklists(0, 'pp_group', array('suppress_caption' => true)); } do_action('pp_edit_group_profile', $agent_type, $agent_id); ?>
public static function display($agents_subset, $agent_type, $all_agents, $name_attrib, $item_assignments, $args) { $defaults = array('eligible_ids' => array(), 'locked_ids' => array(), 'add_group_link' => true, 'show_subset_caption' => true, 'hide_checkboxes' => false); $args = array_merge($defaults, (array) $args); extract($args, EXTR_SKIP); $caption_length_limit = defined('PP_AGENTS_CAPTION_LIMIT') ? PP_AGENTS_CAPTION_LIMIT : 20; $emsize_threshold = defined('PP_AGENTS_EMSIZE_THRESHOLD') ? PP_AGENTS_EMSIZE_THRESHOLD : 4; static $exec_count = 0; $exec_count++; // support abbreviated checkbox id for label association if ('eligible' == $agents_subset) { $caption = __('eligible (%d):', 'pp'); $item_assignments = array_intersect_key($item_assignments, $all_agents); if (!($agent_count = count($all_agents) - count($item_assignments))) { return; } } else { $caption = __('current (%d):', 'pp'); $agent_count = count($item_assignments); } echo "<div>"; echo "<ul class='pp-list_horiz'><li>"; if ($show_subset_caption) { printf("<div class='pp-agents_caption'><strong>{$caption}</strong></div>", $agent_count); } echo '</li>'; echo '</ul>'; // -------- construct captions and determine required list item width ----------- $captions = $full_captions = $draw_agents = array(); global $wp_locale; $rtl = isset($wp_locale) && 'rtl' == $wp_locale->text_direction; $longest_caption_length = 10; foreach ($all_agents as $agent) { $id = $agent->ID; $skip = false; switch ($agents_subset) { case 'current': if (!isset($item_assignments[$id])) { $skip = true; } break; default: //'eligible' if (isset($item_assignments[$id])) { $skip = true; } if ($eligible_ids && !in_array($id, $eligible_ids)) { $skip = true; } } if ($skip) { unset($all_agents[$id]); continue; } if ('pp_group' == $agent_type && $agent->metagroup_id) { $caption = PP_GroupRetrieval::get_metagroup_name($agent->metagroup_type, $agent->metagroup_id, $agent->name); } else { $caption = $agent->name; } if (strlen($caption) > $caption_length_limit) { $full_captions[$id] = $caption; if ($rtl) { $caption = '...' . substr($caption, strlen($caption) - $caption_length_limit); } else { $caption = substr($caption, 0, $caption_length_limit) . '...'; } } if (strlen($caption) > $longest_caption_length) { $longest_caption_length = strlen($caption) >= $caption_length_limit ? $caption_length_limit + 2 : strlen($caption); } $captions[$id] = $caption; } //-------- end caption construction -------------- if ($agent_count > $emsize_threshold) { $ems_per_character = defined('PP_UI_EMS_PER_CHARACTER') ? PP_UI_EMS_PER_CHARACTER : 0.85; $list_width_ems = $ems_per_character * $longest_caption_length; $ul_class = 'pp-agents-list_' . intval($list_width_ems); echo "<div id='div_{$agents_subset}_{$name_attrib}' class='pp-{$agent_type} pp-{$agents_subset}'>" . "<div class='pp-agents_emsized'>" . "<ul class='pp-agents-list {$ul_class}' id='list_{$agents_subset}_{$name_attrib}'>"; } else { $ul_class = "pp-agents-list_auto"; echo "<div class='pp-{$agent_type}'>" . "<ul class='pp-agents-list {$ul_class}' id='list_{$agents_subset}_{$name_attrib}'>"; } if (pp_group_type_editable($agent_type)) { $edit_link_base = apply_filters('pp_groups_base_url', 'admin.php') . "?page=pp-edit-permissions&action=edit&agent_type={$agent_type}&agent_id="; $edit_title_text = __('view / edit group', 'pp'); $edit_caption = __ppw('edit', 'pp'); } else { $edit_link_base = ''; } foreach ($all_agents as $agent) { $id = $agent->ID; if (!empty($agent->metagroup_id)) { $display_name = isset($agent->display_name) ? $agent->display_name : ''; $li_title = "title='" . PP_GroupRetrieval::get_metagroup_descript($agent->metagroup_type, $agent->metagroup_id, $display_name) . "'"; } elseif (isset($full_captions[$id])) { $li_title = "title='{$full_captions[$id]}'"; } else { $li_title = "title='{$captions[$id]}'"; } $checked = isset($item_assignments[$id]) ? ' checked="checked"' : ''; $disabled = $locked_ids && in_array($id, $locked_ids) ? " disabled='disabled'" : ''; echo "<li {$li_title}>"; if ($hide_checkboxes) { echo '• '; } else { echo "<input type='checkbox' name='{$name_attrib}[]'{$disabled}{$checked} value='{$id}' id='r{$exec_count}_{$id}' />"; } echo "<label for='r{$exec_count}_{$id}'>"; echo ' ' . $captions[$id]; echo '</label>'; if ($edit_link_base && pp_has_group_cap('pp_edit_groups', $id, $agent_type)) { echo ' <a href=" ' . $edit_link_base . $id . '" style="display:none" target="_blank" title="' . $edit_title_text . '">' . $edit_caption . '</a>'; } echo '</li>'; } //foreach agent echo "<li></li></ul>"; // prevent invalid markup if no other li's if ($agent_count > $emsize_threshold) { echo '</div>'; } echo '</div></div>'; }