Skip to:
Content

BuddyPress.org

Ticket #6020: 6020.1.diff

File 6020.1.diff, 4.8 KB (added by tharsheblows, 10 years ago)

fixing message to be translatable in bp-group-actions

  • src/bp-groups/bp-groups-actions.php

     
    365365 * @since BuddyPress (1.2.4)
    366366 */
    367367function groups_action_leave_group() {
     368
     369        $group_id = bp_get_current_group_id();
     370        $user_id = bp_loggedin_user_id();
     371
    368372        if ( ! bp_is_single_item() || ! bp_is_groups_component() || ! bp_is_current_action( 'leave-group' ) ) {
    369373                return false;
    370374        }
     
    375379        }
    376380
    377381        // User wants to leave any group
    378         if ( groups_is_user_member( bp_loggedin_user_id(), bp_get_current_group_id() ) ) {
     382        if ( groups_is_user_member( $user_id, $group_id ) ) {
    379383                $bp = buddypress();
    380 
     384               
    381385                // Stop sole admins from abandoning their group
    382                 $group_admins = groups_get_group_admins( bp_get_current_group_id() );
     386                $group_admins = groups_get_group_admins( $group_id );
    383387
    384                 if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() ) {
     388                if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == $user_id ) {
    385389                        bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' );
    386390                } elseif ( ! groups_leave_group( $bp->groups->current_group->id ) ) {
    387391                        bp_core_add_message( __( 'There was an error leaving the group.', 'buddypress' ), 'error' );
    388392                } else {
    389                         bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) );
     393                        //if users can leave, unsubscribe them from the forum and topics
     394                        groups_leave_group_unsubscribe_forum( $group_id, $user_id );
     395                         bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) );         
    390396                }
    391397
    392398                $redirect = bp_get_group_permalink( groups_get_current_group() );
  • src/bp-groups/bp-groups-forums.php

     
    428428function groups_total_forum_topic_count( $status = 'public', $search_terms = false ) {
    429429        return apply_filters( 'groups_total_forum_topic_count', BP_Groups_Group::get_global_topic_count( $status, $search_terms ) );
    430430}
     431
     432/**
     433 * Unsubscribe user from all forums and topics when leaving a group
     434 *
     435 * @since
     436 *
     437 * @param int $group_id  ID of the group.
     438 * @param int $user_id The user whose subscriptions need to be deleted.
     439 * @return bool true if any have been deleted
     440 */
     441function groups_leave_group_unsubscribe_forum( $group_id, $user_id ){
     442       
     443        //check if bbPress is active
     444        if(  !class_exists('bbPress') ){
     445                return false;
     446        }
     447
     448        //get the forum associated with the group
     449        $forums = groups_get_groupmeta( $group_id, 'forum_id' );
     450        if( empty( $forums ) ){
     451                return false;
     452        }
     453
     454        foreach( $forums as $forum ){
     455               
     456                //get a user's forum and topic subscriptions   
     457                $forum_subscriptions = bbp_get_user_subscribed_forum_ids( $user_id );
     458                $topic_subscriptions = bbp_get_user_subscribed_topic_ids( $user_id );
     459       
     460                //bail if no subscriptions
     461                if( empty( $forum_subscriptions ) && empty( $topic_subscriptions ) ){
     462                        return false;
     463                }
     464               
     465                $group_forums_subscribed = array_intersect( (array) $forum, $forum_subscriptions );
     466                //unsubscribe if subscribed to the forum
     467                if( !empty( $group_forums_subscribed ) ){
     468                        foreach( $group_forums_subscribed as $group_forum_subscribed ){
     469                                bbp_remove_user_subscription( $user_id, $group_forum_subscribed );
     470                        }
     471                }
     472       
     473                //get all the child topics for the forum, no matter what they are
     474                $topics = (array) bbp_get_all_child_ids( $forum, 'topic' );
     475       
     476                //are any of the forum topics in the user's topic subscriptions?
     477                $group_topics_subscribed = array_intersect( $topics, $topic_subscriptions );
     478
     479                //if they are, unsubscribe them
     480                if( !empty( $group_topics_subscribed ) ){
     481                        foreach( $group_topics_subscribed as $group_topic_subscribed ){
     482                                bbp_remove_user_subscription( $user_id, $group_topic_subscribed );
     483                        }
     484       
     485                }
     486        }
     487
     488        $unsubs = ( !empty( $group_forums_subscribed ) || !empty( $group_topics_subscribed ) ) ? true : false;
     489        return $unsubs;
     490}
     491add_action( 'groups_ban_member', 'groups_leave_group_unsubscribe_forum', 10, 2);
     492add_action( 'groups_remove_member', 'groups_leave_group_unsubscribe_forum', 10, 2);
     493 No newline at end of file
  • src/bp-groups/bp-groups-functions.php

     
    371371                return false;
    372372        }
    373373
     374        //if users can leave, unsubscribe them from the forum and topics
     375        groups_leave_group_unsubscribe_forum( $group_id, $user_id );
     376
    374377        bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) );
    375378
    376379        do_action( 'groups_leave_group', $group_id, $user_id );