Skip to:
Content

bbPress.org

Changeset 5905


Ignore:
Timestamp:
08/10/2015 03:28:28 PM (6 years ago)
Author:
johnjamesjacoby
Message:

BuddyPress: Introduce BBP_Forums_Group_Extension::update_group_forum_visibility() to keep group forum visibility in alignment with BuddyPress Group visibility.

This changeset ensures that when a BuddyPress Group's visibility changes, it's bbPress forum visibility changes along with it. This avoids a UX issue where Group visibility and Forum visibility could become misaligned when updating a Group.

Props boonebgorges. Fixes #2599.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/extend/buddypress/groups.php

    r5868 r5905  
    8383
    8484        // Possibly redirect
    85         add_action( 'bbp_template_redirect',         array( $this, 'redirect_canonical'              ) );
     85        add_action( 'bbp_template_redirect',          array( $this, 'redirect_canonical'              ) );
    8686
    8787        // Remove group forum cap map when view is done
    88         add_action( 'bbp_after_group_forum_display', array( $this, 'remove_group_forum_meta_cap_map' ) );
    89 
    90         // bbPress needs to listen to BuddyPress group deletion.
    91         add_action( 'groups_before_delete_group',    array( $this, 'disconnect_forum_from_group'     ) );
     88        add_action( 'bbp_after_group_forum_display',  array( $this, 'remove_group_forum_meta_cap_map' ) );
     89
     90        // Check if group-forum status should be changed
     91        add_action( 'groups_group_after_save',        array( $this, 'update_group_forum_visibility'   ) );
     92
     93        // bbPress needs to listen to BuddyPress group deletion
     94        add_action( 'groups_before_delete_group',     array( $this, 'disconnect_forum_from_group'     ) );
    9295
    9396        // Adds a bbPress metabox to the new BuddyPress Group Admin UI
    94         add_action( 'bp_groups_admin_meta_boxes',    array( $this, 'group_admin_ui_edit_screen'      ) );
     97        add_action( 'bp_groups_admin_meta_boxes',     array( $this, 'group_admin_ui_edit_screen'      ) );
    9598
    9699        // Saves the bbPress options if they come from the BuddyPress Group Admin UI
    97         add_action( 'bp_group_admin_edit_after',     array( $this, 'edit_screen_save'                ) );
     100        add_action( 'bp_group_admin_edit_after',      array( $this, 'edit_screen_save'                ) );
    98101
    99102        // Adds a hidden input value to the "Group Settings" page
    100         add_action( 'bp_before_group_settings_admin', array( $this, 'group_settings_hidden_field'    ) );
     103        add_action( 'bp_before_group_settings_admin', array( $this, 'group_settings_hidden_field'     ) );
    101104    }
    102105
     
    681684            'group_id' => $group_id
    682685        ) );
     686    }
     687
     688    /**
     689     * Set forums' status to match the privacy status of the associated group
     690     *
     691     * Fired whenever a group is saved
     692     *
     693     * @param BP_Groups_Group $group Group object.
     694     */
     695    public static function update_group_forum_visibility( BP_Groups_Group $group ) {
     696
     697        // Get group forum IDs
     698        $forum_ids = bbp_get_group_forum_ids( $group->id );
     699
     700        // Bail if no forum IDs available
     701        if ( empty( $forum_ids ) ) {
     702            return;
     703        }
     704
     705        // Loop through forum IDs
     706        foreach ( $forum_ids as $forum_id ) {
     707
     708            // Get forum from ID
     709            $forum = bbp_get_forum( $forum_id );
     710
     711            // Check for change
     712            if ( $group->status !== $forum->post_status ) {
     713                switch ( $group->status ) {
     714
     715                    // Changed to hidden
     716                    case 'hidden' :
     717                        bbp_hide_forum( $forum_id, $forum->post_status );
     718                        break;
     719
     720                    // Changed to private
     721                    case 'private' :
     722                        bbp_privatize_forum( $forum_id, $forum->post_status );
     723                        break;
     724
     725                    // Changed to public
     726                    case 'public' :
     727                    default :
     728                        bbp_publicize_forum( $forum_id, $forum->post_status );
     729                        break;
     730                }
     731            }
     732        }
    683733    }
    684734
Note: See TracChangeset for help on using the changeset viewer.