Skip to:
Content

BuddyPress.org

Ticket #8139: 8139.09.02-capabilities.patch

File 8139.09.02-capabilities.patch, 10.1 KB (added by imath, 3 months ago)
  • 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..f7d89c672 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 = is_user_logged_in() && bp_get_members_invitations_allowed();
     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..5b5d21bd8 100644
     
    1313        ?>
    1414</h2>
    1515
    16 <p class="bp-feedback info">
    17         <span class="bp-icon" aria-hidden="true"></span>
    18         <span class="bp-help-text">
    19                 <?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' ); ?>
    20         </span>
    21 </p>
    22 
    23 <form class="standard-form network-invitation-form" id="network-invitation-form" method="post">
    24         <label for="bp_members_invitation_invitee_email">
    25                 <?php esc_html_e( 'Email', 'buddypress' ); ?>
    26                 <span class="bp-required-field-label"><?php esc_html_e( '(required)', 'buddypress' ); ?></span>
    27         </label>
    28         <input id="bp_members_invitation_invitee_email" type="email" name="invitee_email" required="required">
    29 
    30         <label for="bp_members_invitation_message">
    31                 <?php esc_html_e( 'Add a personalized message to the invitation (optional)', 'buddypress' ); ?>
    32         </label>
    33         <textarea id="bp_members_invitation_message" name="invite_message"></textarea>
    34 
    35         <input type="hidden" name="action" value="send-invite">
    36 
    37         <?php bp_nouveau_submit_button( 'member-send-invite' ); ?>
    38 </form>
     16<?php if ( bp_user_can( bp_displayed_user_id(), 'bp_members_send_invitation' ) ) : ?>
     17
     18        <?php bp_nouveau_user_feedback( 'member-invitations-help' ); ?>
     19
     20        <form class="standard-form network-invitation-form" id="network-invitation-form" method="post">
     21                <label for="bp_members_invitation_invitee_email">
     22                        <?php esc_html_e( 'Email', 'buddypress' ); ?>
     23                        <span class="bp-required-field-label"><?php esc_html_e( '(required)', 'buddypress' ); ?></span>
     24                </label>
     25                <input id="bp_members_invitation_invitee_email" type="email" name="invitee_email" required="required">
     26
     27                <label for="bp_members_invitation_message">
     28                        <?php esc_html_e( 'Add a personalized message to the invitation (optional)', 'buddypress' ); ?>
     29                </label>
     30                <textarea id="bp_members_invitation_message" name="invite_message"></textarea>
     31
     32                <input type="hidden" name="action" value="send-invite">
     33
     34                <?php bp_nouveau_submit_button( 'member-send-invite' ); ?>
     35        </form>
     36
     37<?php else : ?>
     38
     39        <?php bp_nouveau_user_feedback( 'member-invitations-not-allowed' ); ?>
     40
     41<?php endif; ?>
  • src/bp-templates/bp-nouveau/includes/functions.php

    diff --git src/bp-templates/bp-nouveau/includes/functions.php src/bp-templates/bp-nouveau/includes/functions.php
    index 1b17c6294..7fcb08943 100644
    function bp_nouveau_get_user_feedback( $feedback_id = '' ) { 
    10901090                                'type'    => 'info',
    10911091                                'message' => __( 'Currently only your friends can invite you to groups. Uncheck the box to allow any member to send invites.', 'buddypress' ),
    10921092                        ),
    1093                         'member-invites-none'               => array(
     1093                        'member-invitations-help'           => array(
     1094                                'type'    => 'info',
     1095                                'message' => __( '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' ),
     1096                        ),
     1097                        'member-invitations-none'           => array(
    10941098                                'type'    => 'info',
    10951099                                'message' => __( 'There are no invitations to display.', 'buddypress' ),
    10961100                        ),
     1101                        'member-invitations-not-allowed'    => array(
     1102                                'type'    => 'error',
     1103                                /**
     1104                                 * Use this filter to edit the restricted feedback message displayed into the Send invitation form.
     1105                                 *
     1106                                 * @since 8.0.0
     1107                                 *
     1108                                 * @param string $value The restricted feedback message displayed into the Send invitation form.
     1109                                 */
     1110                                'message' => apply_filters(
     1111                                        'members_invitations_form_access_restricted',
     1112                                        __( 'Sorry, you are not allowed to send invitations.', 'buddypress' )
     1113                                ),
     1114                        ),
    10971115                )
    10981116        );
    10991117