Skip to:
Content

bbPress.org

Changeset 5080


Ignore:
Timestamp:
08/19/2013 07:47:49 AM (8 years ago)
Author:
johnjamesjacoby
Message:

Separate content replacement from title replacement in forum and topic archives, allowing pages with matching slugs but empty post_content to replace the_content as expected. Fixes situation where a user creates a "Forums" page and leaves the content empty, expecting bbPress to replace it.

Also use the $page->ID to help "Edit" links to point to the correct post ID.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/core/theme-compat.php

    r5043 r5080  
    475475        // Page exists where this archive should be
    476476        $page = bbp_get_page_by_path( bbp_get_root_slug() );
    477         if ( !empty( $page ) ) {
     477
     478        // Should we replace the content...
     479        if ( empty( $page->post_content ) ) {
     480
     481            // Use the topics archive
     482            if ( 'topics' === bbp_show_on_root() ) {
     483                $new_content = $bbp_shortcodes->display_topic_index();
     484
     485            // No page so show the archive
     486            } else {
     487                $new_content = $bbp_shortcodes->display_forum_index();
     488            }
     489
     490        // ...or use the existing page content?
     491        } else {
    478492            $new_content = apply_filters( 'the_content', $page->post_content );
    479             $new_title   = apply_filters( 'the_title',   $page->post_title   );
    480 
    481         // Use the topics archive
    482         } elseif ( 'topics' === bbp_show_on_root() ) {
    483             $new_content = $bbp_shortcodes->display_topic_index();
    484             $new_title   = bbp_get_topic_archive_title();
    485 
    486         // No page so show the archive
     493        }
     494
     495        // Should we replace the title...
     496        if ( empty( $page->post_title ) ) {
     497
     498            // Use the topics archive
     499            if ( 'topics' === bbp_show_on_root() ) {
     500                $new_title = bbp_get_topic_archive_title();
     501
     502            // No page so show the archive
     503            } else {
     504                $new_title = bbp_get_forum_archive_title();
     505            }
     506
     507        // ...or use the existing page title?
    487508        } else {
    488             $new_content = $bbp_shortcodes->display_forum_index();
    489             $new_title   = bbp_get_forum_archive_title();
     509            $new_title = apply_filters( 'the_title',   $page->post_title   );
    490510        }
    491511
    492512        // Reset post
    493513        bbp_theme_compat_reset_post( array(
    494             'ID'             => 0,
     514            'ID'             => !empty( $page->ID ) ? $page->ID : 0,
    495515            'post_title'     => $new_title,
    496516            'post_author'    => 0,
     
    541561        // Page exists where this archive should be
    542562        $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() );
    543         if ( !empty( $page ) ) {
     563
     564        // Should we replace the content...
     565        if ( empty( $page->post_content ) ) {
     566            $new_content = $bbp_shortcodes->display_topic_index();
     567
     568        // ...or use the existing page content?
     569        } else {
    544570            $new_content = apply_filters( 'the_content', $page->post_content );
    545 
    546         // No page so show the archive
     571        }
     572
     573        // Should we replace the title...
     574        if ( empty( $page->post_title ) ) {
     575            $new_title = bbp_get_topic_archive_title();
     576
     577        // ...or use the existing page title?
    547578        } else {
    548             $new_content = $bbp_shortcodes->display_topic_index();
     579            $new_title = apply_filters( 'the_title',   $page->post_title   );
    549580        }
    550581
    551582        // Reset post
    552583        bbp_theme_compat_reset_post( array(
    553             'ID'             => 0,
     584            'ID'             => !empty( $page->ID ) ? $page->ID : 0,
    554585            'post_title'     => bbp_get_topic_archive_title(),
    555586            'post_author'    => 0,
Note: See TracChangeset for help on using the changeset viewer.