<?php } if (!empty($messages)) { foreach ($messages as $msg) { echo $msg; } } ?> <div class="wrap pp-groups"> <?php pp_icon(); ?> <h2> <?php if ('pp_group' == $agent_type || !($group_type_obj = pp_get_group_type_object($agent_type))) { $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';
<?php } ?> <div class="wrap" id="group-profile-page"> <?php pp_icon(); ?> <h2><?php if ('user' == $agent_type) { $agent_id ? _e('Edit User Permissions', 'pp') : _e('Add User Permissions', 'pp'); } elseif ('wp_role' == $metagroup_type) { _e('Edit Permission Group (WP Role)', 'pp'); } elseif ('pp_group' == $agent_type) { _e('Edit Permission Group', 'pp'); } elseif ($group_type_obj = pp_get_group_type_object($agent_type)) { printf(__('Edit Permissions (%s)', 'pp'), $group_type_obj->labels->singular_name); } ?> </h2> <div id="pp_cred_wrap"> <form id="agent-profile" class="pp-admin <?php echo esc_attr($agent_type) . '-profile'; ?> " action="<?php echo esc_url($url); ?> " method="post"<?php do_action('pp_group_edit_form_tag'); ?>
} uasort($tax_types, 'strnatcasecmp'); // sort by values without resetting keys $types = array_merge($types, $tax_types); } } else { // 'associate' exceptions regulate parent assignment. This does not pertain to taxonomies, but may apply to other post types as specified by the filter. $aff_types = (array) apply_filters('pp_parent_types', array($for_type), $for_type); foreach ($aff_types as $_type) { if ($type_obj = get_post_type_object($_type)) { $types[$_type] = $type_obj->labels->name; } } } } elseif (in_array($for_src_name, array('pp_group', 'pp_net_group'))) { if ($group_type_obj = pp_get_group_type_object($for_src_name)) { $types[$for_src_name] = $group_type_obj->labels->name; } } $types = apply_filters('pp_exception_via_types', $types, $for_src_name, $for_type, $operation, $mod_type); foreach ($types as $val => $title) { $class = $for_type == $val ? ' class="pp-post-object"' : ''; $html .= "<option value='{$val}'{$class}>{$title}</option>"; } break; case 'get_assign_for_ui': if (!is_user_logged_in()) { echo '<p>' . __('(login timed out)', 'pp') . '</p><div class="pp-checkbox"><input type="checkbox" name="pp_select_for_item" style="display:none"><input type="checkbox" name="pp_select_for_item" style="display:none"></div>'; exit; } if ($via_type) {
function pp_nav_menu_item_group_meta_box($object, $post_type) { global $_nav_menu_placeholder, $nav_menu_selected_id; $post_type_name = $post_type['args']->name; // paginate browsing for large numbers of post objects $per_page = 50; $pagenum = isset($_REQUEST[$post_type_name . '-tab']) && isset($_REQUEST['paged']) ? absint($_REQUEST['paged']) : 1; $offset = 0 < $pagenum ? $per_page * ($pagenum - 1) : 0; $args = array('offset' => $offset, 'order' => 'ASC', 'orderby' => 'title', 'posts_per_page' => $per_page, 'post_type' => $post_type_name, 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false); if ('attachment' == $post_type_name) { $args['post_status'] = 'inherit'; } /* if ( isset( $post_type['args']->_default_query ) ) $args = array_merge($args, (array) $post_type['args']->_default_query ); $get_posts = new WP_Query; $posts = $get_posts->query( $args ); if ( ! $get_posts->post_count ) { */ if (!($posts = pp_get_groups($post_type_name))) { echo '<p>' . __('No items.') . '</p>'; return; } //$post_type_object = get_post_type_object($post_type_name); $post_type_object = pp_get_group_type_object($post_type_name); //$num_pages = $get_posts->max_num_pages; $num_pages = 1; $page_links = paginate_links(array('base' => add_query_arg(array($post_type_name . '-tab' => 'all', 'paged' => '%#%', 'item-type' => 'post_type', 'item-object' => $post_type_name)), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => $num_pages, 'current' => $pagenum)); if (!$posts) { $error = '<li id="error">' . $post_type['args']->labels->not_found . '</li>'; } $db_fields = false; /* if ( is_post_type_hierarchical( $post_type_name ) ) { $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); } */ $db_fields = array('parent' => 'post_parent', 'id' => 'ID'); $walker = new PP_Walker_Nav_Menu_Checklist($db_fields); $current_tab = 'most-recent'; if (isset($_REQUEST[$post_type_name . '-tab']) && in_array($_REQUEST[$post_type_name . '-tab'], array('all', 'search'))) { $current_tab = pp_sanitize_key($_REQUEST[$post_type_name . '-tab']); } /* if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { $current_tab = 'search'; } */ $removed_args = array('action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce'); ?> <div id="posttype-<?php echo $post_type_name; ?> " class="posttypediv"> <ul id="posttype-<?php echo $post_type_name; ?> -tabs" class="posttype-tabs add-menu-item-tabs"> <li <?php echo 'most-recent' == $current_tab ? ' class="tabs"' : ''; ?> ><a class="nav-tab-link" href="<?php if ($nav_menu_selected_id) { echo esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); } ?> #tabs-panel-posttype-<?php echo $post_type_name; ?> -most-recent"><?php _e('Most Recent'); ?> </a></li> <li <?php echo 'all' == $current_tab ? ' class="tabs"' : ''; ?> ><a class="nav-tab-link" href="<?php if ($nav_menu_selected_id) { echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); } ?> #<?php echo $post_type_name; ?> -all"><?php _e('View All'); ?> </a></li> <!-- <li -search </li> --> </ul> <div id="tabs-panel-posttype-<?php echo $post_type_name; ?> -most-recent" class="tabs-panel <?php echo 'most-recent' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'; ?> "> <ul id="<?php echo $post_type_name; ?> checklist-most-recent" class="categorychecklist form-no-clear"> <?php //$recent_args = array_merge( $args, array( 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 15 ) ); //$most_recent = $get_posts->query( $recent_args ); $_args = array('skip_meta_types' => 'wp_role', 'order_by' => 'ug.add_date_gmt DESC'); global $wpdb; $groups_table = apply_filters('pp_use_groups_table', $wpdb->pp_groups, $post_type_name); $group_members_table = apply_filters('pp_use_group_members_table', $wpdb->pp_group_members, $post_type_name); $_args['join'] = "INNER JOIN {$group_members_table} AS ug ON {$groups_table}.ID = ug.group_id"; $most_recent = pp_get_groups($post_type_name, $_args); foreach (array_keys($most_recent) as $key) { $most_recent[$key]->object_id = $posts[$key]->ID; $most_recent[$key]->title = $posts[$key]->name; $most_recent[$key]->post_parent = 0; //$most_recent[$key]->post_type = $post_type_name; $most_recent[$key]->custom_source = $post_type_name; } $args['walker'] = $walker; echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $most_recent), 0, (object) $args); ?> </ul> </div><!-- /.tabs-panel --> <!-- search <div class="tabs-panel"> </div> --> <div id="<?php echo $post_type_name; ?> -all" class="tabs-panel tabs-panel-view-all <?php echo 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'; ?> "> <?php if (!empty($page_links)) { ?> <div class="add-menu-item-pagelinks"> <?php echo $page_links; ?> </div> <?php } ?> <ul id="<?php echo $post_type_name; ?> checklist" class="list:<?php echo $post_type_name; ?> categorychecklist form-no-clear"> <?php $db_fields = array('parent' => 'post_parent', 'id' => 'ID'); $walker = new PP_Walker_Nav_Menu_Checklist($db_fields); $args['walker'] = $walker; /* // kevinB: add "(none)" item for include exceptions $front_page_obj = (object) array( 'ID' => 0, 'post_parent' => 0, 'post_content' => '', 'post_excerpt' => '', 'post_title' => __( '(none)', 'pp' ), 'object_id' => 0, 'title' => __( '(none)', 'pp' ), 'menu_item_parent' => 0, 'db_id' => 0 ); $front_page_obj->_add_to_top = true; $front_page_obj->label = __( '(none)', 'pp' ); array_unshift( $posts, $front_page_obj ); $posts = apply_filters( 'nav_menu_items_'.$post_type_name, $posts, $args, $post_type ); */ $_args = array('skip_meta_types' => 'wp_role'); $posts = pp_get_groups($post_type_name, $_args); foreach (array_keys($posts) as $key) { $posts[$key]->object_id = $posts[$key]->ID; $posts[$key]->title = $posts[$key]->name; $posts[$key]->post_parent = 0; //$posts[$key]->post_type = $post_type_name; $posts[$key]->custom_source = $post_type_name; } $checkbox_items = walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args); if ('all' == $current_tab && !empty($_REQUEST['selectall'])) { $checkbox_items = preg_replace('/(type=(.)checkbox(\\2))/', '$1 checked=$2checked$2', $checkbox_items); } echo $checkbox_items; ?> </ul> <?php if (!empty($page_links)) { ?> <div class="add-menu-item-pagelinks"> <?php echo $page_links; ?> </div> <?php } ?> </div><!-- /.tabs-panel --> <p class="button-controls"> <span class="list-controls"> <a href="<?php echo esc_url(add_query_arg(array($post_type_name . '-tab' => 'all', 'selectall' => 1), remove_query_arg($removed_args))); ?> #posttype-<?php echo $post_type_name; ?> " class="select-all"><?php _e('Select All'); ?> </a> </span> <span class="add-to-menu"> <img class="waiting" style="display:none" src="<?php echo esc_url(admin_url('images/wpspin_light.gif')); ?> " alt="" /> <input type="submit"<?php disabled($nav_menu_selected_id, 0); ?> class="button-secondary submit-add-<?php echo $post_type_name; ?> -exception" value="<?php esc_attr_e('Add Exceptions', 'pp'); ?> " name="add-post-type-menu-item" id="submit-posttype-<?php echo $post_type_name; ?> " /> </span> </p> </div> <!-- /.posttypediv --> <?php }
function pp_get_type_object($src_name, $object_type) { if ('post' == $src_name) { return get_post_type_object($object_type); } elseif ('term' == $src_name) { return get_taxonomy($object_type); } else { if ($group_type_object = pp_get_group_type_object($object_type)) { $group_type_object->hierarchical = false; return $group_type_object; } elseif ($type_obj = apply_filters('pp_exception_type', null, $src_name, $object_type)) { return $type_obj; } } }
public static function display_ui_user_groups($include_role_metagroups = false, $args = array()) { $defaults = array('initial_hide' => false, 'selected_only' => false, 'hide_checkboxes' => false, 'force_display' => false, 'edit_membership_link' => false, 'user_id' => false); extract(array_merge($defaults, $args), EXTR_SKIP); require_once dirname(__FILE__) . '/permissions-ui_pp.php'; if (!is_numeric($user_id)) { global $profileuser; $user_id = !empty($profileuser) ? $profileuser->ID : 0; } $group_types = pp_get_group_types(array('editable' => true)); foreach ($group_types as $agent_type) { //if ( ! $agent_type = apply_filters( 'pp_query_group_type', '' ) ) // $agent_type = 'pp_group'; if ('pp_group' == $agent_type && in_array('pp_net_group', $group_types)) { continue; } if (!pp_has_group_cap('pp_manage_members', 0, $agent_type)) { continue; } if (!($all_groups = pp_get_groups($agent_type))) { continue; } $reqd_caps = (array) apply_filters('pp_edit_groups_reqd_caps', array('pp_edit_groups')); // @todo: reinstate? //$editable_ids = pp_get_groups( 'pp_group', FILTERED_PP, 'id', compact('reqd_caps') ); if (current_user_can('pp_manage_members')) { $editable_ids = array_keys($all_groups); } else { $editable_ids = array(); } $stored_groups = pp_get_groups_for_user($user_id, $agent_type, array('cols' => 'id')); //$addable_ids = array_diff( $editable_ids, array_keys($stored_groups) ); $locked_ids = array_diff(array_keys($stored_groups), $editable_ids); // can't manually edit membership of WP Roles groups or other metagroups lacking _ed_ suffix $all_ids = array(); foreach ($all_groups as $key => $group) { if ($selected_only && !isset($stored_groups[$group->ID])) { unset($all_groups[$key]); continue; } $all_ids[] = $group->ID; if (!$include_role_metagroups && !empty($group->metagroup_id) && 'wp_role' == $group->metagroup_type) { $editable_ids = array_diff($editable_ids, array($group->ID)); unset($stored_groups[$group->ID]); unset($all_groups[$key]); } elseif (!in_array($group->ID, $editable_ids) && !in_array($group->ID, $locked_ids)) { unset($all_groups[$key]); } } $locked_ids = array_diff(array_keys($stored_groups), $editable_ids); // avoid incorrect eligible count if orphaned group roles are included in editable_ids $editable_ids = array_intersect($editable_ids, $all_ids); if (!$all_groups && !$force_display) { continue; } $style = $initial_hide ? "style='display:none'" : ''; echo "<div id='userprofile_groupsdiv_pp' class='pp-group-box pp-group_members' {$style}>"; echo "<h3>"; if ('pp_group' == $agent_type) { if (defined('GROUPS_CAPTION_RS')) { echo GROUPS_CAPTION_RS; } else { _e('Permission Groups', 'pp'); } } else { $group_type_obj = pp_get_group_type_object($agent_type); echo $group_type_obj->labels->name; } echo "</h3>"; $css_id = $agent_type; $args = array('eligible_ids' => $editable_ids, 'locked_ids' => $locked_ids, 'show_subset_caption' => false, 'hide_checkboxes' => $hide_checkboxes); require_once dirname(__FILE__) . '/agents_ui_pp.php'; $pp_agents_ui = pp_init_agents_ui(); $pp_agents_ui->agents_ui($agent_type, $all_groups, $css_id, $stored_groups, $args); if ($edit_membership_link || !$all_groups && $force_display) { ?> <p> <?php if (!$all_groups && $force_display) { _e('This user is not a member of any Permission Groups.', 'pp'); ?> • <?php } ?> <a href='user-edit.php?user_id=<?php echo $user_id; ?> #userprofile_groupsdiv_pp' title='<?php echo esc_attr(__('Edit this user's group membership', 'pp')); ?> '><?php _e('add / edit membership'); ?> </a> <span class="pp-subtext"> <?php $note = apply_filters('pp_user_profile_groups_note', defined('BP_VERSION') ? __('note: BuddyPress Groups and other externally defined groups are not listed here, even if they modify permissions', 'pp') : '', $user_id, $args); echo $note; ?> </span> </p> <?php } echo '</div>'; } // end foreach agent_type echo "<input type='hidden' name='pp_editing_user_groups' value='1' />"; }