Skip to:
Content

BuddyPress.org

Ticket #8139: 8139.09-capabilities.patch

File 8139.09-capabilities.patch, 6.9 KB (added by dcavins, 3 years ago)

Centralize some "user can" logic to make it filterable and consistent.

  • src/bp-members/bp-members-adminbar.php

    diff --git src/bp-members/bp-members-adminbar.php src/bp-members/bp-members-adminbar.php
    index 282be654c..c9ff861c0 100644
    function bp_members_admin_bar_add_invitations_menu() { 
    193193                return;
    194194        }
    195195
    196         if ( is_user_logged_in() && bp_get_members_invitations_allowed() && ( bp_current_user_can( 'bp_members_send_invitation' ) || bp_members_invitations_user_has_sent_invites() ) ) {
     196        if ( bp_current_user_can( 'bp_members_invitations_view_screens' ) ) {
    197197                $bp               = buddypress();
    198198                $invitations_link = trailingslashit( bp_loggedin_user_domain() . bp_get_members_invitations_slug() );
    199199
    function bp_members_admin_bar_add_invitations_menu() { 
    209209                        )
    210210                );
    211211
    212                 if ( bp_current_user_can( 'bp_members_send_invitation' ) ) {
     212                if ( bp_current_user_can( 'bp_members_invitations_view_send_screen' ) ) {
    213213                        $wp_admin_bar->add_node(
    214214                                array(
    215215                                        'id'     => $bp->my_account_menu_id . '-invitations-send',
    216216                                        'parent' => $bp->my_account_menu_id . '-invitations',
    217217                                        'title'  => __( 'Send Invites', 'buddypress' ),
    218                                         'href'   => $invitations_link,
     218                                        'href'   => $invitations_link . 'send-invites/',
    219219                                        'meta'   => array(
    220220                                                'class'  => 'ab-sub-secondary'
    221221                                        )
  • src/bp-members/bp-members-filters.php

    diff --git src/bp-members/bp-members-filters.php src/bp-members/bp-members-filters.php
    index d0d65e4fe..e244bf32d 100644
    function bp_members_user_can_filter( $retval, $user_id, $capability, $site_id, $ 
    149149                        break;
    150150
    151151                case 'bp_members_send_invitation':
    152                         if ( bp_get_members_invitations_allowed() ) {
     152                        if ( is_user_logged_in() && bp_get_members_invitations_allowed() ) {
    153153                                $retval = true;
    154154                        }
    155155                        break;
    function bp_members_user_can_filter( $retval, $user_id, $capability, $site_id, $ 
    167167                                }
    168168                        }
    169169                        break;
     170
     171                case 'bp_members_invitations_view_screens':
     172                        $retval = bp_get_members_invitations_allowed() && ( bp_user_can( $user_id, 'bp_members_send_invitation' ) || bp_members_invitations_user_has_sent_invites( $user_id ) );
     173                        break;
     174
     175                case 'bp_members_invitations_view_send_screen':
     176                        $retval = bp_user_can( $user_id, 'bp_members_send_invitation' );
     177                        break;
    170178        }
    171179
    172180        return $retval;
  • src/bp-members/bp-members-invitations.php

    diff --git src/bp-members/bp-members-invitations.php src/bp-members/bp-members-invitations.php
    index 2a04c3dbd..a89b9f54a 100644
    function bp_members_invitations_setup_nav() { 
    1515                return;
    1616        }
    1717
    18         $user_has_access  = bp_user_has_access();
    19         $user_can_send    = bp_user_can( bp_displayed_user_id(), 'bp_members_send_invitation' );
    20         $user_has_invites = bp_members_invitations_user_has_sent_invites( bp_displayed_user_id() );
     18        $user_has_access     = bp_user_has_access();
     19        $default_subnav_slug = ( bp_is_my_profile() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_send_screen' ) ) ? 'send-invites' : 'list-invites';
    2120
    2221        /* Add 'Invitations' to the main user profile navigation */
    2322        bp_core_new_nav_item(
    function bp_members_invitations_setup_nav() { 
    2625                        'slug'                    => bp_get_members_invitations_slug(),
    2726                        'position'                => 80,
    2827                        'screen_function'         => 'members_screen_send_invites',
    29                         'default_subnav_slug'     => ( $user_can_send && bp_is_my_profile() ) ? 'send-invites' : 'list-invites',
    30                         'show_for_displayed_user' => $user_has_access && ( $user_can_send || $user_has_invites )
     28                        'default_subnav_slug'     => $default_subnav_slug,
     29                        'show_for_displayed_user' => $user_has_access && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_screens' )
    3130                )
    3231        );
    3332
    function bp_members_invitations_setup_nav() { 
    4241                        'parent_url'      => $parent_link,
    4342                        'screen_function' => 'members_screen_send_invites',
    4443                        'position'        => 10,
    45                         'user_has_access' => $user_has_access && $user_can_send && bp_is_my_profile()
     44                        'user_has_access' => $user_has_access && bp_is_my_profile() && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_send_screen' )
    4645                )
    4746        );
    4847
    function bp_members_invitations_setup_nav() { 
    5453                        'parent_url'      => $parent_link,
    5554                        'screen_function' => 'members_screen_list_sent_invites',
    5655                        'position'        => 20,
    57                         'user_has_access' => $user_has_access && ( $user_can_send || $user_has_invites )
     56                        'user_has_access' => $user_has_access && bp_user_can( bp_displayed_user_id(), 'bp_members_invitations_view_screens' )
    5857                )
    5958        );
    6059}
  • src/bp-templates/bp-legacy/buddypress/members/single/invitations/send-invites.php

    diff --git src/bp-templates/bp-legacy/buddypress/members/single/invitations/send-invites.php src/bp-templates/bp-legacy/buddypress/members/single/invitations/send-invites.php
    index 6eeb3b62f..5cd0af16c 100644
     
    1414        ?>
    1515</h2>
    1616
     17<?php if ( bp_user_can( bp_displayed_user_id(), 'bp_members_send_invitation' ) ) : ?>
     18
    1719<form class="standard-form members-invitation-form" id="members-invitation-form" method="post">
    1820        <p class="description"><?php esc_html_e( 'Fill out the form below to invite a new user to join this site. Upon submission of the form, an email will be sent to the invitee containing a link to accept your invitation. You may also add a custom message to the email.', 'buddypress' ); ?></p>
    1921
     
    3032                <input id="submit" type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Send Invitation', 'buddypress' ) ?>" />
    3133        </p>
    3234</form>
     35
     36<?php else : ?>
     37
     38        <p class="bp-feedback error">
     39                <span class="bp-icon" aria-hidden="true"></span>
     40                <span class="bp-help-text">
     41                        <?php echo apply_filters( 'members_invitations_form_access_restricted', esc_html__( 'Sorry, you are not allowed to send invitations.', 'buddypress' ) ); ?>
     42                </span>
     43        </p>
     44
     45<?php endif; ?>
  • src/bp-templates/bp-nouveau/buddypress/members/single/invitations/send-invites.php

    diff --git src/bp-templates/bp-nouveau/buddypress/members/single/invitations/send-invites.php src/bp-templates/bp-nouveau/buddypress/members/single/invitations/send-invites.php
    index 077c1fa24..b9b80f707 100644
     
    1313        ?>
    1414</h2>
    1515
     16<?php if ( bp_user_can( bp_displayed_user_id(), 'bp_members_send_invitation' ) ) : ?>
     17
    1618<p class="bp-feedback info">
    1719        <span class="bp-icon" aria-hidden="true"></span>
    1820        <span class="bp-help-text">
     
    3638
    3739        <?php bp_nouveau_submit_button( 'member-send-invite' ); ?>
    3840</form>
     41
     42<?php else : ?>
     43
     44        <p class="bp-feedback error">
     45                <span class="bp-icon" aria-hidden="true"></span>
     46                <span class="bp-help-text">
     47                        <?php echo apply_filters( 'members_invitations_form_access_restricted', esc_html__( 'Sorry, you are not allowed to send invitations.', 'buddypress' ) ); ?>
     48                </span>
     49        </p>
     50
     51<?php endif; ?>