/** * This fun little function fills up some WordPress globals with dummy data to * stop your average page template from complaining about it missing. * * @since bbPress (r3108) * @global WP_Query $wp_query * @global object $post * @param array $args */ function bbp_theme_compat_reset_post($args = array()) { global $wp_query, $post; // Default arguments $defaults = array('ID' => -9999, 'post_status' => bbp_get_public_status_id(), 'post_author' => 0, 'post_parent' => 0, 'post_type' => 'page', 'post_date' => 0, 'post_date_gmt' => 0, 'post_modified' => 0, 'post_modified_gmt' => 0, 'post_content' => '', 'post_title' => '', 'post_excerpt' => '', 'post_content_filtered' => '', 'post_mime_type' => '', 'post_password' => '', 'post_name' => '', 'guid' => '', 'menu_order' => 0, 'pinged' => '', 'to_ping' => '', 'ping_status' => '', 'comment_status' => 'closed', 'comment_count' => 0, 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false); // Switch defaults if post is set if (isset($wp_query->post)) { $defaults = array('ID' => $wp_query->post->ID, 'post_status' => $wp_query->post->post_status, 'post_author' => $wp_query->post->post_author, 'post_parent' => $wp_query->post->post_parent, 'post_type' => $wp_query->post->post_type, 'post_date' => $wp_query->post->post_date, 'post_date_gmt' => $wp_query->post->post_date_gmt, 'post_modified' => $wp_query->post->post_modified, 'post_modified_gmt' => $wp_query->post->post_modified_gmt, 'post_content' => $wp_query->post->post_content, 'post_title' => $wp_query->post->post_title, 'post_excerpt' => $wp_query->post->post_excerpt, 'post_content_filtered' => $wp_query->post->post_content_filtered, 'post_mime_type' => $wp_query->post->post_mime_type, 'post_password' => $wp_query->post->post_password, 'post_name' => $wp_query->post->post_name, 'guid' => $wp_query->post->guid, 'menu_order' => $wp_query->post->menu_order, 'pinged' => $wp_query->post->pinged, 'to_ping' => $wp_query->post->to_ping, 'ping_status' => $wp_query->post->ping_status, 'comment_status' => $wp_query->post->comment_status, 'comment_count' => $wp_query->post->comment_count, 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false); } $dummy = bbp_parse_args($args, $defaults, 'theme_compat_reset_post'); // Clear out the post related globals unset($wp_query->posts); unset($wp_query->post); unset($post); // Setup the dummy post object $wp_query->post = new stdClass(); $wp_query->post->ID = $dummy['ID']; $wp_query->post->post_status = $dummy['post_status']; $wp_query->post->post_author = $dummy['post_author']; $wp_query->post->post_parent = $dummy['post_parent']; $wp_query->post->post_type = $dummy['post_type']; $wp_query->post->post_date = $dummy['post_date']; $wp_query->post->post_date_gmt = $dummy['post_date_gmt']; $wp_query->post->post_modified = $dummy['post_modified']; $wp_query->post->post_modified_gmt = $dummy['post_modified_gmt']; $wp_query->post->post_content = $dummy['post_content']; $wp_query->post->post_title = $dummy['post_title']; $wp_query->post->post_excerpt = $dummy['post_excerpt']; $wp_query->post->post_content_filtered = $dummy['post_content_filtered']; $wp_query->post->post_mime_type = $dummy['post_mime_type']; $wp_query->post->post_password = $dummy['post_password']; $wp_query->post->post_name = $dummy['post_name']; $wp_query->post->guid = $dummy['guid']; $wp_query->post->menu_order = $dummy['menu_order']; $wp_query->post->pinged = $dummy['pinged']; $wp_query->post->to_ping = $dummy['to_ping']; $wp_query->post->ping_status = $dummy['ping_status']; $wp_query->post->comment_status = $dummy['comment_status']; $wp_query->post->comment_count = $dummy['comment_count']; // Set the $post global $post = $wp_query->post; // Setup the dummy post loop $wp_query->posts[0] = $wp_query->post; // Prevent comments form from appearing $wp_query->post_count = 1; $wp_query->is_404 = $dummy['is_404']; $wp_query->is_page = $dummy['is_page']; $wp_query->is_single = $dummy['is_single']; $wp_query->is_archive = $dummy['is_archive']; $wp_query->is_tax = $dummy['is_tax']; /** * Force the header back to 200 status if not a deliberate 404 * * @see http://bbpress.trac.wordpress.org/ticket/1973 */ if (!$wp_query->is_404()) { status_header(200); } // If we are resetting a post, we are in theme compat bbp_set_theme_compat_active(); }
/** * This fun little function fills up some WordPress globals with dummy data to * stop your average page template from complaining about it missing. * * @since bbPress (r3108) * @global WP_Query $wp_query * @global object $post * @param array $args */ function bbp_theme_compat_reset_post($args = array()) { global $wp_query, $post; // Default arguments $defaults = array('ID' => -9999, 'post_title' => '', 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_excerpt' => '', 'post_type' => 'page', 'post_status' => bbp_get_public_status_id(), 'post_name' => '', 'comment_status' => 'closed', 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false); // Switch defaults if post is set if (isset($wp_query->post)) { $defaults = array('ID' => get_the_ID(), 'post_title' => get_the_title(), 'post_author' => get_the_author_meta('ID'), 'post_date' => get_the_date(), 'post_content' => get_the_content(), 'post_excerpt' => get_the_excerpt(), 'post_type' => get_post_type(), 'post_status' => get_post_status(), 'post_name' => !empty($wp_query->post->post_name) ? $wp_query->post->post_name : '', 'comment_status' => comments_open(), 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false); } $dummy = bbp_parse_args($args, $defaults, 'theme_compat_reset_post'); // Clear out the post related globals unset($wp_query->posts); unset($wp_query->post); unset($post); // Setup the dummy post object $wp_query->post = new stdClass(); $wp_query->post->ID = $dummy['ID']; $wp_query->post->post_title = $dummy['post_title']; $wp_query->post->post_author = $dummy['post_author']; $wp_query->post->post_date = $dummy['post_date']; $wp_query->post->post_content = $dummy['post_content']; $wp_query->post->post_excerpt = $dummy['post_excerpt']; $wp_query->post->post_type = $dummy['post_type']; $wp_query->post->post_status = $dummy['post_status']; $wp_query->post->post_name = $dummy['post_name']; $wp_query->post->comment_status = $dummy['comment_status']; // Set the $post global $post = $wp_query->post; // Setup the dummy post loop $wp_query->posts[0] = $wp_query->post; // Prevent comments form from appearing $wp_query->post_count = 1; $wp_query->is_404 = $dummy['is_404']; $wp_query->is_page = $dummy['is_page']; $wp_query->is_single = $dummy['is_single']; $wp_query->is_archive = $dummy['is_archive']; $wp_query->is_tax = $dummy['is_tax']; // If we are resetting a post, we are in theme compat bbp_set_theme_compat_active(); }
/** * This fun little function fills up some WordPress globals with dummy data to * stop your average page template from complaining about it missing. * * @since 2.0.0 bbPress (r3108) * * @global WP_Query $wp_query * @global object $post * @param array $args */ function bbp_theme_compat_reset_post($args = array()) { global $wp_query, $post; // Switch defaults if post is set if (isset($wp_query->post)) { $dummy = bbp_parse_args($args, array('ID' => $wp_query->post->ID, 'post_status' => $wp_query->post->post_status, 'post_author' => $wp_query->post->post_author, 'post_parent' => $wp_query->post->post_parent, 'post_type' => $wp_query->post->post_type, 'post_date' => $wp_query->post->post_date, 'post_date_gmt' => $wp_query->post->post_date_gmt, 'post_modified' => $wp_query->post->post_modified, 'post_modified_gmt' => $wp_query->post->post_modified_gmt, 'post_content' => $wp_query->post->post_content, 'post_title' => $wp_query->post->post_title, 'post_excerpt' => $wp_query->post->post_excerpt, 'post_content_filtered' => $wp_query->post->post_content_filtered, 'post_mime_type' => $wp_query->post->post_mime_type, 'post_password' => $wp_query->post->post_password, 'post_name' => $wp_query->post->post_name, 'guid' => $wp_query->post->guid, 'menu_order' => $wp_query->post->menu_order, 'pinged' => $wp_query->post->pinged, 'to_ping' => $wp_query->post->to_ping, 'ping_status' => $wp_query->post->ping_status, 'comment_status' => $wp_query->post->comment_status, 'comment_count' => $wp_query->post->comment_count, 'filter' => $wp_query->post->filter, 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false), 'theme_compat_reset_post'); } else { $dummy = bbp_parse_args($args, array('ID' => -9999, 'post_status' => bbp_get_public_status_id(), 'post_author' => 0, 'post_parent' => 0, 'post_type' => 'page', 'post_date' => 0, 'post_date_gmt' => 0, 'post_modified' => 0, 'post_modified_gmt' => 0, 'post_content' => '', 'post_title' => '', 'post_excerpt' => '', 'post_content_filtered' => '', 'post_mime_type' => '', 'post_password' => '', 'post_name' => '', 'guid' => '', 'menu_order' => 0, 'pinged' => '', 'to_ping' => '', 'ping_status' => '', 'comment_status' => 'closed', 'comment_count' => 0, 'filter' => 'raw', 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false), 'theme_compat_reset_post'); } // Bail if dummy post is empty if (empty($dummy)) { return; } // Set the $post global $post = new WP_Post((object) $dummy); // Copy the new post global into the main $wp_query $wp_query->post = $post; $wp_query->posts = array($post); // Prevent comments form from appearing $wp_query->post_count = 1; $wp_query->is_404 = $dummy['is_404']; $wp_query->is_page = $dummy['is_page']; $wp_query->is_single = $dummy['is_single']; $wp_query->is_archive = $dummy['is_archive']; $wp_query->is_tax = $dummy['is_tax']; // Reset is_singular based on page/single args // https://bbpress.trac.wordpress.org/ticket/2545 $wp_query->is_singular = $wp_query->is_single; // Clean up the dummy post unset($dummy); /** * Force the header back to 200 status if not a deliberate 404 * * @see https://bbpress.trac.wordpress.org/ticket/1973 */ if (!$wp_query->is_404()) { status_header(200); } // If we are resetting a post, we are in theme compat bbp_set_theme_compat_active(true); }
/** * 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() || bbp_is_single_user_edit()) { // Reset post bbp_theme_compat_reset_post(array('post_title' => esc_attr(bbp_get_displayed_user_field('display_name')), 'comment_status' => 'closed')); /** Forums ************************************************************/ // Single forum edit } 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' => 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')); // 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')); /** 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_topic_split() || bbp_is_topic_merge()) { // 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()) { // 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 ********************************************************/ } elseif (bbp_is_topic_tag_edit()) { // 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('post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'))); } elseif (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('post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'))); /** Single Forums/Topics/Replies **************************************/ } elseif (bbp_is_custom_post_type()) { bbp_set_theme_compat_active(); } /** * 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); }