function bp_groups_template( $user_id, $type, $page, $per_page, $max, $slug, $search_terms, $populate_extras ) { global $bp; $this->pag_page = isset( $_REQUEST['grpage'] ) ? intval( $_REQUEST['grpage'] ) : $page; $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; if ( 'invites' == $type ) { $this->groups = groups_get_invites_for_user( $user_id, $this->pag_num, $this->pag_page ); } else if ( 'single-group' == $type ) { $group = new stdClass; $group->group_id = BP_Groups_Group::get_id_from_slug($slug); $this->groups = array( $group ); } else { $this->groups = groups_get_groups( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' =>$this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) ); } if ( 'invites' == $type ) { $this->total_group_count = (int)$this->groups['total']; $this->group_count = (int)$this->groups['total']; $this->groups = $this->groups['groups']; } else if ( 'single-group' == $type ) { $this->single_group = true; $this->total_group_count = 1; $this->group_count = 1; } else { if ( !$max || $max >= (int)$this->groups['total'] ) { $this->total_group_count = (int)$this->groups['total']; } else { $this->total_group_count = (int)$max; } $this->groups = $this->groups['groups']; if ( $max ) { if ( $max >= count($this->groups) ) { $this->group_count = count( $this->groups ); } else { $this->group_count = (int)$max; } } else { $this->group_count = count( $this->groups ); } } // Build pagination links if ( (int)$this->total_group_count && (int)$this->pag_num ) { $this->pag_links = paginate_links( array( 'base' => add_query_arg( array( 'grpage' => '%#%', 'num' => $this->pag_num, 's' => $search_terms, 'sortby' => $this->sort_by, 'order' => $this->order ) ), 'format' => '', 'total' => ceil( (int)$this->total_group_count / (int)$this->pag_num ), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1 ) ); } }
function ajax_navigation_func() { $notifyAmount = bp_notifications_get_unread_notification_count(bp_loggedin_user_id()); $messageAmount = messages_get_unread_count(); $friendRequests = bp_friend_get_total_requests_count(); $groups = groups_get_invites_for_user(bp_loggedin_user_id()); $groupInvites = $groups['total']; $navigationData = array('notifyAmount' => $notifyAmount, 'messageAmount' => $messageAmount, 'friendRequests' => $friendRequests, 'groupInvites' => $groupInvites); echo json_encode($navigationData); die; }
function __construct($args = array()) { // Backward compatibility with old method of passing arguments if (!is_array($args) || func_num_args() > 1) { _deprecated_argument(__METHOD__, '1.7', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__)); $old_args_keys = array(0 => 'user_id', 1 => 'type', 2 => 'page', 3 => 'per_page', 4 => 'max', 5 => 'slug', 6 => 'search_terms', 7 => 'populate_extras', 8 => 'include', 9 => 'exclude', 10 => 'show_hidden', 11 => 'page_arg'); $func_args = func_get_args(); $args = bp_core_parse_args_array($old_args_keys, $func_args); } $defaults = array('type' => 'active', 'page' => 1, 'per_page' => 20, 'max' => false, 'show_hidden' => false, 'page_arg' => 'grpage', 'user_id' => 0, 'slug' => false, 'include' => false, 'exclude' => false, 'search_terms' => '', 'meta_query' => false, 'populate_extras' => true, 'update_meta_cache' => true); $r = wp_parse_args($args, $defaults); extract($r); $this->pag_page = isset($_REQUEST[$page_arg]) ? intval($_REQUEST[$page_arg]) : $page; $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page; if (bp_current_user_can('bp_moderate') || is_user_logged_in() && $user_id == bp_loggedin_user_id()) { $show_hidden = true; } if ('invites' == $type) { $this->groups = groups_get_invites_for_user($user_id, $this->pag_num, $this->pag_page, $exclude); } else { if ('single-group' == $type) { $this->single_group = true; if (groups_get_current_group()) { $group = groups_get_current_group(); } else { $group = groups_get_group(array('group_id' => BP_Groups_Group::get_id_from_slug($r['slug']), 'populate_extras' => $r['populate_extras'])); } // backwards compatibility - the 'group_id' variable is not part of the // BP_Groups_Group object, but we add it here for devs doing checks against it // // @see https://buddypress.trac.wordpress.org/changeset/3540 // // this is subject to removal in a future release; devs should check against // $group->id instead $group->group_id = $group->id; $this->groups = array($group); } else { $this->groups = groups_get_groups(array('type' => $type, 'order' => $order, 'orderby' => $orderby, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'meta_query' => $meta_query, 'include' => $include, 'exclude' => $exclude, 'populate_extras' => $populate_extras, 'update_meta_cache' => $update_meta_cache, 'show_hidden' => $show_hidden)); } } if ('invites' == $type) { $this->total_group_count = (int) $this->groups['total']; $this->group_count = (int) $this->groups['total']; $this->groups = $this->groups['groups']; } else { if ('single-group' == $type) { if (empty($group->id)) { $this->total_group_count = 0; $this->group_count = 0; } else { $this->total_group_count = 1; $this->group_count = 1; } } else { if (empty($max) || $max >= (int) $this->groups['total']) { $this->total_group_count = (int) $this->groups['total']; } else { $this->total_group_count = (int) $max; } $this->groups = $this->groups['groups']; if (!empty($max)) { if ($max >= count($this->groups)) { $this->group_count = count($this->groups); } else { $this->group_count = (int) $max; } } else { $this->group_count = count($this->groups); } } } // Build pagination links if ((int) $this->total_group_count && (int) $this->pag_num) { $this->pag_links = paginate_links(array('base' => add_query_arg(array($page_arg => '%#%', 'num' => $this->pag_num, 's' => $search_terms, 'sortby' => $this->sort_by, 'order' => $this->order)), 'format' => '', 'total' => ceil((int) $this->total_group_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Group pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Group pagination next text', 'buddypress'), 'mid_size' => 1)); } }
function __construct($user_id, $type, $page, $per_page, $max, $slug, $search_terms, $populate_extras, $include = false, $exclude = false, $show_hidden = false) { global $bp; $this->pag_page = isset($_REQUEST['grpage']) ? intval($_REQUEST['grpage']) : $page; $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page; if (bp_current_user_can('bp_moderate') || is_user_logged_in() && $user_id == bp_loggedin_user_id()) { $show_hidden = true; } if ('invites' == $type) { $this->groups = groups_get_invites_for_user($user_id, $this->pag_num, $this->pag_page, $exclude); } else { if ('single-group' == $type) { $group = new stdClass(); $group->group_id = BP_Groups_Group::get_id_from_slug($slug); $this->groups = array($group); } else { $this->groups = groups_get_groups(array('type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'include' => $include, 'exclude' => $exclude, 'populate_extras' => $populate_extras, 'show_hidden' => $show_hidden)); } } if ('invites' == $type) { $this->total_group_count = (int) $this->groups['total']; $this->group_count = (int) $this->groups['total']; $this->groups = $this->groups['groups']; } else { if ('single-group' == $type) { $this->single_group = true; $this->total_group_count = 1; $this->group_count = 1; } else { if (empty($max) || $max >= (int) $this->groups['total']) { $this->total_group_count = (int) $this->groups['total']; } else { $this->total_group_count = (int) $max; } $this->groups = $this->groups['groups']; if (!empty($max)) { if ($max >= count($this->groups)) { $this->group_count = count($this->groups); } else { $this->group_count = (int) $max; } } else { $this->group_count = count($this->groups); } } } // Build pagination links if ((int) $this->total_group_count && (int) $this->pag_num) { $this->pag_links = paginate_links(array('base' => add_query_arg(array('grpage' => '%#%', 'num' => $this->pag_num, 's' => $search_terms, 'sortby' => $this->sort_by, 'order' => $this->order)), 'format' => '', 'total' => ceil((int) $this->total_group_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Group pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Group pagination next text', 'buddypress'), 'mid_size' => 1)); } }
/** * @group groups_get_invites_for_user * @group group_invitations * @group group_membership */ public function test_groups_get_invites_for_user_with_exclude() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $g1 = $this->factory->group->create(array('creator_id' => $u1)); $g2 = $this->factory->group->create(array('creator_id' => $u1)); $g3 = $this->factory->group->create(array('creator_id' => $u1)); self::invite_user_to_group($u2, $g1, $u1); self::invite_user_to_group($u2, $g2, $u1); self::invite_user_to_group($u2, $g3, $u1); $groups = groups_get_invites_for_user($u2, false, false, array($g2)); $this->assertEqualSets(array($g1, $g3), wp_list_pluck($groups['groups'], 'id')); }
/** * Set up the Toolbar * * @global BuddyPress $bp The one true BuddyPress instance */ function setup_admin_bar() { global $bp; // Prevent debug notices $wp_admin_nav = array(); // Menus for logged in user if (is_user_logged_in()) { // Setup the logged in user variables $user_domain = bp_loggedin_user_domain(); $groups_link = trailingslashit($user_domain . $this->slug); // Pending group invites $count = groups_get_invites_for_user(bp_loggedin_user_id()); $title = __('Groups', 'buddypress'); $pending = __('No Pending Invites', 'buddypress'); if (!empty($count['total'])) { $title = sprintf(__('Groups <span class="count">%s</span>', 'buddypress'), $count['total']); $pending = sprintf(__('Pending Invites <span class="count">%s</span>', 'buddypress'), $count['total']); } // Add the "My Account" sub menus $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => trailingslashit($groups_link)); // My Groups $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-memberships', 'title' => __('Memberships', 'buddypress'), 'href' => trailingslashit($groups_link)); // Invitations $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-invites', 'title' => $pending, 'href' => trailingslashit($groups_link . 'invites')); } parent::setup_admin_bar($wp_admin_nav); }
function bp_groups_user_groups_template($user_id, $type, $per_page, $max, $slug, $filter) { global $bp; if (!$user_id) { $user_id = $bp->displayed_user->id; } $this->pag_page = isset($_REQUEST['grpage']) ? intval($_REQUEST['grpage']) : 1; $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page; switch ($type) { case 'recently-joined': $this->groups = groups_get_recently_joined_for_user($user_id, $this->pag_num, $this->pag_page, $filter); break; case 'popular': $this->groups = groups_get_most_popular_for_user($user_id, $this->pag_num, $this->pag_page, $filter); break; case 'admin-of': $this->groups = groups_get_user_is_admin_of($user_id, $this->pag_num, $this->pag_page, $filter); break; case 'mod-of': $this->groups = groups_get_user_is_mod_of($user_id, $this->pag_num, $this->pag_page, $filter); break; case 'alphabetical': $this->groups = groups_get_alphabetically_for_user($user_id, $this->pag_num, $this->pag_page, $filter); break; case 'invites': $this->groups = groups_get_invites_for_user(); break; case 'single-group': $group = new stdClass(); $group->group_id = BP_Groups_Group::get_id_from_slug($slug); $this->groups = array($group); break; case 'active': default: $this->groups = groups_get_recently_active_for_user($user_id, $this->pag_num, $this->pag_page, $filter); break; } if ('invites' == $type) { $this->total_group_count = count($this->groups); $this->group_count = count($this->groups); } else { if ('single-group' == $type) { $this->single_group = true; $this->total_group_count = 1; $this->group_count = 1; } else { if (!$max) { $this->total_group_count = (int) $this->groups['total']; } else { $this->total_group_count = (int) $max; } $this->groups = $this->groups['groups']; if ($max) { if ($max >= count($this->groups)) { $this->group_count = count($this->groups); } else { $this->group_count = (int) $max; } } else { $this->group_count = count($this->groups); } } } $this->pag_links = paginate_links(array('base' => add_query_arg(array('grpage' => '%#%', 'num' => $this->pag_num, 's' => $_REQUEST['s'], 'sortby' => $this->sort_by, 'order' => $this->order)), 'format' => '', 'total' => ceil($this->total_group_count / $this->pag_num), 'current' => $this->pag_page, 'prev_text' => '«', 'next_text' => '»', 'mid_size' => 1)); }