/**
 * Possibly intercept the template being loaded
 *
 * Listens to the 'template_include' filter and waits for any bbPress specific
 * template condition to be met. If one is met and the template file exists,
 * it will be used; otherwise 
 *
 * Note that the _edit() checks are ahead of their counterparts, to prevent them
 * from being stomped on accident.
 *
 * @since bbPress (r3032)
 *
 * @param string $template
 *
 * @uses bbp_is_single_user() To check if page is single user
 * @uses bbp_get_single_user_template() To get user template
 * @uses bbp_is_single_user_edit() To check if page is single user edit
 * @uses bbp_get_single_user_edit_template() To get user edit template
 * @uses bbp_is_single_view() To check if page is single view
 * @uses bbp_get_single_view_template() To get view template
 * @uses bbp_is_search() To check if page is search
 * @uses bbp_get_search_template() To get search template
 * @uses bbp_is_forum_edit() To check if page is forum edit
 * @uses bbp_get_forum_edit_template() To get forum edit template
 * @uses bbp_is_topic_merge() To check if page is topic merge
 * @uses bbp_get_topic_merge_template() To get topic merge template
 * @uses bbp_is_topic_split() To check if page is topic split
 * @uses bbp_get_topic_split_template() To get topic split template
 * @uses bbp_is_topic_edit() To check if page is topic edit
 * @uses bbp_get_topic_edit_template() To get topic edit template
 * @uses bbp_is_reply_move() To check if page is reply move
 * @uses bbp_get_reply_move_template() To get reply move template
 * @uses bbp_is_reply_edit() To check if page is reply edit
 * @uses bbp_get_reply_edit_template() To get reply edit template
 * @uses bbp_set_theme_compat_template() To set the global theme compat template
 *
 * @return string The path to the template file that is being used
 */
function bbp_template_include_theme_supports($template = '')
{
    // Editing a user
    if (bbp_is_single_user_edit() && ($new_template = bbp_get_single_user_edit_template())) {
        // User favorites
    } elseif (bbp_is_favorites() && ($new_template = bbp_get_favorites_template())) {
        // User favorites
    } elseif (bbp_is_subscriptions() && ($new_template = bbp_get_subscriptions_template())) {
        // Viewing a user
    } elseif (bbp_is_single_user() && ($new_template = bbp_get_single_user_template())) {
        // Single View
    } elseif (bbp_is_single_view() && ($new_template = bbp_get_single_view_template())) {
        // Search
    } elseif (bbp_is_search() && ($new_template = bbp_get_search_template())) {
        // Forum edit
    } elseif (bbp_is_forum_edit() && ($new_template = bbp_get_forum_edit_template())) {
        // Single Forum
    } elseif (bbp_is_single_forum() && ($new_template = bbp_get_single_forum_template())) {
        // Forum Archive
    } elseif (bbp_is_forum_archive() && ($new_template = bbp_get_forum_archive_template())) {
        // Topic merge
    } elseif (bbp_is_topic_merge() && ($new_template = bbp_get_topic_merge_template())) {
        // Topic split
    } elseif (bbp_is_topic_split() && ($new_template = bbp_get_topic_split_template())) {
        // Topic edit
    } elseif (bbp_is_topic_edit() && ($new_template = bbp_get_topic_edit_template())) {
        // Single Topic
    } elseif (bbp_is_single_topic() && ($new_template = bbp_get_single_topic_template())) {
        // Topic Archive
    } elseif (bbp_is_topic_archive() && ($new_template = bbp_get_topic_archive_template())) {
        // Reply move
    } elseif (bbp_is_reply_move() && ($new_template = bbp_get_reply_move_template())) {
        // Editing a reply
    } elseif (bbp_is_reply_edit() && ($new_template = bbp_get_reply_edit_template())) {
        // Single Reply
    } elseif (bbp_is_single_reply() && ($new_template = bbp_get_single_reply_template())) {
        // Editing a topic tag
    } elseif (bbp_is_topic_tag_edit() && ($new_template = bbp_get_topic_tag_edit_template())) {
        // Viewing a topic tag
    } elseif (bbp_is_topic_tag() && ($new_template = bbp_get_topic_tag_template())) {
    }
    // A bbPress template file was located, so override the WordPress template
    // and use it to switch off bbPress's theme compatibility.
    if (!empty($new_template)) {
        $template = bbp_set_template_included($new_template);
    }
    return apply_filters('bbp_template_include_theme_supports', $template);
}
Exemple #2
0
/**
 * Possibly intercept the template being loaded
 *
 * Listens to the 'template_include' filter and waits for any bbPress specific
 * template condition to be met. If one is met and the template file exists,
 * it will be used; otherwise 
 *
 * Note that the _edit() checks are ahead of their counterparts, to prevent them
 * from being stomped on accident.
 *
 * @since bbPress (r3032)
 *
 * @param string $template
 *
 * @uses bbp_is_single_user() To check if page is single user
 * @uses bbp_get_single_user_template() To get user template
 * @uses bbp_is_single_user_edit() To check if page is single user edit
 * @uses bbp_get_single_user_edit_template() To get user edit template
 * @uses bbp_is_single_view() To check if page is single view
 * @uses bbp_get_single_view_template() To get view template
 * @uses bbp_is_forum_edit() To check if page is forum edit
 * @uses bbp_get_forum_edit_template() To get forum edit template
 * @uses bbp_is_topic_merge() To check if page is topic merge
 * @uses bbp_get_topic_merge_template() To get topic merge template
 * @uses bbp_is_topic_split() To check if page is topic split
 * @uses bbp_get_topic_split_template() To get topic split template
 * @uses bbp_is_topic_edit() To check if page is topic edit
 * @uses bbp_get_topic_edit_template() To get topic edit template
 * @uses bbp_is_reply_edit() To check if page is reply edit
 * @uses bbp_get_reply_edit_template() To get reply edit template
 * @uses bbp_set_theme_compat_template() To set the global theme compat template
 *
 * @return string The path to the template file that is being used
 */
function bbp_template_include_theme_supports($template = '')
{
    // Editing a user
    if (bbp_is_single_user_edit() && ($new_template = bbp_get_single_user_edit_template())) {
        // User favorites
    } elseif (bbp_is_favorites() && ($new_template = bbp_get_favorites_template())) {
        // User favorites
    } elseif (bbp_is_subscriptions() && ($new_template = bbp_get_subscriptions_template())) {
        // Viewing a user
    } elseif (bbp_is_single_user() && ($new_template = bbp_get_single_user_template())) {
        // Single View
    } elseif (bbp_is_single_view() && ($new_template = bbp_get_single_view_template())) {
        // Forum edit
    } elseif (bbp_is_forum_edit() && ($new_template = bbp_get_forum_edit_template())) {
        // Single Forum
    } elseif (bbp_is_single_forum() && ($new_template = bbp_get_single_forum_template())) {
        // Forum Archive
    } elseif (bbp_is_forum_archive() && ($new_template = bbp_get_forum_archive_template())) {
        // Topic merge
    } elseif (bbp_is_topic_merge() && ($new_template = bbp_get_topic_merge_template())) {
        // Topic split
    } elseif (bbp_is_topic_split() && ($new_template = bbp_get_topic_split_template())) {
        // Topic edit
    } elseif (bbp_is_topic_edit() && ($new_template = bbp_get_topic_edit_template())) {
        // Single Topic
    } elseif (bbp_is_single_topic() && ($new_template = bbp_get_single_topic_template())) {
        // Topic Archive
    } elseif (bbp_is_topic_archive() && ($new_template = bbp_get_topic_archive_template())) {
        // Editing a reply
    } elseif (bbp_is_reply_edit() && ($new_template = bbp_get_reply_edit_template())) {
        // Single Reply
    } elseif (bbp_is_single_reply() && ($new_template = bbp_get_single_reply_template())) {
        // Editing a topic tag
    } elseif (bbp_is_topic_tag_edit() && ($new_template = bbp_get_topic_tag_edit_template())) {
        // Viewing a topic tag
    } elseif (bbp_is_topic_tag() && ($new_template = bbp_get_topic_tag_template())) {
    }
    // bbPress template file exists
    if (!empty($new_template)) {
        // Override the WordPress template with a bbPress one
        $template = $new_template;
        // @see: bbp_template_include_theme_compat()
        bbpress()->theme_compat->bbpress_template = true;
    }
    return apply_filters('bbp_template_include_theme_supports', $template);
}
/**
 * Redirect if unathorized user is attempting to edit a forum
 *
 * @since bbPress (r3607)
 *
 * @uses bbp_is_forum_edit()
 * @uses current_user_can()
 * @uses bbp_get_forum_id()
 * @uses wp_safe_redirect()
 * @uses bbp_get_forum_permalink()
 */
function bbp_check_forum_edit()
{
    // Bail if not editing a topic
    if (!bbp_is_forum_edit()) {
        return;
    }
    // User cannot edit topic, so redirect back to reply
    if (!current_user_can('edit_forum', bbp_get_forum_id())) {
        wp_safe_redirect(bbp_get_forum_permalink());
        exit;
    }
}
/**
 * Return a breadcrumb ( forum -> topic -> reply )
 *
 * @since bbPress (r2589)
 *
 * @param string $sep Separator. Defaults to '←'
 * @param bool $current_page Include the current item
 * @param bool $root Include the root page if one exists
 *
 * @uses get_post() To get the post
 * @uses bbp_get_forum_permalink() To get the forum link
 * @uses bbp_get_topic_permalink() To get the topic link
 * @uses bbp_get_reply_permalink() To get the reply link
 * @uses get_permalink() To get the permalink
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_forum_title() To get the forum title
 * @uses bbp_get_topic_title() To get the topic title
 * @uses bbp_get_reply_title() To get the reply title
 * @uses get_the_title() To get the title
 * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs
 * @return string Breadcrumbs
 */
function bbp_get_breadcrumb($args = array())
{
    // Turn off breadcrumbs
    if (apply_filters('bbp_no_breadcrumb', is_front_page())) {
        return;
    }
    // Define variables
    $front_id = $root_id = 0;
    $ancestors = $crumbs = $tag_data = array();
    $pre_root_text = $pre_front_text = $pre_current_text = '';
    $pre_include_root = $pre_include_home = $pre_include_current = true;
    /** Home Text *********************************************************/
    // No custom home text
    if (empty($args['home_text'])) {
        // Set home text to page title
        $front_id = get_option('page_on_front');
        if (!empty($front_id)) {
            $pre_front_text = get_the_title($front_id);
            // Default to 'Home'
        } else {
            $pre_front_text = __('Home', 'bbpress');
        }
    }
    /** Root Text *********************************************************/
    // No custom root text
    if (empty($args['root_text'])) {
        $page = bbp_get_page_by_path(bbp_get_root_slug());
        if (!empty($page)) {
            $root_id = $page->ID;
        }
        $pre_root_text = bbp_get_forum_archive_title();
    }
    /** Includes **********************************************************/
    // Root slug is also the front page
    if (!empty($front_id) && $front_id == $root_id) {
        $pre_include_root = false;
    }
    // Don't show root if viewing forum archive
    if (bbp_is_forum_archive()) {
        $pre_include_root = false;
    }
    // Don't show root if viewing page in place of forum archive
    if (!empty($root_id) && ((is_single() || is_page()) && $root_id == get_the_ID())) {
        $pre_include_root = false;
    }
    /** Current Text ******************************************************/
    // Forum archive
    if (bbp_is_forum_archive()) {
        $pre_current_text = bbp_get_forum_archive_title();
        // Topic archive
    } elseif (bbp_is_topic_archive()) {
        $pre_current_text = bbp_get_topic_archive_title();
        // View
    } elseif (bbp_is_single_view()) {
        $pre_current_text = bbp_get_view_title();
        // Single Forum
    } elseif (bbp_is_single_forum()) {
        $pre_current_text = bbp_get_forum_title();
        // Single Topic
    } elseif (bbp_is_single_topic()) {
        $pre_current_text = bbp_get_topic_title();
        // Single Topic
    } elseif (bbp_is_single_reply()) {
        $pre_current_text = bbp_get_reply_title();
        // Topic Tag (or theme compat topic tag)
    } elseif (bbp_is_topic_tag() || get_query_var('bbp_topic_tag') && !bbp_is_topic_tag_edit()) {
        // Always include the tag name
        $tag_data[] = bbp_get_topic_tag_name();
        // If capable, include a link to edit the tag
        if (current_user_can('manage_topic_tags')) {
            $tag_data[] = '<a href="' . bbp_get_topic_tag_edit_link() . '" class="bbp-edit-topic-tag-link">' . __('(Edit)', 'bbpress') . '</a>';
        }
        // Implode the results of the tag data
        $pre_current_text = sprintf(__('Topic Tag: %s', 'bbpress'), implode(' ', $tag_data));
        // Edit Topic Tag
    } elseif (bbp_is_topic_tag_edit()) {
        $pre_current_text = __('Edit', 'bbpress');
        // Single
    } else {
        $pre_current_text = get_the_title();
    }
    /** Parse Args ********************************************************/
    // Parse args
    $defaults = array('before' => '<div class="bbp-breadcrumb"><p>', 'after' => '</p></div>', 'sep' => __('&rsaquo;', 'bbpress'), 'pad_sep' => 1, 'include_home' => $pre_include_home, 'home_text' => $pre_front_text, 'include_root' => $pre_include_root, 'root_text' => $pre_root_text, 'include_current' => $pre_include_current, 'current_text' => $pre_current_text);
    $r = bbp_parse_args($args, $defaults, 'get_breadcrumb');
    extract($r);
    /** Ancestors *********************************************************/
    // Get post ancestors
    if (is_page() || is_single() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit()) {
        $ancestors = array_reverse(get_post_ancestors(get_the_ID()));
    }
    // Do we want to include a link to home?
    if (!empty($include_home) || empty($home_text)) {
        $crumbs[] = '<a href="' . trailingslashit(home_url()) . '" class="bbp-breadcrumb-home">' . $home_text . '</a>';
    }
    // Do we want to include a link to the forum root?
    if (!empty($include_root) || empty($root_text)) {
        // Page exists at root slug path, so use its permalink
        $page = bbp_get_page_by_path(bbp_get_root_slug());
        if (!empty($page)) {
            $root_url = get_permalink($page->ID);
            // Use the root slug
        } else {
            $root_url = get_post_type_archive_link(bbp_get_forum_post_type());
        }
        // Add the breadcrumb
        $crumbs[] = '<a href="' . $root_url . '" class="bbp-breadcrumb-root">' . $root_text . '</a>';
    }
    // Ancestors exist
    if (!empty($ancestors)) {
        // Loop through parents
        foreach ((array) $ancestors as $parent_id) {
            // Parents
            $parent = get_post($parent_id);
            // Switch through post_type to ensure correct filters are applied
            switch ($parent->post_type) {
                // Forum
                case bbp_get_forum_post_type():
                    $crumbs[] = '<a href="' . bbp_get_forum_permalink($parent->ID) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title($parent->ID) . '</a>';
                    break;
                    // Topic
                // Topic
                case bbp_get_topic_post_type():
                    $crumbs[] = '<a href="' . bbp_get_topic_permalink($parent->ID) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title($parent->ID) . '</a>';
                    break;
                    // Reply (Note: not in most themes)
                // Reply (Note: not in most themes)
                case bbp_get_reply_post_type():
                    $crumbs[] = '<a href="' . bbp_get_reply_permalink($parent->ID) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title($parent->ID) . '</a>';
                    break;
                    // WordPress Post/Page/Other
                // WordPress Post/Page/Other
                default:
                    $crumbs[] = '<a href="' . get_permalink($parent->ID) . '" class="bbp-breadcrumb-item">' . get_the_title($parent->ID) . '</a>';
                    break;
            }
        }
        // Edit topic tag
    } elseif (bbp_is_topic_tag_edit()) {
        $crumbs[] = '<a href="' . get_term_link(bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id()) . '" class="bbp-breadcrumb-topic-tag">' . sprintf(__('Topic Tag: %s', 'bbpress'), bbp_get_topic_tag_name()) . '</a>';
    }
    /** Current ***********************************************************/
    // Add current page to breadcrumb
    if (!empty($include_current) || empty($pre_current_text)) {
        $crumbs[] = '<span class="bbp-breadcrumb-current">' . $current_text . '</span>';
    }
    /** Separator *********************************************************/
    // Wrap the separator in a span before padding and filter
    if (!empty($sep)) {
        $sep = '<span class="bbp-breadcrumb-separator">' . $sep . '</span>';
    }
    // Pad the separator
    if (!empty($pad_sep)) {
        $sep = str_pad($sep, strlen($sep) + (int) $pad_sep * 2, ' ', STR_PAD_BOTH);
    }
    /** Finish Up *********************************************************/
    // Filter the separator and breadcrumb
    $sep = apply_filters('bbp_breadcrumb_separator', $sep);
    $crumbs = apply_filters('bbp_breadcrumbs', $crumbs);
    // Build the trail
    $trail = !empty($crumbs) ? $before . implode($sep, $crumbs) . $after : '';
    return apply_filters('bbp_get_breadcrumb', $trail, $crumbs, $r);
}
Exemple #5
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;
}
Exemple #6
0
		</div>
	</div>

<?php 
} else {
    ?>

	<div id="no-forum-<?php 
    bbp_forum_id();
    ?>
" class="bbp-no-forum">
		<div class="bbp-template-notice">
			<p><?php 
    is_user_logged_in() ? _e('You cannot create new forums.', 'bbpress') : _e('You must be logged in to create new forums.', 'bbpress');
    ?>
</p>
		</div>
	</div>

<?php 
}
?>

<?php 
if (bbp_is_forum_edit()) {
    ?>

</div>

<?php 
}
Exemple #7
0
/**
 * Custom page title for bbPress pages
 *
 * @since bbPress (r2788)
 *
 * @param string $title Optional. The title (not used).
 * @param string $sep Optional, default is '&raquo;'. How to separate the
 *                     various items within the page title.
 * @param string $seplocation Optional. Direction to display title, 'right'.
 * @uses bbp_is_single_user() To check if it's a user profile page
 * @uses bbp_is_single_user_edit() To check if it's a user profile edit page
 * @uses bbp_is_user_home() To check if the profile page is of the current user
 * @uses get_query_var() To get the user id
 * @uses get_userdata() To get the user data
 * @uses bbp_is_single_forum() To check if it's a forum
 * @uses bbp_get_forum_title() To get the forum title
 * @uses bbp_is_single_topic() To check if it's a topic
 * @uses bbp_get_topic_title() To get the topic title
 * @uses bbp_is_single_reply() To check if it's a reply
 * @uses bbp_get_reply_title() To get the reply title
 * @uses is_tax() To check if it's the tag page
 * @uses get_queried_object() To get the queried object
 * @uses bbp_is_single_view() To check if it's a view
 * @uses bbp_get_view_title() To get the view title
 * @uses apply_filters() Calls 'bbp_raw_title' with the title
 * @uses apply_filters() Calls 'bbp_profile_page_wp_title' with the title,
 *                        separator and separator location
 * @return string The tite
 */
function bbp_title($title = '', $sep = '&raquo;', $seplocation = '')
{
    // Title array
    $new_title = array();
    /** Archives **************************************************************/
    // Forum Archive
    if (bbp_is_forum_archive()) {
        $new_title['text'] = bbp_get_forum_archive_title();
        // Topic Archive
    } elseif (bbp_is_topic_archive()) {
        $new_title['text'] = bbp_get_topic_archive_title();
        /** Edit ******************************************************************/
        // Forum edit page
    } elseif (bbp_is_forum_edit()) {
        $new_title['text'] = bbp_get_forum_title();
        $new_title['format'] = esc_attr__('Forum Edit: %s', 'bbpress');
        // Topic edit page
    } elseif (bbp_is_topic_edit()) {
        $new_title['text'] = bbp_get_topic_title();
        $new_title['format'] = esc_attr__('Topic Edit: %s', 'bbpress');
        // Reply edit page
    } elseif (bbp_is_reply_edit()) {
        $new_title['text'] = bbp_get_reply_title();
        $new_title['format'] = esc_attr__('Reply Edit: %s', 'bbpress');
        // Topic tag edit page
    } elseif (bbp_is_topic_tag_edit()) {
        $new_title['text'] = bbp_get_topic_tag_name();
        $new_title['format'] = esc_attr__('Topic Tag Edit: %s', 'bbpress');
        /** Singles ***************************************************************/
        // Forum page
    } elseif (bbp_is_single_forum()) {
        $new_title['text'] = bbp_get_forum_title();
        $new_title['format'] = esc_attr__('Forum: %s', 'bbpress');
        // Topic page
    } elseif (bbp_is_single_topic()) {
        $new_title['text'] = bbp_get_topic_title();
        $new_title['format'] = esc_attr__('Topic: %s', 'bbpress');
        // Replies
    } elseif (bbp_is_single_reply()) {
        $new_title['text'] = bbp_get_reply_title();
        // Topic tag page
    } elseif (bbp_is_topic_tag() || get_query_var('bbp_topic_tag')) {
        $new_title['text'] = bbp_get_topic_tag_name();
        $new_title['format'] = esc_attr__('Topic Tag: %s', 'bbpress');
        /** Users *****************************************************************/
        // Profile page
    } elseif (bbp_is_single_user()) {
        // User is viewing their own profile
        if (bbp_is_user_home()) {
            $new_title['text'] = esc_attr_x('Your', 'User viewing his/her own profile', 'bbpress');
            // User is viewing someone else's profile (so use their display name)
        } else {
            $new_title['text'] = sprintf(esc_attr_x("%s's", 'User viewing another users profile', 'bbpress'), get_userdata(bbp_get_user_id())->display_name);
        }
        // User topics created
        if (bbp_is_single_user_topics()) {
            $new_title['format'] = esc_attr__("%s Topics", 'bbpress');
            // User rueplies created
        } elseif (bbp_is_single_user_replies()) {
            $new_title['format'] = esc_attr__("%s Replies", 'bbpress');
            // User favorites
        } elseif (bbp_is_favorites()) {
            $new_title['format'] = esc_attr__("%s Favorites", 'bbpress');
            // User subscriptions
        } elseif (bbp_is_subscriptions()) {
            $new_title['format'] = esc_attr__("%s Subscriptions", 'bbpress');
            // User "home"
        } else {
            $new_title['format'] = esc_attr__("%s Profile", 'bbpress');
        }
        // Profile edit page
    } elseif (bbp_is_single_user_edit()) {
        // Current user
        if (bbp_is_user_home_edit()) {
            $new_title['text'] = esc_attr__('Edit Your Profile', 'bbpress');
            // Other user
        } else {
            $new_title['text'] = get_userdata(bbp_get_user_id())->display_name;
            $new_title['format'] = esc_attr__("Edit %s's Profile", 'bbpress');
        }
        /** Views *****************************************************************/
        // Views
    } elseif (bbp_is_single_view()) {
        $new_title['text'] = bbp_get_view_title();
        $new_title['format'] = esc_attr__('View: %s', 'bbpress');
        /** Search ****************************************************************/
        // Search
    } elseif (bbp_is_search()) {
        $new_title['text'] = bbp_get_search_title();
    }
    // This filter is deprecated. Use 'bbp_before_title_parse_args' instead.
    $new_title = apply_filters('bbp_raw_title_array', $new_title);
    // Set title array defaults
    $new_title = bbp_parse_args($new_title, array('text' => $title, 'format' => '%s'), 'title');
    // Get the formatted raw title
    $new_title = sprintf($new_title['format'], $new_title['text']);
    // Filter the raw title
    $new_title = apply_filters('bbp_raw_title', $new_title, $sep, $seplocation);
    // Compare new title with original title
    if ($new_title === $title) {
        return $title;
    }
    // Temporary separator, for accurate flipping, if necessary
    $t_sep = '%WP_TITILE_SEP%';
    $prefix = '';
    if (!empty($new_title)) {
        $prefix = " {$sep} ";
    }
    // sep on right, so reverse the order
    if ('right' === $seplocation) {
        $new_title_array = array_reverse(explode($t_sep, $new_title));
        $new_title = implode(" {$sep} ", $new_title_array) . $prefix;
        // sep on left, do not reverse
    } else {
        $new_title_array = explode($t_sep, $new_title);
        $new_title = $prefix . implode(" {$sep} ", $new_title_array);
    }
    // Filter and return
    return apply_filters('bbp_title', $new_title, $sep, $seplocation);
}
/**
 * Return value of forum visibility
 *
 * @since bbPress (r3563)
 *
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses bbp_get_forum_visibility_id() To get the topic forum id
 * @uses apply_filters() Calls 'bbp_get_form_forum_visibility' with the forum
 * @return string Value of topic content field
 */
function bbp_get_form_forum_visibility()
{
    // Get _POST data
    if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && isset($_POST['bbp_forum_visibility'])) {
        $forum_visibility = $_POST['bbp_forum_visibility'];
    } elseif (bbp_is_forum_edit()) {
        $forum_visibility = bbp_get_forum_visibility();
    } else {
        $forum_visibility = bbpress()->public_status_id;
    }
    return apply_filters('bbp_get_form_forum_visibility', esc_attr($forum_visibility));
}
Exemple #9
0
/**
 * Return the forum visibility dropdown
 *
 * @since bbPress (r3563)
 *
 * @param int $forum_id The forum id to use
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses bbp_get_forum_visibility() To get the forum visibility
 * @uses apply_filters()
 * @return string HTML select list for selecting forum visibility
 */
function bbp_get_form_forum_visibility_dropdown($args = '')
{
    // Backpat for handling passing of a forum ID
    if (is_int($args)) {
        $forum_id = (int) $args;
        $args = array();
    } else {
        $forum_id = 0;
    }
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('select_id' => 'bbp_forum_visibility', 'tab' => bbp_get_tab_index(), 'forum_id' => $forum_id, 'selected' => false), 'forum_type_select');
    // No specific selected value passed
    if (empty($r['selected'])) {
        // Post value is passed
        if (bbp_is_post_request() && isset($_POST[$r['select_id']])) {
            $r['selected'] = $_POST[$r['select_id']];
            // No Post value was passed
        } else {
            // Edit topic
            if (bbp_is_forum_edit()) {
                $r['forum_id'] = bbp_get_forum_id($r['forum_id']);
                $r['selected'] = bbp_get_forum_visibility($r['forum_id']);
                // New topic
            } else {
                $r['selected'] = bbp_get_public_status_id();
            }
        }
    }
    // Used variables
    $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
    // Start an output buffer, we'll finish it after the select loop
    ob_start();
    ?>

		<select name="<?php 
    echo esc_attr($r['select_id']);
    ?>
" id="<?php 
    echo esc_attr($r['select_id']);
    ?>
_select"<?php 
    echo $tab;
    ?>
>

			<?php 
    foreach (bbp_get_forum_visibilities() as $key => $label) {
        ?>

				<option value="<?php 
        echo esc_attr($key);
        ?>
"<?php 
        selected($key, $r['selected']);
        ?>
><?php 
        echo esc_html($label);
        ?>
</option>

			<?php 
    }
    ?>

		</select>

		<?php 
    // Return the results
    return apply_filters('bbp_get_form_forum_type_dropdown', ob_get_clean(), $r);
}
/**
 * Performs a series of checks to ensure the current user can create forums.
 *
 * @since 2.1.0 bbPress (r3549)
 *
 * @uses bbp_is_user_keymaster()
 * @uses bbp_is_forum_edit()
 * @uses current_user_can()
 * @uses bbp_get_forum_id()
 *
 * @return bool
 */
function bbp_current_user_can_access_create_forum_form()
{
    // Users need to earn access
    $retval = false;
    // Always allow keymasters
    if (bbp_is_user_keymaster()) {
        $retval = true;
        // Looking at a single forum & forum is open
    } elseif ((is_page() || is_single()) && bbp_is_forum_open()) {
        $retval = bbp_current_user_can_publish_forums();
        // User can edit this topic
    } elseif (bbp_is_forum_edit()) {
        $retval = current_user_can('edit_forum', bbp_get_forum_id());
    }
    // Allow access to be filtered
    return (bool) apply_filters('bbp_current_user_can_access_create_forum_form', (bool) $retval);
}
Exemple #11
0
/**
 * Performs a series of checks to ensure the current user can create forums.
 *
 * @since bbPress (r3549)
 *
 * @uses bbp_is_forum_edit()
 * @uses current_user_can()
 * @uses bbp_get_forum_id()
 *
 * @return bool
 */
function bbp_current_user_can_access_create_forum_form()
{
    // Users need to earn access
    $retval = false;
    // Always allow super admins
    if (is_super_admin()) {
        $retval = true;
    } elseif ((is_page() || is_single()) && bbp_is_forum_open()) {
        $retval = bbp_current_user_can_publish_forums();
    } elseif (bbp_is_forum_edit()) {
        $retval = current_user_can('edit_forum', bbp_get_forum_id());
    }
    // Allow access to be filtered
    return (bool) apply_filters('bbp_current_user_can_access_create_forum_form', (bool) $retval);
}
Exemple #12
0
/**
 * Reset main query vars and filter 'the_content' to output a bbPress
 * template part as needed.
 *
 * @since 2.0.0 bbPress (r3032)
 *
 * @param string $template
 * @uses bbp_is_single_user() To check if page is single user
 * @uses bbp_get_single_user_template() To get user template
 * @uses bbp_is_single_user_edit() To check if page is single user edit
 * @uses bbp_get_single_user_edit_template() To get user edit template
 * @uses bbp_is_single_view() To check if page is single view
 * @uses bbp_get_single_view_template() To get view template
 * @uses bbp_is_search() To check if page is search
 * @uses bbp_get_search_template() To get search template
 * @uses bbp_is_forum_edit() To check if page is forum edit
 * @uses bbp_get_forum_edit_template() To get forum edit template
 * @uses bbp_is_topic_merge() To check if page is topic merge
 * @uses bbp_get_topic_merge_template() To get topic merge template
 * @uses bbp_is_topic_split() To check if page is topic split
 * @uses bbp_get_topic_split_template() To get topic split template
 * @uses bbp_is_topic_edit() To check if page is topic edit
 * @uses bbp_get_topic_edit_template() To get topic edit template
 * @uses bbp_is_reply_move() To check if page is reply move
 * @uses bbp_get_reply_move_template() To get reply move template
 * @uses bbp_is_reply_edit() To check if page is reply edit
 * @uses bbp_get_reply_edit_template() To get reply edit template
 * @uses bbp_set_theme_compat_template() To set the global theme compat template
 */
function bbp_template_include_theme_compat($template = '')
{
    /**
     * Bail if a root template was already found. This prevents unintended
     * recursive filtering of 'the_content'.
     *
     * @link https://bbpress.trac.wordpress.org/ticket/2429
     */
    if (bbp_is_template_included()) {
        return $template;
    }
    /**
     * If BuddyPress is activated at a network level, the action order is
     * reversed, which causes the template integration to fail. If we're looking
     * at a BuddyPress page here, bail to prevent the extra processing.
     *
     * This is a bit more brute-force than is probably necessary, but gets the
     * job done while we work towards something more elegant.
     */
    if (function_exists('is_buddypress') && is_buddypress()) {
        return $template;
    }
    // Define local variable(s)
    $bbp_shortcodes = bbpress()->shortcodes;
    // Bail if shortcodes are unset somehow
    if (!is_a($bbp_shortcodes, 'BBP_Shortcodes')) {
        return $template;
    }
    /** Users *************************************************************/
    if (bbp_is_single_user_edit() || bbp_is_single_user()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => bbp_buffer_template_part('content', 'single-user', false), 'post_type' => '', 'post_title' => bbp_get_displayed_user_field('display_name'), 'post_status' => bbp_get_public_status_id(), 'is_single' => true, 'is_archive' => false, 'comment_status' => 'closed'));
        /** 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());
        // Should we replace the content...
        if (empty($page->post_content)) {
            // Use the topics archive
            if ('topics' === bbp_show_on_root()) {
                $new_content = $bbp_shortcodes->display_topic_index();
                // No page so show the archive
            } else {
                $new_content = $bbp_shortcodes->display_forum_index();
            }
            // ...or use the existing page content?
        } else {
            $new_content = apply_filters('the_content', $page->post_content);
        }
        // Should we replace the title...
        if (empty($page->post_title)) {
            // Use the topics archive
            if ('topics' === bbp_show_on_root()) {
                $new_title = bbp_get_topic_archive_title();
                // No page so show the archive
            } else {
                $new_title = bbp_get_forum_archive_title();
            }
            // ...or use the existing page title?
        } else {
            $new_title = apply_filters('the_title', $page->post_title);
        }
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => !empty($page->ID) ? $page->ID : 0, 'post_title' => $new_title, 'post_author' => 0, 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed'));
        // Single Forum
    } elseif (bbp_is_forum_edit()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_forum_form(), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed'));
    } elseif (bbp_is_single_forum()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_forum(array('id' => bbp_get_forum_id())), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed'));
        /** 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());
        // Should we replace the content...
        if (empty($page->post_content)) {
            $new_content = $bbp_shortcodes->display_topic_index();
            // ...or use the existing page content?
        } else {
            $new_content = apply_filters('the_content', $page->post_content);
        }
        // Should we replace the title...
        if (empty($page->post_title)) {
            $new_title = bbp_get_topic_archive_title();
            // ...or use the existing page title?
        } else {
            $new_title = apply_filters('the_title', $page->post_title);
        }
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => !empty($page->ID) ? $page->ID : 0, 'post_title' => bbp_get_topic_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed'));
        // Single Topic
    } elseif (bbp_is_topic_edit() || bbp_is_single_topic()) {
        // Split
        if (bbp_is_topic_split()) {
            $new_content = bbp_buffer_template_part('form', 'topic-split', false);
            // Merge
        } elseif (bbp_is_topic_merge()) {
            $new_content = bbp_buffer_template_part('form', 'topic-merge', false);
            // Edit
        } elseif (bbp_is_topic_edit()) {
            $new_content = $bbp_shortcodes->display_topic_form();
            // Single
        } else {
            $new_content = $bbp_shortcodes->display_topic(array('id' => bbp_get_topic_id()));
        }
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_topic_id(), 'post_title' => bbp_get_topic_title(), 'post_author' => bbp_get_topic_author_id(), 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_topic_status(), 'is_single' => true, 'comment_status' => 'closed'));
        /** Replies ***********************************************************/
        // Reply archive
    } elseif (is_post_type_archive(bbp_get_reply_post_type())) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => __('Replies', 'bbpress'), 'post_author' => 0, 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_reply_index(), 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed'));
        // Single Reply
    } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) {
        // Move
        if (bbp_is_reply_move()) {
            $new_content = bbp_buffer_template_part('form', 'reply-move', false);
            // Edit
        } elseif (bbp_is_reply_edit()) {
            $new_content = $bbp_shortcodes->display_reply_form();
            // Single
        } else {
            $new_content = $bbp_shortcodes->display_reply(array('id' => get_the_ID()));
        }
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_reply_id(), 'post_title' => bbp_get_reply_title(), 'post_author' => bbp_get_reply_author_id(), 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_reply_status(), 'comment_status' => 'closed'));
        /** Views *************************************************************/
    } elseif (bbp_is_single_view()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_view_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_view(array('id' => get_query_var(bbp_get_view_rewrite_id()))), 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed'));
        /** Search ************************************************************/
    } elseif (bbp_is_search()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_search_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_search(array('search' => get_query_var(bbp_get_search_rewrite_id()))), 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed'));
        /** Topic Tags ********************************************************/
        // Topic Tag Edit
    } elseif (bbp_is_topic_tag_edit() || bbp_is_topic_tag()) {
        // Stash the current term in a new var
        set_query_var('bbp_topic_tag', get_query_var('term'));
        // Show topics of tag
        if (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();
        }
        // Reset the post with our new title
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => $new_content, 'post_type' => '', 'post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed', 'is_tax' => true));
    }
    /**
     * Bail if the template already matches a bbPress template. This includes
     * archive-* and single-* WordPress post_type matches (allowing
     * themes to use the expected format) as well as all bbPress-specific
     * template files for users, topics, forums, etc...
     *
     * We do this after the above checks to prevent incorrect 404 body classes
     * and header statuses, as well as to set the post global as needed.
     *
     * @see https://bbpress.trac.wordpress.org/ticket/1478/
     */
    if (bbp_is_template_included()) {
        return $template;
        /**
         * If we are relying on bbPress's built in theme compatibility to load
         * the proper content, we need to intercept the_content, replace the
         * output, and display ours instead.
         *
         * To do this, we first remove all filters from 'the_content' and hook
         * our own function into it, which runs a series of checks to determine
         * the context, and then uses the built in shortcodes to output the
         * correct results from inside an output buffer.
         *
         * Uses bbp_get_theme_compat_templates() to provide fall-backs that
         * should be coded without superfluous mark-up and logic (prev/next
         * navigation, comments, date/time, etc...)
         *
         * Hook into the 'bbp_get_bbpress_template' to override the array of
         * possible templates, or 'bbp_bbpress_template' to override the result.
         */
    } elseif (bbp_is_theme_compat_active()) {
        bbp_remove_all_filters('the_content');
        $template = bbp_get_theme_compat_templates();
    }
    return apply_filters('bbp_template_include_theme_compat', $template);
}
Exemple #13
0
 static function media_view_settings($settings, $post)
 {
     $forum_id = 0;
     if (is_admin()) {
     } elseif (bbp_is_single_user_edit() || bbp_is_single_user()) {
     } elseif (bbp_is_forum_archive()) {
     } elseif (bbp_is_forum_edit()) {
         $forum_id = bbp_get_forum_id();
     } elseif (bbp_is_single_forum()) {
         $forum_id = bbp_get_forum_id();
     } elseif (bbp_is_topic_archive()) {
     } elseif (bbp_is_topic_edit() || bbp_is_single_topic()) {
         $forum_id = bbp_get_forum_id();
     } elseif (is_post_type_archive(bbp_get_reply_post_type())) {
     } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) {
         $forum_id = bbp_get_forum_id();
     } elseif (bbp_is_single_view()) {
     } elseif (bbp_is_search()) {
     } elseif (bbp_is_topic_tag_edit() || bbp_is_topic_tag()) {
         $forum_id = bbp_get_forum_id();
     }
     if ($forum_id) {
         // @setcookie('_bbp_forum_id', $forum_id, 0, COOKIEPATH, COOKIE_DOMAIN);
         if (empty($settings['post'])) {
             $settings['post'] = array('id' => $forum_id, 'nonce' => wp_create_nonce('update-post_' . $forum_id));
         }
     } else {
         // @setcookie('_bbp_forum_id', ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);
     }
     return $settings;
 }
/**
 * 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;
}
Exemple #15
0
 public static function template_no_access($template)
 {
     global $wp_query, $post;
     $check_perm = false;
     if (bbp_is_single_user_edit() || bbp_is_single_user()) {
     } elseif (bbp_is_forum_archive()) {
     } elseif (bbp_is_forum_edit()) {
         $forum_id = bbp_get_forum_id();
         if (bbp_is_forum($forum_id) && !bbp_user_can_view_forum(array('forum_id' => $forum_id)) && !bbp_is_forum_private($forum_id, false)) {
             $check_perm = true;
         }
     } elseif (bbp_is_single_forum()) {
         $forum_id = bbp_get_forum_id();
         if (bbp_is_forum($forum_id) && !bbp_user_can_view_forum(array('forum_id' => $forum_id)) && !bbp_is_forum_private($forum_id, false)) {
             $check_perm = true;
         }
     } elseif (bbp_is_topic_archive()) {
     } elseif (bbp_is_topic_edit() || bbp_is_single_topic()) {
         $check_perm = true;
     } elseif (is_post_type_archive(bbp_get_reply_post_type())) {
     } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) {
         $check_perm = true;
     } elseif (bbp_is_single_view()) {
     } elseif (bbp_is_search()) {
     } elseif (bbp_is_topic_tag_edit() || bbp_is_topic_tag()) {
     }
     if ($check_perm && empty($post->post_content)) {
         $user_id = get_current_user_id();
         $forum_id = bbp_get_forum_id();
         if (!self::view_forum(false, $forum_id, $user_id)) {
             ob_start();
             bbp_get_template_part('feedback', 'no-access');
             $content = ob_get_clean();
             $post->post_content = "\n{$content}\n";
             $wp_query->post = $post;
             $wp_query->posts = array($post);
         }
     }
     return $template;
 }