[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Groups group members loop template class. 4 * 5 * @package BuddyPress 6 * @since 1.1.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Group Members Loop template class. 14 * 15 * @since 1.0.0 16 */ 17 class BP_Groups_Group_Members_Template { 18 19 /** 20 * @since 1.0.0 21 * @var int 22 */ 23 public $current_member = -1; 24 25 /** 26 * @since 1.0.0 27 * @var int 28 */ 29 public $member_count; 30 31 /** 32 * @since 1.0.0 33 * @var array 34 */ 35 public $members; 36 37 /** 38 * @since 1.0.0 39 * @var object 40 */ 41 public $member; 42 43 /** 44 * @since 1.0.0 45 * @var bool 46 */ 47 public $in_the_loop; 48 49 /** 50 * @since 1.0.0 51 * @var int 52 */ 53 public $pag_page; 54 55 /** 56 * @since 1.0.0 57 * @var int 58 */ 59 public $pag_num; 60 61 /** 62 * @since 1.0.0 63 * @var array|string|void 64 */ 65 public $pag_links; 66 67 /** 68 * @since 1.0.0 69 * @var int 70 */ 71 public $total_group_count; 72 73 /** 74 * Constructor. 75 * 76 * @since 1.5.0 77 * 78 * @param array $args { 79 * An array of optional arguments. 80 * @type int $group_id ID of the group whose members are being 81 * queried. Default: current group ID. 82 * @type int $page Page of results to be queried. Default: 1. 83 * @type int $per_page Number of items to return per page of 84 * results. Default: 20. 85 * @type int $max Optional. Max number of items to return. 86 * @type array $exclude Optional. Array of user IDs to exclude. 87 * @type bool|int $exclude_admin_mods True (or 1) to exclude admins and mods from 88 * results. Default: 1. 89 * @type bool|int $exclude_banned True (or 1) to exclude banned users from results. 90 * Default: 1. 91 * @type array $group_role Optional. Array of group roles to include. 92 * @type string $search_terms Optional. Search terms to match. 93 * } 94 */ 95 public function __construct( $args = array() ) { 96 $function_args = func_get_args(); 97 98 // Backward compatibility with old method of passing arguments. 99 if ( ! is_array( $args ) || count( $function_args ) > 1 ) { 100 /* translators: 1: the name of the method. 2: the name of the file. */ 101 _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__ ) ); 102 103 $old_args_keys = array( 104 0 => 'group_id', 105 1 => 'per_page', 106 2 => 'max', 107 3 => 'exclude_admins_mods', 108 4 => 'exclude_banned', 109 5 => 'exclude', 110 6 => 'group_role', 111 ); 112 113 $args = bp_core_parse_args_array( $old_args_keys, $function_args ); 114 } 115 116 $r = bp_parse_args( $args, array( 117 'group_id' => bp_get_current_group_id(), 118 'page' => 1, 119 'per_page' => 20, 120 'page_arg' => 'mlpage', 121 'max' => false, 122 'exclude' => false, 123 'exclude_admins_mods' => 1, 124 'exclude_banned' => 1, 125 'group_role' => false, 126 'search_terms' => false, 127 'type' => 'last_joined', 128 ), 'group_members_template' ); 129 130 $this->pag_arg = sanitize_key( $r['page_arg'] ); 131 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] ); 132 $this->pag_num = bp_sanitize_pagination_arg( 'num', $r['per_page'] ); 133 134 /** 135 * Check the current group is the same as the supplied group ID. 136 * It can differ when using {@link bp_group_has_members()} outside the Groups screens. 137 */ 138 $current_group = groups_get_current_group(); 139 if ( empty( $current_group ) || ( $current_group && $current_group->id !== bp_get_current_group_id() ) ) { 140 $current_group = groups_get_group( $r['group_id'] ); 141 } 142 143 // Assemble the base URL for pagination. 144 $base_url = trailingslashit( bp_get_group_permalink( $current_group ) . bp_current_action() ); 145 if ( bp_action_variable() ) { 146 $base_url = trailingslashit( $base_url . bp_action_variable() ); 147 } 148 149 $members_args = $r; 150 151 $members_args['page'] = $this->pag_page; 152 $members_args['per_page'] = $this->pag_num; 153 154 // Get group members for this loop. 155 $this->members = groups_get_group_members( $members_args ); 156 157 if ( empty( $r['max'] ) || ( $r['max'] >= (int) $this->members['count'] ) ) { 158 $this->total_member_count = (int) $this->members['count']; 159 } else { 160 $this->total_member_count = (int) $r['max']; 161 } 162 163 // Reset members array for subsequent looping. 164 $this->members = $this->members['members']; 165 166 if ( empty( $r['max'] ) || ( $r['max'] >= count( $this->members ) ) ) { 167 $this->member_count = (int) count( $this->members ); 168 } else { 169 $this->member_count = (int) $r['max']; 170 } 171 172 $this->pag_links = paginate_links( array( 173 'base' => add_query_arg( array( $this->pag_arg => '%#%' ), $base_url ), 174 'format' => '', 175 'total' => ! empty( $this->pag_num ) ? ceil( $this->total_member_count / $this->pag_num ) : $this->total_member_count, 176 'current' => $this->pag_page, 177 'prev_text' => '←', 178 'next_text' => '→', 179 'mid_size' => 1, 180 'add_args' => array(), 181 ) ); 182 } 183 184 /** 185 * Whether or not there are members to display. 186 * 187 * @since 1.0.0 188 * 189 * @return bool 190 */ 191 public function has_members() { 192 if ( ! empty( $this->member_count ) ) { 193 return true; 194 } 195 196 return false; 197 } 198 199 /** 200 * Increments to the next member to display. 201 * 202 * @since 1.0.0 203 * 204 * @return object 205 */ 206 public function next_member() { 207 $this->current_member++; 208 $this->member = $this->members[ $this->current_member ]; 209 210 return $this->member; 211 } 212 213 /** 214 * Rewinds to the first member to display. 215 * 216 * @since 1.0.0 217 */ 218 public function rewind_members() { 219 $this->current_member = -1; 220 if ( $this->member_count > 0 ) { 221 $this->member = $this->members[0]; 222 } 223 } 224 225 /** 226 * Finishes up the members for display. 227 * 228 * @since 1.0.0 229 * 230 * @return bool 231 */ 232 public function members() { 233 $tick = intval( $this->current_member + 1 ); 234 if ( $tick < $this->member_count ) { 235 return true; 236 } elseif ( $tick == $this->member_count ) { 237 238 /** 239 * Fires right before the rewinding of members list. 240 * 241 * @since 1.0.0 242 * @since 2.3.0 `$this` parameter added. 243 * @since 2.7.0 Action renamed from `loop_end`. 244 * 245 * @param BP_Groups_Group_Members_Template $this Instance of the current Members template. 246 */ 247 do_action( 'group_members_loop_end', $this ); 248 249 // Do some cleaning up after the loop. 250 $this->rewind_members(); 251 } 252 253 $this->in_the_loop = false; 254 return false; 255 } 256 257 /** 258 * Sets up the member to display. 259 * 260 * @since 1.0.0 261 */ 262 public function the_member() { 263 $this->in_the_loop = true; 264 $this->member = $this->next_member(); 265 266 // Loop has just started. 267 if ( 0 == $this->current_member ) { 268 269 /** 270 * Fires if the current member item is the first in the members list. 271 * 272 * @since 1.0.0 273 * @since 2.3.0 `$this` parameter added. 274 * @since 2.7.0 Action renamed from `loop_start`. 275 * 276 * @param BP_Groups_Group_Members_Template $this Instance of the current Members template. 277 */ 278 do_action( 'group_members_loop_start', $this ); 279 } 280 } 281 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Jan 26 01:01:37 2021 | Cross-referenced by PHPXref 0.7.1 |