Skip to:
Content

bbPress.org

Changeset 3386


Ignore:
Timestamp:
08/07/2011 04:21:43 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Fix issue where pagination on topic tag page was not working. This uncovered underlying issues with how posts and globals were reset as part of theme compatibility. Fixes #1589.

Location:
branches/plugin
Files:
10 edited

Legend:

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

    r3384 r3386  
    234234 */
    235235function bbp_is_topic_tag() {
    236 
    237     if ( is_tax( bbp_get_topic_tag_tax_id() ) )
     236    global $bbp;
     237
     238    if ( is_tax( bbp_get_topic_tag_tax_id() ) || !empty( $bbp->topic_query->is_tax ) )
    238239        return true;
    239240
  • branches/plugin/bbp-includes/bbp-core-compatibility.php

    r3374 r3386  
    245245            'post_content' => get_the_content(),
    246246            'post_type'    => get_post_type(),
    247             'post_status'  => get_post_status()
     247            'post_status'  => get_post_status(),
     248            'is_404'       => false,
     249            'is_page'      => false,
     250            'is_single'    => false,
     251            'is_archive'   => false,
     252            'is_tax'       => false,
    248253        );
    249254
     
    257262            'post_content' => '',
    258263            'post_type'    => 'page',
    259             'post_status'  => 'publish'
     264            'post_status'  => 'publish',
     265            'is_404'       => false,
     266            'is_page'      => false,
     267            'is_single'    => false,
     268            'is_archive'   => false,
     269            'is_tax'       => false,
    260270        );
    261271    }
    262272    $dummy = wp_parse_args( $args, $defaults );
     273
     274    // Clear out the post related globals
     275    unset( $wp_query->posts );
     276    unset( $wp_query->post  );
     277    unset( $post            );
    263278
    264279    // Setup the dummy post object
     
    275290
    276291    // Setup the dummy post loop
    277     $wp_query->posts[] = $wp_query->post;
     292    $wp_query->posts[0] = $wp_query->post;
    278293
    279294    // Prevent comments form from appearing
    280295    $wp_query->post_count = 1;
    281     $wp_query->is_404     = false;
    282     $wp_query->is_page    = false;
    283     $wp_query->is_single  = false;
    284     $wp_query->is_archive = false;
    285     $wp_query->is_tax     = false;
     296    $wp_query->is_404     = $dummy['is_404'];
     297    $wp_query->is_page    = $dummy['is_page'];
     298    $wp_query->is_single  = $dummy['is_single'];
     299    $wp_query->is_archive = $dummy['is_archive'];
     300    $wp_query->is_tax     = $dummy['is_tax'];
    286301
    287302    // If we are resetting a post, we are in theme compat
     
    707722
    708723        // Viewing a user
    709         if     ( bbp_is_single_user()       && ( $new_template = bbp_get_single_user_template()       ) ) :
     724        if     ( bbp_is_single_user()      && ( $new_template = bbp_get_single_user_template()      ) ) :
    710725
    711726        // Editing a user
    712         elseif ( bbp_is_single_user_edit()  && ( $new_template = bbp_get_single_user_edit_template() ) ) :
     727        elseif ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
    713728
    714729        // Single View
    715         elseif ( bbp_is_single_view()       && ( $new_template = bbp_get_single_view_template()       ) ) :
     730        elseif ( bbp_is_single_view()      && ( $new_template = bbp_get_single_view_template()      ) ) :
    716731
    717732        // Topic merge
    718         elseif ( bbp_is_topic_merge()       && ( $new_template = bbp_get_topic_merge_template()       ) ) :
     733        elseif ( bbp_is_topic_merge()      && ( $new_template = bbp_get_topic_merge_template()      ) ) :
    719734
    720735        // Topic split
    721         elseif ( bbp_is_topic_split()       && ( $new_template = bbp_get_topic_split_template()       ) ) :
     736        elseif ( bbp_is_topic_split()      && ( $new_template = bbp_get_topic_split_template()      ) ) :
    722737
    723738        // Topic edit
    724         elseif ( bbp_is_topic_edit()        && ( $new_template = bbp_get_topic_edit_template()        ) ) :
     739        elseif ( bbp_is_topic_edit()       && ( $new_template = bbp_get_topic_edit_template()       ) ) :
    725740
    726741        // Editing a reply
    727         elseif ( bbp_is_reply_edit()        && ( $new_template = bbp_get_reply_edit_template()        ) ) :
     742        elseif ( bbp_is_reply_edit()       && ( $new_template = bbp_get_reply_edit_template()       ) ) :
    728743
    729744        // Editing a topic tag
    730         elseif ( bbp_is_topic_tag_edit()    && ( $new_template = bbp_get_topic_tag_edit_template()    ) ) :
     745        elseif ( bbp_is_topic_tag()        && ( $new_template = bbp_get_topic_tag_template()        ) ) :
     746
     747        // Editing a topic tag
     748        elseif ( bbp_is_topic_tag_edit()   && ( $new_template = bbp_get_topic_tag_edit_template()   ) ) :
    731749        endif;
    732750
     
    770788                'post_content' => '',
    771789                'post_type'    => bbp_get_forum_post_type(),
    772                 'post_status'  => 'publish'
     790                'post_status'  => 'publish',
     791                'is_archive'   => true
    773792            ) );
    774793
     
    786805                'post_content' => '',
    787806                'post_type'    => bbp_get_topic_post_type(),
    788                 'post_status'  => 'publish'
     807                'post_status'  => 'publish',
     808                'is_archive'   => true
    789809            ) );
    790810
     
    800820                'post_content' => get_post_field( 'post_content', bbp_get_topic_id() ),
    801821                'post_type'    => bbp_get_topic_post_type(),
    802                 'post_status'  => bbp_get_topic_status()
     822                'post_status'  => bbp_get_topic_status(),
     823                'is_single'    => true
    803824            ) );
    804825
     
    858879            // Reset the post with our new title
    859880            bbp_theme_compat_reset_post( array(
    860                 'post_title' => sprintf( __( 'Edit Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' ),
     881                'post_title' => sprintf( __( 'Edit Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' )
    861882            ) );
    862883
     
    868889            // Reset the post with our new title
    869890            bbp_theme_compat_reset_post( array(
    870                 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' ),
     891                'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' )
    871892            ) );
    872893
     
    10681089            // Show topics of tag
    10691090            } else {
    1070                 $new_content = $bbp->shortcodes->display_topics_of_tag ( array( 'id' => bbp_get_topic_tag_id() ) );
     1091                $new_content = $bbp->shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) );
    10711092            }
    10721093
     
    15011522    // Topic tag page
    15021523    } elseif ( bbp_is_topic_tag() ) {
    1503         $posts_query->query_vars['post_type'] = bbp_get_topic_post_type();
     1524        $posts_query->query_vars['post_type']      = bbp_get_topic_post_type();
     1525        $posts_query->query_vars['posts_per_page'] = get_option( '_bbp_topics_per_page', 15 );
    15041526    }
    15051527
  • branches/plugin/bbp-includes/bbp-core-shortcodes.php

    r3376 r3386  
    133133
    134134        // Unset global queries
    135         $bbp->forum_query      = null;
    136         $bbp->topic_query      = null;
    137         $bbp->reply_query      = null;
     135        $bbp->forum_query      = array();
     136        $bbp->topic_query      = array();
     137        $bbp->reply_query      = array();
    138138
    139139        // Unset global ID's
    140         $bbp->current_forum_id = null;
    141         $bbp->current_topic_id = null;
    142         $bbp->current_reply_id = null;
     140        $bbp->current_forum_id = 0;
     141        $bbp->current_topic_id = 0;
     142        $bbp->current_reply_id = 0;
    143143
    144144        // Reset the post data
  • branches/plugin/bbp-includes/bbp-core-widgets.php

    r3375 r3386  
    653653
    654654                        <?php
     655                        $author_link = bbp_get_reply_author_link( array( 'type' => 'both', 'size' => 14 ) );
     656                        $reply_link  = '<a class="bbp-reply-topic-title" href="' . esc_url( bbp_get_reply_url() ) . '" title="' . bbp_get_reply_excerpt( bbp_get_reply_id(), 50 ) . '">' . bbp_get_reply_topic_title() . '</a>';
     657                       
    655658                        /* translators: bbpress replies widget: 1: reply author, 2: reply link, 3: reply date, 4: reply time */
    656                         printf( _x( $show_date == 'on' ? '%1$s on %2$s, %3$s, %4$s' : '%1$s on %2$s', 'widgets', 'bbpress' ), bbp_get_reply_author_link( array( 'type' => 'both', 'size' => 14 ) ), '<a class="bbp-reply-topic-title" href="' . esc_url( bbp_get_reply_url() ) . '" title="' . bbp_get_reply_excerpt( bbp_get_reply_id(), 50 ) . '">' . bbp_get_reply_topic_title() . '</a>', get_the_date(), get_the_time() );
     659                        printf( _x( $show_date == 'on' ? '%1$s on %2$s, %3$s, %4$s' : '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link, get_the_date(), get_the_time() );
    657660                        ?>
    658661
  • branches/plugin/bbp-includes/bbp-forum-template.php

    r3349 r3386  
    6060function bbp_has_forums( $args = '' ) {
    6161    global $bbp;
    62 
    63     // Make sure we're back where we started
    64     wp_reset_postdata();
    6562
    6663    // Setup possible post__not_in array
  • branches/plugin/bbp-includes/bbp-reply-template.php

    r3382 r3386  
    6969    global $wp_rewrite, $bbp;
    7070
    71     // Make sure we're back where we started
    72     wp_reset_postdata();
    73 
    7471    // Default status
    7572    $default_status = join( ',', array( 'publish', $bbp->closed_status_id ) );
     
    137134
    138135    // Only add pagination if query returned results
    139     if ( (int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) {
     136    if ( !bbp_is_query_name( 'bbp_widget' ) && (int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) {
    140137
    141138        // If pretty permalinks are enabled, make our pagination pretty
     
    245242            $bbp_reply_id = $reply_id;
    246243
     244        // Currently inside a replies loop
     245        elseif ( isset( $bbp->reply_query->post->ID ) )
     246            $bbp_reply_id = $bbp->current_reply_id = $bbp->reply_query->post->ID;
     247
    247248        // Currently viewing a reply
    248249        elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) )
    249250            $bbp_reply_id = $bbp->current_reply_id = $wp_query->post->ID;
    250 
    251         // Currently inside a replies loop
    252         elseif ( isset( $bbp->reply_query->post->ID ) )
    253             $bbp_reply_id = $bbp->current_reply_id = $bbp->reply_query->post->ID;
    254251
    255252        // Fallback
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r3382 r3386  
    6969    global $wp_rewrite, $wp_query, $bbp, $wpdb;
    7070
    71     // Make sure we're back where we started
    72     if ( !bbp_is_topic_tag() )
    73         wp_reset_postdata();
    74 
    7571    // What are the default allowed statuses (based on user caps)
    7672    if ( !bbp_is_query_name( 'bbp_widget' ) && bbp_get_view_all() )
     
    228224
    229225    // Only add pagination if query returned results
    230     if ( ( (int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts ) && (int) $bbp->topic_query->posts_per_page ) {
     226    if ( !bbp_is_query_name( 'bbp_widget' ) && ( (int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts ) && (int) $bbp->topic_query->posts_per_page ) {
    231227
    232228        // Limit the number of topics shown based on maximum allowed pages
     
    244240            elseif ( bbp_is_single_view() )
    245241                $base = bbp_get_view_url();
     242
     243            // Topic tag
     244            elseif ( bbp_is_topic_tag() )
     245                $base = bbp_get_topic_tag_link();
    246246
    247247            // Page or single post
     
    23912391        global $bbp;
    23922392
    2393         if ( !isset( $bbp->topic_query ) )
     2393        if ( empty( $bbp->topic_query ) )
    23942394            return false;
    23952395
     
    24352435        global $bbp;
    24362436
    2437         if ( !isset( $bbp->topic_query ) )
     2437        if ( empty( $bbp->topic_query ) )
    24382438            return false;
    24392439
     
    28242824        // Add before and after if description exists
    28252825        if ( !empty( $term->term_id ) )
    2826             $retval = get_term_link( $term->term_id, bbp_get_topic_tag_tax_id() );
     2826            $retval = get_term_link( $term, bbp_get_topic_tag_tax_id() );
    28272827
    28282828        // No link
  • branches/plugin/bbp-themes/bbp-twentyten/bbpress/form-protected.php

    r3207 r3386  
    88 */
    99
    10 // Make sure we're back where we started
    11 wp_reset_postdata();
    12 
    1310?>
    1411
  • branches/plugin/bbp-themes/bbp-twentyten/bbpress/form-reply.php

    r3366 r3386  
    77 * @subpackage Theme
    88 */
    9 
    10 // Make sure we're back where we started
    11 wp_reset_postdata();
    129
    1310?>
  • branches/plugin/bbp-themes/bbp-twentyten/bbpress/form-topic.php

    r3375 r3386  
    77 * @subpackage Theme
    88 */
    9 
    10 // Make sure we're back where we started
    11 wp_reset_postdata();
    129
    1310?>
Note: See TracChangeset for help on using the changeset viewer.