Skip to:
Content

BuddyPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.