BBP_Forums_Group_Extension::edit_screen_save( int $group_id )
Save the Group Forum data on edit
Description
Parameters
- $group_id
-
(int) (Required) (to handle Group Admin UI hook bp_group_admin_edit_after )
Source
File: bp-forums/groups.php
public function edit_screen_save( $group_id = 0 ) { // Bail if not a POST action if ( ! bbp_is_post_request() ) return; // Admin Nonce check if ( is_admin() ) { check_admin_referer( 'groups_edit_save_' . $this->slug, 'forum_group_admin_ui' ); // Theme-side Nonce check } elseif ( ! bbp_verify_nonce_request( 'groups_edit_save_' . $this->slug ) ) { bbp_add_error( 'bbp_edit_group_forum_screen_save', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'buddyboss' ) ); return; } $edit_forum = !empty( $_POST['bbp-edit-group-forum'] ) ? true : false; $forum_id = 0; $group_id = !empty( $group_id ) ? $group_id : bp_get_current_group_id(); // Keymasters have the ability to reconfigure forums if ( bbp_is_user_keymaster() ) { $forum_ids = ! empty( $_POST['bbp_group_forum_id'] ) ? (array) (int) $_POST['bbp_group_forum_id'] : array(); // Use the existing forum IDs } else { $forum_ids = array_values( bbp_get_group_forum_ids( $group_id ) ); } // Normalize group forum relationships now if ( !empty( $forum_ids ) ) { // Loop through forums, and make sure they exist foreach ( $forum_ids as $forum_id ) { // Look for forum $forum = bbp_get_forum( $forum_id ); // No forum exists, so break the relationship if ( empty( $forum ) ) { $this->remove_forum( array( 'forum_id' => $forum_id ) ); unset( $forum_ids[$forum_id] ); } } // No support for multiple forums yet $forum_id = (int) ( is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids ); } // Update the group ID and forum ID relationships bbp_update_group_forum_ids( $group_id, (array) $forum_ids ); bbp_update_forum_group_ids( $forum_id, (array) $group_id ); // Update the group forum setting $group = $this->toggle_group_forum( $group_id, $edit_forum ); // Create a new forum if ( empty( $forum_id ) && ( true === $edit_forum ) ) { // Set the default forum status switch ( $group->status ) { case 'hidden' : $status = bbp_get_hidden_status_id(); break; case 'private' : $status = bbp_get_private_status_id(); break; case 'public' : default : $status = bbp_get_public_status_id(); break; } // Create the initial forum $forum_id = bbp_insert_forum( array( 'post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group->name, 'post_content' => $group->description, 'post_status' => $status ) ); // Setup forum args with forum ID $new_forum_args = array( 'forum_id' => $forum_id ); // If in admin, also include the group ID if ( is_admin() && !empty( $group_id ) ) { $new_forum_args['group_id'] = $group_id; } // Run the BP-specific functions for new groups $this->new_forum( $new_forum_args ); } // Redirect after save when not in admin if ( !is_admin() ) { bp_core_redirect( trailingslashit( bp_get_group_permalink( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) ); } }
Changelog
Version | Description |
---|---|
bbPress (r3465) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.