/** * BP_Groups_Invite_Template constructor. * * @since 1.5.0 * * @param array $args */ public function __construct($args = array()) { // Backward compatibility with old method of passing arguments. if (!is_array($args) || func_num_args() > 1) { _deprecated_argument(__METHOD__, '2.0.0', 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 => 'group_id'); $func_args = func_get_args(); $args = bp_core_parse_args_array($old_args_keys, $func_args); } $r = wp_parse_args($args, array('page' => 1, 'per_page' => 10, 'page_arg' => 'invitepage', 'user_id' => bp_loggedin_user_id(), 'group_id' => bp_get_current_group_id())); $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']); $iquery = new BP_Group_Member_Query(array('group_id' => $r['group_id'], 'type' => 'first_joined', 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'is_confirmed' => false, 'inviter_id' => $r['user_id'])); $this->invite_data = $iquery->results; $this->total_invite_count = $iquery->total_users; $this->invites = array_values(wp_list_pluck($this->invite_data, 'ID')); $this->invite_count = count($this->invites); // If per_page is set to 0 (show all results), don't generate // pag_links. if (!empty($this->pag_num)) { $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil($this->total_invite_count / $this->pag_num), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1, 'add_args' => array())); } else { $this->pag_links = ''; } }
/** * Constructor method. * * @see bp_has_notifications() For information on the array format. * * @since BuddyPress (1.9.0) * * @param array $args { * An array of arguments. See {@link bp_has_notifications()} * for more details. * } */ public function __construct($args = array()) { // Parse arguments $r = wp_parse_args($args, array('id' => false, 'user_id' => 0, 'item_id' => false, 'secondary_item_id' => false, 'component_name' => bp_notifications_get_registered_components(), 'component_action' => false, 'is_new' => true, 'search_terms' => '', 'order_by' => 'date_notified', 'sort_order' => 'DESC', 'page_arg' => 'npage', 'page' => 1, 'per_page' => 25, 'max' => null, 'meta_query' => false, 'date_query' => false)); // Overrides // Sort order direction $orders = array('ASC', 'DESC'); if (!empty($_GET['sort_order']) && in_array($_GET['sort_order'], $orders)) { $r['sort_order'] = $_GET['sort_order']; } else { $r['sort_order'] = in_array($r['sort_order'], $orders) ? $r['sort_order'] : 'DESC'; } // Setup variables $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']); $this->user_id = $r['user_id']; $this->is_new = $r['is_new']; $this->search_terms = $r['search_terms']; $this->order_by = $r['order_by']; $this->sort_order = $r['sort_order']; $this->query_vars = array('id' => $r['id'], 'user_id' => $this->user_id, 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'component_name' => $r['component_name'], 'component_action' => $r['component_action'], 'meta_query' => $r['meta_query'], 'date_query' => $r['date_query'], 'is_new' => $this->is_new, 'search_terms' => $this->search_terms, 'order_by' => $this->order_by, 'sort_order' => $this->sort_order, 'page' => $this->pag_page, 'per_page' => $this->pag_num); // Setup the notifications to loop through $this->notifications = BP_Notifications_Notification::get($this->query_vars); $this->total_notification_count = BP_Notifications_Notification::get_total_count($this->query_vars); if (empty($this->notifications)) { $this->notification_count = 0; $this->total_notification_count = 0; } else { if (!empty($r['max'])) { if ($r['max'] >= count($this->notifications)) { $this->notification_count = count($this->notifications); } else { $this->notification_count = (int) $r['max']; } } else { $this->notification_count = count($this->notifications); } } if ((int) $this->total_notification_count && (int) $this->pag_num) { $add_args = array('sort_order' => $this->sort_order); $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil((int) $this->total_notification_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Notifications pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Notifications pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => $add_args)); } }
/** * Constructor method. * * The arguments passed to this class constructor are of the same * format as {@link BP_Activity_Activity::get()}. * * @since 1.5.0 * * @see BP_Activity_Activity::get() for a description of the argument * structure, as well as default values. * * @param array $args { * Array of arguments. Supports all arguments from * BP_Activity_Activity::get(), as well as 'page_arg' and * 'include'. Default values for 'per_page' and 'display_comments' * differ from the originating function, and are described below. * @type string $page_arg The string used as a query parameter in * pagination links. Default: 'acpage'. * @type array|bool $include Pass an array of activity IDs to * retrieve only those items, or false to noop the 'include' * parameter. 'include' differs from 'in' in that 'in' forms * an IN clause that works in conjunction with other filters * passed to the function, while 'include' is interpreted as * an exact list of items to retrieve, which skips all other * filter-related parameters. Default: false. * @type int|bool $per_page Default: 20. * @type string|bool $display_comments Default: 'threaded'. * } */ public function __construct($args) { $bp = buddypress(); // Backward compatibility with old method of passing arguments. if (!is_array($args) || func_num_args() > 1) { _deprecated_argument(__METHOD__, '1.6', 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 => 'page', 1 => 'per_page', 2 => 'max', 3 => 'include', 4 => 'sort', 5 => 'filter', 6 => 'search_terms', 7 => 'display_comments', 8 => 'show_hidden', 9 => 'exclude', 10 => 'in', 11 => 'spam', 12 => 'page_arg'); $func_args = func_get_args(); $args = bp_core_parse_args_array($old_args_keys, $func_args); } $defaults = array('page' => 1, 'per_page' => 20, 'page_arg' => 'acpage', 'max' => false, 'fields' => 'all', 'count_total' => false, 'sort' => false, 'include' => false, 'exclude' => false, 'in' => false, 'filter' => false, 'scope' => false, 'search_terms' => false, 'meta_query' => false, 'date_query' => false, 'filter_query' => false, 'display_comments' => 'threaded', 'show_hidden' => false, 'spam' => 'ham_only', 'update_meta_cache' => true); $r = wp_parse_args($args, $defaults); extract($r); $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']); // Check if blog/forum replies are disabled. $this->disable_blogforum_replies = (bool) bp_core_get_root_option('bp-disable-blogforum-comments'); // Get an array of the logged in user's favorite activities. $this->my_favs = maybe_unserialize(bp_get_user_meta(bp_loggedin_user_id(), 'bp_favorite_activities', true)); // Fetch specific activity items based on ID's. if (!empty($include)) { $this->activities = bp_activity_get_specific(array('activity_ids' => explode(',', $include), 'max' => $max, 'count_total' => $count_total, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden, 'spam' => $spam, 'update_meta_cache' => $update_meta_cache)); // Fetch all activity items. } else { $this->activities = bp_activity_get(array('display_comments' => $display_comments, 'max' => $max, 'count_total' => $count_total, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'meta_query' => $meta_query, 'date_query' => $date_query, 'filter_query' => $filter_query, 'filter' => $filter, 'scope' => $scope, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'spam' => $spam, 'update_meta_cache' => $update_meta_cache)); } // The total_activity_count property will be set only if a // 'count_total' query has taken place. if (!is_null($this->activities['total'])) { if (!$max || $max >= (int) $this->activities['total']) { $this->total_activity_count = (int) $this->activities['total']; } else { $this->total_activity_count = (int) $max; } } $this->has_more_items = $this->activities['has_more_items']; $this->activities = $this->activities['activities']; if ($max) { if ($max >= count($this->activities)) { $this->activity_count = count($this->activities); } else { $this->activity_count = (int) $max; } } else { $this->activity_count = count($this->activities); } $this->full_name = bp_get_displayed_user_fullname(); // Fetch parent content for activity comments so we do not have to query in the loop. foreach ((array) $this->activities as $activity) { if ('activity_comment' != $activity->type) { continue; } $parent_ids[] = $activity->item_id; } if (!empty($parent_ids)) { $activity_parents = bp_activity_get_specific(array('activity_ids' => $parent_ids)); } if (!empty($activity_parents['activities'])) { foreach ($activity_parents['activities'] as $parent) { $this->activity_parents[$parent->id] = $parent; } unset($activity_parents); } if ((int) $this->total_activity_count && (int) $this->pag_num) { $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil((int) $this->total_activity_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('←', 'Activity pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Activity pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => array())); } }
/** * Constructor method. * * @see BP_User_Query for an in-depth description of parameters. * * @param string $type Sort order. * @param int $page_number Page of results. * @param int $per_page Number of results per page. * @param int $max Max number of results to return. * @param int $user_id Limit to friends of a user. * @param string $search_terms Limit to users matching search terms. * @param array $include Limit results by these user IDs. * @param bool $populate_extras Fetch optional extras. * @param array $exclude Exclude these IDs from results. * @param array $meta_key Limit to users with a meta_key. * @param array $meta_value Limit to users with a meta_value (with meta_key). * @param string $page_arg Optional. The string used as a query parameter in pagination links. * Default: 'upage'. * @param array|string $member_type Array or comma-separated string of member types to limit results to. * @param array|string $member_type__in Array or comma-separated string of member types to limit results to. * @param array|string $member_type__not_in Array or comma-separated string of member types to exclude * from results. */ function __construct($type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '', $member_type__in = '', $member_type__not_in = '') { $this->pag_arg = sanitize_key($page_arg); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $page_number); $this->pag_num = bp_sanitize_pagination_arg('num', $per_page); $this->type = $type; if (!empty($_REQUEST['letter'])) { $this->members = BP_Core_User::get_users_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude); } else { $this->members = bp_core_get_users(array('type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value, 'member_type' => $member_type, 'member_type__in' => $member_type__in, 'member_type__not_in' => $member_type__not_in)); } if (!$max || $max >= (int) $this->members['total']) { $this->total_member_count = (int) $this->members['total']; } else { $this->total_member_count = (int) $max; } $this->members = $this->members['users']; if ($max) { if ($max >= count($this->members)) { $this->member_count = count($this->members); } else { $this->member_count = (int) $max; } } else { $this->member_count = count($this->members); } if ((int) $this->total_member_count && (int) $this->pag_num) { $pag_args = array($this->pag_arg => '%#%'); if (defined('DOING_AJAX') && true === (bool) DOING_AJAX) { $base = remove_query_arg('s', wp_get_referer()); } else { $base = ''; } /** * Defaults to an empty array to make sure paginate_links() * won't add the $page_arg to the links which would break * pagination in case JavaScript is disabled. */ $add_args = array(); if (!empty($search_terms)) { $query_arg = bp_core_get_component_search_query_arg('members'); $add_args[$query_arg] = urlencode($search_terms); } $this->pag_links = paginate_links(array('base' => add_query_arg($pag_args, $base), 'format' => '', 'total' => ceil((int) $this->total_member_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('←', 'Member pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Member pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => $add_args)); } }
/** * Constructor method. * * @see BP_Blogs_Blog::get() for a description of parameters. * * @param string $type See {@link BP_Blogs_Blog::get()}. * @param string $page See {@link BP_Blogs_Blog::get()}. * @param string $per_page See {@link BP_Blogs_Blog::get()}. * @param string $max See {@link BP_Blogs_Blog::get()}. * @param string $user_id See {@link BP_Blogs_Blog::get()}. * @param string $search_terms See {@link BP_Blogs_Blog::get()}. * @param string $page_arg The string used as a query parameter in * pagination links. Default: 'bpage'. * @param bool $update_meta_cache Whether to pre-fetch metadata for * queried blogs. * @param array|bool $include_blog_ids Array of blog IDs to include. */ public function __construct($type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false) { $this->pag_arg = sanitize_key($page_arg); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $page); $this->pag_num = bp_sanitize_pagination_arg('num', $per_page); // Backwards compatibility support for blogs by first letter if (!empty($_REQUEST['letter'])) { $this->blogs = BP_Blogs_Blog::get_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page); // Typical blogs query } else { $this->blogs = bp_blogs_get_blogs(array('type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'update_meta_cache' => $update_meta_cache, 'include_blog_ids' => $include_blog_ids)); } // Set the total blog count if (empty($max) || $max >= (int) $this->blogs['total']) { $this->total_blog_count = (int) $this->blogs['total']; } else { $this->total_blog_count = (int) $max; } // Set the blogs array (to loop through later $this->blogs = $this->blogs['blogs']; // Get the current blog count to compare maximum against $blog_count = count($this->blogs); // Set the current blog count if (empty($max) || $max >= (int) $blog_count) { $this->blog_count = (int) $blog_count; } else { $this->blog_count = (int) $max; } // Build pagination links based on total blogs and current page number if (!empty($this->total_blog_count) && !empty($this->pag_num)) { $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil((int) $this->total_blog_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('←', 'Blog pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Blog pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => array())); } }
/** * Constructor method. * * @param array $args { * Array of arguments. See bp_has_message_threads() for full description. * } */ public function __construct($args = array()) { // Backward compatibility with old method of passing arguments if (!is_array($args) || func_num_args() > 1) { _deprecated_argument(__METHOD__, '2.2.0', 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 => 'box', 2 => 'per_page', 3 => 'max', 4 => 'type', 5 => 'search_terms', 6 => 'page_arg'); $func_args = func_get_args(); $args = bp_core_parse_args_array($old_args_keys, $func_args); } $r = wp_parse_args($args, array('page' => 1, 'per_page' => 10, 'page_arg' => 'mpage', 'box' => 'inbox', 'type' => 'all', 'user_id' => bp_loggedin_user_id(), 'max' => false, 'search_terms' => '', 'meta_query' => array())); $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']); $this->user_id = $r['user_id']; $this->box = $r['box']; $this->type = $r['type']; $this->search_terms = $r['search_terms']; if ('notices' === $this->box) { $this->threads = BP_Messages_Notice::get_notices(array('pag_num' => $this->pag_num, 'pag_page' => $this->pag_page)); } else { $threads = BP_Messages_Thread::get_current_threads_for_user(array('user_id' => $this->user_id, 'box' => $this->box, 'type' => $this->type, 'limit' => $this->pag_num, 'page' => $this->pag_page, 'search_terms' => $this->search_terms, 'meta_query' => $r['meta_query'])); $this->threads = $threads['threads']; $this->total_thread_count = $threads['total']; } if (!$this->threads) { $this->thread_count = 0; $this->total_thread_count = 0; } else { $total_notice_count = BP_Messages_Notice::get_total_notice_count(); if (empty($r['max']) || (int) $r['max'] >= (int) $total_notice_count) { if ('notices' === $this->box) { $this->total_thread_count = (int) $total_notice_count; } } else { $this->total_thread_count = (int) $r['max']; } if (!empty($r['max'])) { if ((int) $r['max'] >= count($this->threads)) { $this->thread_count = count($this->threads); } else { $this->thread_count = (int) $r['max']; } } else { $this->thread_count = count($this->threads); } } if ((int) $this->total_thread_count && (int) $this->pag_num) { $pag_args = array($r['page_arg'] => '%#%'); if (defined('DOING_AJAX') && true === (bool) DOING_AJAX) { $base = remove_query_arg('s', wp_get_referer()); } else { $base = ''; } $add_args = array(); if (!empty($this->search_terms)) { $add_args['s'] = $this->search_terms; } $this->pag_links = paginate_links(array('base' => add_query_arg($pag_args, $base), 'format' => '', 'total' => ceil((int) $this->total_thread_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Message pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Message pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => $add_args)); } }
/** * Constructor method. * * @since 1.5.0 * * @param array $args { * @type int $group_id ID of the group whose membership requests * are being queried. Default: current group id. * @type int $per_page Number of records to return per page of * results. Default: 10. * @type int $page Page of results to show. Default: 1. * @type int $max Max items to return. Default: false (show all) * } */ public function __construct($args = array()) { // Backward compatibility with old method of passing arguments. if (!is_array($args) || func_num_args() > 1) { _deprecated_argument(__METHOD__, '2.0.0', 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 => 'group_id', 1 => 'per_page', 2 => 'max'); $func_args = func_get_args(); $args = bp_core_parse_args_array($old_args_keys, $func_args); } $r = wp_parse_args($args, array('page' => 1, 'per_page' => 10, 'page_arg' => 'mrpage', 'max' => false, 'type' => 'first_joined', 'group_id' => bp_get_current_group_id())); $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']); $mquery = new BP_Group_Member_Query(array('group_id' => $r['group_id'], 'type' => $r['type'], 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'is_confirmed' => false, 'inviter_id' => 0)); $this->requests = array_values($mquery->results); $this->request_count = count($this->requests); // Compatibility with legacy format of request data objects. foreach ($this->requests as $rk => $rv) { // For legacy reasons, the 'id' property of each // request must match the membership id, not the ID of // the user (as it's returned by BP_Group_Member_Query). $this->requests[$rk]->user_id = $rv->ID; $this->requests[$rk]->id = $rv->membership_id; // Miscellaneous values. $this->requests[$rk]->group_id = $r['group_id']; } if (empty($r['max']) || $r['max'] >= (int) $mquery->total_users) { $this->total_request_count = (int) $mquery->total_users; } else { $this->total_request_count = (int) $r['max']; } if (empty($r['max']) || $r['max'] >= count($this->requests)) { $this->request_count = count($this->requests); } else { $this->request_count = (int) $r['max']; } $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil($this->total_request_count / $this->pag_num), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1, 'add_args' => array())); }
/** * @group pagination * @group bp_sanitize_pagination_arg */ public function test_bp_sanitize_pagination_arg_negative() { $request = $_REQUEST; $arg = 'bp_pagination_test'; $page = 25; $_REQUEST[$arg] = '-25'; $value = bp_sanitize_pagination_arg($arg, $page); $this->assertEquals($value, $page); $_REQUEST = $request; }
/** * Constructor. * * @since 1.5.0 * * @param array $args { * An array of optional arguments. * @type int $group_id ID of the group whose members are being * queried. Default: current group ID. * @type int $page Page of results to be queried. Default: 1. * @type int $per_page Number of items to return per page of * results. Default: 20. * @type int $max Optional. Max number of items to return. * @type array $exclude Optional. Array of user IDs to exclude. * @type bool|int $exclude_admin_mods True (or 1) to exclude admins and mods from * results. Default: 1. * @type bool|int $exclude_banned True (or 1) to exclude banned users from results. * Default: 1. * @type array $group_role Optional. Array of group roles to include. * @type string $search_terms Optional. Search terms to match. * } */ public function __construct($args = array()) { // Backward compatibility with old method of passing arguments. if (!is_array($args) || func_num_args() > 1) { _deprecated_argument(__METHOD__, '2.0.0', 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 => 'group_id', 1 => 'per_page', 2 => 'max', 3 => 'exclude_admins_mods', 4 => 'exclude_banned', 5 => 'exclude', 6 => 'group_role'); $func_args = func_get_args(); $args = bp_core_parse_args_array($old_args_keys, $func_args); } $r = wp_parse_args($args, array('group_id' => bp_get_current_group_id(), 'page' => 1, 'per_page' => 20, 'page_arg' => 'mlpage', 'max' => false, 'exclude' => false, 'exclude_admins_mods' => 1, 'exclude_banned' => 1, 'group_role' => false, 'search_terms' => false, 'type' => 'last_joined')); $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']); /** * Check the current group is the same as the supplied group ID. * It can differ when using {@link bp_group_has_members()} outside the Groups screens. */ $current_group = groups_get_current_group(); if (empty($current_group) || $current_group && $current_group->id !== bp_get_current_group_id()) { $current_group = groups_get_group(array('group_id' => $r['group_id'])); } // Assemble the base URL for pagination. $base_url = trailingslashit(bp_get_group_permalink($current_group) . bp_current_action()); if (bp_action_variable()) { $base_url = trailingslashit($base_url . bp_action_variable()); } $members_args = $r; $members_args['page'] = $this->pag_page; $members_args['per_page'] = $this->pag_num; // Get group members for this loop. $this->members = groups_get_group_members($members_args); if (empty($r['max']) || $r['max'] >= (int) $this->members['count']) { $this->total_member_count = (int) $this->members['count']; } else { $this->total_member_count = (int) $r['max']; } // Reset members array for subsequent looping. $this->members = $this->members['members']; if (empty($r['max']) || $r['max'] >= count($this->members)) { $this->member_count = (int) count($this->members); } else { $this->member_count = (int) $r['max']; } $this->pag_links = paginate_links(array('base' => add_query_arg(array($this->pag_arg => '%#%'), $base_url), 'format' => '', 'total' => !empty($this->pag_num) ? ceil($this->total_member_count / $this->pag_num) : $this->total_member_count, 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1, 'add_args' => array())); }
/** * Constructor method. * * @see BP_Groups_Group::get() for an in-depth description of arguments. * * @param array $args { * Array of arguments. Accepts all arguments accepted by * {@link BP_Groups_Group::get()}. In cases where the default * values of the params differ, they have been discussed below. * @type int $per_page Default: 20. * @type int $page Default: 1. * } */ 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('page' => 1, 'per_page' => 20, 'page_arg' => 'grpage', 'max' => false, 'type' => 'active', 'order' => 'DESC', 'orderby' => 'date_created', 'show_hidden' => false, 'user_id' => 0, 'slug' => false, 'include' => false, 'exclude' => false, 'parent_id' => null, 'search_terms' => '', 'group_type' => '', 'group_type__in' => '', 'group_type__not_in' => '', 'meta_query' => false, 'update_meta_cache' => true, 'update_admin_cache' => false); $r = wp_parse_args($args, $defaults); extract($r); $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['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); } elseif ('single-group' == $type) { $this->single_group = true; if (groups_get_current_group()) { $group = groups_get_current_group(); } else { $group = groups_get_group(BP_Groups_Group::get_id_from_slug($r['slug'])); } // 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, 'group_type' => $group_type, 'group_type__in' => $group_type__in, 'group_type__not_in' => $group_type__not_in, 'include' => $include, 'exclude' => $exclude, 'parent_id' => $parent_id, 'update_meta_cache' => $update_meta_cache, 'update_admin_cache' => $update_admin_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']; } elseif ('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) { $pag_args = array($this->pag_arg => '%#%'); if (defined('DOING_AJAX') && true === (bool) DOING_AJAX) { $base = remove_query_arg('s', wp_get_referer()); } else { $base = ''; } $add_args = array('num' => $this->pag_num, 'sortby' => $this->sort_by, 'order' => $this->order); if (!empty($search_terms)) { $query_arg = bp_core_get_component_search_query_arg('groups'); $add_args[$query_arg] = urlencode($search_terms); } $this->pag_links = paginate_links(array('base' => add_query_arg($pag_args, $base), '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, 'add_args' => $add_args)); } }