BBP_Forums_Group_Extension::edit_screen_save( int $group_id )

Save the Group Forum data on edit

Description

Parameters

$group_id

(Required) (to handle Group Admin UI hook bp_group_admin_edit_after )

Source

File: bp-forums/groups.php

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
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

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.