BP_XProfile_Data_Template
The main profile template loop class.
Description
This is responsible for loading profile field, group, and data and displaying it.
Source
File: bp-xprofile/classes/class-bp-xprofile-data-template.php
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | class BP_XProfile_Data_Template { /** * The loop iterator. * * @since BuddyPress 1.5.0 * @var int */ public $current_group = -1; /** * The number of groups returned by the paged query. * * @since BuddyPress 1.5.0 * @var int */ public $group_count ; /** * Array of groups located by the query. * * @since BuddyPress 1.5.0 * @var array */ public $groups ; /** * The group object currently being iterated on. * * @since BuddyPress 1.5.0 * @var object */ public $group ; /** * The current field. * * @since BuddyPress 1.5.0 * @var int */ public $current_field = -1; /** * The field count. * * @since BuddyPress 1.5.0 * @var int */ public $field_count ; /** * Field has data. * * @since BuddyPress 1.5.0 * @var bool */ public $field_has_data ; /** * The field. * * @since BuddyPress 1.5.0 * @var int */ public $field ; /** * A flag for whether the loop is currently being iterated. * * @since BuddyPress 1.5.0 * @var bool */ public $in_the_loop ; /** * The user ID. * * @since BuddyPress 1.5.0 * @var int */ public $user_id ; /** * Get activity items, as specified by parameters. * * @see BP_XProfile_Group::get() for more details about parameters. * * @since BuddyPress 1.5.0 * @since BuddyPress 2.4.0 Introduced `$member_type` argument. * * @param array|string $args { * An array of arguments. All items are optional. * * @type int $user_id Fetch field data for this user ID. * @type string|array $member_type Limit results to those matching profile type(s). * @type int $profile_group_id Field group to fetch fields & data for. * @type int|bool $hide_empty_groups Should empty field groups be skipped. * @type int|bool $fetch_fields Fetch fields for field group. * @type int|bool $fetch_field_data Fetch field data for fields in group. * @type array $exclude_groups Exclude these field groups. * @type array $exclude_fields Exclude these fields. * @type int|bool $hide_empty_fields Should empty fields be skipped. * @type int|bool $fetch_visibility_level Fetch visibility levels. * @type int|bool $update_meta_cache Should metadata cache be updated. * } */ public function __construct( $args = '' ) { // Backward compatibility with old method of passing arguments. if ( ! is_array ( $args ) || func_num_args() > 1 ) { _deprecated_argument( __METHOD__ , '2.3.0' , sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.' , 'buddyboss' ), __METHOD__ , __FILE__ ) ); $old_args_keys = array ( 0 => 'user_id' , 1 => 'profile_group_id' , 2 => 'hide_empty_groups' , 3 => 'fetch_fields' , 4 => 'fetch_field_data' , 5 => 'exclude_groups' , 6 => 'exclude_fields' , 7 => 'hide_empty_fields' , 8 => 'fetch_visibility_level' , 9 => 'update_meta_cache' ); $args = bp_core_parse_args_array( $old_args_keys , func_get_args() ); } $r = wp_parse_args( $args , array ( 'profile_group_id' => false, 'user_id' => false, 'member_type' => 'any' , 'hide_empty_groups' => false, 'hide_empty_fields' => false, 'fetch_fields' => false, 'fetch_field_data' => false, 'fetch_visibility_level' => false, 'exclude_groups' => false, 'exclude_fields' => false, 'update_meta_cache' => true ) ); $this ->groups = bp_xprofile_get_groups( $r ); $this ->group_count = count ( $this ->groups ); $this ->user_id = $r [ 'user_id' ]; } /** * Whether or not the loop has field groups. * * @since BuddyPress 1.0.0 * * @return bool */ public function has_groups() { if ( ! empty ( $this ->group_count ) ) { return true; } return false; } /** * Increments to the next group of fields. * * @since BuddyPress 1.0.0 * * @return object */ public function next_group() { $this ->current_group++; $this ->group = $this ->groups[ $this ->current_group ]; $this ->field_count = 0; if ( ! empty ( $this ->group->fields ) ) { /** * Filters the group fields for the next_group method. * * @since BuddyPress 1.1.0 * * @param array $fields Array of fields for the group. * @param int $id ID of the field group. */ $this ->group->fields = apply_filters( 'xprofile_group_fields' , $this ->group->fields, $this ->group->id ); $this ->field_count = count ( $this ->group->fields ); } return $this ->group; } /** * Rewinds to the start of the groups list. * * @since BuddyPress 1.0.0 */ public function rewind_groups() { $this ->current_group = -1; if ( $this ->group_count > 0 ) { $this ->group = $this ->groups[0]; } } /** * Kicks off the profile groups. * * @since BuddyPress 1.0.0 * * @return bool */ public function profile_groups() { if ( $this ->current_group + 1 < $this ->group_count ) { return true; } elseif ( $this ->current_group + 1 == $this ->group_count ) { /** * Fires right before the rewinding of profile groups. * * @since BuddyPress 1.1.0 */ do_action( 'xprofile_template_loop_end' ); // Do some cleaning up after the loop. $this ->rewind_groups(); } $this ->in_the_loop = false; return false; } /** * Sets up the profile group. * * @since BuddyPress 1.0.0 */ public function the_profile_group() { global $group ; $this ->in_the_loop = true; $group = $this ->next_group(); // Loop has just started. if ( 0 === $this ->current_group ) { /** * Fires if the current group is the first in the loop. * * @since BuddyPress 1.1.0 */ do_action( 'xprofile_template_loop_start' ); } } /** Fields ****************************************************************/ /** * Increments to the next field. * * @since BuddyPress 1.0.0 * * @return int */ public function next_field() { $this ->current_field++; $this ->field = $this ->group->fields[ $this ->current_field ]; return $this ->field; } /** * Rewinds to the start of the fields. * * @since BuddyPress 1.0.0 */ public function rewind_fields() { $this ->current_field = -1; if ( $this ->field_count > 0 ) { $this ->field = $this ->group->fields[0]; } } /** * Whether or not the loop has fields. * * @since BuddyPress 1.0.0 * * @return bool */ public function has_fields() { $has_data = false; for ( $i = 0, $count = count ( $this ->group->fields ); $i < $count ; ++ $i ) { $field = & $this ->group->fields[ $i ]; if ( ! empty ( $field ->data ) && ( $field ->data->value != null ) ) { $has_data = true; } } return $has_data ; } /** * Kick off the profile fields. * * @since BuddyPress 1.0.0 * * @return bool */ public function profile_fields() { if ( $this ->current_field + 1 < $this ->field_count ) { return true; } elseif ( $this ->current_field + 1 == $this ->field_count ) { // Do some cleaning up after the loop. $this ->rewind_fields(); } return false; } /** * Set up the profile fields. * * @since BuddyPress 1.0.0 */ public function the_profile_field() { global $field ; $field = $this ->next_field(); // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731. if ( ! empty ( $field ->data ) && ( ! empty ( $field ->data->value ) || ( '0' === $field ->data->value ) ) ) { $value = maybe_unserialize( $field ->data->value ); } else { $value = false; } if ( ! empty ( $value ) || ( '0' === $value ) ) { $this ->field_has_data = true; } else { $this ->field_has_data = false; } } } |
Changelog
Version | Description |
---|---|
BuddyPress 1.0.0 | Introduced. |
Methods
- __construct — Get activity items, as specified by parameters.
- has_fields — Whether or not the loop has fields.
- has_groups — Whether or not the loop has field groups.
- next_field — Increments to the next field.
- next_group — Increments to the next group of fields.
- profile_fields — Kick off the profile fields.
- profile_groups — Kicks off the profile groups.
- rewind_fields — Rewinds to the start of the fields.
- rewind_groups — Rewinds to the start of the groups list.
- the_profile_field — Set up the profile fields.
- the_profile_group — Sets up the profile group.
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.