/** * Run the view's query * * @since 2.0.0 bbPress (r2789) * * @param string $view Optional. View id * @param mixed $new_args New arguments. See {@link bbp_has_topics()} * @uses bbp_get_view_id() To get the view id * @uses bbp_get_view_query_args() To get the view query args * @uses sanitize_title() To sanitize the view name * @uses bbp_has_topics() To make the topics query * @return bool False if the view doesn't exist, otherwise if topics are there */ function bbp_view_query($view = '', $new_args = '') { $view = bbp_get_view_id($view); if (empty($view)) { return false; } $query_args = bbp_get_view_query_args($view); if (!empty($new_args)) { $new_args = bbp_parse_args($new_args, '', 'view_query'); $query_args = array_merge($query_args, $new_args); } return bbp_has_topics($query_args); }
/** * This function is hooked into the WordPress 'request' action and is * responsible for sniffing out the query vars and serving up RSS2 feeds if * the stars align and the user has requested a feed of any bbPress type. * * @since 2.0.0 bbPress (r3171) * * @param array $query_vars * @return array */ function bbp_request_feed_trap($query_vars = array()) { // Looking at a feed if (isset($query_vars['feed'])) { // Forum/Topic/Reply Feed if (isset($query_vars['post_type'])) { // Matched post type $post_type = false; // Post types to check $post_types = array(bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type()); // Cast query vars as array outside of foreach loop $qv_array = (array) $query_vars['post_type']; // Check if this query is for a bbPress post type foreach ($post_types as $bbp_pt) { if (in_array($bbp_pt, $qv_array, true)) { $post_type = $bbp_pt; break; } } // Looking at a bbPress post type if (!empty($post_type)) { // Supported select query vars $select_query_vars = array('p' => false, 'name' => false, $post_type => false); // Setup matched variables to select foreach ($query_vars as $key => $value) { if (isset($select_query_vars[$key])) { $select_query_vars[$key] = $value; } } // Remove any empties $select_query_vars = array_filter($select_query_vars); // What bbPress post type are we looking for feeds on? switch ($post_type) { // Forum case bbp_get_forum_post_type(): // Define local variable(s) $meta_query = array(); // Single forum if (!empty($select_query_vars)) { // Load up our own query query_posts(array_merge(array('post_type' => bbp_get_forum_post_type(), 'feed' => true), $select_query_vars)); // Restrict to specific forum ID $meta_query = array(array('key' => '_bbp_forum_id', 'value' => bbp_get_forum_id(), 'type' => 'NUMERIC', 'compare' => '=')); } // Only forum replies if (!empty($_GET['type']) && bbp_get_reply_post_type() === $_GET['type']) { // The query $the_query = array('author' => 0, 'feed' => true, 'post_type' => bbp_get_reply_post_type(), 'post_parent' => 'any', 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => bbp_get_replies_per_rss_page(), 'order' => 'DESC', 'meta_query' => $meta_query); // Output the feed bbp_display_replies_feed_rss2($the_query); // Only forum topics } elseif (!empty($_GET['type']) && bbp_get_topic_post_type() === $_GET['type']) { // The query $the_query = array('author' => 0, 'feed' => true, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => bbp_get_forum_id(), 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => bbp_get_topics_per_rss_page(), 'order' => 'DESC'); // Output the feed bbp_display_topics_feed_rss2($the_query); // All forum topics and replies } else { // Exclude private/hidden forums if not looking at single if (empty($select_query_vars)) { $meta_query = array(bbp_exclude_forum_ids('meta_query')); } // The query $the_query = array('author' => 0, 'feed' => true, 'post_type' => array(bbp_get_reply_post_type(), bbp_get_topic_post_type()), 'post_parent' => 'any', 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => bbp_get_replies_per_rss_page(), 'order' => 'DESC', 'meta_query' => $meta_query); // Output the feed bbp_display_replies_feed_rss2($the_query); } break; // Topic feed - Show replies // Topic feed - Show replies case bbp_get_topic_post_type(): // Single topic if (!empty($select_query_vars)) { // Load up our own query query_posts(array_merge(array('post_type' => bbp_get_topic_post_type(), 'feed' => true), $select_query_vars)); // Output the feed bbp_display_replies_feed_rss2(array('feed' => true)); // All topics } else { // The query $the_query = array('author' => 0, 'feed' => true, 'post_parent' => 'any', 'posts_per_page' => bbp_get_topics_per_rss_page(), 'show_stickies' => false); // Output the feed bbp_display_topics_feed_rss2($the_query); } break; // Replies // Replies case bbp_get_reply_post_type(): // The query $the_query = array('posts_per_page' => bbp_get_replies_per_rss_page(), 'meta_query' => array(array()), 'feed' => true); // All replies if (empty($select_query_vars)) { bbp_display_replies_feed_rss2($the_query); } break; } } // Single Topic Vview } elseif (isset($query_vars[bbp_get_view_rewrite_id()])) { // Get the view $view = $query_vars[bbp_get_view_rewrite_id()]; // We have a view to display a feed if (!empty($view)) { // Get the view query $the_query = bbp_get_view_query_args($view); // Output the feed bbp_display_topics_feed_rss2($the_query); } } // @todo User profile feeds } // No feed so continue on return $query_vars; }
/** * This function is hooked into the WordPress 'request' action and is * responsible for sniffing out the query vars and serving up RSS2 feeds if * the stars align and the user has requested a feed of any bbPress type. * * @since bbPress (r3171) * * @param array $query_vars * @return array */ function bbp_request_feed_trap($query_vars = array()) { // Looking at a feed if (isset($query_vars['feed'])) { // Forum/Topic/Reply Feed if (isset($query_vars['post_type'])) { // What bbPress post type are we looking for feeds on? switch ($query_vars['post_type']) { // Forum case bbp_get_forum_post_type(): // Define local variable(s) $meta_query = array(); // Single forum if (isset($query_vars[bbp_get_forum_post_type()])) { // Get the forum by the path $forum = get_page_by_path($query_vars[bbp_get_forum_post_type()], OBJECT, bbp_get_forum_post_type()); $forum_id = $forum->ID; // Load up our own query query_posts(array('post_type' => bbp_get_forum_post_type(), 'ID' => $forum_id, 'feed' => true)); // Restrict to specific forum ID $meta_query = array(array('key' => '_bbp_forum_id', 'value' => $forum_id, 'type' => 'numeric', 'compare' => '=')); } // Only forum replies if (!empty($_GET['type']) && bbp_get_reply_post_type() == $_GET['type']) { // The query $the_query = array('author' => 0, 'feed' => true, 'post_type' => bbp_get_reply_post_type(), 'post_parent' => 'any', 'post_status' => join(',', array(bbp_get_public_status_id(), bbp_get_closed_status_id())), 'posts_per_page' => bbp_get_replies_per_rss_page(), 'order' => 'DESC', 'meta_query' => $meta_query); // Output the feed bbp_display_replies_feed_rss2($the_query); // Only forum topics } elseif (!empty($_GET['type']) && bbp_get_topic_post_type() == $_GET['type']) { // The query $the_query = array('author' => 0, 'feed' => true, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $forum_id, 'post_status' => join(',', array(bbp_get_public_status_id(), bbp_get_closed_status_id())), 'posts_per_page' => bbp_get_topics_per_rss_page(), 'order' => 'DESC'); // Output the feed bbp_display_topics_feed_rss2($the_query); // All forum topics and replies } else { // Exclude private/hidden forums if not looking at single if (empty($query_vars['forum'])) { $meta_query = array(bbp_exclude_forum_ids('meta_query')); } // The query $the_query = array('author' => 0, 'feed' => true, 'post_type' => array(bbp_get_reply_post_type(), bbp_get_topic_post_type()), 'post_parent' => 'any', 'post_status' => join(',', array(bbp_get_public_status_id(), bbp_get_closed_status_id())), 'posts_per_page' => bbp_get_replies_per_rss_page(), 'order' => 'DESC', 'meta_query' => $meta_query); // Output the feed bbp_display_replies_feed_rss2($the_query); } break; // Topic feed - Show replies // Topic feed - Show replies case bbp_get_topic_post_type(): // Single topic if (isset($query_vars[bbp_get_topic_post_type()])) { // Load up our own query query_posts(array('post_type' => bbp_get_topic_post_type(), 'name' => $query_vars[bbp_get_topic_post_type()], 'feed' => true)); // Output the feed bbp_display_replies_feed_rss2(array('feed' => true)); // All topics } else { // The query $the_query = array('author' => 0, 'feed' => true, 'post_parent' => 'any', 'posts_per_page' => bbp_get_topics_per_rss_page(), 'show_stickies' => false); // Output the feed bbp_display_topics_feed_rss2($the_query); } break; // Replies // Replies case bbp_get_reply_post_type(): // The query $the_query = array('posts_per_page' => bbp_get_replies_per_rss_page(), 'meta_query' => array(array()), 'feed' => true); // All replies if (!isset($query_vars[bbp_get_reply_post_type()])) { bbp_display_replies_feed_rss2($the_query); } break; } // Single Topic Vview } elseif (isset($query_vars['bbp_view'])) { // Get the view $view = $query_vars['bbp_view']; // We have a view to display a feed if (!empty($view)) { // Get the view query $the_query = bbp_get_view_query_args($view); // Output the feed bbp_display_topics_feed_rss2($the_query); } } // @todo User profile feeds } // No feed so continue on return $query_vars; }
/** * Add checks for bbPress conditions to parse_query action * * If it's a user page, WP_Query::bbp_is_single_user is set to true. * If it's a user edit page, WP_Query::bbp_is_single_user_edit is set to true * and the the 'wp-admin/includes/user.php' file is included. * In addition, on user/user edit pages, WP_Query::home is set to false & query * vars 'bbp_user_id' with the displayed user id and 'author_name' with the * displayed user's nicename are added. * * If it's a forum edit, WP_Query::bbp_is_forum_edit is set to true * If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true * If it's a reply edit, WP_Query::bbp_is_reply_edit is set to true. * * If it's a view page, WP_Query::bbp_is_view is set to true * If it's a search page, WP_Query::bbp_is_search is set to true * * @since bbPress (r2688) * * @param WP_Query $posts_query * * @uses get_query_var() To get {@link WP_Query} query var * @uses is_email() To check if the string is an email * @uses get_user_by() To try to get the user by email and nicename * @uses get_userdata() to get the user data * @uses current_user_can() To check if the current user can edit the user * @uses is_user_member_of_blog() To check if user profile page exists * @uses WP_Query::set_404() To set a 404 status * @uses apply_filters() Calls 'enable_edit_any_user_configuration' with true * @uses bbp_get_view_query_args() To get the view query args * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses remove_action() To remove the auto save post revision action */ function bbp_parse_query($posts_query) { // Bail if $posts_query is not the main loop if (!$posts_query->is_main_query()) { return; } // Bail if filters are suppressed on this query if (true === $posts_query->get('suppress_filters')) { return; } // Bail if in admin if (is_admin()) { return; } // Get query variables $bbp_view = $posts_query->get(bbp_get_view_rewrite_id()); $bbp_user = $posts_query->get(bbp_get_user_rewrite_id()); $is_edit = $posts_query->get(bbp_get_edit_rewrite_id()); // It is a user page - We'll also check if it is user edit if (!empty($bbp_user)) { /** Find User *********************************************************/ // Setup the default user variable $the_user = false; // If using pretty permalinks, use the email or slug if (get_option('permalink_structure')) { // Email was passed if (is_email($bbp_user)) { $the_user = get_user_by('email', $bbp_user); // Try nicename } else { $the_user = get_user_by('slug', $bbp_user); } } // No user found by slug/email, so try the ID if it's numeric if (empty($the_user) && is_numeric($bbp_user)) { $the_user = get_user_by('id', $bbp_user); } // 404 and bail if user does not have a profile if (empty($the_user->ID) || !bbp_user_has_profile($the_user->ID)) { $posts_query->set_404(); return; } /** User Exists *******************************************************/ $is_favs = $posts_query->get(bbp_get_user_favorites_rewrite_id()); $is_subs = $posts_query->get(bbp_get_user_subscriptions_rewrite_id()); $is_topics = $posts_query->get(bbp_get_user_topics_rewrite_id()); $is_replies = $posts_query->get(bbp_get_user_replies_rewrite_id()); // View or edit? if (!empty($is_edit)) { // We are editing a profile $posts_query->bbp_is_single_user_edit = true; // Load the core WordPress contact methods if (!function_exists('_wp_get_user_contactmethods')) { include_once ABSPATH . 'wp-includes/registration.php'; } // Load the edit_user functions if (!function_exists('edit_user')) { require_once ABSPATH . 'wp-admin/includes/user.php'; } // Load the grant/revoke super admin functions if (is_multisite() && !function_exists('revoke_super_admin')) { require_once ABSPATH . 'wp-admin/includes/ms.php'; } // Editing a user $posts_query->bbp_is_edit = true; // User favorites } elseif (!empty($is_favs)) { $posts_query->bbp_is_single_user_favs = true; // User subscriptions } elseif (!empty($is_subs)) { $posts_query->bbp_is_single_user_subs = true; // User topics } elseif (!empty($is_topics)) { $posts_query->bbp_is_single_user_topics = true; // User topics } elseif (!empty($is_replies)) { $posts_query->bbp_is_single_user_replies = true; // User profile } else { $posts_query->bbp_is_single_user_profile = true; } // Looking at a single user $posts_query->bbp_is_single_user = true; // Make sure 404 is not set $posts_query->is_404 = false; // Correct is_home variable $posts_query->is_home = false; // User is looking at their own profile if (get_current_user_id() === $the_user->ID) { $posts_query->bbp_is_single_user_home = true; } // Set bbp_user_id for future reference $posts_query->set('bbp_user_id', $the_user->ID); // Set author_name as current user's nicename to get correct posts $posts_query->set('author_name', $the_user->user_nicename); // Set the displayed user global to this user bbpress()->displayed_user = $the_user; // View Page } elseif (!empty($bbp_view)) { // Check if the view exists by checking if there are query args are set $view_args = bbp_get_view_query_args($bbp_view); // Bail if view args is false (view isn't registered) if (false === $view_args) { $posts_query->set_404(); return; } // Correct is_home variable $posts_query->is_home = false; // We are in a custom topic view $posts_query->bbp_is_view = true; // Search Page } elseif (isset($posts_query->query_vars[bbp_get_search_rewrite_id()])) { // Check if there are search query args set $search_terms = bbp_get_search_terms(); if (!empty($search_terms)) { $posts_query->bbp_search_terms = $search_terms; } // Correct is_home variable $posts_query->is_home = false; // We are in a search query $posts_query->bbp_is_search = true; // Forum/Topic/Reply Edit Page } elseif (!empty($is_edit)) { // Get the post type from the main query loop $post_type = $posts_query->get('post_type'); // Check which post_type we are editing, if any if (!empty($post_type)) { switch ($post_type) { // We are editing a forum case bbp_get_forum_post_type(): $posts_query->bbp_is_forum_edit = true; $posts_query->bbp_is_edit = true; break; // We are editing a topic // We are editing a topic case bbp_get_topic_post_type(): $posts_query->bbp_is_topic_edit = true; $posts_query->bbp_is_edit = true; break; // We are editing a reply // We are editing a reply case bbp_get_reply_post_type(): $posts_query->bbp_is_reply_edit = true; $posts_query->bbp_is_edit = true; break; } // We are editing a topic tag } elseif (bbp_is_topic_tag()) { $posts_query->bbp_is_topic_tag_edit = true; $posts_query->bbp_is_edit = true; } // We save post revisions on our own remove_action('pre_post_update', 'wp_save_post_revision'); // Topic tag page } elseif (bbp_is_topic_tag()) { $posts_query->set('bbp_topic_tag', get_query_var('term')); $posts_query->set('post_type', bbp_get_topic_post_type()); $posts_query->set('posts_per_page', bbp_get_topics_per_page()); // Do topics on forums root } elseif (is_post_type_archive(array(bbp_get_forum_post_type(), bbp_get_topic_post_type())) && 'topics' === bbp_show_on_root()) { $posts_query->bbp_show_topics_on_root = true; } }
/** * Add checks for bbPress conditions to parse_query action * * If it's a user page, WP_Query::bbp_is_single_user is set to true. * If it's a user edit page, WP_Query::bbp_is_single_user_edit is set to true * and the the 'wp-admin/includes/user.php' file is included. * In addition, on user/user edit pages, WP_Query::home is set to false & query * vars 'bbp_user_id' with the displayed user id and 'author_name' with the * displayed user's nicename are added. * * If it's a forum edit, WP_Query::bbp_is_forum_edit is set to true * If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true * If it's a reply edit, WP_Query::bbp_is_reply_edit is set to true. * * If it's a view page, WP_Query::bbp_is_view is set to true * * @since bbPress (r2688) * * @param WP_Query $posts_query * * @uses get_query_var() To get {@link WP_Query} query var * @uses is_email() To check if the string is an email * @uses get_user_by() To try to get the user by email and nicename * @uses WP_User to get the user data * @uses WP_Query::set_404() To set a 404 status * @uses current_user_can() To check if the current user can edit the user * @uses apply_filters() Calls 'enable_edit_any_user_configuration' with true * @uses bbp_get_view_query_args() To get the view query args * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses remove_action() To remove the auto save post revision action */ function bbp_parse_query($posts_query) { // Bail if $posts_query is not the main loop if (!$posts_query->is_main_query()) { return; } // Bail if filters are suppressed on this query if (true == $posts_query->get('suppress_filters')) { return; } // Bail if in admin if (is_admin()) { return; } // Get query variables $bbp_user = $posts_query->get(bbp_get_user_rewrite_id()); $bbp_view = $posts_query->get(bbp_get_view_rewrite_id()); $is_edit = $posts_query->get(bbp_get_edit_rewrite_id()); // It is a user page - We'll also check if it is user edit if (!empty($bbp_user)) { // Not a user_id so try email and slug if (!is_numeric($bbp_user)) { // Email was passed if (is_email($bbp_user)) { $bbp_user = get_user_by('email', $bbp_user); // Try nicename } else { $bbp_user = get_user_by('slug', $bbp_user); } // If we were successful, set to ID if (is_object($bbp_user)) { $bbp_user = $bbp_user->ID; } } // Create new user $user = new WP_User($bbp_user); // Bail if no user if (!isset($user) || empty($user) || empty($user->ID)) { $posts_query->set_404(); return; } /** User Exists *******************************************************/ // View or edit? if (!empty($is_edit)) { // We are editing a profile $posts_query->bbp_is_single_user_edit = true; // Load the core WordPress contact methods if (!function_exists('_wp_get_user_contactmethods')) { include_once ABSPATH . 'wp-includes/registration.php'; } // Load the edit_user functions if (!function_exists('edit_user')) { require_once ABSPATH . 'wp-admin/includes/user.php'; } // Editing a user $posts_query->bbp_is_edit = true; // We are viewing a profile } else { $posts_query->bbp_is_single_user = true; } // Make sure 404 is not set $posts_query->is_404 = false; // Correct is_home variable $posts_query->is_home = false; // Set bbp_user_id for future reference $posts_query->set('bbp_user_id', $user->ID); // Set author_name as current user's nicename to get correct posts $posts_query->set('author_name', $user->user_nicename); // Set the displayed user global to this user bbpress()->displayed_user = $user; // View Page } elseif (!empty($bbp_view)) { // Check if the view exists by checking if there are query args are set $view_args = bbp_get_view_query_args($bbp_view); // Bail if view args is false (view isn't registered) if (false === $view_args) { $posts_query->set_404(); return; } // Correct is_home variable $posts_query->is_home = false; // We are in a custom topic view $posts_query->bbp_is_view = true; // Forum/Topic/Reply Edit Page } elseif (!empty($is_edit)) { // Get the post type from the main query loop $post_type = $posts_query->get('post_type'); // Check which post_type we are editing, if any if (!empty($post_type)) { switch ($post_type) { // We are editing a forum case bbp_get_forum_post_type(): $posts_query->bbp_is_forum_edit = true; $posts_query->bbp_is_edit = true; break; // We are editing a topic // We are editing a topic case bbp_get_topic_post_type(): $posts_query->bbp_is_topic_edit = true; $posts_query->bbp_is_edit = true; break; // We are editing a reply // We are editing a reply case bbp_get_reply_post_type(): $posts_query->bbp_is_reply_edit = true; $posts_query->bbp_is_edit = true; break; } // We are editing a topic tag } elseif (bbp_is_topic_tag()) { $posts_query->bbp_is_topic_tag_edit = true; $posts_query->bbp_is_edit = true; } // We save post revisions on our own remove_action('pre_post_update', 'wp_save_post_revision'); // Topic tag page } elseif (bbp_is_topic_tag()) { $posts_query->set('bbp_topic_tag', get_query_var('term')); $posts_query->set('post_type', bbp_get_topic_post_type()); $posts_query->set('posts_per_page', bbp_get_topics_per_page()); } }