Skip to:
Content

BuddyPress.org

Changeset 11544


Ignore:
Timestamp:
04/28/2017 02:36:15 PM (8 years ago)
Author:
dcavins
Message:

Add $is_visible and $is_user_member properties to BP_Groups_Group object.

During single group setup in the BP_Groups_Component, we're doing
some checks that duplicate logic that is, or should be, handled in
BP_Groups_Group. Then, BP_Groups_Component can rely on
BP_Groups_Group to provide the details via recently added magic
methods.

Note: $is_user_member is an alias of $is_member for backward
compatibility.

Fixes #7494.

Location:
trunk/src/bp-groups/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r11405 r11544  
    241241            if ( ! bp_is_item_admin() ) {
    242242                bp_update_is_item_mod  ( groups_is_user_mod  ( bp_loggedin_user_id(), $this->current_group->id ), 'groups' );
    243             }
    244 
    245             // Is the logged in user a member of the group?
    246             if ( ( is_user_logged_in() && groups_is_user_member( bp_loggedin_user_id(), $this->current_group->id ) ) ) {
    247                 $this->current_group->is_user_member = true;
    248             } else {
    249                 $this->current_group->is_user_member = false;
    250             }
    251 
    252             // Should this group be visible to the logged in user?
    253             if ( 'public' == $this->current_group->status || $this->current_group->is_user_member ) {
    254                 $this->current_group->is_visible = true;
    255             } else {
    256                 $this->current_group->is_visible = false;
    257243            }
    258244
     
    558544            // show a "Request Membership" nav item.
    559545            if ( is_user_logged_in() &&
    560                  ! $this->current_group->is_user_member &&
     546                 ! $this->current_group->is_member &&
    561547                 ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) &&
    562548                 $this->current_group->status == 'private' &&
  • trunk/src/bp-groups/classes/class-bp-groups-group.php

    r11533 r11544  
    127127
    128128    /**
     129     * Is the current user a member of this group?
     130     * Alias of $is_member for backward compatibility.
     131     *
     132     * @since 2.9.0
     133     * @var bool
     134     */
     135    protected $is_user_member;
     136
     137    /**
    129138     * Does the current user have an outstanding invitation to this group?
    130139     *
     
    157166     */
    158167    protected $user_has_access;
     168
     169    /**
     170     * Can the current user know that this group exists?
     171     *
     172     * @since 2.9.0
     173     * @var bool
     174     */
     175    protected $is_visible;
    159176
    160177    /**
     
    417434
    418435            case 'is_member' :
     436            case 'is_user_member' :
    419437                return $this->get_is_member();
    420438
     
    427445            case 'user_has_access' :
    428446                return $this->get_user_has_access();
     447
     448            case 'is_visible' :
     449                return $this->is_visible();
    429450
    430451            default :
     
    449470            case 'is_invited' :
    450471            case 'is_member' :
     472            case 'is_user_member' :
    451473            case 'is_pending' :
    452474            case 'last_activity' :
     
    454476            case 'total_member_count' :
    455477            case 'user_has_access' :
     478            case 'is_visible' :
    456479            case 'forum_id' :
    457480                return true;
     
    606629
    607630        return $this->user_has_access;
     631    }
     632
     633    /**
     634     * Checks whether the current user can know the group exists.
     635     *
     636     * @since 2.9.0
     637     *
     638     * @return bool
     639     */
     640    protected function is_visible() {
     641        if ( isset( $this->is_visible ) ) {
     642            return $this->is_visible;
     643        }
     644
     645        if ( 'hidden' === $this->status ) {
     646
     647            // Assume user can not know about hidden groups.
     648            $this->is_visible = false;
     649
     650            // Group members or community moderators have access.
     651            if ( ( is_user_logged_in() && $this->get_is_member() ) || bp_current_user_can( 'bp_moderate' ) ) {
     652                $this->is_visible = true;
     653            }
     654        } else {
     655            $this->is_visible = true;
     656        }
     657
     658        return $this->is_visible;
    608659    }
    609660
Note: See TracChangeset for help on using the changeset viewer.