Пример #1
0
/**
 * Return the topic archive title
 *
 * @since 2.0.0 bbPress (r3249)
 *
 * @param string $title Default text to use as title
 *
 * @uses bbp_get_page_by_path() Check if page exists at root path
 * @uses get_the_title() Use the page title at the root path
 * @uses get_post_type_object() Load the post type object
 * @uses bbp_get_topic_post_type() Get the topic post type ID
 * @uses get_post_type_labels() Get labels for topic post type
 * @uses apply_filters() Allow output to be manipulated
 *
 * @return string The topic archive title
 */
function bbp_get_topic_archive_title($title = '')
{
    // If no title was passed
    if (empty($title)) {
        // Set root text to page title
        $page = bbp_get_page_by_path(bbp_get_topic_archive_slug());
        if (!empty($page)) {
            $title = get_the_title($page->ID);
            // Default to topic post type name label
        } else {
            $tto = get_post_type_object(bbp_get_topic_post_type());
            $title = $tto->labels->name;
        }
    }
    return apply_filters('bbp_get_topic_archive_title', $title);
}
Пример #2
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;
}
Пример #3
0
/**
 * Return the forum URL
 *
 * @since bbPress (r3979)
 *
 * @uses home_url() To get the home URL
 * @uses bbp_get_topic_archive_slug() To get the topics archive location
 * @param string $path Additional path with leading slash
 * @return The URL to the topics archive
 */
function bbp_get_topics_url($path = '/')
{
    return home_url(bbp_get_topic_archive_slug() . $path);
}
Пример #4
0
 /**
  * Add bbPress-specific rewrite rules for uri's that are not
  * setup for us by way of custom post types or taxonomies. This includes:
  * - Front-end editing
  * - Topic views
  * - User profiles
  *
  * @since bbPress (r2688)
  * @todo Extract into an API
  */
 public static function add_rewrite_rules()
 {
     /** Setup *************************************************************/
     // Add rules to top or bottom?
     $priority = 'top';
     // Single Slugs
     $forum_slug = bbp_get_forum_slug();
     $topic_slug = bbp_get_topic_slug();
     $reply_slug = bbp_get_reply_slug();
     $ttag_slug = bbp_get_topic_tag_tax_slug();
     // Archive Slugs
     $user_slug = bbp_get_user_slug();
     $view_slug = bbp_get_view_slug();
     $search_slug = bbp_get_search_slug();
     $topic_archive_slug = bbp_get_topic_archive_slug();
     $reply_archive_slug = bbp_get_reply_archive_slug();
     // Tertiary Slugs
     $feed_slug = 'feed';
     $edit_slug = 'edit';
     $paged_slug = bbp_get_paged_slug();
     $user_favs_slug = bbp_get_user_favorites_slug();
     $user_subs_slug = bbp_get_user_subscriptions_slug();
     // Unique rewrite ID's
     $feed_id = 'feed';
     $edit_id = bbp_get_edit_rewrite_id();
     $view_id = bbp_get_view_rewrite_id();
     $paged_id = bbp_get_paged_rewrite_id();
     $search_id = bbp_get_search_rewrite_id();
     $user_id = bbp_get_user_rewrite_id();
     $user_favs_id = bbp_get_user_favorites_rewrite_id();
     $user_subs_id = bbp_get_user_subscriptions_rewrite_id();
     $user_tops_id = bbp_get_user_topics_rewrite_id();
     $user_reps_id = bbp_get_user_replies_rewrite_id();
     // Rewrite rule matches used repeatedly below
     $root_rule = '/([^/]+)/?$';
     $feed_rule = '/([^/]+)/' . $feed_slug . '/?$';
     $edit_rule = '/([^/]+)/' . $edit_slug . '/?$';
     $paged_rule = '/([^/]+)/' . $paged_slug . '/?([0-9]{1,})/?$';
     // Search rules (without slug check)
     $search_root_rule = '/?$';
     $search_paged_rule = '/' . $paged_slug . '/?([0-9]{1,})/?$';
     /** Add ***************************************************************/
     // User profile rules
     $tops_rule = '/([^/]+)/' . $topic_archive_slug . '/?$';
     $reps_rule = '/([^/]+)/' . $reply_archive_slug . '/?$';
     $favs_rule = '/([^/]+)/' . $user_favs_slug . '/?$';
     $subs_rule = '/([^/]+)/' . $user_subs_slug . '/?$';
     $tops_paged_rule = '/([^/]+)/' . $topic_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
     $reps_paged_rule = '/([^/]+)/' . $reply_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
     $favs_paged_rule = '/([^/]+)/' . $user_favs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
     $subs_paged_rule = '/([^/]+)/' . $user_subs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
     // Edit Forum|Topic|Reply|Topic-tag
     add_rewrite_rule($forum_slug . $edit_rule, 'index.php?' . bbp_get_forum_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority);
     add_rewrite_rule($topic_slug . $edit_rule, 'index.php?' . bbp_get_topic_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority);
     add_rewrite_rule($reply_slug . $edit_rule, 'index.php?' . bbp_get_reply_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority);
     add_rewrite_rule($ttag_slug . $edit_rule, 'index.php?' . bbp_get_topic_tag_tax_id() . '=$matches[1]&' . $edit_id . '=1', $priority);
     // User Pagination|Edit|View
     add_rewrite_rule($user_slug . $tops_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($user_slug . $reps_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($user_slug . $favs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($user_slug . $subs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($user_slug . $tops_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1', $priority);
     add_rewrite_rule($user_slug . $reps_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1', $priority);
     add_rewrite_rule($user_slug . $favs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1', $priority);
     add_rewrite_rule($user_slug . $subs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1', $priority);
     add_rewrite_rule($user_slug . $edit_rule, 'index.php?' . $user_id . '=$matches[1]&' . $edit_id . '=1', $priority);
     add_rewrite_rule($user_slug . $root_rule, 'index.php?' . $user_id . '=$matches[1]', $priority);
     // Topic-View Pagination|Feed|View
     add_rewrite_rule($view_slug . $paged_rule, 'index.php?' . $view_id . '=$matches[1]&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($view_slug . $feed_rule, 'index.php?' . $view_id . '=$matches[1]&' . $feed_id . '=$matches[2]', $priority);
     add_rewrite_rule($view_slug . $root_rule, 'index.php?' . $view_id . '=$matches[1]', $priority);
     // Search All
     add_rewrite_rule($search_slug . $search_paged_rule, 'index.php?' . $paged_id . '=$matches[1]', $priority);
     add_rewrite_rule($search_slug . $search_root_rule, 'index.php?' . $search_id, $priority);
 }
Пример #5
0
/**
 * Return the link to the user's topics
 *
 * @since 2.2.0 bbPress (r4225)
 *
 * @param int $user_id Optional. User id
 * @uses bbp_get_user_profile_url() To get the user profile url
 * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the
 *                        user profile url and user id
 * @return string Permanent link to user profile page
 */
function bbp_get_user_topics_created_url($user_id = 0)
{
    // Use displayed user ID if there is one, and one isn't requested
    $user_id = bbp_get_user_id($user_id);
    if (empty($user_id)) {
        return false;
    }
    // Allow early overriding of the profile URL to cut down on processing
    $early_url = apply_filters('bbp_pre_get_user_topics_created_url', $user_id);
    if (is_string($early_url)) {
        return $early_url;
    }
    // Get user profile URL
    $profile_url = bbp_get_user_profile_url($user_id);
    // Pretty permalinks
    if (bbp_use_pretty_urls()) {
        $url = trailingslashit($profile_url) . bbp_get_topic_archive_slug();
        $url = user_trailingslashit($url);
        // Unpretty permalinks
    } else {
        $url = add_query_arg(array(bbp_get_user_topics_rewrite_id() => '1'), $profile_url);
    }
    return apply_filters('bbp_get_user_topics_created_url', $url, $user_id);
}
Пример #6
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);
}
Пример #7
0
 /**
  * Set up the admin bar
  *
  * @since bbPress (r3552)
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     // Menus for logged in user
     if (is_user_logged_in()) {
         // Setup the logged in user variables
         $user_domain = bp_loggedin_user_domain();
         $forums_link = trailingslashit($user_domain . $this->slug);
         // Add the "My Account" sub menus
         $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __('Forums', 'bbpress'), 'href' => trailingslashit($forums_link));
         // Topics
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-topics', 'title' => __('Topics Started', 'bbpress'), 'href' => trailingslashit($forums_link . bbp_get_topic_archive_slug()));
         // Replies
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-replies', 'title' => __('Replies Created', 'bbpress'), 'href' => trailingslashit($forums_link . bbp_get_reply_archive_slug()));
         // Favorites
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-favorites', 'title' => __('Favorite Topics', 'bbpress'), 'href' => trailingslashit($forums_link . bbp_get_user_favorites_slug()));
         // Subscriptions
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-subscriptions', 'title' => __('Subscribed Topics', 'bbpress'), 'href' => trailingslashit($forums_link . bbp_get_user_subscriptions_slug()));
     }
     parent::setup_admin_bar($wp_admin_nav);
 }
Пример #8
0
 /**
  * Setup the post types for forums, topics and replies
  *
  * @since bbPress (r2597)
  * @uses register_post_type() To register the post types
  * @uses apply_filters() Calls various filters to modify the arguments
  *                        sent to register_post_type()
  */
 public static function register_post_types()
 {
     // Define local variable(s)
     $post_type = array();
     /** Forums ************************************************************/
     // Forum labels
     $post_type['labels'] = array('name' => __('Forums', 'bbpress'), 'menu_name' => __('Forums', 'bbpress'), 'singular_name' => __('Forum', 'bbpress'), 'all_items' => __('All Forums', 'bbpress'), 'add_new' => __('New Forum', 'bbpress'), 'add_new_item' => __('Create New Forum', 'bbpress'), 'edit' => __('Edit', 'bbpress'), 'edit_item' => __('Edit Forum', 'bbpress'), 'new_item' => __('New Forum', 'bbpress'), 'view' => __('View Forum', 'bbpress'), 'view_item' => __('View Forum', 'bbpress'), 'search_items' => __('Search Forums', 'bbpress'), 'not_found' => __('No forums found', 'bbpress'), 'not_found_in_trash' => __('No forums found in Trash', 'bbpress'), 'parent_item_colon' => __('Parent Forum:', 'bbpress'));
     // Forum rewrite
     $post_type['rewrite'] = array('slug' => bbp_get_forum_slug(), 'with_front' => false);
     // Forum supports
     $post_type['supports'] = array('title', 'editor', 'revisions');
     // Register Forum content type
     register_post_type(bbp_get_forum_post_type(), apply_filters('bbp_register_forum_post_type', array('labels' => $post_type['labels'], 'rewrite' => $post_type['rewrite'], 'supports' => $post_type['supports'], 'description' => __('bbPress Forums', 'bbpress'), 'capabilities' => bbp_get_forum_caps(), 'capability_type' => array('forum', 'forums'), 'menu_position' => 555555, 'has_archive' => bbp_get_root_slug(), 'exclude_from_search' => true, 'show_in_nav_menus' => true, 'public' => true, 'show_ui' => current_user_can('bbp_forums_admin'), 'can_export' => true, 'hierarchical' => true, 'query_var' => true, 'menu_icon' => '')));
     /** Topics ************************************************************/
     // Topic labels
     $post_type['labels'] = array('name' => __('Topics', 'bbpress'), 'menu_name' => __('Topics', 'bbpress'), 'singular_name' => __('Topic', 'bbpress'), 'all_items' => __('All Topics', 'bbpress'), 'add_new' => __('New Topic', 'bbpress'), 'add_new_item' => __('Create New Topic', 'bbpress'), 'edit' => __('Edit', 'bbpress'), 'edit_item' => __('Edit Topic', 'bbpress'), 'new_item' => __('New Topic', 'bbpress'), 'view' => __('View Topic', 'bbpress'), 'view_item' => __('View Topic', 'bbpress'), 'search_items' => __('Search Topics', 'bbpress'), 'not_found' => __('No topics found', 'bbpress'), 'not_found_in_trash' => __('No topics found in Trash', 'bbpress'), 'parent_item_colon' => __('Forum:', 'bbpress'));
     // Topic rewrite
     $post_type['rewrite'] = array('slug' => bbp_get_topic_slug(), 'with_front' => false);
     // Topic supports
     $post_type['supports'] = array('title', 'editor', 'revisions');
     // Register Topic content type
     register_post_type(bbp_get_topic_post_type(), apply_filters('bbp_register_topic_post_type', array('labels' => $post_type['labels'], 'rewrite' => $post_type['rewrite'], 'supports' => $post_type['supports'], 'description' => __('bbPress Topics', 'bbpress'), 'capabilities' => bbp_get_topic_caps(), 'capability_type' => array('topic', 'topics'), 'menu_position' => 555555, 'has_archive' => bbp_get_topic_archive_slug(), 'exclude_from_search' => true, 'show_in_nav_menus' => false, 'public' => true, 'show_ui' => current_user_can('bbp_topics_admin'), 'can_export' => true, 'hierarchical' => false, 'query_var' => true, 'menu_icon' => '')));
     /** Replies ***********************************************************/
     // Reply labels
     $post_type['labels'] = array('name' => __('Replies', 'bbpress'), 'menu_name' => __('Replies', 'bbpress'), 'singular_name' => __('Reply', 'bbpress'), 'all_items' => __('All Replies', 'bbpress'), 'add_new' => __('New Reply', 'bbpress'), 'add_new_item' => __('Create New Reply', 'bbpress'), 'edit' => __('Edit', 'bbpress'), 'edit_item' => __('Edit Reply', 'bbpress'), 'new_item' => __('New Reply', 'bbpress'), 'view' => __('View Reply', 'bbpress'), 'view_item' => __('View Reply', 'bbpress'), 'search_items' => __('Search Replies', 'bbpress'), 'not_found' => __('No replies found', 'bbpress'), 'not_found_in_trash' => __('No replies found in Trash', 'bbpress'), 'parent_item_colon' => __('Topic:', 'bbpress'));
     // Reply rewrite
     $post_type['rewrite'] = array('slug' => bbp_get_reply_slug(), 'with_front' => false);
     // Reply supports
     $post_type['supports'] = array('title', 'editor', 'revisions');
     // Register reply content type
     register_post_type(bbp_get_reply_post_type(), apply_filters('bbp_register_reply_post_type', array('labels' => $post_type['labels'], 'rewrite' => $post_type['rewrite'], 'supports' => $post_type['supports'], 'description' => __('bbPress Replies', 'bbpress'), 'capabilities' => bbp_get_reply_caps(), 'capability_type' => array('reply', 'replies'), 'menu_position' => 555555, 'exclude_from_search' => true, 'has_archive' => false, 'show_in_nav_menus' => false, 'public' => true, 'show_ui' => current_user_can('bbp_replies_admin'), 'can_export' => true, 'hierarchical' => false, 'query_var' => true, 'menu_icon' => '')));
 }
Пример #9
0
 /**
  * Set up the admin bar
  *
  * @since 2.1.0 bbPress (r3552)
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     // Menus for logged in user
     if (is_user_logged_in()) {
         // If BuddyPress is network activated and bbPress is
         // not activated on a the root blog but on any child one
         if (!bp_is_root_blog()) {
             $user_id = bbp_get_current_user_id();
             $my_account_link = bbp_get_user_profile_url($user_id);
             $my_topics_link = bbp_get_user_topics_created_url($user_id);
             $my_replies_link = bbp_get_user_replies_created_url($user_id);
             $my_favorites_link = bbp_get_favorites_permalink($user_id);
             $my_subscriptions_link = bbp_get_subscriptions_permalink($user_id);
         } else {
             // Setup the logged in user variables
             $user_domain = bp_loggedin_user_domain();
             $forums_link = trailingslashit($user_domain . $this->slug);
             $my_account_link = trailingslashit($forums_link);
             $my_topics_link = trailingslashit($forums_link . bbp_get_topic_archive_slug());
             $my_replies_link = trailingslashit($forums_link . bbp_get_reply_archive_slug());
             $my_favorites_link = trailingslashit($forums_link . bbp_get_user_favorites_slug());
             $my_subscriptions_link = trailingslashit($forums_link . bbp_get_user_subscriptions_slug());
         }
         // Add the "My Account" sub menus
         $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __('Forums', 'bbpress'), 'href' => $my_account_link);
         // Topics
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-topics', 'title' => __('Topics Started', 'bbpress'), 'href' => $my_topics_link);
         // Replies
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-replies', 'title' => __('Replies Created', 'bbpress'), 'href' => $my_replies_link);
         // Favorites
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-favorites', 'title' => __('Favorite Topics', 'bbpress'), 'href' => $my_favorites_link);
         // Subscriptions
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-subscriptions', 'title' => __('Subscribed Topics', 'bbpress'), 'href' => $my_subscriptions_link);
     }
     parent::setup_admin_bar($wp_admin_nav);
 }
Пример #10
0
 /**
  * Override bbPress profile URL with BuddyPress profile URL
  *
  * @since bbPress (r3401)
  * @param string $url
  * @param int $user_id
  * @param string $user_nicename
  * @return string
  */
 public function user_profile_url($user_id)
 {
     // Define local variable(s)
     $profile_url = '';
     $component_slug = bbpress()->extend->buddypress->slug;
     // Special handling for forum component
     if (bp_is_current_component($component_slug)) {
         // Empty action or 'topics' action
         if (!bp_current_action() || bp_is_current_action(bbp_get_topic_archive_slug())) {
             $profile_url = bp_core_get_user_domain($user_id) . $component_slug . '/' . bbp_get_topic_archive_slug();
             // Empty action or 'topics' action
         } elseif (bp_is_current_action(bbp_get_reply_archive_slug())) {
             $profile_url = bp_core_get_user_domain($user_id) . $component_slug . '/' . bbp_get_reply_archive_slug();
             // 'favorites' action
         } elseif (bbp_is_favorites_active() && bp_is_current_action(bbp_get_user_favorites_slug())) {
             $profile_url = $this->get_favorites_permalink('', $user_id);
             // 'subscriptions' action
         } elseif (bbp_is_subscriptions_active() && bp_is_current_action(bbp_get_user_subscriptions_slug())) {
             $profile_url = $this->get_subscriptions_permalink('', $user_id);
         }
         // Not in users' forums area
     } else {
         $profile_url = bp_core_get_user_domain($user_id);
     }
     return trailingslashit($profile_url);
 }
Пример #11
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.
 *
 * @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;
}
Пример #12
0
/**
 * Return the link to the user's topics
 *
 * @since bbPress (r4225)
 *
 * @param int $user_id Optional. User id
 * @uses bbp_get_user_profile_url() To get the user profile url
 * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the
 *                        user profile url and user id
 * @return string Permanent link to user profile page
 */
function bbp_get_user_topics_created_url($user_id = 0)
{
    global $wp_rewrite;
    // Use displayed user ID if there is one, and one isn't requested
    $user_id = bbp_get_user_id($user_id);
    if (empty($user_id)) {
        return false;
    }
    // Allow early overriding of the profile URL to cut down on processing
    $early_url = apply_filters('bbp_pre_get_user_topics_created_url', (int) $user_id);
    if (is_string($early_url)) {
        return $early_url;
    }
    // Pretty permalinks
    if ($wp_rewrite->using_permalinks()) {
        $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%/' . bbp_get_topic_archive_slug();
        $user = get_userdata($user_id);
        if (!empty($user->user_nicename)) {
            $user_nicename = $user->user_nicename;
        } else {
            $user_nicename = $user->user_login;
        }
        $url = str_replace('%' . bbp_get_user_rewrite_id() . '%', $user_nicename, $url);
        $url = home_url(user_trailingslashit($url));
        // Unpretty permalinks
    } else {
        $url = add_query_arg(array(bbp_get_user_rewrite_id() => $user_id, bbp_get_user_topics_rewrite_id() => '1'), home_url('/'));
    }
    return apply_filters('bbp_get_user_topics_created_url', $url, $user_id);
}