Skip to:
Content

bbPress.org

Changeset 5012


Ignore:
Timestamp:
07/10/2013 05:20:45 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Allow topic form shortcode to accept a forum_id attribute. Props netweb, GautamGupta. Fixes #1649.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/common/shortcodes.php

    r5002 r5012  
    378378     * post/page contents are displayed first.
    379379     *
    380      * @since bbPress (r3031)
    381      *
    382      * @uses get_template_part()
    383      */
    384     public function display_topic_form() {
    385 
    386         // Start output buffer
    387         $this->start( 'bbp_topic_form' );
    388 
    389         // Output templates
    390         bbp_get_template_part( 'form', 'topic' );
     380     * Supports 'forum_id' attribute to display the topic form for a particular
     381     * forum. This currently has styling issues from not being wrapped in
     382     * <div id="bbpress-forums"></div> which will need to be sorted out later.
     383     *
     384     * @since bbPress (r3031)
     385     *
     386     * @param array $attr
     387     * @param string $content
     388     * @uses get_template_part()
     389     * @return string
     390     */
     391    public function display_topic_form( $attr, $content = '' ) {
     392
     393        // Sanity check supplied info
     394        if ( !empty( $content ) || ( !empty( $attr['forum_id'] ) && ( !is_numeric( $attr['forum_id'] ) || !bbp_is_forum( $attr['forum_id'] ) ) ) )
     395            return $content;
     396
     397        // Unset globals
     398        $this->unset_globals();
     399
     400        // If forum id is set, use the 'bbp_single_forum' query name
     401        if ( !empty( $attr['forum_id'] ) ) {
     402
     403            // Set the global current_forum_id for future requests
     404            bbpress()->current_forum_id = $forum_id = bbp_get_forum_id( $attr['forum_id'] );
     405
     406            // Start output buffer
     407            $this->start( 'bbp_single_forum' );
     408
     409        // No forum id was passed
     410        } else {
     411
     412            // Set the $forum_id variable to satisfy checks below
     413            $forum_id = 0;
     414
     415            // Start output buffer
     416            $this->start( 'bbp_topic_form' );
     417        }
     418
     419        // If the forum id is set, check forum caps else display normal topic form
     420        if ( empty( $forum_id ) || bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
     421            bbp_get_template_part( 'form', 'topic' );
     422
     423        // Forum is private and user does not have caps
     424        } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
     425            bbp_get_template_part( 'feedback', 'no-access' );
     426        }
    391427
    392428        // Return contents of output buffer
     
    755791        else
    756792            bbp_get_template_part( 'feedback', 'logged-in'      );
    757    
     793
    758794        // Return contents of output buffer
    759795        return $this->end();
Note: See TracChangeset for help on using the changeset viewer.