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); }
} if ('user' == $agent_type) { ?> <div> <?php if ($agent_id) { $roles = array(); $user = pp_get_user($agent_id); $user->retrieve_extra_groups(); $post_types = pp_get_enabled_post_types(array(), 'object'); $taxonomies = pp_get_enabled_taxonomies(array(), 'object'); foreach (array_keys($user->groups) as $agent_type) { foreach (array_keys($user->groups[$agent_type]) as $_agent_id) { $args = compact($post_types, $taxonomies); $args['query_agent_ids'] = array_keys($user->groups[$agent_type]); $roles = array_merge($roles, ppc_get_roles($agent_type, $_agent_id, $args)); } } require_once dirname(__FILE__) . '/profile_ui_pp.php'; PP_ProfileUI::display_ui_user_groups(false, array('initial_hide' => true, 'selected_only' => true, 'force_display' => true, 'edit_membership_link' => true, 'hide_checkboxes' => true, 'user_id' => $agent_id)); $role_group_caption = sprintf(__('Supplemental Roles %1$s(from primary role or %2$sgroup membership%3$s)%4$s', 'pp'), '<small>', "<a class='pp-show-groups' href='#'>", '</a>', '</small>'); PP_GroupsUI::_current_roles_ui($roles, array('read_only' => true, 'class' => 'pp-group-roles', 'caption' => $role_group_caption)); $exceptions = array(); $args = array('assign_for' => '', 'inherited_from' => 0, 'extra_cols' => array('i.assign_for', 'i.eitem_id'), 'post_types' => array_keys($post_types), 'taxonomies' => array_keys($taxonomies), 'return_raw_results' => true); foreach (array_keys($user->groups) as $agent_type) { $args['agent_type'] = $agent_type; $args['ug_clause'] = " AND e.agent_type = '{$agent_type}' AND e.agent_id IN ('" . implode("','", array_keys($user->groups[$agent_type])) . "')"; $args['query_agent_ids'] = array_keys($user->groups[$agent_type]); $exceptions = array_merge($exceptions, ppc_get_exceptions($args)); } $role_group_caption = sprintf(__('Exceptions %1$s(from primary role or %2$sgroup membership%3$s)%4$s', 'pp'), '<small>', "<a class='pp-show-groups' href='#'>", '</a>', '</small>');
public static function display_ui_user_roles($user) { $roles = array(); $post_types = pp_get_enabled_post_types(array(), 'object'); $taxonomies = pp_get_enabled_taxonomies(array(), 'object'); $is_administrator = pp_bulk_roles_enabled() && current_user_can('pp_manage_groups'); $edit_url = $is_administrator ? "admin.php?page=pp-edit-permissions&action=edit&agent_id={$user->ID}&agent_type=user" : ''; $user->retrieve_extra_groups(); foreach (array_keys($user->groups) as $agent_type) { foreach (array_keys($user->groups[$agent_type]) as $agent_id) { $roles = array_merge($roles, ppc_get_roles($agent_type, $agent_id, array('post_types' => $post_types, 'taxonomies' => $taxonomies, 'query_agent_ids' => array_keys($user->groups[$agent_type])))); } } $link = current_user_can('pp_assign_roles') ? "admin.php?page=pp-edit-permissions&action=edit&agent_type=user&agent_id={$user->ID}" : ''; PP_GroupsUI::_current_roles_ui($roles, array('read_only' => true, 'link' => '', 'caption' => sprintf(__('Supplemental Roles %1$s(from primary role or group membership)%2$s', 'pp'), '<small>', '</small>'))); self::abbreviated_exceptions_ui('user', $user->ID, array('edit_url' => '', 'class' => 'pp-group-roles', 'caption' => __('Exceptions (from primary role or group membership)', 'pp'), 'join_groups' => 'groups_only', 'display_limit' => 12)); }