Skip to:
Content

BuddyPress.org

Ticket #8474: 8474-group-invites.patch

File 8474-group-invites.patch, 6.1 KB (added by imath, 3 years ago)
  • src/bp-templates/bp-nouveau/buddypress/common/js-templates/invites/index.php

    diff --git src/bp-templates/bp-nouveau/buddypress/common/js-templates/invites/index.php src/bp-templates/bp-nouveau/buddypress/common/js-templates/invites/index.php
    index b99183c59..ae21663b0 100644
     
    66 * dealing with invites.
    77 *
    88 * @since 3.0.0
    9  * @version 6.0.0
     9 * @version 10.0.0
    1010 */
    1111?>
    1212
     
    5757                        {{data.name}}
    5858                </div>
    5959
    60                 <# if ( undefined !== data.is_sent ) { #>
     60                <# if ( 'invited' === data.scope ) { #>
    6161                        <div class="item-meta">
    6262
    63                                 <# if ( undefined !== data.invited_by ) { #>
     63                                <# if ( data.invited_by.length > 0 ) { #>
    6464                                        <ul class="group-inviters">
    6565                                                <li><?php esc_html_e( 'Invited by:', 'buddypress' ); ?></li>
    6666                                                <# for ( i in data.invited_by ) { #>
     
    8282        </div>
    8383
    8484        <div class="action">
    85                 <# if ( undefined === data.is_sent || ( false === data.is_sent && true === data.can_edit ) ) { #>
     85                <# if ( true === data.can_invite ) { #>
    8686                        <button type="button" class="button invite-button group-add-remove-invite-button bp-tooltip bp-icons<# if ( data.selected ) { #> selected<# } #>" data-bp-tooltip="<# if ( data.selected ) { #><?php esc_attr_e( 'Cancel invitation', 'buddypress' ); ?><# } else { #><?php echo esc_attr_x( 'Invite', 'button', 'buddypress' ); ?><# } #>">
    8787                                <span class="icons" aria-hidden="true"></span>
    8888                                <span class="bp-screen-reader-text">
     
    9595                        </button>
    9696                <# } #>
    9797
    98                 <# if ( undefined !== data.can_edit && true === data.can_edit ) { #>
     98                <# if ( true === data.can_edit ) { #>
    9999                        <button type="button" class="button invite-button group-remove-invite-button bp-tooltip bp-icons" data-bp-tooltip="<?php echo esc_attr_x( 'Cancel invitation', 'button', 'buddypress' ); ?>">
    100100                                <span class=" icons" aria-hidden="true"></span>
    101101                                <span class="bp-screen-reader-text"><?php echo esc_attr_x( 'Cancel invitation', 'button', 'buddypress' ); ?></span>
  • src/bp-templates/bp-nouveau/includes/groups/ajax.php

    diff --git src/bp-templates/bp-nouveau/includes/groups/ajax.php src/bp-templates/bp-nouveau/includes/groups/ajax.php
    index a6cedb82c..6f98a618c 100644
    function bp_nouveau_ajax_get_users_to_invite() { 
    283283                wp_send_json_error( $response );
    284284        }
    285285
     286        if ( ! bp_is_group_create() && ! bp_groups_user_can_send_invites( bp_get_current_group_id(), bp_loggedin_user_id() ) ) {
     287                $invite_status = bp_group_get_invite_status( bp_get_current_group_id() );
     288                if ( 'admins' === $invite_status ) {
     289                        $message = __( 'Inviting members to join this group is restricted to Group Administrators.', 'buddypress' );
     290                } else {
     291                        $message = __( 'Inviting members to join this group is restricted to Group Moderators and Administrators.', 'buddypress' );
     292                }
     293
     294                wp_send_json_error(
     295                        array(
     296                                'feedback' => $message,
     297                                'type'     => 'error',
     298                        )
     299                );
     300        }
     301
    286302        $request = bp_parse_args(
    287303                $_POST,
    288304                array(
  • src/bp-templates/bp-nouveau/includes/groups/functions.php

    diff --git src/bp-templates/bp-nouveau/includes/groups/functions.php src/bp-templates/bp-nouveau/includes/groups/functions.php
    index f87d873af..9f765d247 100644
    function bp_nouveau_groups_get_inviter_ids( $user_id, $group_id ) { 
    199199 * @since 3.0.0
    200200 */
    201201function bp_nouveau_prepare_group_potential_invites_for_js( $user ) {
    202         $bp = buddypress();
     202        $bp    = buddypress();
     203        $scope = '';
     204        if ( isset( $bp->groups->invites_scope ) ) {
     205                $scope = $bp->groups->invites_scope;
     206        }
    203207
    204208        $response = array(
    205                 'id'           => intval( $user->ID ),
    206                 'name'         => $user->display_name,
    207                 'avatar'       => htmlspecialchars_decode( bp_core_fetch_avatar( array(
    208                         'item_id' => $user->ID,
    209                         'object'  => 'user',
    210                         'type'    => 'thumb',
    211                         'width'   => 50,
    212                         'height'  => 50,
    213                         'html'    => false )
    214                 ) ),
     209                'id'      => intval( $user->ID ),
     210                'name'    => $user->display_name,
     211                'avatar'  => htmlspecialchars_decode(
     212                        bp_core_fetch_avatar(
     213                                array(
     214                                        'item_id' => $user->ID,
     215                                        'object'  => 'user',
     216                                        'type'    => 'thumb',
     217                                        'width'   => 50,
     218                                        'height'  => 50,
     219                                        'html'    => false
     220                                )
     221                        )
     222                ),
     223                'scope'      => $scope,
     224                'is_sent'    => false,
     225                'invited_by' => array(),
     226                'can_invite' => 'invited' !== $scope,
    215227        );
    216228
    217229        // Do extra queries only if needed
    218         if ( ! empty( $bp->groups->invites_scope ) && 'invited' === $bp->groups->invites_scope ) {
    219                 $response['is_sent']  = (bool) groups_check_user_has_invite( $user->ID, bp_get_current_group_id() );
    220 
    221                 $inviter_ids = bp_nouveau_groups_get_inviter_ids( $user->ID, bp_get_current_group_id() );
     230        if ( 'invited' === $scope ) {
     231                $response['is_sent'] = (bool) groups_check_user_has_invite( $user->ID, bp_get_current_group_id() );
     232                $inviter_ids         = bp_nouveau_groups_get_inviter_ids( $user->ID, bp_get_current_group_id() );
    222233
    223234                foreach ( $inviter_ids as $inviter_id ) {
    224235                        $class = false;
    function bp_nouveau_prepare_group_potential_invites_for_js( $user ) { 
    228239                        }
    229240
    230241                        $response['invited_by'][] = array(
    231                                 'avatar' => htmlspecialchars_decode( bp_core_fetch_avatar( array(
    232                                         'item_id' => $inviter_id,
    233                                         'object'  => 'user',
    234                                         'type'    => 'thumb',
    235                                         'width'   => 50,
    236                                         'height'  => 50,
    237                                         'html'    => false,
    238                                         'class'   => $class,
    239                                 ) ) ),
     242                                'avatar' => htmlspecialchars_decode(
     243                                        bp_core_fetch_avatar(
     244                                                array(
     245                                                        'item_id' => $inviter_id,
     246                                                        'object'  => 'user',
     247                                                        'type'    => 'thumb',
     248                                                        'width'   => 50,
     249                                                        'height'  => 50,
     250                                                        'html'    => false,
     251                                                        'class'   => $class,
     252                                                )
     253                                        )
     254                                ),
    240255                                'user_link' => bp_core_get_userlink( $inviter_id, false, true ),
    241256                                'user_name' => bp_core_get_username( $inviter_id ),
    242257                        );
    243258                }
    244259
    245                 if ( bp_is_item_admin() ) {
    246                         $response['can_edit'] = true;
    247                 } else {
    248                         $response['can_edit'] = in_array( bp_loggedin_user_id(), $inviter_ids, true );
    249                 }
     260                $response['can_edit'] = bp_is_item_admin() || in_array( bp_loggedin_user_id(), $inviter_ids, true );
    250261        }
    251262
    252263        /**