Example #1
0
/**
 * Replaces the_content() if the post_type being displayed is one that would
 * normally be handled by bbPress, but proper single page templates do not
 * exist in the currently active theme.
 *
 * Note that we do *not* currently use is_main_query() here. This is because so
 * many existing themes either use query_posts() or fail to use wp_reset_query()
 * when running queries before the main loop, causing theme compat to fail.
 *
 * @since bbPress (r3034)
 * @param string $content
 * @return type
 */
function bbp_replace_the_content($content = '')
{
    // Bail if not inside the query loop
    if (!in_the_loop()) {
        return $content;
    }
    $bbp = bbpress();
    // Define local variable(s)
    $new_content = '';
    // Bail if shortcodes are unset somehow
    if (!is_a($bbp->shortcodes, 'BBP_Shortcodes')) {
        return $content;
    }
    // Use shortcode API to display forums/topics/replies because they are
    // already output buffered and ready to fit inside the_content
    /** Users *************************************************************/
    // Profile View
    if (bbp_is_single_user_edit() || bbp_is_single_user()) {
        ob_start();
        bbp_get_template_part('content', 'single-user');
        $new_content = ob_get_contents();
        ob_end_clean();
        /** Forums ************************************************************/
        // Forum archive
    } elseif (bbp_is_forum_archive()) {
        // Page exists where this archive should be
        $page = bbp_get_page_by_path(bbp_get_root_slug());
        if (!empty($page)) {
            // Restore previously unset filters
            bbp_restore_all_filters('the_content');
            // Remove 'bbp_replace_the_content' filter to prevent infinite loops
            remove_filter('the_content', 'bbp_replace_the_content');
            // Start output buffer
            ob_start();
            // Grab the content of this page
            $new_content = apply_filters('the_content', $page->post_content);
            // Clean up the buffer
            ob_end_clean();
            // Add 'bbp_replace_the_content' filter back (@see $this::start())
            add_filter('the_content', 'bbp_replace_the_content');
            // No page so show the archive
        } else {
            $new_content = $bbp->shortcodes->display_forum_index();
        }
        // Forum Edit
    } elseif (bbp_is_forum_edit()) {
        $new_content = $bbp->shortcodes->display_forum_form();
        // Single Forum
    } elseif (bbp_is_single_forum()) {
        $new_content = $bbp->shortcodes->display_forum(array('id' => get_the_ID()));
        /** Topics ************************************************************/
        // Topic archive
    } elseif (bbp_is_topic_archive()) {
        // Page exists where this archive should be
        $page = bbp_get_page_by_path(bbp_get_topic_archive_slug());
        if (!empty($page)) {
            // Restore previously unset filters
            bbp_restore_all_filters('the_content');
            // Remove 'bbp_replace_the_content' filter to prevent infinite loops
            remove_filter('the_content', 'bbp_replace_the_content');
            // Start output buffer
            ob_start();
            // Grab the content of this page
            $new_content = apply_filters('the_content', $page->post_content);
            // Clean up the buffer
            ob_end_clean();
            // Add 'bbp_replace_the_content' filter back (@see $this::start())
            add_filter('the_content', 'bbp_replace_the_content');
            // No page so show the archive
        } else {
            $new_content = $bbp->shortcodes->display_topic_index();
        }
        // Topic Edit
    } elseif (bbp_is_topic_edit()) {
        // Split
        if (bbp_is_topic_split()) {
            ob_start();
            bbp_get_template_part('form', 'topic-split');
            $new_content = ob_get_contents();
            ob_end_clean();
            // Merge
        } elseif (bbp_is_topic_merge()) {
            ob_start();
            bbp_get_template_part('form', 'topic-merge');
            $new_content = ob_get_contents();
            ob_end_clean();
            // Edit
        } else {
            $new_content = $bbp->shortcodes->display_topic_form();
        }
        // Single Topic
    } elseif (bbp_is_single_topic()) {
        $new_content = $bbp->shortcodes->display_topic(array('id' => get_the_ID()));
        /** Replies ***********************************************************/
        // Reply archive
    } elseif (is_post_type_archive(bbp_get_reply_post_type())) {
        //$new_content = $bbp->shortcodes->display_reply_index();
        // Reply Edit
    } elseif (bbp_is_reply_edit()) {
        $new_content = $bbp->shortcodes->display_reply_form();
        // Single Reply
    } elseif (bbp_is_single_reply()) {
        $new_content = $bbp->shortcodes->display_reply(array('id' => get_the_ID()));
        /** Views *************************************************************/
    } elseif (bbp_is_single_view()) {
        $new_content = $bbp->shortcodes->display_view(array('id' => get_query_var('bbp_view')));
        /** Topic Tags ********************************************************/
        // Show topics of tag
    } elseif (bbp_is_topic_tag()) {
        $new_content = $bbp->shortcodes->display_topics_of_tag(array('id' => bbp_get_topic_tag_id()));
        // Edit topic tag
    } elseif (bbp_is_topic_tag_edit()) {
        $new_content = $bbp->shortcodes->display_topic_tag_form();
    }
    // Juggle the content around and try to prevent unsightly comments
    if (!empty($new_content) && $new_content != $content) {
        // Set the content to be the new content
        $content = apply_filters('bbp_replace_the_content', $new_content, $content);
        // Clean up after ourselves
        unset($new_content);
        // Reset the $post global
        wp_reset_postdata();
    }
    // Return possibly hi-jacked content
    return $content;
}
Example #2
0
 protected function onWidget(array $args, \Drone\HTML &$html)
 {
     if (($page = get_post((int) $this->wo('page'))) !== null) {
         if (function_exists('bbp_version') && is_bbpress()) {
             bbp_restore_all_filters('the_content');
         }
         $html->add(Func::wpProcessContent($page->post_content));
     }
 }
/**
 * Replaces the_content() if the post_type being displayed is one that would
 * normally be handled by bbPress, but proper single page templates do not
 * exist in the currently active theme.
 *
 * @since bbPress (r3034)
 * @param string $content
 * @return type
 */
function bbp_replace_the_content($content = '')
{
    $bbp = bbpress();
    // Define local variable(s)
    $new_content = '';
    // Bail if shortcodes are unset somehow
    if (!is_a($bbp->shortcodes, 'BBP_Shortcodes')) {
        return $content;
    }
    // Use shortcode API to display forums/topics/replies because they are
    // already output buffered and ready to fit inside the_content
    /** Users *************************************************************/
    // Profile View
    if (bbp_is_single_user()) {
        ob_start();
        bbp_get_template_part('content', 'single-user');
        $new_content = ob_get_contents();
        ob_end_clean();
        // Profile Edit
    } elseif (bbp_is_single_user_edit()) {
        ob_start();
        bbp_get_template_part('content', 'single-user-edit');
        $new_content = ob_get_contents();
        ob_end_clean();
        /** Forums ************************************************************/
        // Reply Edit
    } elseif (bbp_is_forum_edit()) {
        $new_content = $bbp->shortcodes->display_forum_form();
        // Forum archive
    } elseif (bbp_is_forum_archive()) {
        // Page exists where this archive should be
        $page = bbp_get_page_by_path(bbp_get_root_slug());
        if (!empty($page)) {
            // Restore previously unset filters
            bbp_restore_all_filters('the_content');
            // Remove 'bbp_replace_the_content' filter to prevent infinite loops
            remove_filter('the_content', 'bbp_replace_the_content');
            // Start output buffer
            ob_start();
            // Grab the content of this page
            $new_content = apply_filters('the_content', $page->post_content);
            // Clean up the buffer
            ob_end_clean();
            // Add 'bbp_replace_the_content' filter back (@see $this::start())
            add_filter('the_content', 'bbp_replace_the_content');
            // No page so show the archive
        } else {
            $new_content = $bbp->shortcodes->display_forum_index();
        }
        /** Topics ************************************************************/
        // Topic archive
    } elseif (bbp_is_topic_archive()) {
        // Page exists where this archive should be
        $page = bbp_get_page_by_path(bbp_get_topic_archive_slug());
        if (!empty($page)) {
            // Restore previously unset filters
            bbp_restore_all_filters('the_content');
            // Remove 'bbp_replace_the_content' filter to prevent infinite loops
            remove_filter('the_content', 'bbp_replace_the_content');
            // Start output buffer
            ob_start();
            // Grab the content of this page
            $new_content = apply_filters('the_content', $page->post_content);
            // Clean up the buffer
            ob_end_clean();
            // Add 'bbp_replace_the_content' filter back (@see $this::start())
            add_filter('the_content', 'bbp_replace_the_content');
            // No page so show the archive
        } else {
            $new_content = $bbp->shortcodes->display_topic_index();
        }
        // Single topic
    } elseif (bbp_is_topic_edit()) {
        // Split
        if (bbp_is_topic_split()) {
            ob_start();
            bbp_get_template_part('form', 'topic-split');
            $new_content = ob_get_contents();
            ob_end_clean();
            // Merge
        } elseif (bbp_is_topic_merge()) {
            ob_start();
            bbp_get_template_part('form', 'topic-merge');
            $new_content = ob_get_contents();
            ob_end_clean();
            // Edit
        } else {
            $new_content = $bbp->shortcodes->display_topic_form();
        }
        /** Replies ***********************************************************/
        // Reply archive
    } elseif (is_post_type_archive(bbp_get_reply_post_type())) {
        //$new_content = $bbp->shortcodes->display_reply_index();
        // Reply Edit
    } elseif (bbp_is_reply_edit()) {
        $new_content = $bbp->shortcodes->display_reply_form();
        /** Views *************************************************************/
    } elseif (bbp_is_single_view()) {
        $new_content = $bbp->shortcodes->display_view(array('id' => get_query_var('bbp_view')));
        /** Topic Tags ********************************************************/
    } elseif (get_query_var('bbp_topic_tag')) {
        // Edit topic tag
        if (bbp_is_topic_tag_edit()) {
            $new_content = $bbp->shortcodes->display_topic_tag_form();
            // Show topics of tag
        } else {
            $new_content = $bbp->shortcodes->display_topics_of_tag(array('id' => bbp_get_topic_tag_id()));
        }
        /** Forums/Topics/Replies *********************************************/
    } else {
        // Check the post_type
        switch (get_post_type()) {
            // Single Forum
            case bbp_get_forum_post_type():
                $new_content = $bbp->shortcodes->display_forum(array('id' => get_the_ID()));
                break;
                // Single Topic
            // Single Topic
            case bbp_get_topic_post_type():
                $new_content = $bbp->shortcodes->display_topic(array('id' => get_the_ID()));
                break;
                // Single Reply
            // Single Reply
            case bbp_get_reply_post_type():
                $new_content = $bbp->shortcodes->display_reply(array('id' => get_the_ID()));
                break;
        }
    }
    // Juggle the content around and try to prevent unsightly comments
    if (!empty($new_content) && $new_content != $content) {
        // Set the content to be the new content
        $content = apply_filters('bbp_replace_the_content', $new_content, $content);
        // Clean up after ourselves
        unset($new_content);
        /**
         * Supplemental hack to prevent stubborn comments_template() output.
         *
         * @see comments_template() For why we're doing this :)
         *
         * Note: If a theme uses custom code to output comments, it's
         *       possible all of this dancing around is for not.
         *
         * Note: If you need to keep these globals around for any special
         *       reason, we've provided a failsafe hook to bypass this you
         *       can put in your plugin or theme below ---v
         *
         *       apply_filters( 'bbp_spill_the_beans', '__return_true' );
         */
        if (!apply_filters('bbp_spill_the_beans', false)) {
            // Empty globals that aren't being used in this loop anymore
            $GLOBALS['withcomments'] = false;
            $GLOBALS['post'] = false;
            // Reset the post data when the next sidebar is fired
            add_action('get_sidebar', 'bbp_theme_compat_reset_post_data');
            add_action('get_footer', 'bbp_theme_compat_reset_post_data');
        }
    }
    // Return possibly hi-jacked content
    return $content;
}