Skip to:
Content

bbPress.org

Changeset 3679


Ignore:
Timestamp:
01/17/2012 10:08:48 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Introduce functions and code to help create new forums from within the theme:

  • Turn on forum-form shortcode
  • Add supplemental actions for saving forum extras on new/edit
  • bbp_save_forum_extras() function to handle forum metadata saving
  • See #1669
Location:
branches/plugin/bbp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-core-shortcodes.php

    r3665 r3679  
    5959            'bbp-forum-index'  => array( $this, 'display_forum_index' ),
    6060
     61            // Topic form
     62            'bbp-forum-form'   => array( $this, 'display_forum_form'  ),
     63
     64            // Specific forum - pass an 'id' attribute
    6165            'bbp-single-forum' => array( $this, 'display_forum'       ),
    6266
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r3678 r3679  
    283283            do_action( 'bbp_new_forum', $forum_args );
    284284
     285            /** Additional Actions (After Save) *******************************/
     286
     287            do_action( 'bbp_new_forum_post_extras', $forum_id );
     288
    285289            /** Redirect ******************************************************/
    286290
     
    366370
    367371    // Define local variable(s)
    368     $forum = $forum_id = $forum_parent_id = $anonymous_data = 0;
     372    $anonymous_data = array();
     373    $forum = $forum_id = $forum_parent_id = 0;
    369374    $forum_title = $forum_content = $forum_edit_reason = '';
    370375
     
    405410    /** Forum Parent ***********************************************************/
    406411
    407     // Forum id was passed
     412    // Forum parent id was passed
    408413    if ( is_numeric( $_POST['bbp_forum_parent_id'] ) ) {
    409414        $forum_parent_id = (int) $_POST['bbp_forum_parent_id'];
     
    456461        bbp_add_error( 'bbp_edit_forum_content', __( '<strong>ERROR</strong>: Your forum cannot be empty.', 'bbpress' ) );
    457462
    458     /** forum Blacklist *******************************************************/
     463    /** Forum Blacklist *******************************************************/
    459464
    460465    if ( !bbp_check_for_blacklist( $anonymous_data, bbp_get_forum_author_id( $forum_id ), $forum_title, $forum_content ) )
     
    571576            $append_error = ( is_wp_error( $forum_id ) && $forum_id->get_error_message() ) ? $forum_id->get_error_message() . ' ' : '';
    572577            bbp_add_error( 'bbp_forum_error', __( '<strong>ERROR</strong>: The following problem(s) have been found with your forum:' . $append_error . 'Please try again.', 'bbpress' ) );
     578        }
     579    }
     580}
     581
     582/**
     583 * Handle the saving of core forum metadata (Status, Visibility, and Type)
     584 *
     585 * @since bbPress (r3678)
     586 * @param int $forum_id
     587 * @uses bbp_is_forum_closed() To check if forum is closed
     588 * @uses bbp_close_forum() To close forum
     589 * @uses bbp_open_forum() To open forum
     590 * @uses bbp_is_forum_category() To check if forum is a category
     591 * @uses bbp_categorize_forum() To turn forum into a category
     592 * @uses bbp_normalize_forum() To turn category into forum
     593 * @uses bbp_get_public_status_id() To get the public status ID
     594 * @uses bbp_get_private_status_id() To get the private status ID
     595 * @uses bbp_get_hidden_status_id() To get the hidden status ID
     596 * @uses bbp_get_forum_visibility() To get the forums visibility
     597 * @uses bbp_hide_forum() To hide a forum
     598 * @uses bbp_privatize_forum() To make a forum private
     599 * @uses bbp_publicize_forum() To make a forum public
     600 * @return If forum ID is empty
     601 */
     602function bbp_save_forum_extras( $forum_id = 0 ) {
     603
     604    // Validate the forum ID
     605    $forum_id = bbp_get_forum_id( $forum_id );
     606
     607    // Bail if forum ID is empty
     608    if ( empty( $forum_id ) )
     609        return;
     610
     611    /** Forum Status ******************************************************/
     612
     613    if ( !empty( $_POST['bbp_forum_status'] ) && in_array( $_POST['bbp_forum_status'], array( 'open', 'closed' ) ) ) {
     614        if ( 'closed' == $_POST['bbp_forum_status'] && !bbp_is_forum_closed( $forum_id, false ) ) {
     615            bbp_close_forum( $forum_id );
     616        } elseif ( 'open' == $_POST['bbp_forum_status'] && bbp_is_forum_closed( $forum_id, false ) ) {
     617            bbp_open_forum( $forum_id );
     618        }
     619    }
     620
     621    /** Forum Type ********************************************************/
     622
     623    if ( !empty( $_POST['bbp_forum_type'] ) && in_array( $_POST['bbp_forum_type'], array( 'forum', 'category' ) ) ) {
     624        if ( 'category' == $_POST['bbp_forum_type'] && !bbp_is_forum_category( $forum_id ) ) {
     625            bbp_categorize_forum( $forum_id );
     626        } elseif ( 'forum' == $_POST['bbp_forum_type'] && bbp_is_forum_category( $forum_id ) ) {
     627            bbp_normalize_forum( $forum_id );
     628        }
     629    }
     630
     631    /** Forum Visibility **************************************************/
     632
     633    if ( !empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() ) ) ) {
     634
     635        // Get forums current visibility
     636        $visibility = bbp_get_forum_visibility( $forum_id );
     637
     638        // If new visibility is different, change it
     639        if ( $visibility != $_POST['bbp_forum_visibility'] ) {
     640
     641            // What is the new forum visibility setting?
     642            switch ( $_POST['bbp_forum_visibility'] ) {
     643
     644                // Hidden
     645                case bbp_get_hidden_status_id()  :
     646                    bbp_hide_forum( $forum_id, $visibility );
     647                    break;
     648
     649                // Private
     650                case bbp_get_private_status_id() :
     651                    bbp_privatize_forum( $forum_id, $visibility );
     652                    break;
     653
     654                // Publish (default)
     655                case bbp_get_public_status_id()  :
     656                default        :
     657                    bbp_publicize_forum( $forum_id, $visibility );
     658                    break;
     659            }
    573660        }
    574661    }
Note: See TracChangeset for help on using the changeset viewer.