BBP_Forums_Group_Extension::create_screen_save( $group_id )

Save the Group Forum data on create

Description

Source

File: bp-forums/groups.php

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
public function create_screen_save( $group_id = 0 ) {
 
    // Nonce check
    if ( ! bbp_verify_nonce_request( 'groups_create_save_' . $this->slug ) ) {
        bbp_add_error( 'bbp_create_group_forum_screen_save', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'buddyboss' ) );
        return;
    }
 
    // Check for possibly empty group_id
    if ( empty( $group_id ) ) {
        $group_id = bp_get_new_group_id();
    }
 
    $create_forum = !empty( $_POST['bbp-create-group-forum'] ) ? true : false;
    $forum_id     = 0;
    $forum_ids    = bbp_get_group_forum_ids( $group_id );
 
    if ( !empty( $forum_ids ) )
        $forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids;
 
    // Create a forum, or not
    switch ( $create_forum ) {
        case true  :
 
            // Bail if initial content was already created
            if ( !empty( $forum_id ) )
                return;
 
            // Set the default forum status
            switch ( bp_get_new_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'   => bp_get_new_group_name(),
                'post_content' => bp_get_new_group_description(),
                'post_status'  => $status
            ) );
 
            // Run the BP-specific functions for new groups
            $this->new_forum( array( 'forum_id' => $forum_id ) );
 
            // Update forum active
            groups_update_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true );
 
            // Toggle forum on
            $this->toggle_group_forum( bp_get_new_group_id(), true );
 
            break;
        case false :
 
            // Forum was created but is now being undone
            if ( !empty( $forum_id ) ) {
 
                // Delete the forum
                wp_delete_post( $forum_id, true );
 
                // Delete meta values
                groups_delete_groupmeta( bp_get_new_group_id(), 'forum_id' );
                groups_delete_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id );
 
                // Toggle forum off
                $this->toggle_group_forum( bp_get_new_group_id(), false );
            }
 
            break;
    }
}

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.