BP_Core_Members_Template
The main member template loop class.
Description
Responsible for loading a group of members into a loop for display.
Source
File: bp-members/classes/class-bp-core-members-template.php
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | class BP_Core_Members_Template { /** * The loop iterator. * * @since BuddyPress 1.0.0 * @var int */ public $current_member = -1; /** * The number of members returned by the paged query. * * @since BuddyPress 1.0.0 * @var int */ public $member_count ; /** * Array of members located by the query. * * @since BuddyPress 1.0.0 * @var array */ public $members ; /** * The member object currently being iterated on. * * @since BuddyPress 1.0.0 * @var object */ public $member ; /** * A flag for whether the loop is currently being iterated. * * @since BuddyPress 1.0.0 * @var bool */ public $in_the_loop ; /** * The type of member being requested. Used for ordering results. * * @since BuddyPress 2.3.0 * @var string */ public $type ; /** * The unique string used for pagination queries. * * @since BuddyPress 2.2.0 * @var string */ public $pag_arg ; /** * The page number being requested. * * @since BuddyPress 1.0.0 * @var string */ public $pag_page ; /** * The number of items being requested per page. * * @since BuddyPress 1.0.0 * @var string */ public $pag_num ; /** * An HTML string containing pagination links. * * @since BuddyPress 1.0.0 * @var string */ public $pag_links ; /** * The total number of members matching the query parameters. * * @since BuddyPress 1.0.0 * @var int */ public $total_member_count ; /** * Constructor method. * * @since BuddyPress 1.5.0 * * @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 profile types to limit results to. * @param array|string $member_type__in Array or comma-separated string of profile types to limit results to. * @param array|string $member_type__not_in Array or comma-separated string of profile 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' => __( '←' , 'buddyboss' ), 'next_text' => __( '→' , 'buddyboss' ), 'mid_size' => 1, 'add_args' => $add_args , ) ); } } /** * Whether there are members available in the loop. * * @since BuddyPress 1.0.0 * * @see bp_has_members() * * @return bool True if there are items in the loop, otherwise false. */ function has_members() { if ( $this ->member_count ) return true; return false; } /** * Set up the next member and iterate index. * * @since BuddyPress 1.0.0 * * @return object The next member to iterate over. */ function next_member() { $this ->current_member++; $this ->member = $this ->members[ $this ->current_member]; return $this ->member; } /** * Rewind the members and reset member index. * * @since BuddyPress 1.0.0 */ function rewind_members() { $this ->current_member = -1; if ( $this ->member_count > 0 ) { $this ->member = $this ->members[0]; } } /** * Whether there are members left in the loop to iterate over. * * This method is used by {@link bp_members()} as part of the while loop * that controls iteration inside the members loop, eg: * while ( bp_members() ) { ... * * @since BuddyPress 1.2.0 * * @see bp_members() * * @return bool True if there are more members to show, otherwise false. */ function members() { if ( $this ->current_member + 1 < $this ->member_count ) { return true; } elseif ( $this ->current_member + 1 == $this ->member_count ) { /** * Fires right before the rewinding of members listing. * * @since BuddyPress 1.5.0 */ do_action( 'member_loop_end' ); // Do some cleaning up after the loop. $this ->rewind_members(); } $this ->in_the_loop = false; return false; } /** * Set up the current member inside the loop. * * Used by {@link bp_the_member()} to set up the current member data * while looping, so that template tags used during that iteration make * reference to the current member. * * @since BuddyPress 1.0.0 * * @see bp_the_member() */ function the_member() { $this ->in_the_loop = true; $this ->member = $this ->next_member(); // Loop has just started. if ( 0 == $this ->current_member ) { /** * Fires if the current member is the first in the loop. * * @since BuddyPress 1.5.0 */ do_action( 'member_loop_start' ); } } } |
Changelog
Version | Description |
---|---|
BuddyPress 1.0.0 | Introduced. |
Methods
- __construct — Constructor method.
- has_members — Whether there are members available in the loop.
- members — Whether there are members left in the loop to iterate over.
- next_member — Set up the next member and iterate index.
- rewind_members — Rewind the members and reset member index.
- the_member — Set up the current member inside the loop.
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.