Changeset 11089 for trunk/src/bp-groups/classes/class-bp-groups-group.php
- Timestamp:
- 09/13/2016 05:35:42 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/classes/class-bp-groups-group.php
r11087 r11089 114 114 * @var bool 115 115 */ 116 p ublic$is_member;116 protected $is_member; 117 117 118 118 /** … … 122 122 * @var bool 123 123 */ 124 p ublic$is_invited;124 protected $is_invited; 125 125 126 126 /** … … 130 130 * @var bool 131 131 */ 132 p ublic$is_pending;132 protected $is_pending; 133 133 134 134 /** … … 146 146 * @var bool 147 147 */ 148 p ublic$user_has_access;148 protected $user_has_access; 149 149 150 150 /** … … 165 165 * @param array $args { 166 166 * Array of optional arguments. 167 * @type bool $populate_extras Whether to fetch "extra" data about the group 168 * (group admins/mods, access for the current user). 169 * Default: false. 167 * @type bool $populate_extras Deprecated. 170 168 * } 171 169 */ 172 170 public function __construct( $id = null, $args = array() ) { 173 $this->args = wp_parse_args( $args, array(174 'populate_extras' => false,175 ) );176 177 171 if ( !empty( $id ) ) { 178 172 $this->id = (int) $id; … … 217 211 $this->enable_forum = (int) $group->enable_forum; 218 212 $this->date_created = $group->date_created; 219 220 // Are we getting extra group data?221 if ( ! empty( $this->args['populate_extras'] ) ) {222 223 // Set user-specific data.224 $user_id = bp_loggedin_user_id();225 $this->is_member = groups_is_user_member( $user_id, $this->id );226 $this->is_invited = groups_check_user_has_invite( $user_id, $this->id );227 $this->is_pending = groups_check_for_membership_request( $user_id, $this->id );228 229 // If this is a private or hidden group, does the current user have access?230 if ( ( 'private' === $this->status ) || ( 'hidden' === $this->status ) ) {231 232 // Assume user does not have access to hidden/private groups.233 $this->user_has_access = false;234 235 // Group members or community moderators have access.236 if ( ( $this->is_member && is_user_logged_in() ) || bp_current_user_can( 'bp_moderate' ) ) {237 $this->user_has_access = true;238 }239 } else {240 $this->user_has_access = true;241 }242 }243 213 } 244 214 … … 425 395 return $this->get_mods(); 426 396 397 case 'is_member' : 398 return $this->get_is_member(); 399 400 case 'is_invited' : 401 return groups_check_user_has_invite( bp_loggedin_user_id(), $this->id ); 402 403 case 'is_pending' : 404 return groups_check_for_membership_request( bp_loggedin_user_id(), $this->id ); 405 406 case 'user_has_access' : 407 return $this->get_user_has_access(); 408 427 409 default : 428 410 break; … … 445 427 case 'last_activity' : 446 428 case 'total_member_count' : 429 case 'admins' : 430 case 'mods' : 447 431 return true; 448 432 449 433 default : 450 434 return false; 435 } 436 } 437 438 /** 439 * Magic setter. 440 * 441 * Used to maintain backward compatibility for properties that are now 442 * accessible only via magic method. 443 * 444 * @since 2.7.0 445 * 446 * @param string $key Property name. 447 */ 448 public function __set( $key, $value ) { 449 switch ( $key ) { 450 case 'user_has_access' : 451 return $this->user_has_access = (bool) $value; 451 452 } 452 453 } … … 529 530 $this->admins = $admin_objects; 530 531 $this->mods = $mod_objects; 532 } 533 534 /** 535 * Checks whether the logged-in user is a member of the group. 536 * 537 * @since 2.7.0 538 * 539 * @return bool 540 */ 541 protected function get_is_member() { 542 if ( isset( $this->is_member ) ) { 543 return $this->is_member; 544 } 545 546 $this->is_member = groups_is_user_member( bp_loggedin_user_id(), $this->id ); 547 return $this->is_member; 548 } 549 550 /** 551 * Checks whether the logged-in user has access to the group. 552 * 553 * @since 2.7.0 554 * 555 * @return bool 556 */ 557 protected function get_user_has_access() { 558 if ( isset( $this->user_has_access ) ) { 559 return $this->user_has_access; 560 } 561 562 if ( ( 'private' === $this->status ) || ( 'hidden' === $this->status ) ) { 563 564 // Assume user does not have access to hidden/private groups. 565 $this->user_has_access = false; 566 567 // Group members or community moderators have access. 568 if ( ( is_user_logged_in() && $this->get_is_member() ) || bp_current_user_can( 'bp_moderate' ) ) { 569 $this->user_has_access = true; 570 } 571 } else { 572 $this->user_has_access = true; 573 } 574 575 return $this->user_has_access; 531 576 } 532 577
Note: See TracChangeset
for help on using the changeset viewer.