Skip to content

Commit

Permalink
Move the invite_status group meta check out of groups_join_group()
Browse files Browse the repository at this point in the history
 [13874] introduced a regression where groups whose creation process is abandoned become unjoinable & or when using the WP BuddyPress CLI to create groups.

To avoid this, we now perform the check higher up the chain, namely in the places in BuddyPress where `groups_join_group()` is called.

Props boonebgorges, vapvarun.

See #9241 (trunk)
Fixes #9238
Closes buddypress#381



git-svn-id: https://buddypress.svn.wordpress.org/trunk@14043 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
  • Loading branch information
imath committed Oct 10, 2024
1 parent 00eb574 commit 35f1c21
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/bp-groups/actions/join.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ function groups_action_join_group() {
return;
}

/*
* Ensure that the invite_status key exists, to avoid a group being joinable when its
* creation process was interrupted.
*/
if ( ! groups_get_groupmeta( bp_get_current_group_id(), 'invite_status' ) ) {
return;
}

// Nonce check.
if ( ! check_admin_referer( 'groups_join_group' ) ) {
return;
Expand Down
10 changes: 1 addition & 9 deletions src/bp-groups/bp-groups-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,7 @@ function groups_join_group( $group, $user_id = 0 ) {

$group = bp_get_group( $group );

/*
* When the group create first step is completed, the group's status has not been defined by the
* group creator yet and defaults to public. As the group status & the invite status are set once
* the group create second step is completed, we need to wait for this step to be achieved to let
* users join the group being created otherwise it would be possible for a user to "pre-join" a
* private/hidden group. Checking if the invite status is set is the only way to make sure this
* second step has been completed. If it's not the case, no need to go further.
*/
if ( empty( $group->id ) || ! groups_get_groupmeta( $group->id, 'invite_status' ) ) {
if ( empty( $group->id ) ) {
return false;
}

Expand Down
9 changes: 9 additions & 0 deletions src/bp-templates/bp-legacy/buddypress-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,15 @@ function bp_legacy_theme_ajax_joinleave_group() {
esc_html_e( 'Error joining group', 'buddypress' );
}

/*
* Ensure that the invite_status key exists, to avoid a group
* being joinable when its creation process was interrupted.
*/
if ( ! groups_get_groupmeta( $group->id, 'invite_status' ) ) {
esc_html_e( 'Error joining group', 'buddypress' );
break;
}

check_ajax_referer( 'groups_join_group' );

if ( ! groups_join_group( $group->id ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/bp-templates/bp-nouveau/includes/groups/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function bp_nouveau_ajax_joinleave_group() {
'feedback' => $errors['member'],
'type' => 'error',
);
} elseif ( 'public' !== $group->status ) {
} elseif ( 'public' !== $group->status || ! groups_get_groupmeta( $group->id, 'invite_status' ) ) {
$response = array(
'feedback' => $errors['cannot'],
'type' => 'error',
Expand Down

0 comments on commit 35f1c21

Please sign in to comment.