Skip to:
Content

BuddyPress.org

Changeset 7384


Ignore:
Timestamp:
09/17/2013 05:24:00 PM (11 years ago)
Author:
r-a-y
Message:

Fix redirect when a user leaves a hidden group from the group's page.

Usually when a user leaves a group from the group's page, it redirects
back to the group's homepage, however for hidden groups this creates
a 404.

This commit redirects the user back to their list of groups when
leaving a hidden group.

Commit also adds phpDoc and uses some API functions instead of the $bp
global.

Fixes #5077. Props imath.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-actions.php

    r7351 r7384  
    238238add_action( 'bp_actions', 'groups_action_join_group' );
    239239
    240 
     240/**
     241 * When a group member clicks on the "Leave Group" button from a group's page,
     242 * this function is run.
     243 *
     244 * Note: When leaving a group from the group directory, AJAX is used and
     245 * another function handles this. See {@link bp_legacy_theme_ajax_joinleave_group()}.
     246 *
     247 * @since BuddyPress (1.2.4)
     248 */
    241249function groups_action_leave_group() {
    242     global $bp;
    243 
    244     if ( !bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action( 'leave-group' ) )
    245         return false;
     250    if ( ! bp_is_single_item() || ! bp_is_groups_component() || ! bp_is_current_action( 'leave-group' ) ) {
     251        return false;
     252    }
    246253
    247254    // Nonce check
    248     if ( !check_admin_referer( 'groups_leave_group' ) )
    249         return false;
     255    if ( ! check_admin_referer( 'groups_leave_group' ) ) {
     256        return false;
     257    }
    250258
    251259    // User wants to leave any group
    252     if ( groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
     260    if ( groups_is_user_member( bp_loggedin_user_id(), bp_get_current_group_id() ) ) {
     261        $bp = buddypress();
    253262
    254263        // Stop sole admins from abandoning their group
    255         $group_admins = groups_get_group_admins( $bp->groups->current_group->id );
    256         if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() )
     264        $group_admins = groups_get_group_admins( bp_get_current_group_id() );
     265
     266        if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() ) {
    257267            bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' );
    258 
    259         elseif ( !groups_leave_group( $bp->groups->current_group->id ) )
     268        } elseif ( ! groups_leave_group( $bp->groups->current_group->id ) ) {
    260269            bp_core_add_message( __( 'There was an error leaving the group.', 'buddypress' ), 'error' );
    261         else
     270        } else {
    262271            bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) );
    263 
    264         bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
     272        }
     273           
     274        $redirect = bp_get_group_permalink( groups_get_current_group() );
     275       
     276        if( 'hidden' == $bp->groups->current_group->status ) {
     277            $redirect = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() );
     278        }
     279
     280        bp_core_redirect( $redirect );
    265281    }
    266282
Note: See TracChangeset for help on using the changeset viewer.