Skip to:
Content

BuddyPress.org

Changeset 13629


Ignore:
Timestamp:
11/01/2023 04:04:56 PM (8 months 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.

Location:
trunk/src
Files:
1 added
4 edited

Legend:

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

    r13614 r13629  
    281281}
    282282add_action( 'add_admin_bar_menus', 'bp_members_remove_edit_page_menu' );
    283 
    284 /**
    285  * Add the "Invitations" menu and submenus.
    286  *
    287  * @since 8.0.0
    288  *
    289  * @global WP_Admin_Bar $wp_admin_bar WordPress object implementing a Toolbar API.
    290  */
    291 function bp_members_admin_bar_add_invitations_menu() {
    292     global $wp_admin_bar;
    293 
    294     // Bail if this is an ajax request.
    295     if ( wp_doing_ajax() ) {
    296         return;
    297     }
    298 
    299     if ( bp_current_user_can( 'bp_members_invitations_view_screens' ) ) {
    300         $bp          = buddypress();
    301         $invite_slug = bp_get_members_invitations_slug();
    302 
    303         $wp_admin_bar->add_node(
    304             array(
    305                 'id'     => $bp->my_account_menu_id . '-invitations',
    306                 'parent' => $bp->my_account_menu_id,
    307                 'title'  => __( 'Invitations', 'buddypress' ),
    308                 'href'   => bp_loggedin_user_url( bp_members_get_path_chunks( array( $invite_slug ) ) ),
    309                 'meta'   => array(
    310                     'class'  => 'ab-sub-secondary'
    311                 )
    312             )
    313         );
    314 
    315         if ( bp_current_user_can( 'bp_members_invitations_view_send_screen' ) ) {
    316             $wp_admin_bar->add_node(
    317                 array(
    318                     'id'     => $bp->my_account_menu_id . '-invitations-send',
    319                     'parent' => $bp->my_account_menu_id . '-invitations',
    320                     'title'  => __( 'Send Invites', 'buddypress' ),
    321                     'href'   => bp_loggedin_user_url( bp_members_get_path_chunks( array( $invite_slug, 'send-invites' ) ) ),
    322                     'meta'   => array(
    323                         'class'  => 'ab-sub-secondary'
    324                     )
    325                 )
    326             );
    327         }
    328 
    329         $wp_admin_bar->add_node(
    330             array(
    331                 'id'     => $bp->my_account_menu_id . '-invitations-list',
    332                 'parent' => $bp->my_account_menu_id . '-invitations',
    333                 'title'  => __( 'Pending Invites', 'buddypress' ),
    334                 'href'   => bp_loggedin_user_url( bp_members_get_path_chunks( array( $invite_slug, 'list-invites' ) ) ),
    335                 'meta'   => array(
    336                     'class'  => 'ab-sub-secondary'
    337                 )
    338             )
    339         );
    340     }
    341 }
    342 add_action( 'bp_setup_admin_bar', 'bp_members_admin_bar_add_invitations_menu', 90 );
  • 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}
  • trunk/src/bp-members/bp-members-loader.php

    r13105 r13629  
    2020}
    2121add_action( 'bp_setup_components', 'bp_setup_members', 1 );
     22
     23/**
     24 * Set up the bp-members-invitations component.
     25 *
     26 * @since 12.0.0
     27 */
     28function bp_setup_members_invitations() {
     29    buddypress()->members_invitations = new BP_Members_Invitations_Component();
     30}
     31add_action( 'bp_setup_components', 'bp_setup_members_invitations', 1 );
  • trunk/src/class-buddypress.php

    r13588 r13629  
    767767            'BP_Members_Invitation_Manager'              => 'members',
    768768            'BP_Members_Invitations_Template'            => 'members',
     769            'BP_Members_Invitations_Component'           => 'members',
    769770
    770771            'BP_REST_Messages_Endpoint'                  => 'messages',
Note: See TracChangeset for help on using the changeset viewer.