| 1131 | function groups_action_leave_group() { |
| 1132 | global $bp; |
| 1133 | |
| 1134 | if ( !$bp->is_single_item || $bp->current_component != $bp->groups->slug || $bp->current_action != 'leave-group' ) |
| 1135 | return false; |
| 1136 | |
| 1137 | if ( !check_admin_referer( 'groups_leave_group' ) ) |
| 1138 | return false; |
| 1139 | |
| 1140 | // user wants to leave a group |
| 1141 | if ( groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) { |
| 1142 | if ( !groups_leave_group($bp->groups->current_group->id) ) { |
| 1143 | bp_core_add_message( __('There was an error leaving the group.', 'buddypress'), 'error' ); |
| 1144 | } else { |
| 1145 | bp_core_add_message( __('You left the group.', 'buddypress') ); |
| 1146 | } |
| 1147 | bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); |
| 1148 | } |
| 1149 | |
| 1150 | bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) ); |
| 1151 | } |
| 1152 | add_action( 'wp', 'groups_action_leave_group', 3 ); |
| 1153 | |