Example #1
0
/**
 * Handle the saving of core forum metadata (Status, Visibility, and Type)
 *
 * @since bbPress (r3678)
 * @param int $forum_id
 * @uses bbp_is_forum_closed() To check if forum is closed
 * @uses bbp_close_forum() To close forum
 * @uses bbp_open_forum() To open forum
 * @uses bbp_is_forum_category() To check if forum is a category
 * @uses bbp_categorize_forum() To turn forum into a category
 * @uses bbp_normalize_forum() To turn category into forum
 * @uses bbp_get_public_status_id() To get the public status ID
 * @uses bbp_get_private_status_id() To get the private status ID
 * @uses bbp_get_hidden_status_id() To get the hidden status ID
 * @uses bbp_get_forum_visibility() To get the forums visibility
 * @uses bbp_hide_forum() To hide a forum
 * @uses bbp_privatize_forum() To make a forum private
 * @uses bbp_publicize_forum() To make a forum public
 * @return If forum ID is empty
 */
function bbp_save_forum_extras($forum_id = 0)
{
    // Validate the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if forum ID is empty
    if (empty($forum_id) || !bbp_is_forum($forum_id)) {
        return;
    }
    /** Forum Status ******************************************************/
    if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
        if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
            bbp_close_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
            bbp_open_forum($forum_id);
        }
    }
    /** Forum Type ********************************************************/
    if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
        if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_categorize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        }
    }
    /** Forum Visibility **************************************************/
    if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array(bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id()))) {
        // Get forums current visibility
        $visibility = bbp_get_forum_visibility($forum_id);
        // What is the new forum visibility setting?
        switch ($_POST['bbp_forum_visibility']) {
            // Hidden
            case bbp_get_hidden_status_id():
                bbp_hide_forum($forum_id, $visibility);
                break;
                // Private
            // Private
            case bbp_get_private_status_id():
                bbp_privatize_forum($forum_id, $visibility);
                break;
                // Publish (default)
            // Publish (default)
            case bbp_get_public_status_id():
            default:
                bbp_publicize_forum($forum_id, $visibility);
                break;
        }
    }
}
Example #2
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($forum_id = 0)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $forum_attr = apply_filters('bbp_forum_visibilities', array(bbp_get_public_status_id() => __('Public', 'bbpress'), bbp_get_private_status_id() => __('Private', 'bbpress'), bbp_get_hidden_status_id() => __('Hidden', 'bbpress')));
    $visibility_output = '<select name="bbp_forum_visibility" id="bbp_forum_visibility_select">' . "\n";
    foreach ($forum_attr as $value => $label) {
        $visibility_output .= "\t" . '<option value="' . $value . '"' . selected(bbp_get_forum_visibility($forum_id), $value, false) . '>' . esc_html($label) . '</option>' . "\n";
    }
    $visibility_output .= '</select>';
    return apply_filters('bbp_get_form_forum_visibility_dropdown', $visibility_output, $forum_id, $forum_attr);
}
Example #3
0
/**
 * Reset main query vars and filter 'the_content' to output a bbPress
 * template part as needed.
 *
 * @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
 */
function bbp_template_include_theme_compat($template = '')
{
    // 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...
    if (!empty(bbpress()->theme_compat->bbpress_template)) {
        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' => '', 'post_type' => '', 'post_title' => esc_attr(bbp_get_displayed_user_field('display_name')), 'post_status' => bbp_get_public_status_id(), 'is_archive' => false, 'comment_status' => 'closed'));
        /** Forums ************************************************************/
        // Forum archive
    } elseif (bbp_is_forum_archive()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_forum_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_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() || 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' => get_post_field('post_content', 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()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_topic_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_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()) {
        // 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' => get_post_field('post_content', bbp_get_topic_id()), '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' => '', '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()) {
        // 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' => get_post_field('post_content', bbp_get_reply_id()), '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' => '', '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'));
        // Reset the post with our new title
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_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'));
    }
    /**
     * 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.
     */
    if (bbp_is_theme_compat_active()) {
        // Remove all filters from the_content
        bbp_remove_all_filters('the_content');
        // Add a filter on the_content late, which we will later remove
        add_filter('the_content', 'bbp_replace_the_content');
        // Find the appropriate template file
        $template = bbp_get_theme_compat_templates();
    }
    return apply_filters('bbp_template_include_theme_compat', $template);
}
Example #4
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);
}
Example #5
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);
}
Example #6
0
/**
 * Handle the saving of core forum metadata (Status, Visibility, and Type)
 *
 * @since 2.1.0 bbPress (r3678)
 *
 * @param int $forum_id
 * @uses bbp_is_forum_closed() To check if forum is closed
 * @uses bbp_close_forum() To close forum
 * @uses bbp_open_forum() To open forum
 * @uses bbp_is_forum_category() To check if forum is a category
 * @uses bbp_categorize_forum() To turn forum into a category
 * @uses bbp_normalize_forum() To turn category into forum
 * @uses bbp_get_public_status_id() To get the public status ID
 * @uses bbp_get_private_status_id() To get the private status ID
 * @uses bbp_get_hidden_status_id() To get the hidden status ID
 * @uses bbp_get_forum_visibility() To get the forums visibility
 * @uses bbp_hide_forum() To hide a forum
 * @uses bbp_privatize_forum() To make a forum private
 * @uses bbp_publicize_forum() To make a forum public
 * @return If forum ID is empty
 */
function bbp_save_forum_extras($forum_id = 0)
{
    // Validate the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if forum ID is empty
    if (empty($forum_id) || !bbp_is_forum($forum_id)) {
        return;
    }
    /** Forum Status **********************************************************/
    if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
        if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
            bbp_close_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_open($forum_id, false)) {
            bbp_open_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
            bbp_open_forum($forum_id);
        }
    }
    /** Forum Type ************************************************************/
    if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
        if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_categorize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        }
    }
    /** Forum Visibility ******************************************************/
    if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array_keys(bbp_get_forum_visibilities()))) {
        // Get forums current visibility
        $old_visibility = bbp_get_forum_visibility($forum_id);
        // Sanitize the new visibility
        $new_visibility = sanitize_key($_POST['bbp_forum_visibility']);
        // What is the new forum visibility setting?
        switch ($new_visibility) {
            // Hidden
            case bbp_get_hidden_status_id():
                bbp_hide_forum($forum_id, $old_visibility);
                break;
                // Private
            // Private
            case bbp_get_private_status_id():
                bbp_privatize_forum($forum_id, $old_visibility);
                break;
                // Publish (default)
            // Publish (default)
            case bbp_get_public_status_id():
            default:
                bbp_publicize_forum($forum_id, $old_visibility);
                break;
        }
        /**
         * Allow custom forum visibility save actions
         *
         * @since 2.6.0 bbPress (r5855)
         *
         * @param int    $forum_id       The forum ID
         * @param string $old_visibility The current forum visibility
         * @param string $new_visibility The new forum visibility
         */
        do_action('bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility);
    }
    /** Forum Moderators ******************************************************/
    // Either replace terms
    if (bbp_allow_forum_mods()) {
        if (current_user_can('assign_moderators') && !empty($_POST['bbp_moderators'])) {
            // Escape tag input
            $users = sanitize_text_field($_POST['bbp_moderators']);
            // Explode by comma
            $users = strstr($users, ',') ? explode(',', $users) : (array) $users;
            $user_ids = bbp_get_user_ids_from_nicenames($users);
            // Update forum moderators
            if (!empty($user_ids)) {
                // Remove all moderators
                bbp_remove_moderator($forum_id, null);
                // Add moderators
                foreach ($user_ids as $user_id) {
                    bbp_add_moderator($forum_id, $user_id);
                }
            }
            // ...or remove them.
        } elseif (isset($_POST['bbp_moderators'])) {
            bbp_remove_moderator($forum_id, null);
        }
    }
}
Example #7
0
 /**
  * @covers ::bbp_is_forum_hidden
  */
 public function test_bbp_is_forum_hidden()
 {
     $f = $this->factory->forum->create(array('post_status' => 'hidden'));
     $forum = bbp_get_forum_visibility($f);
     $this->assertSame('hidden', $forum);
     $forum_status_id = bbp_get_hidden_status_id($f);
     $this->assertSame('hidden', $forum_status_id);
     $this->assertTrue(bbp_is_forum_hidden($f));
 }
Example #8
0
/**
 * Handle the saving of core forum metadata (Status, Visibility, and Type)
 *
 * @since 2.1.0 bbPress (r3678)
 *
 * @param int $forum_id
 * @uses bbp_is_forum_closed() To check if forum is closed
 * @uses bbp_close_forum() To close forum
 * @uses bbp_open_forum() To open forum
 * @uses bbp_is_forum_category() To check if forum is a category
 * @uses bbp_categorize_forum() To turn forum into a category
 * @uses bbp_normalize_forum() To turn category into forum
 * @uses bbp_get_public_status_id() To get the public status ID
 * @uses bbp_get_private_status_id() To get the private status ID
 * @uses bbp_get_hidden_status_id() To get the hidden status ID
 * @uses bbp_get_forum_visibility() To get the forums visibility
 * @uses bbp_hide_forum() To hide a forum
 * @uses bbp_privatize_forum() To make a forum private
 * @uses bbp_publicize_forum() To make a forum public
 * @return If forum ID is empty
 */
function bbp_save_forum_extras($forum_id = 0)
{
    // Validate the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if forum ID is empty
    if (empty($forum_id) || !bbp_is_forum($forum_id)) {
        return;
    }
    /** Forum Status **********************************************************/
    if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
        if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
            bbp_close_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_open($forum_id, false)) {
            bbp_open_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
            bbp_open_forum($forum_id);
        }
    }
    /** Forum Type ************************************************************/
    if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
        if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_categorize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        }
    }
    /** Forum Visibility ******************************************************/
    if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array_keys(bbp_get_forum_visibilities()))) {
        // Get forums current visibility
        $old_visibility = bbp_get_forum_visibility($forum_id);
        // Sanitize the new visibility
        $new_visibility = sanitize_key($_POST['bbp_forum_visibility']);
        // What is the new forum visibility setting?
        switch ($new_visibility) {
            // Hidden
            case bbp_get_hidden_status_id():
                bbp_hide_forum($forum_id, $old_visibility);
                break;
                // Private
            // Private
            case bbp_get_private_status_id():
                bbp_privatize_forum($forum_id, $old_visibility);
                break;
                // Publish (default)
            // Publish (default)
            case bbp_get_public_status_id():
            default:
                bbp_publicize_forum($forum_id, $old_visibility);
                break;
        }
        /**
         * Allow custom forum visibility save actions
         *
         * @since 2.6.0 bbPress (r5855)
         *
         * @param int    $forum_id       The forum ID
         * @param string $old_visibility The current forum visibility
         * @param string $new_visibility The new forum visibility
         */
        do_action('bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility);
    }
}