Skip to:
Content

BuddyPress.org

Changeset 13862


Ignore:
Timestamp:
05/11/2024 10:19:04 AM (7 months ago)
Author:
imath
Message:

BP Nouveau: use the right user ID to accept a group invite

The displayed user ID should only be used when an administrator is viewing a user profile. In all other contexts, the logged in user ID needs to be used. This change is fixing the issue when accepting such an invite from the groups directory.

Props kainelabsteam, dcavins

Fixes #9135
Closes https://github.com/buddypress/buddypress/pull/285

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/groups/ajax.php

    r13504 r13862  
    44 *
    55 * @since 3.0.0
    6  * @version 12.0.0
     6 * @version 14.0.0
    77 */
    88
     
    7575    // Cast gid as integer.
    7676    $group_id = (int) $_POST['item_id'];
     77    $user_id  = bp_loggedin_user_id();
     78
     79    if ( bp_is_user_groups() && bp_current_user_can_moderate() ) {
     80        $user_id = bp_displayed_user_id();
     81    }
    7782
    7883    $errors = array(
     
    8186    );
    8287
    83     if ( groups_is_user_banned( bp_loggedin_user_id(), $group_id ) ) {
     88    if ( groups_is_user_banned( $user_id, $group_id ) ) {
    8489        $response['feedback'] = $errors['cannot'];
    8590
     
    98103
    99104        case 'groups_accept_invite':
    100             if ( ! groups_check_user_has_invite( bp_displayed_user_id(), $group_id ) ) {
     105            if ( ! groups_check_user_has_invite( $user_id, $group_id ) ) {
    101106                wp_send_json_error( $response );
    102107            }
    103108
    104             if ( ! groups_accept_invite( bp_displayed_user_id(), $group_id ) ) {
     109            if ( ! groups_accept_invite( $user_id, $group_id ) ) {
    105110                $response = array(
    106111                    'feedback' => sprintf(
     
    138143
    139144        case 'groups_reject_invite':
    140             if ( ! groups_reject_invite( bp_displayed_user_id(), $group_id ) ) {
     145            if ( ! groups_reject_invite( $user_id, $group_id ) ) {
    141146                $response = array(
    142147                    'feedback' => sprintf(
     
    159164
    160165        case 'groups_join_group':
    161             if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
     166            if ( groups_is_user_member( $user_id, $group->id ) ) {
    162167                $response = array(
    163168                    'feedback' => $errors['member'],
     
    190195
    191196            case 'groups_request_membership' :
    192                 if ( ! groups_send_membership_request( [ 'user_id' => bp_loggedin_user_id(), 'group_id' => $group->id ] ) ) {
     197                if ( ! groups_send_membership_request( [ 'user_id' => $user_id, 'group_id' => $group->id ] ) ) {
    193198                    $response = array(
    194199                        'feedback' => sprintf(
Note: See TracChangeset for help on using the changeset viewer.