Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/21/2012 07:13:50 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Introduce toggle_group_forum() method to handle saving of enable_forum group setting. Fixes issue with setting not being saved when creating a new group. Props boonebgorges. Fixes #2122.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/extend/buddypress/group.php

    r4609 r4613  
    302302
    303303        // Update the group forum setting
    304         $group               = new BP_Groups_Group( $group_id );
    305         $group->enable_forum = $edit_forum;
    306         $group->save();
     304        $group = $this->toggle_group_forum( $group_id, $edit_forum );
    307305
    308306        // Create a new forum
     
    420418                groups_update_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true );
    421419
     420                // Toggle forum on
     421                $this->toggle_group_forum( bp_get_new_group_id(), true );
     422
    422423                break;
    423424            case false :
     
    425426                // Forum was created but is now being undone
    426427                if ( !empty( $forum_id ) ) {
     428
     429                    // Delete the forum
    427430                    wp_delete_post( $forum_id, true );
     431
     432                    // Delete meta values
    428433                    groups_delete_groupmeta( bp_get_new_group_id(), 'forum_id' );
    429434                    groups_delete_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id );
     435
     436                    // Toggle forum off
     437                    $this->toggle_group_forum( bp_get_new_group_id(), false );
    430438                }
    431439
     
    496504        bbp_remove_forum_id_from_group( $group_id, $forum_id );
    497505        bbp_remove_group_id_from_forum( $forum_id, $group_id );
     506    }
     507
     508    /**
     509     * Toggle the enable_forum group setting on or off
     510     *
     511     * @since bbPress (r4612)
     512     *
     513     * @param int $group_id The group to toggle
     514     * @param bool $enabled True for on, false for off
     515     * @uses groups_get_group() To get the group to toggle
     516     * @return False if group is not found, otherwise return the group
     517     */
     518    public function toggle_group_forum( $group_id = 0, $enabled = false ) {
     519
     520        // Get the group
     521        $group = groups_get_group( array( 'group_id' => $group_id ) );
     522
     523        // Bail if group cannot be found
     524        if ( empty( $group ) )
     525            return false;
     526
     527        // Set forum enabled status
     528        $group->enable_forum = (int) $enabled;
     529
     530        // Save the group
     531        $group->save();
     532
     533        // Return the group
     534        return $group;
    498535    }
    499536
Note: See TracChangeset for help on using the changeset viewer.