[ 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( 117 $args, 118 array( 119 'group_id' => bp_get_current_group_id(), 120 'page' => 1, 121 'per_page' => 20, 122 'page_arg' => 'mlpage', 123 'max' => false, 124 'exclude' => false, 125 'exclude_admins_mods' => 1, 126 'exclude_banned' => 1, 127 'group_role' => false, 128 'search_terms' => false, 129 'type' => 'last_joined', 130 ), 131 'group_members_template' 132 ); 133 134 $this->pag_arg = sanitize_key( $r['page_arg'] ); 135 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] ); 136 $this->pag_num = bp_sanitize_pagination_arg( 'num', $r['per_page'] ); 137 138 /** 139 * Check the current group is the same as the supplied group ID. 140 * It can differ when using {@link bp_group_has_members()} outside the Groups screens. 141 */ 142 $current_group = groups_get_current_group(); 143 if ( empty( $current_group ) || ( $current_group && $current_group->id !== bp_get_current_group_id() ) ) { 144 $current_group = groups_get_group( $r['group_id'] ); 145 } 146 147 // Assemble the base URL for pagination. 148 $base_url = trailingslashit( bp_get_group_permalink( $current_group ) . bp_current_action() ); 149 if ( bp_action_variable() ) { 150 $base_url = trailingslashit( $base_url . bp_action_variable() ); 151 } 152 153 $members_args = $r; 154 155 $members_args['page'] = $this->pag_page; 156 $members_args['per_page'] = $this->pag_num; 157 158 // Get group members for this loop. 159 $this->members = groups_get_group_members( $members_args ); 160 161 if ( empty( $r['max'] ) || ( $r['max'] >= (int) $this->members['count'] ) ) { 162 $this->total_member_count = (int) $this->members['count']; 163 } else { 164 $this->total_member_count = (int) $r['max']; 165 } 166 167 // Reset members array for subsequent looping. 168 $this->members = $this->members['members']; 169 170 if ( empty( $r['max'] ) || ( $r['max'] >= count( $this->members ) ) ) { 171 $this->member_count = (int) count( $this->members ); 172 } else { 173 $this->member_count = (int) $r['max']; 174 } 175 176 $this->pag_links = paginate_links( array( 177 'base' => add_query_arg( array( $this->pag_arg => '%#%' ), $base_url ), 178 'format' => '', 179 'total' => ! empty( $this->pag_num ) ? ceil( $this->total_member_count / $this->pag_num ) : $this->total_member_count, 180 'current' => $this->pag_page, 181 'prev_text' => '←', 182 'next_text' => '→', 183 'mid_size' => 1, 184 'add_args' => array(), 185 ) ); 186 } 187 188 /** 189 * Whether or not there are members to display. 190 * 191 * @since 1.0.0 192 * 193 * @return bool 194 */ 195 public function has_members() { 196 if ( ! empty( $this->member_count ) ) { 197 return true; 198 } 199 200 return false; 201 } 202 203 /** 204 * Increments to the next member to display. 205 * 206 * @since 1.0.0 207 * 208 * @return object 209 */ 210 public function next_member() { 211 $this->current_member++; 212 $this->member = $this->members[ $this->current_member ]; 213 214 return $this->member; 215 } 216 217 /** 218 * Rewinds to the first member to display. 219 * 220 * @since 1.0.0 221 */ 222 public function rewind_members() { 223 $this->current_member = -1; 224 if ( $this->member_count > 0 ) { 225 $this->member = $this->members[0]; 226 } 227 } 228 229 /** 230 * Finishes up the members for display. 231 * 232 * @since 1.0.0 233 * 234 * @return bool 235 */ 236 public function members() { 237 $tick = intval( $this->current_member + 1 ); 238 if ( $tick < $this->member_count ) { 239 return true; 240 } elseif ( $tick == $this->member_count ) { 241 242 /** 243 * Fires right before the rewinding of members list. 244 * 245 * @since 1.0.0 246 * @since 2.3.0 `$this` parameter added. 247 * @since 2.7.0 Action renamed from `loop_end`. 248 * 249 * @param BP_Groups_Group_Members_Template $this Instance of the current Members template. 250 */ 251 do_action( 'group_members_loop_end', $this ); 252 253 // Do some cleaning up after the loop. 254 $this->rewind_members(); 255 } 256 257 $this->in_the_loop = false; 258 return false; 259 } 260 261 /** 262 * Sets up the member to display. 263 * 264 * @since 1.0.0 265 */ 266 public function the_member() { 267 $this->in_the_loop = true; 268 $this->member = $this->next_member(); 269 270 // Loop has just started. 271 if ( 0 == $this->current_member ) { 272 273 /** 274 * Fires if the current member item is the first in the members list. 275 * 276 * @since 1.0.0 277 * @since 2.3.0 `$this` parameter added. 278 * @since 2.7.0 Action renamed from `loop_start`. 279 * 280 * @param BP_Groups_Group_Members_Template $this Instance of the current Members template. 281 */ 282 do_action( 'group_members_loop_start', $this ); 283 } 284 } 285 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |