Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/01/2023 04:04:56 PM (3 years ago)
Author:
dcavins
Message:

Introduce BP_Members_Invitations_Component.

Introduce a slim BP_Members_Invitations_Component
to handle the addition and management of member and admin bar navigation items for the member invitations feature.

Fixes #9013.

File:
1 edited

Legend:

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

    r13441 r13629  
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
    12 
    13 /**
    14  * Set up the displayed user's Members Invitations nav.
    15  *
    16  * @since 8.0.0
    17  */
    18 function bp_members_invitations_setup_nav() {
    19         if ( ! bp_get_members_invitations_allowed() ) {
    20                 return;
    21         }
    22 
    23         $user_has_access     = bp_user_has_access();
    24         $default_subnav_slug = ( bp_is_my_profile() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_send_screen' ) ) ? 'send-invites' : 'list-invites';
    25 
    26         /* Add 'Invitations' to the main user profile navigation */
    27         bp_core_new_nav_item(
    28                 array(
    29                         'name'                    => __( 'Invitations', 'buddypress' ),
    30                         'slug'                    => bp_get_members_invitations_slug(),
    31                         'position'                => 80,
    32                         'screen_function'         => 'members_screen_send_invites',
    33                         'default_subnav_slug'     => $default_subnav_slug,
    34                         'show_for_displayed_user' => $user_has_access && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_screens' )
    35                 )
    36         );
    37 
    38         /* Create two subnav items for community invitations */
    39         bp_core_new_subnav_item(
    40                 array(
    41                         'name'            => __( 'Send Invites', 'buddypress' ),
    42                         'slug'            => 'send-invites',
    43                         'parent_slug'     => bp_get_members_invitations_slug(),
    44                         'screen_function' => 'members_screen_send_invites',
    45                         'position'        => 10,
    46                         'user_has_access' => $user_has_access && bp_is_my_profile() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_send_screen' )
    47                 )
    48         );
    49 
    50         bp_core_new_subnav_item(
    51                 array(
    52                         'name'            => __( 'Pending Invites', 'buddypress' ),
    53                         'slug'            => 'list-invites',
    54                         'parent_slug'     => bp_get_members_invitations_slug(),
    55                         'screen_function' => 'members_screen_list_sent_invites',
    56                         'position'        => 20,
    57                         'user_has_access' => $user_has_access && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_screens' )
    58                 )
    59         );
    60 }
    61 add_action( 'bp_setup_nav', 'bp_members_invitations_setup_nav' );
    6212
    6313/**
     
    217167add_filter( 'bp_members_membership_requests_bypass_manual_approval', 'bp_members_invitations_maybe_bypass_request_approval', 10, 2 );
    218168add_filter( 'bp_members_membership_requests_bypass_manual_approval_multisite', 'bp_members_invitations_maybe_bypass_request_approval', 10, 2 );
     169
     170/**
     171 * Whether a user can access invitations screens.
     172 * Referred to by BP_Members_Invitations_Component::register_nav().
     173 *
     174 * @since 12.0.0
     175 *
     176 * @param bool $access Whether the user can view member invitations screens.
     177 */
     178function bp_members_invitations_user_can_view_screens() {
     179        return bp_user_has_access() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_screens' );
     180}
     181
     182/**
     183 * Whether a user can access the send invitations member screen.
     184 * Referred to by BP_Members_Invitations_Component::register_nav().
     185 *
     186 * @since 12.0.0
     187 *
     188 * @param bool $access Whether the user can view member invitations send screen.
     189 */
     190function bp_members_invitations_user_can_view_send_screen() {
     191        return bp_is_my_profile() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_send_screen' );
     192}
Note: See TracChangeset for help on using the changeset viewer.