Skip to:
Content

BuddyPress.org

Changeset 12917


Ignore:
Timestamp:
04/28/2021 11:50:09 PM (3 months ago)
Author:
dcavins
Message:

Member Invites: Introduce BP_Members_Invitation_Manager.

Introduce new BP_Members_Invitation_Manager class, bp_user_can filter.

See #8139.

Location:
trunk/src
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-filters.php

    r10711 r12917  
    128128}
    129129add_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 );
     130
     131/**
     132 * Filter the bp_user_can value to determine what the user can do in the members component.
     133 *
     134 * @since 8.0.0
     135 *
     136 * @param bool   $retval     Whether or not the current user has the capability.
     137 * @param int    $user_id
     138 * @param string $capability The capability being checked for.
     139 * @param int    $site_id    Site ID. Defaults to the BP root blog.
     140 * @param array  $args       Array of extra arguments passed.
     141 *
     142 * @return bool
     143 */
     144function bp_members_user_can_filter( $retval, $user_id, $capability, $site_id, $args = array() ) {
     145
     146    switch ( $capability ) {
     147        case 'bp_members_manage_membership_requests':
     148            $retval = bp_user_can( $user_id, 'bp_moderate' );
     149            break;
     150
     151        case 'bp_members_send_invitation':
     152            if ( bp_get_members_invitations_allowed() ) {
     153                $retval = true;
     154            }
     155            break;
     156
     157        case 'bp_members_receive_invitation':
     158            if ( bp_get_members_invitations_allowed() ) {
     159                $retval = true;
     160                // The invited user must not already be a member of the network.
     161                if ( empty( $args['invitee_email'] ) || false !== get_user_by( 'email', $args['invitee_email'] ) ) {
     162                    $retval = false;
     163                }
     164                // The invited user must not have opted out from being contacted from this site.
     165                if ( bp_user_has_opted_out( $args['invitee_email'] ) ) {
     166                    $retval = false;
     167                }
     168            }
     169            break;
     170    }
     171
     172    return $retval;
     173}
     174add_filter( 'bp_user_can', 'bp_members_user_can_filter', 10, 5 );
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r12898 r12917  
    4040            array(
    4141                'adminbar_myaccount_order' => 20,
    42                 'search_query_arg' => 'members_search',
     42                'search_query_arg'         => 'members_search',
     43                'features'                 => array( 'invitations' )
    4344            )
    4445        );
     
    6566            'widgets',
    6667            'cache',
     68            'invitations',
    6769        );
    6870
     
    234236            $bp->profile->id   = 'profile';
    235237        }
     238
     239        /** Network Invitations **************************************************
     240         */
     241
     242        $bp->members->invitations = new stdClass;
    236243    }
    237244
  • trunk/src/class-buddypress.php

    r12899 r12917  
    623623            'BP_REST_Attachments_Member_Cover_Endpoint'  => 'members',
    624624            'BP_REST_Signup_Endpoint'                    => 'members',
     625            'BP_Members_Invitation_Manager'              => 'members',
    625626
    626627            'BP_REST_Messages_Endpoint' => 'messages',
Note: See TracChangeset for help on using the changeset viewer.