Skip to:
Content

bbPress.org

Changeset 2972


Ignore:
Timestamp:
04/01/2011 03:00:10 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Improve logic behind setting the current_forum/topic/reply_id global variables

Location:
branches/plugin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-forum-template.php

    r2957 r2972  
    140140        // Easy empty checking
    141141        if ( !empty( $forum_id ) && is_numeric( $forum_id ) )
    142             $bbp_forum_id = $forum_id;
     142            $bbp_forum_id = $bbp->current_forum_id = $forum_id;
    143143
    144144        // Currently inside a forum loop
    145145        elseif ( !empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) )
    146             $bbp_forum_id = $bbp->forum_query->post->ID;
     146            $bbp_forum_id = $bbp->current_forum_id = $bbp->forum_query->post->ID;
    147147
    148148        // Currently viewing a forum
    149149        elseif ( bbp_is_forum() && isset( $wp_query->post->ID ) )
    150             $bbp_forum_id = $wp_query->post->ID;
     150            $bbp_forum_id = $bbp->current_forum_id = $wp_query->post->ID;
    151151
    152152        // Currently viewing a topic
    153153        elseif ( bbp_is_topic() )
    154             $bbp_forum_id = bbp_get_topic_forum_id();
     154            $bbp_forum_id = $bbp->current_forum_id = bbp_get_topic_forum_id();
    155155
    156156        // Fallback
    157157        else
    158158            $bbp_forum_id = 0;
    159 
    160         // Set global
    161         $bbp->current_forum_id = $bbp_forum_id;
    162159
    163160        return apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );
  • branches/plugin/bbp-includes/bbp-reply-template.php

    r2962 r2972  
    221221        // Currently viewing a reply
    222222        elseif ( ( bbp_is_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) )
    223             $bbp_reply_id = $wp_query->post->ID;
     223            $bbp_reply_id = $bbp->current_reply_id = $wp_query->post->ID;
    224224
    225225        // Currently inside a replies loop
    226226        elseif ( isset( $bbp->reply_query->post->ID ) )
    227             $bbp_reply_id = $bbp->reply_query->post->ID;
     227            $bbp_reply_id = $bbp->current_reply_id = $bbp->reply_query->post->ID;
    228228
    229229        // Fallback
     
    231231            $bbp_reply_id = 0;
    232232
    233         $bbp->current_reply_id = $bbp_reply_id;
     233        // Check if current_reply_id is set, and check post_type if so
     234        if ( !empty( $bbp->current_reply_id ) && ( bbp_get_reply_post_type() != get_post_field( 'post_type', $bbp_reply_id ) ) )
     235            $bbp->current_reply_id = null;
    234236
    235237        return apply_filters( 'bbp_get_reply_id', (int) $bbp_reply_id, $reply_id );
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r2970 r2972  
    293293     */
    294294    function bbp_get_topic_id( $topic_id = 0 ) {
    295         global $bbp, $wp_query, $bbp;
     295        global $bbp, $wp_query;
    296296
    297297        // Easy empty checking
     
    305305        // Currently viewing a topic
    306306        elseif ( ( bbp_is_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) )
    307             $bbp_topic_id = $wp_query->post->ID;
     307            $bbp_topic_id = $bbp->current_topic_id = $wp_query->post->ID;
     308
     309        // Currently viewing a topic
     310        elseif ( bbp_is_reply() )
     311            $bbp_topic_id = $bbp->current_topic_id = bbp_get_reply_topic_id();
    308312
    309313        // Fallback
     
    311315            $bbp_topic_id = 0;
    312316
    313         $bbp->current_topic_id = $bbp_topic_id;
     317        // Check if current_reply_id is set, and check post_type if so
     318        if ( !empty( $bbp->current_topic_id ) && ( bbp_get_topic_post_type() != get_post_field( 'post_type', $bbp_topic_id ) ) )
     319            $bbp->current_topic_id = null;
    314320
    315321        return apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id, $topic_id );
  • branches/plugin/bbpress.php

    r2964 r2972  
    146146     * @var string Current forum id
    147147     */
    148     var $current_forum_id;
     148    var $current_forum_id = null;
    149149
    150150    /**
    151151     * @var string Current topic id
    152152     */
    153     var $current_topic_id;
     153    var $current_topic_id = null;
    154154
    155155    /**
    156156     * @var string Current reply id
    157157     */
    158     var $current_reply_id;
     158    var $current_reply_id = null;
    159159
    160160    /** User ******************************************************************/
Note: See TracChangeset for help on using the changeset viewer.