public static function get_pp_groups_for_user($user_id, $args = array()) { $defaults = array('agent_type' => 'pp_group', 'member_type' => 'member', 'status' => 'active', 'cols' => 'all', 'metagroup_type' => null, 'force_refresh' => false, 'query_user_ids' => false); $args = array_merge($defaults, $args); if (is_null($args['metagroup_type'])) { unset($args['metagroup_type']); } extract($args, EXTR_SKIP); global $wpdb; $groups_table = apply_filters('pp_use_groups_table', $wpdb->pp_groups, $agent_type); $members_table = apply_filters('pp_use_group_members_table', $wpdb->pp_group_members, $agent_type); if (empty($members_table)) { return array(); } if ($cols == 'all' || !empty($metagroup_type)) { $join = apply_filters('pp_get_groups_for_user_join', "INNER JOIN {$groups_table} AS g ON {$members_table}.group_id = g.ID", $user_id, $args); } else { $join = ''; } if ('any' == $status) { $status = ''; } $status_clause = $status ? $wpdb->prepare("AND status = %s", $status) : ''; $metagroup_clause = !empty($metagroup_type) ? $wpdb->prepare("AND g.metagroup_type = %s", $metagroup_type) : ''; $user_id = (int) $user_id; $user_groups = array(); if ('pp_group' == $agent_type) { static $all_group; static $auth_group; if (!pp_is_content_administrator() || !pp_get_option('suppress_administrator_metagroups')) { if (!isset($all_group)) { $all_group = pp_get_metagroup('wp_role', 'wp_all'); } if (!isset($auth_group)) { $auth_group = pp_get_metagroup('wp_role', 'wp_auth'); } } } if ('all' == $cols) { $query = "SELECT * FROM {$members_table} {$join} WHERE user_id = '{$user_id}' AND member_type = '{$member_type}' {$status_clause} {$metagroup_clause} ORDER BY {$members_table}.group_id"; $results = $wpdb->get_results($query); foreach ($results as $row) { $user_groups[$row->group_id] = (object) (array) $row; } // force storage by value if ('pp_group' == $agent_type) { if ($all_group) { $user_groups[$all_group->ID] = $all_group; } if ($auth_group) { $user_groups[$auth_group->ID] = $auth_group; } } $user_groups = apply_filters('pp_get_pp_groups_for_user', $user_groups, $results, $user_id, $args); } else { if ($query_user_ids) { static $user_groups; if (!isset($user_groups)) { $user_groups = array(); } if (!isset($user_groups[$agent_type])) { $user_groups[$agent_type] = array(); } } else { $user_groups = array($agent_type => array()); $query_user_ids = $user_id; } if (!isset($user_groups[$agent_type][$user_id]) || $force_refresh) { $query = "SELECT user_id, group_id, add_date_gmt FROM {$members_table} {$join} WHERE user_id IN ('" . implode("','", (array) $query_user_ids) . "') AND member_type = '{$member_type}' {$status_clause} {$metagroup_clause} ORDER BY group_id"; $results = $wpdb->get_results($query); foreach ($results as $row) { $user_groups[$agent_type][$row->user_id][$row->group_id] = $row->add_date_gmt; } } if ('pp_group' == $agent_type) { foreach ((array) $query_user_ids as $_user_id) { if ($all_group) { $user_groups[$agent_type][$_user_id][$all_group->ID] = '0000-00-00 00:00:00'; } if ($auth_group) { $user_groups[$agent_type][$_user_id][$auth_group->ID] = '0000-00-00 00:00:00'; } } } return isset($user_groups[$agent_type][$user_id]) ? $user_groups[$agent_type][$user_id] : array(); } return $user_groups; }
?> <?php if ('user' == $agent_type && $agent_id) { global $wp_roles; $user = new WP_User($agent_id); $primary_role = reset($user->roles); if (isset($wp_roles->role_names[$primary_role])) { ?> <tr> <th><label><!-- <label for="user_login"> --><?php echo __('Primary Role:', 'pp'); ?> </label></th> <td><?php if ($role_group_id = pp_get_metagroup('wp_role', $primary_role, array('cols' => 'id'))) { echo "<a href='admin.php?page=pp-edit-permissions&action=edit&agent_type=pp_group&agent_id={$role_group_id}'>{$wp_roles->role_names[$primary_role]}</a>"; } else { echo $wp_roles->role_names[$primary_role]; } ?> </td> </tr> <?php } } elseif ($agent_id) { ?> <tr> <th><label for="description"><?php echo __ppw('Description:', 'pp'); ?>
function _get_pp_groups($args = array()) { $args = (array) $args; if (!$this->ID) { $user_groups = array(); if (pp_get_option('anonymous_unfiltered')) { $this->allcaps['pp_unfiltered'] = true; } else { if ($anon_group = pp_get_metagroup('wp_role', 'wp_anon')) { $user_groups[$anon_group->ID] = $anon_group; } if ($all_group = pp_get_metagroup('wp_role', 'wp_all')) { $user_groups[$all_group->ID] = $all_group; } } } else { $user_groups = pp_get_groups_for_user($this->ID, $args['agent_type'], $args); if (isset($this->roles)) { if (pp_get_option('dynamic_wp_roles') || defined('PP_FORCE_DYNAMIC_ROLES')) { $have_role_group_names = array(); foreach ($user_groups as $group) { if ('wp_role' == $group->metagroup_type) { $have_role_group_names[] = $group->metagroup_id; } } if ($missing_role_group_names = array_diff($this->roles, $have_role_group_names)) { global $wpdb; $groups_table = apply_filters('pp_use_groups_table', $wpdb->pp_groups); $add_metagroups = $wpdb->get_results("SELECT * FROM {$groups_table} WHERE metagroup_type = 'wp_role' AND metagroup_id IN ('" . implode("','", $missing_role_group_names) . "')"); foreach ($add_metagroups as $row) { $row->group_id = $row->ID; $row->status = 'active'; $user_groups[$row->ID] = $row; } } } } } return $user_groups; }