Skip to:
Content

BuddyPress.org

Changeset 13192


Ignore:
Timestamp:
12/17/2021 07:34:03 PM (3 years ago)
Author:
imath
Message:

Stop using the && operator inside the Group invites JS templates

The BP Nouveau template pack's Invite UI is failing to render the fetched members when the active theme is supporting the WordPress Full Site editing. The reason is the underscore JS library weirdly doesn't recognize the && operator. To avoid this issue, we've edited the Nouveau Ajax actions/ Group Invites JS templates to set new properties making this operator useless.

This commit also improves the user feedback when invites are restricted to mods or admin (or both) and the current user is a regular group member.

See #8474

Location:
trunk/src/bp-templates/bp-nouveau
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/buddypress/common/js-templates/invites/index.php

    r12513 r13192  
    77 *
    88 * @since 3.0.0
    9  * @version 6.0.0
     9 * @version 10.0.0
    1010 */
    1111?>
     
    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>
     
    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>
     
    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>
  • trunk/src/bp-templates/bp-nouveau/includes/groups/ajax.php

    r13115 r13192  
    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,
  • trunk/src/bp-templates/bp-nouveau/includes/groups/functions.php

    r13191 r13192  
    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         ) ),
    215     );
    216 
    217     // 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() );
    222 
    223         foreach ( $inviter_ids as $inviter_id ) {
    224             $class = false;
    225 
    226             if ( bp_loggedin_user_id() === (int) $inviter_id ) {
    227                 $class = 'group-self-inviter';
    228             }
    229 
    230             $response['invited_by'][] = array(
    231                 'avatar' => htmlspecialchars_decode( bp_core_fetch_avatar( array(
    232                     'item_id' => $inviter_id,
     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,
    233215                    'object'  => 'user',
    234216                    'type'    => 'thumb',
    235217                    'width'   => 50,
    236218                    'height'  => 50,
    237                     'html'    => false,
    238                     'class'   => $class,
    239                 ) ) ),
     219                    'html'    => false
     220                )
     221            )
     222        ),
     223        'scope'      => $scope,
     224        'is_sent'    => false,
     225        'invited_by' => array(),
     226        'can_invite' => 'invited' !== $scope,
     227    );
     228
     229    // Do extra queries only if needed
     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() );
     233
     234        foreach ( $inviter_ids as $inviter_id ) {
     235            $class = false;
     236
     237            if ( bp_loggedin_user_id() === (int) $inviter_id ) {
     238                $class = 'group-self-inviter';
     239            }
     240
     241            $response['invited_by'][] = array(
     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 ),
     
    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
Note: See TracChangeset for help on using the changeset viewer.