Skip to:
Content

Ticket #5339: 5339.toggle_is_page.patch

File 5339.toggle_is_page.patch, 2.0 KB (added by r-a-y, 4 years ago)
  • bp-core/bp-core-theme-compatibility.php

    function bp_comments_open( $open, $post_id = 0 ) { 
    819819        // Allow override of the override
    820820        return apply_filters( 'bp_force_comment_status', $retval, $open, $post_id );
    821821}
     822
     823/**
     824 * Do not allow {@link comments_template()} to render during theme compatibility.
     825 *
     826 * When theme compatibility sets the 'is_page' flag to true via
     827 * {@link bp_theme_compat_reset_post()}, themes that use comments_template()
     828 * in their page template will run.
     829 *
     830 * To prevent comments_template() from rendering, we set the 'is_page' and
     831 * 'is_single' flags to false since that function looks at these conditionals
     832 * before querying the database for comments and loading the comments template.
     833 *
     834 * This is done during the output buffer as late as possible to prevent any
     835 * wonkiness.
     836 *
     837 * @since BuddyPress (1.9.2)
     838 *
     839 * @param string $retval The current post content.
     840 */
     841function bp_toggle_is_page( $retval = '' ) {
     842        global $wp_query;
     843
     844        $wp_query->is_single = false;
     845        $wp_query->is_page   = false;
     846
     847        // set a flag so we know that we've toggled these WP_Query properties
     848        buddypress()->theme_compat->is_page_toggled = true;
     849
     850        return $retval;
     851}
     852add_filter( 'bp_replace_the_content', 'bp_toggle_is_page', 9999 );
     853
     854/**
     855 * Restores the 'is_single' and 'is_page' flags if toggled by BuddyPress.
     856 *
     857 * @since BuddyPress (1.9.2)
     858 *
     859 * @see bp_toggle_is_page()
     860 * @param object $query The WP_Query object.
     861 */
     862function bp_loop_end( $query ) {
     863        // check for our special flag and revert some WP_Query properties
     864        if ( isset( buddypress()->theme_compat->is_page_toggled ) ) {
     865                $query->is_single = true;
     866                $query->is_page   = true;
     867                unset( buddypress()->theme_compat->is_page_toggled );
     868        }
     869}
     870add_action( 'loop_end', 'bp_loop_end' );
     871 No newline at end of file