/** * Return the replies link of the topic * * @since 2.0.0 bbPress (r2740) * * @param int $topic_id Optional. Topic id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_topic() To get the topic * @uses bbp_get_topic_reply_count() To get the topic reply count * @uses bbp_get_topic_permalink() To get the topic permalink * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden * reply count * @uses current_user_can() To check if the current user can edit others * replies * @uses apply_filters() Calls 'bbp_get_topic_replies_link' with the * replies link and topic id */ function bbp_get_topic_replies_link($topic_id = 0) { $topic = bbp_get_topic($topic_id); $topic_id = $topic->ID; $replies = sprintf(_n('%s reply', '%s replies', bbp_get_topic_reply_count($topic_id, true), 'bbpress'), bbp_get_topic_reply_count($topic_id)); $retval = ''; // First link never has view=all if (bbp_get_view_all('edit_others_replies')) { $retval .= "<a href='" . esc_url(bbp_remove_view_all(bbp_get_topic_permalink($topic_id))) . "'>{$replies}</a>"; } else { $retval .= $replies; } // Any deleted replies? $deleted = bbp_get_topic_reply_count_hidden($topic_id); // This forum has hidden topics if (!empty($deleted) && current_user_can('edit_others_replies')) { // Extra text $extra = sprintf(esc_html__(' (+ %d hidden)', 'bbpress'), $deleted); // No link if (bbp_get_view_all()) { $retval .= " {$extra}"; // Link } else { $retval .= " <a href='" . esc_url(bbp_add_view_all(bbp_get_topic_permalink($topic_id), true)) . "'>{$extra}</a>"; } } return apply_filters('bbp_get_topic_replies_link', $retval, $topic_id); }
/** * Handles the front end edit forum submission * * @param string $action The requested action to compare this function to * @uses bbPress:errors::add() To log various error messages * @uses bbp_get_forum() To get the forum * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses bbp_is_forum_anonymous() To check if forum is by an anonymous user * @uses current_user_can() To check if the current user can edit the forum * @uses bbp_filter_anonymous_post_data() To filter anonymous data * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error} * @uses esc_attr() For sanitization * @uses bbp_is_forum_category() To check if the forum is a category * @uses bbp_is_forum_closed() To check if the forum is closed * @uses bbp_is_forum_private() To check if the forum is private * @uses remove_filter() To remove kses filters if needed * @uses apply_filters() Calls 'bbp_edit_forum_pre_title' with the title and * forum id * @uses apply_filters() Calls 'bbp_edit_forum_pre_content' with the content * and forum id * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors * @uses wp_save_post_revision() To save a forum revision * @uses bbp_update_forum_revision_log() To update the forum revision log * @uses wp_update_post() To update the forum * @uses do_action() Calls 'bbp_edit_forum' with the forum id, forum id, * anonymous data and reply author * @uses bbp_move_forum_handler() To handle movement of a forum from one forum * to another * @uses bbp_get_forum_permalink() To get the forum permalink * @uses wp_safe_redirect() To redirect to the forum link * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error * messages */ function bbp_edit_forum_handler($action = '') { // Bail if action is not bbp-edit-forum if ('bbp-edit-forum' !== $action) { return; } // Define local variable(s) $anonymous_data = array(); $forum = $forum_id = $forum_parent_id = 0; $forum_title = $forum_content = $forum_edit_reason = ''; /** Forum *****************************************************************/ // Forum id was not passed if (empty($_POST['bbp_forum_id'])) { bbp_add_error('bbp_edit_forum_id', __('<strong>ERROR</strong>: Forum ID not found.', 'bbpress')); return; // Forum id was passed } elseif (is_numeric($_POST['bbp_forum_id'])) { $forum_id = (int) $_POST['bbp_forum_id']; $forum = bbp_get_forum($forum_id); } // Nonce check if (!bbp_verify_nonce_request('bbp-edit-forum_' . $forum_id)) { bbp_add_error('bbp_edit_forum_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; // Forum does not exist } elseif (empty($forum)) { bbp_add_error('bbp_edit_forum_not_found', __('<strong>ERROR</strong>: The forum you want to edit was not found.', 'bbpress')); return; // User cannot edit this forum } elseif (!current_user_can('edit_forum', $forum_id)) { bbp_add_error('bbp_edit_forum_permissions', __('<strong>ERROR</strong>: You do not have permission to edit that forum.', 'bbpress')); return; } // Remove kses filters from title and content for capable users and if the nonce is verified if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_forum']) && wp_create_nonce('bbp-unfiltered-html-forum_' . $forum_id) === $_POST['_bbp_unfiltered_html_forum']) { remove_filter('bbp_edit_forum_pre_title', 'wp_filter_kses'); remove_filter('bbp_edit_forum_pre_content', 'bbp_encode_bad', 10); remove_filter('bbp_edit_forum_pre_content', 'bbp_filter_kses', 30); } /** Forum Parent ***********************************************************/ // Forum parent id was passed if (!empty($_POST['bbp_forum_parent_id'])) { $forum_parent_id = bbp_get_forum_id($_POST['bbp_forum_parent_id']); } // Current forum this forum is in $current_parent_forum_id = bbp_get_forum_parent_id($forum_id); // Forum exists if (!empty($forum_parent_id) && $forum_parent_id !== $current_parent_forum_id) { // Forum is closed and user cannot access if (bbp_is_forum_closed($forum_parent_id) && !current_user_can('edit_forum', $forum_parent_id)) { bbp_add_error('bbp_edit_forum_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new forums.', 'bbpress')); } // Forum is private and user cannot access if (bbp_is_forum_private($forum_parent_id) && !current_user_can('read_private_forums')) { bbp_add_error('bbp_edit_forum_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress')); } // Forum is hidden and user cannot access if (bbp_is_forum_hidden($forum_parent_id) && !current_user_can('read_hidden_forums')) { bbp_add_error('bbp_edit_forum_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress')); } } /** Forum Title ***********************************************************/ if (!empty($_POST['bbp_forum_title'])) { $forum_title = esc_attr(strip_tags($_POST['bbp_forum_title'])); } // Filter and sanitize $forum_title = apply_filters('bbp_edit_forum_pre_title', $forum_title, $forum_id); // No forum title if (empty($forum_title)) { bbp_add_error('bbp_edit_forum_title', __('<strong>ERROR</strong>: Your forum needs a title.', 'bbpress')); } /** Forum Content *********************************************************/ if (!empty($_POST['bbp_forum_content'])) { $forum_content = $_POST['bbp_forum_content']; } // Filter and sanitize $forum_content = apply_filters('bbp_edit_forum_pre_content', $forum_content, $forum_id); // No forum content if (empty($forum_content)) { bbp_add_error('bbp_edit_forum_content', __('<strong>ERROR</strong>: Your forum description cannot be empty.', 'bbpress')); } /** Forum Blacklist *******************************************************/ if (!bbp_check_for_blacklist($anonymous_data, bbp_get_forum_author_id($forum_id), $forum_title, $forum_content)) { bbp_add_error('bbp_forum_blacklist', __('<strong>ERROR</strong>: Your forum cannot be edited at this time.', 'bbpress')); } /** Forum Moderation ******************************************************/ $post_status = bbp_get_public_status_id(); if (!bbp_check_for_moderation($anonymous_data, bbp_get_forum_author_id($forum_id), $forum_title, $forum_content)) { $post_status = bbp_get_pending_status_id(); } /** Additional Actions (Before Save) **************************************/ do_action('bbp_edit_forum_pre_extras', $forum_id); // Bail if errors if (bbp_has_errors()) { return; } /** No Errors *************************************************************/ // Add the content of the form to $forum_data as an array // Just in time manipulation of forum data before being edited $forum_data = apply_filters('bbp_edit_forum_pre_insert', array('ID' => $forum_id, 'post_title' => $forum_title, 'post_content' => $forum_content, 'post_status' => $post_status, 'post_parent' => $forum_parent_id)); // Insert forum $forum_id = wp_update_post($forum_data); /** Revisions *************************************************************/ /** * @todo omitted for 2.1 // Revision Reason if ( !empty( $_POST['bbp_forum_edit_reason'] ) ) $forum_edit_reason = esc_attr( strip_tags( $_POST['bbp_forum_edit_reason'] ) ); // Update revision log if ( !empty( $_POST['bbp_log_forum_edit'] ) && ( "1" === $_POST['bbp_log_forum_edit'] ) && ( $revision_id = wp_save_post_revision( $forum_id ) ) ) { bbp_update_forum_revision_log( array( 'forum_id' => $forum_id, 'revision_id' => $revision_id, 'author_id' => bbp_get_current_user_id(), 'reason' => $forum_edit_reason ) ); } */ /** No Errors *************************************************************/ if (!empty($forum_id) && !is_wp_error($forum_id)) { // Update counts, etc... do_action('bbp_edit_forum', array('forum_id' => $forum_id, 'post_parent' => $forum_parent_id, 'forum_author' => $forum->post_author, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id())); // If the new forum parent id is not equal to the old forum parent // id, run the bbp_move_forum action and pass the forum's parent id // as the first arg and new forum parent id as the second. // @todo implement //if ( $forum_id !== $forum->post_parent ) // bbp_move_forum_handler( $forum_parent_id, $forum->post_parent, $forum_id ); /** Additional Actions (After Save) ***********************************/ do_action('bbp_edit_forum_post_extras', $forum_id); /** Redirect **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // View all? $view_all = bbp_get_view_all(); // Get the forum URL $forum_url = bbp_get_forum_permalink($forum_id, $redirect_to); // Add view all? if (!empty($view_all)) { $forum_url = bbp_add_view_all($forum_url); } // Allow to be filtered $forum_url = apply_filters('bbp_edit_forum_redirect_to', $forum_url, $view_all, $redirect_to); /** Successful Edit ***************************************************/ // Redirect back to new forum wp_safe_redirect($forum_url); // For good measure exit; /** Errors ****************************************************************/ } else { $append_error = is_wp_error($forum_id) && $forum_id->get_error_message() ? $forum_id->get_error_message() . ' ' : ''; bbp_add_error('bbp_forum_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your forum:' . $append_error . 'Please try again.', 'bbpress')); } }
/** * Handles the front end edit topic submission * * @param string $action The requested action to compare this function to * @uses bbp_add_error() To add an error message * @uses bbp_get_topic() To get the topic * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses bbp_is_topic_anonymous() To check if topic is by an anonymous user * @uses current_user_can() To check if the current user can edit the topic * @uses bbp_filter_anonymous_post_data() To filter anonymous data * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error} * @uses esc_attr() For sanitization * @uses bbp_is_forum_category() To check if the forum is a category * @uses bbp_is_forum_closed() To check if the forum is closed * @uses bbp_is_forum_private() To check if the forum is private * @uses remove_filter() To remove kses filters if needed * @uses apply_filters() Calls 'bbp_edit_topic_pre_title' with the title and * topic id * @uses apply_filters() Calls 'bbp_edit_topic_pre_content' with the content * and topic id * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors * @uses wp_save_post_revision() To save a topic revision * @uses bbp_update_topic_revision_log() To update the topic revision log * @uses bbp_stick_topic() To stick or super stick the topic * @uses bbp_unstick_topic() To unstick the topic * @uses wp_update_post() To update the topic * @uses do_action() Calls 'bbp_edit_topic' with the topic id, forum id, * anonymous data and reply author * @uses bbp_move_topic_handler() To handle movement of a topic from one forum * to another * @uses bbp_get_topic_permalink() To get the topic permalink * @uses wp_safe_redirect() To redirect to the topic link * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error * messages */ function bbp_edit_topic_handler($action = '') { // Bail if action is not bbp-edit-topic if ('bbp-edit-topic' !== $action) { return; } // Define local variable(s) $revisions_removed = false; $topic = $topic_id = $topic_author = $forum_id = $anonymous_data = 0; $topic_title = $topic_content = $topic_edit_reason = ''; /** Topic *****************************************************************/ // Topic id was not passed if (empty($_POST['bbp_topic_id'])) { bbp_add_error('bbp_edit_topic_id', __('<strong>ERROR</strong>: Topic ID not found.', 'bbpress')); return; // Topic id was passed } elseif (is_numeric($_POST['bbp_topic_id'])) { $topic_id = (int) $_POST['bbp_topic_id']; $topic = bbp_get_topic($topic_id); } // Topic does not exist if (empty($topic)) { bbp_add_error('bbp_edit_topic_not_found', __('<strong>ERROR</strong>: The topic you want to edit was not found.', 'bbpress')); return; // Topic exists } else { // Check users ability to create new topic if (!bbp_is_topic_anonymous($topic_id)) { // User cannot edit this topic if (!current_user_can('edit_topic', $topic_id)) { bbp_add_error('bbp_edit_topic_permissions', __('<strong>ERROR</strong>: You do not have permission to edit that topic.', 'bbpress')); } // Set topic author $topic_author = bbp_get_topic_author_id($topic_id); // It is an anonymous post } else { // Filter anonymous data $anonymous_data = bbp_filter_anonymous_post_data(array(), true); } } // Nonce check if (!bbp_verify_nonce_request('bbp-edit-topic_' . $topic_id)) { bbp_add_error('bbp_edit_topic_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; } // Remove kses filters from title and content for capable users and if the nonce is verified if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_topic']) && wp_create_nonce('bbp-unfiltered-html-topic_' . $topic_id) === $_POST['_bbp_unfiltered_html_topic']) { remove_filter('bbp_edit_topic_pre_title', 'wp_filter_kses'); remove_filter('bbp_edit_topic_pre_content', 'bbp_encode_bad', 10); remove_filter('bbp_edit_topic_pre_content', 'bbp_filter_kses', 30); } /** Topic Forum ***********************************************************/ // Forum id was not passed if (empty($_POST['bbp_forum_id'])) { bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress')); // Forum id was passed } elseif (is_numeric($_POST['bbp_forum_id'])) { $forum_id = (int) $_POST['bbp_forum_id']; } // Current forum this topic is in $current_forum_id = bbp_get_topic_forum_id($topic_id); // Forum exists if (!empty($forum_id) && $forum_id !== $current_forum_id) { // Forum is a category if (bbp_is_forum_category($forum_id)) { bbp_add_error('bbp_edit_topic_forum_category', __('<strong>ERROR</strong>: This forum is a category. No topics can be created in it.', 'bbpress')); // Forum is not a category } else { // Forum is closed and user cannot access if (bbp_is_forum_closed($forum_id) && !current_user_can('edit_forum', $forum_id)) { bbp_add_error('bbp_edit_topic_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress')); } // Forum is private and user cannot access if (bbp_is_forum_private($forum_id)) { if (!current_user_can('read_private_forums')) { bbp_add_error('bbp_edit_topic_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress')); } // Forum is hidden and user cannot access } elseif (bbp_is_forum_hidden($forum_id)) { if (!current_user_can('read_hidden_forums')) { bbp_add_error('bbp_edit_topic_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress')); } } } } /** Topic Title ***********************************************************/ if (!empty($_POST['bbp_topic_title'])) { $topic_title = esc_attr(strip_tags($_POST['bbp_topic_title'])); } // Filter and sanitize $topic_title = apply_filters('bbp_edit_topic_pre_title', $topic_title, $topic_id); // No topic title if (empty($topic_title)) { bbp_add_error('bbp_edit_topic_title', __('<strong>ERROR</strong>: Your topic needs a title.', 'bbpress')); } /** Topic Content *********************************************************/ if (!empty($_POST['bbp_topic_content'])) { $topic_content = $_POST['bbp_topic_content']; } // Filter and sanitize $topic_content = apply_filters('bbp_edit_topic_pre_content', $topic_content, $topic_id); // No topic content if (empty($topic_content)) { bbp_add_error('bbp_edit_topic_content', __('<strong>ERROR</strong>: Your topic cannot be empty.', 'bbpress')); } /** Topic Blacklist *******************************************************/ if (!bbp_check_for_blacklist($anonymous_data, $topic_author, $topic_title, $topic_content)) { bbp_add_error('bbp_topic_blacklist', __('<strong>ERROR</strong>: Your topic cannot be edited at this time.', 'bbpress')); } /** Topic Status **********************************************************/ // Maybe put into moderation if (!bbp_check_for_moderation($anonymous_data, $topic_author, $topic_title, $topic_content)) { // Set post status to pending if public or closed if (in_array($topic->post_status, array(bbp_get_public_status_id(), bbp_get_closed_status_id()))) { $topic_status = bbp_get_pending_status_id(); } // Check a whitelist of possible topic status ID's } elseif (!empty($_POST['bbp_topic_status']) && in_array($_POST['bbp_topic_status'], array_keys(bbp_get_topic_statuses()))) { $topic_status = $_POST['bbp_topic_status']; // Use existing post_status } else { $topic_status = $topic->post_status; } /** Topic Tags ************************************************************/ // Either replace terms if (bbp_allow_topic_tags() && current_user_can('assign_topic_tags') && !empty($_POST['bbp_topic_tags'])) { // Escape tag input $terms = esc_attr(strip_tags($_POST['bbp_topic_tags'])); // Explode by comma if (strstr($terms, ',')) { $terms = explode(',', $terms); } // Add topic tag ID as main key $terms = array(bbp_get_topic_tag_tax_id() => $terms); // ...or remove them. } elseif (isset($_POST['bbp_topic_tags'])) { $terms = array(bbp_get_topic_tag_tax_id() => array()); // Existing terms } else { $terms = array(bbp_get_topic_tag_tax_id() => explode(',', bbp_get_topic_tag_names($topic_id, ','))); } /** Additional Actions (Before Save) **************************************/ do_action('bbp_edit_topic_pre_extras', $topic_id); // Bail if errors if (bbp_has_errors()) { return; } /** No Errors *************************************************************/ // Add the content of the form to $topic_data as an array // Just in time manipulation of topic data before being edited $topic_data = apply_filters('bbp_edit_topic_pre_insert', array('ID' => $topic_id, 'post_title' => $topic_title, 'post_content' => $topic_content, 'post_status' => $topic_status, 'post_parent' => $forum_id, 'post_author' => $topic_author, 'post_type' => bbp_get_topic_post_type(), 'tax_input' => $terms)); // Toggle revisions to avoid duplicates if (post_type_supports(bbp_get_topic_post_type(), 'revisions')) { $revisions_removed = true; remove_post_type_support(bbp_get_topic_post_type(), 'revisions'); } // Insert topic $topic_id = wp_update_post($topic_data); // Toggle revisions back on if (true === $revisions_removed) { $revisions_removed = false; add_post_type_support(bbp_get_topic_post_type(), 'revisions'); } /** No Errors *************************************************************/ if (!empty($topic_id) && !is_wp_error($topic_id)) { // Update counts, etc... do_action('bbp_edit_topic', $topic_id, $forum_id, $anonymous_data, $topic_author, true); /** Revisions *********************************************************/ // Revision Reason if (!empty($_POST['bbp_topic_edit_reason'])) { $topic_edit_reason = esc_attr(strip_tags($_POST['bbp_topic_edit_reason'])); } // Update revision log if (!empty($_POST['bbp_log_topic_edit']) && "1" === $_POST['bbp_log_topic_edit']) { $revision_id = wp_save_post_revision($topic_id); if (!empty($revision_id)) { bbp_update_topic_revision_log(array('topic_id' => $topic_id, 'revision_id' => $revision_id, 'author_id' => bbp_get_current_user_id(), 'reason' => $topic_edit_reason)); } } /** Move Topic ********************************************************/ // If the new forum id is not equal to the old forum id, run the // bbp_move_topic action and pass the topic's forum id as the // first arg and topic id as the second to update counts. if ($forum_id !== $topic->post_parent) { bbp_move_topic_handler($topic_id, $topic->post_parent, $forum_id); } /** Stickies **********************************************************/ if (!empty($_POST['bbp_stick_topic']) && in_array($_POST['bbp_stick_topic'], array_keys(bbp_get_topic_types()))) { // What's the caps? if (current_user_can('moderate')) { // What's the haps? switch ($_POST['bbp_stick_topic']) { // Sticky in forum case 'stick': bbp_stick_topic($topic_id); break; // Sticky in all forums // Sticky in all forums case 'super': bbp_stick_topic($topic_id, true); break; // Normal // Normal case 'unstick': default: bbp_unstick_topic($topic_id); break; } } } /** Additional Actions (After Save) ***********************************/ do_action('bbp_edit_topic_post_extras', $topic_id); /** Redirect **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // View all? $view_all = bbp_get_view_all(); // Get the topic URL $topic_url = bbp_get_topic_permalink($topic_id, $redirect_to); // Add view all? if (!empty($view_all)) { $topic_url = bbp_add_view_all($topic_url); } // Allow to be filtered $topic_url = apply_filters('bbp_edit_topic_redirect_to', $topic_url, $view_all, $redirect_to); /** Successful Edit ***************************************************/ // Redirect back to new topic wp_safe_redirect($topic_url); // For good measure exit; /** Errors ****************************************************************/ } else { $append_error = is_wp_error($topic_id) && $topic_id->get_error_message() ? $topic_id->get_error_message() . ' ' : ''; bbp_add_error('bbp_topic_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your topic:' . $append_error . 'Please try again.', 'bbpress')); } }
/** * The main search loop. WordPress does the heavy lifting. * * @since bbPress (r4579) * * @param mixed $args All the arguments supported by {@link WP_Query} * @uses bbp_get_view_all() Are we showing all results? * @uses bbp_get_public_status_id() To get the public status id * @uses bbp_get_closed_status_id() To get the closed status id * @uses bbp_get_spam_status_id() To get the spam status id * @uses bbp_get_trash_status_id() To get the trash status id * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_replies_per_page() To get the replies per page option * @uses bbp_get_paged() To get the current page value * @uses bbp_get_search_terms() To get the search terms * @uses WP_Query To make query and get the search results * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks * @uses bbp_get_search_url() To get the forum search url * @uses paginate_links() To paginate search results * @uses apply_filters() Calls 'bbp_has_search_results' with * bbPress::search_query::have_posts() * and bbPress::reply_query * @return object Multidimensional array of search information */ function bbp_has_search_results($args = '') { global $wp_rewrite; /** Defaults **************************************************************/ $default_post_type = array(bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type()); // Default query args $default = array('post_type' => $default_post_type, 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true, 's' => bbp_get_search_terms()); // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { // Default view=all statuses $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id()); // Add support for private status if (current_user_can('read_private_topics')) { $post_statuses[] = bbp_get_private_status_id(); } // Join post statuses together $default['post_status'] = implode(',', $post_statuses); // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $default['perm'] = 'readable'; } /** Setup *****************************************************************/ // Parse arguments against default values $r = bbp_parse_args($args, $default, 'has_search_results'); // Get bbPress $bbp = bbpress(); // Call the query if (!empty($r['s'])) { $bbp->search_query = new WP_Query($r); } // Add pagination values to query object $bbp->search_query->posts_per_page = $r['posts_per_page']; $bbp->search_query->paged = $r['paged']; // Never home, regardless of what parse_query says $bbp->search_query->is_home = false; // Only add pagination is query returned results if (!empty($bbp->search_query->found_posts) && !empty($bbp->search_query->posts_per_page)) { // Array of arguments to add after pagination links $add_args = array(); // If pretty permalinks are enabled, make our pagination pretty if ($wp_rewrite->using_permalinks()) { // Shortcode territory if (is_page() || is_single()) { $base = trailingslashit(get_permalink()); // Default search location } else { $base = trailingslashit(bbp_get_search_results_url()); } // Add pagination base $base = $base . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/'); // Unpretty permalinks } else { $base = add_query_arg('paged', '%#%'); } // Add args if (bbp_get_view_all()) { $add_args['view'] = 'all'; } // Add pagination to query object $bbp->search_query->pagination_links = paginate_links(apply_filters('bbp_search_results_pagination', array('base' => $base, 'format' => '', 'total' => ceil((int) $bbp->search_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->search_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1, 'add_args' => $add_args))); // Remove first page from pagination if ($wp_rewrite->using_permalinks()) { $bbp->search_query->pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $bbp->search_query->pagination_links); } else { $bbp->search_query->pagination_links = str_replace('&paged=1', '', $bbp->search_query->pagination_links); } } // Return object return apply_filters('bbp_has_search_results', $bbp->search_query->have_posts(), $bbp->search_query); }
/** * Return the paginated url to the reply in the reply loop * * @since bbPress (r2679) * * @param int $reply_id Optional. Reply id * @param $string $redirect_to Optional. Pass a redirect value for use with * shortcodes and other fun things. * @uses bbp_get_reply_id() To get the reply id * @uses bbp_get_reply_topic_id() To get the reply topic id * @uses bbp_get_topic_permalink() To get the topic permalink * @uses bbp_get_reply_position() To get the reply position * @uses get_option() To get the replies per page option * @uses WP_Rewrite::using_permalinks() To check if the blog uses * permalinks * @uses add_query_arg() To add custom args to the url * @uses apply_filters() Calls 'bbp_get_reply_url' with the reply url, * reply id and bool count hidden * @return string Link to reply relative to paginated topic */ function bbp_get_reply_url($reply_id = 0, $redirect_to = '') { // Set needed variables $reply_id = bbp_get_reply_id($reply_id); $topic_id = bbp_get_reply_topic_id($reply_id); // Hierarchical reply page if (bbp_thread_replies()) { $reply_page = 1; // Standard reply page } else { $reply_page = ceil((int) bbp_get_reply_position($reply_id, $topic_id) / (int) bbp_get_replies_per_page()); } $reply_hash = '#post-' . $reply_id; $topic_link = bbp_get_topic_permalink($topic_id, $redirect_to); $topic_url = remove_query_arg('view', $topic_link); // Don't include pagination if on first page if (1 >= $reply_page) { $url = trailingslashit($topic_url) . $reply_hash; // Include pagination } else { global $wp_rewrite; // Pretty permalinks if ($wp_rewrite->using_permalinks()) { $url = trailingslashit($topic_url) . trailingslashit($wp_rewrite->pagination_base) . trailingslashit($reply_page) . $reply_hash; // Yucky links } else { $url = add_query_arg('paged', $reply_page, $topic_url) . $reply_hash; } } // Add topic view query arg back to end if it is set if (bbp_get_view_all()) { $url = bbp_add_view_all($url); } return apply_filters('bbp_get_reply_url', $url, $reply_id, $redirect_to); }
/** * Return the topics link of the forum * * @since bbPress (r2883) * * @param int $forum_id Optional. Topic id * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_forum() To get the forum * @uses bbp_get_forum_topic_count() To get the forum topic count * @uses bbp_get_forum_permalink() To get the forum permalink * @uses remove_query_arg() To remove args from the url * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden * topic count * @uses current_user_can() To check if the current user can edit others * topics * @uses add_query_arg() To add custom args to the url * @uses apply_filters() Calls 'bbp_get_forum_topics_link' with the * topics link and forum id */ function bbp_get_forum_topics_link($forum_id = 0) { $forum = bbp_get_forum($forum_id); $forum_id = $forum->ID; $topics = bbp_get_forum_topic_count($forum_id); $topics = sprintf(_n('%s topic', '%s topics', $topics, 'bbpress'), $topics); $retval = ''; // First link never has view=all if (bbp_get_view_all('edit_others_topics')) { $retval .= "<a href='" . esc_url(bbp_remove_view_all(bbp_get_forum_permalink($forum_id))) . "'>{$topics}</a>"; } else { $retval .= $topics; } // Get deleted topics $deleted = bbp_get_forum_topic_count_hidden($forum_id); // This forum has hidden topics if (!empty($deleted) && current_user_can('edit_others_topics')) { // Extra text $extra = sprintf(__(' (+ %d hidden)', 'bbpress'), $deleted); // No link if (bbp_get_view_all()) { $retval .= " {$extra}"; // Link } else { $retval .= " <a href='" . esc_url(bbp_add_view_all(bbp_get_forum_permalink($forum_id), true)) . "'>{$extra}</a>"; } } return apply_filters('bbp_get_forum_topics_link', $retval, $forum_id); }
/** * Append 'view=all' to query string if it's already there from referer * * @since 2.0.0 bbPress (r3325) * * @param string $original_link Original Link to be modified * @param bool $force Override bbp_get_view_all() check * @uses current_user_can() To check if the current user can moderate * @uses add_query_arg() To add 'view' arg to the url * @uses apply_filters() Calls 'bbp_add_view_all' with the link and original link * @return string The link with 'view=all' appended if necessary */ function bbp_add_view_all($original_link = '', $force = false) { // Are we appending the view=all vars? if (bbp_get_view_all() || !empty($force)) { $link = add_query_arg(array('view' => 'all'), $original_link); } else { $link = $original_link; } return apply_filters('bbp_add_view_all', $link, $original_link); }
/** * Add the reported status to the list of post statuses so it shows up in view=all * * Used in the has_topics and has_replies queries * * @param array $r query args * @return array */ public function insert_report_status($r) { // Ignore admin queries and only proceed if we're in a view=all query if (is_admin() || !bbp_get_view_all()) { return $r; } if (!isset($r['post_status'])) { return $r; } $statuses = explode(',', $r['post_status']); // Add our custom status to the has_topics query args $statuses[] = $this->get_reported_status_id(); $r['post_status'] = implode(',', $statuses); return $r; }
function tehnik_bbp_has_topics($args = '') { global $wp_rewrite; /** Defaults ************************************************************* */ // Other defaults $default_topic_search = !empty($_REQUEST['ts']) ? $_REQUEST['ts'] : false; $default_show_stickies = (bool) (bbp_is_single_forum() || bbp_is_topic_archive()) && false === $default_topic_search; $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any'; // Default argument array $default = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $default_post_parent, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 's' => $default_topic_search, 'show_stickies' => $default_show_stickies, 'max_num_pages' => false); //Get an array of IDs which the current user has permissions to view $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($default)); // The default forum query with allowed forum ids array added $default['post__in'] = $allowed_forums; // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { // Default view=all statuses $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id()); // Add support for private status if (current_user_can('read_private_topics')) { $post_statuses[] = bbp_get_private_status_id(); } // Join post statuses together $default['post_status'] = join(',', $post_statuses); // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $default['perm'] = 'readable'; } // Maybe query for topic tags if (bbp_is_topic_tag()) { $default['term'] = bbp_get_topic_tag_slug(); $default['taxonomy'] = bbp_get_topic_tag_tax_id(); } /** Setup **************************************************************** */ // Parse arguments against default values $r = bbp_parse_args($args, $default, 'has_topics'); // Get bbPress $bbp = bbpress(); // Call the query $bbp->topic_query = new WP_Query($r); // Set post_parent back to 0 if originally set to 'any' if ('any' == $r['post_parent']) { $r['post_parent'] = 0; } // Limited the number of pages shown if (!empty($r['max_num_pages'])) { $bbp->topic_query->max_num_pages = $r['max_num_pages']; } /** Stickies ************************************************************* */ // Put sticky posts at the top of the posts array if (!empty($r['show_stickies']) && $r['paged'] <= 1) { // Get super stickies and stickies in this forum $stickies = bbp_get_super_stickies(); // Get stickies for current forum if (!empty($r['post_parent'])) { $stickies = array_merge($stickies, bbp_get_stickies($r['post_parent'])); } // Remove any duplicate stickies $stickies = array_unique($stickies); // We have stickies if (is_array($stickies) && !empty($stickies)) { // Start the offset at -1 so first sticky is at correct 0 offset $sticky_offset = -1; // Loop over topics and relocate stickies to the front. foreach ($stickies as $sticky_index => $sticky_ID) { // Get the post offset from the posts array $post_offsets = wp_filter_object_list($bbp->topic_query->posts, array('ID' => $sticky_ID), 'OR', 'ID'); // Continue if no post offsets if (empty($post_offsets)) { continue; } // Loop over posts in current query and splice them into position foreach (array_keys($post_offsets) as $post_offset) { $sticky_offset++; $sticky = $bbp->topic_query->posts[$post_offset]; // Remove sticky from current position array_splice($bbp->topic_query->posts, $post_offset, 1); // Move to front, after other stickies array_splice($bbp->topic_query->posts, $sticky_offset, 0, array($sticky)); // Cleanup unset($stickies[$sticky_index]); unset($sticky); } // Cleanup unset($post_offsets); } // Cleanup unset($sticky_offset); // If any posts have been excluded specifically, Ignore those that are sticky. if (!empty($stickies) && !empty($r['post__not_in'])) { $stickies = array_diff($stickies, $r['post__not_in']); } // Fetch sticky posts that weren't in the query results if (!empty($stickies)) { // Query to use in get_posts to get sticky posts $sticky_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => 'any', 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies); //Get an array of IDs which the current user has permissions to view $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($sticky_query)); // The default forum query with allowed forum ids array added $sticky_query['post__in'] = $allowed_forums; // Cleanup unset($stickies); // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { $sticky_query['post_status'] = $r['post_status']; // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $sticky_query['post_status'] = $r['perm']; } // Get all stickies $sticky_posts = get_posts($sticky_query); if (!empty($sticky_posts)) { // Get a count of the visible stickies $sticky_count = count($sticky_posts); // Merge the stickies topics with the query topics . $bbp->topic_query->posts = array_merge($sticky_posts, $bbp->topic_query->posts); // Adjust loop and counts for new sticky positions $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count; $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count; // Cleanup unset($sticky_posts); } } } } // If no limit to posts per page, set it to the current post_count if (-1 == $r['posts_per_page']) { $r['posts_per_page'] = $bbp->topic_query->post_count; } // Add pagination values to query object $bbp->topic_query->posts_per_page = $r['posts_per_page']; $bbp->topic_query->paged = $r['paged']; // Only add pagination if query returned results if (((int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts) && (int) $bbp->topic_query->posts_per_page) { // Limit the number of topics shown based on maximum allowed pages if (!empty($r['max_num_pages']) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count) { $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count; } // If pretty permalinks are enabled, make our pagination pretty if ($wp_rewrite->using_permalinks()) { // User's topics if (bbp_is_single_user_topics()) { $base = bbp_get_user_topics_created_url(bbp_get_displayed_user_id()); // User's favorites } elseif (bbp_is_favorites()) { $base = bbp_get_favorites_permalink(bbp_get_displayed_user_id()); // User's subscriptions } elseif (bbp_is_subscriptions()) { $base = bbp_get_subscriptions_permalink(bbp_get_displayed_user_id()); // Root profile page } elseif (bbp_is_single_user()) { $base = bbp_get_user_profile_url(bbp_get_displayed_user_id()); // View } elseif (bbp_is_single_view()) { $base = bbp_get_view_url(); // Topic tag } elseif (bbp_is_topic_tag()) { $base = bbp_get_topic_tag_link(); // Page or single post } elseif (is_page() || is_single()) { $base = get_permalink(); // Topic archive } elseif (bbp_is_topic_archive()) { $base = bbp_get_topics_url(); // Default } else { $base = get_permalink((int) $r['post_parent']); } // Use pagination base $base = trailingslashit($base) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/'); // Unpretty pagination } else { $base = add_query_arg('paged', '%#%'); } // Pagination settings with filter $bbp_topic_pagination = apply_filters('bbp_topic_pagination', array('base' => $base, 'format' => '', 'total' => $r['posts_per_page'] == $bbp->topic_query->found_posts ? 1 : ceil((int) $bbp->topic_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->topic_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1)); // Add pagination to query object $bbp->topic_query->pagination_links = paginate_links($bbp_topic_pagination); // Remove first page from pagination $bbp->topic_query->pagination_links = str_replace($wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links); } // Return object return array($bbp->topic_query->have_posts(), $bbp->topic_query); }
/** * Redirect to the group forum screen * * @since bbPress (r3653) */ public function new_reply_redirect_to($redirect_url = '', $redirect_to = '', $reply_id = 0) { global $wp_rewrite; if (bp_is_group()) { $topic_id = bbp_get_reply_topic_id($reply_id); $topic = bbp_get_topic($topic_id); $reply_position = bbp_get_reply_position($reply_id, $topic_id); $reply_page = ceil((int) $reply_position / (int) bbp_get_replies_per_page()); $reply_hash = '#post-' . $reply_id; $topic_url = trailingslashit(bp_get_group_permalink(groups_get_current_group())) . trailingslashit($this->slug) . trailingslashit($this->topic_slug) . trailingslashit($topic->post_name); // Don't include pagination if on first page if (1 >= $reply_page) { $redirect_url = trailingslashit($topic_url) . $reply_hash; // Include pagination } else { $redirect_url = trailingslashit($topic_url) . trailingslashit($wp_rewrite->pagination_base) . trailingslashit($reply_page) . $reply_hash; } // Add topic view query arg back to end if it is set if (bbp_get_view_all()) { $redirect_url = bbp_add_view_all($redirect_url); } } return $redirect_url; }
function firmasite_social_bbp_get_topic_pagination($args = '') { global $wp_rewrite; $defaults = array('topic_id' => bbp_get_topic_id(), 'before' => '<div class="makeit-pag-small">', 'after' => '</div>'); $r = bbp_parse_args($args, $defaults, 'get_topic_pagination'); extract($r); // If pretty permalinks are enabled, make our pagination pretty if ($wp_rewrite->using_permalinks()) { $base = trailingslashit(get_permalink($topic_id)) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/'); } else { $base = add_query_arg('paged', '%#%', get_permalink($topic_id)); } // Get total and add 1 if topic is included in the reply loop $total = bbp_get_topic_reply_count($topic_id, true); // Bump if topic is in loop if (!bbp_show_lead_topic()) { $total++; } // Pagination settings $pagination = array('type' => 'list', 'base' => $base, 'format' => '', 'total' => ceil((int) $total / (int) bbp_get_replies_per_page()), 'current' => 0, 'prev_next' => false, 'mid_size' => 2, 'end_size' => 3, 'add_args' => bbp_get_view_all() ? array('view' => 'all') : false); // Add pagination to query object $pagination_links = paginate_links($pagination); if (!empty($pagination_links)) { // Remove first page from pagination if ($wp_rewrite->using_permalinks()) { $pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $pagination_links); } else { $pagination_links = str_replace('&paged=1', '', $pagination_links); } // Add before and after to pagination links $pagination_links = $before . $pagination_links . $after; } return apply_filters('bbp_get_topic_pagination', $pagination_links, $args); }
function pg_get_user_unread($user_id = 0) { // Default to the displayed user $user_id = bbp_get_user_id($user_id); if (empty($user_id)) { return false; } // If user has unread topics, load them $read_ids = (string) get_user_meta($user_id, '_bbp_mar_read_ids', true); $read_ids = (array) explode(',', $read_ids); $read_ids = array_filter($read_ids); if (!empty($read_ids)) { //so we have unreads, so need to create a list of unread that the user can see //so first we create a list of topics the user can see global $wpdb; $topic = bbp_get_topic_post_type(); $post_ids = $wpdb->get_col("select ID from {$wpdb->posts} where post_type = '{$topic}'"); //check this list against those the user is allowed to see, and create a list of valid ones for the wp_query in bbp_has_topics $allowed_posts = check_private_groups_topic_ids($post_ids); //now we need to take out of that list all read topics for that user foreach ($read_ids as $read_id) { if (($key = array_search($read_id, $allowed_posts)) !== false) { unset($allowed_posts[$key]); } } //so now we have an allowed list that has only topics the user can see, but not topics the user has read //now we use the code from bbp_has_topics to run the list - we can't call it as PG already filters the original function global $wp_rewrite; /** Defaults **************************************************************/ // Other defaults $default_topic_search = !empty($_REQUEST['ts']) ? $_REQUEST['ts'] : false; $default_show_stickies = (bool) (bbp_is_single_forum() || bbp_is_topic_archive()) && false === $default_topic_search; $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any'; // Default argument array $default = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $default_post_parent, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 's' => $default_topic_search, 'show_stickies' => $default_show_stickies, 'max_num_pages' => false, 'post__in' => $allowed_posts); // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { // Default view=all statuses $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id()); // Add support for private status if (current_user_can('read_private_topics')) { $post_statuses[] = bbp_get_private_status_id(); } // Join post statuses together $default['post_status'] = implode(',', $post_statuses); // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $default['perm'] = 'readable'; } // Maybe query for topic tags if (bbp_is_topic_tag()) { $default['term'] = bbp_get_topic_tag_slug(); $default['taxonomy'] = bbp_get_topic_tag_tax_id(); } /** Setup *****************************************************************/ // Parse arguments against default values //stopped to prevent parsing //$r = bbp_parse_args( $args, $default, 'has_topics' ); // Get bbPress $bbp = bbpress(); // Call the query //now query the original default $bbp->topic_query = new WP_Query($default); // Set post_parent back to 0 if originally set to 'any' if ('any' === $r['post_parent']) { $r['post_parent'] = 0; } // Limited the number of pages shown if (!empty($r['max_num_pages'])) { $bbp->topic_query->max_num_pages = $r['max_num_pages']; } /** Stickies **************************************************************/ // Put sticky posts at the top of the posts array if (!empty($r['show_stickies']) && $r['paged'] <= 1) { // Get super stickies and stickies in this forum $stickies = bbp_get_super_stickies(); // Get stickies for current forum if (!empty($r['post_parent'])) { $stickies = array_merge($stickies, bbp_get_stickies($r['post_parent'])); } // Remove any duplicate stickies $stickies = array_unique($stickies); // We have stickies if (is_array($stickies) && !empty($stickies)) { // Start the offset at -1 so first sticky is at correct 0 offset $sticky_offset = -1; // Loop over topics and relocate stickies to the front. foreach ($stickies as $sticky_index => $sticky_ID) { // Get the post offset from the posts array $post_offsets = wp_filter_object_list($bbp->topic_query->posts, array('ID' => $sticky_ID), 'OR', 'ID'); // Continue if no post offsets if (empty($post_offsets)) { continue; } // Loop over posts in current query and splice them into position foreach (array_keys($post_offsets) as $post_offset) { $sticky_offset++; $sticky = $bbp->topic_query->posts[$post_offset]; // Remove sticky from current position array_splice($bbp->topic_query->posts, $post_offset, 1); // Move to front, after other stickies array_splice($bbp->topic_query->posts, $sticky_offset, 0, array($sticky)); // Cleanup unset($stickies[$sticky_index]); unset($sticky); } // Cleanup unset($post_offsets); } // Cleanup unset($sticky_offset); // If any posts have been excluded specifically, Ignore those that are sticky. if (!empty($stickies) && !empty($r['post__not_in'])) { $stickies = array_diff($stickies, $r['post__not_in']); } // Fetch sticky posts that weren't in the query results if (!empty($stickies)) { // Query to use in get_posts to get sticky posts $sticky_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => 'any', 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies); // Cleanup unset($stickies); // Conditionally exclude private/hidden forum ID's $exclude_forum_ids = bbp_exclude_forum_ids('array'); if (!empty($exclude_forum_ids)) { $sticky_query['post_parent__not_in'] = $exclude_forum_ids; } // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { $sticky_query['post_status'] = $r['post_status']; // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $sticky_query['post_status'] = $r['perm']; } // Get all stickies $sticky_posts = get_posts($sticky_query); if (!empty($sticky_posts)) { // Get a count of the visible stickies $sticky_count = count($sticky_posts); // Merge the stickies topics with the query topics . $bbp->topic_query->posts = array_merge($sticky_posts, $bbp->topic_query->posts); // Adjust loop and counts for new sticky positions $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count; $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count; // Cleanup unset($sticky_posts); } } } } // If no limit to posts per page, set it to the current post_count if (-1 === $r['posts_per_page']) { $r['posts_per_page'] = $bbp->topic_query->post_count; } // Add pagination values to query object $bbp->topic_query->posts_per_page = $r['posts_per_page']; $bbp->topic_query->paged = $r['paged']; // Only add pagination if query returned results if (((int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts) && (int) $bbp->topic_query->posts_per_page) { // Limit the number of topics shown based on maximum allowed pages if (!empty($r['max_num_pages']) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count) { $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count; } // If pretty permalinks are enabled, make our pagination pretty if ($wp_rewrite->using_permalinks()) { // User's topics if (bbp_is_single_user_topics()) { $base = bbp_get_user_topics_created_url(bbp_get_displayed_user_id()); // User's favorites } elseif (bbp_is_favorites()) { $base = bbp_get_favorites_permalink(bbp_get_displayed_user_id()); // User's subscriptions } elseif (bbp_is_subscriptions()) { $base = bbp_get_subscriptions_permalink(bbp_get_displayed_user_id()); // Root profile page } elseif (bbp_is_single_user()) { $base = bbp_get_user_profile_url(bbp_get_displayed_user_id()); // View } elseif (bbp_is_single_view()) { $base = bbp_get_view_url(); // Topic tag } elseif (bbp_is_topic_tag()) { $base = bbp_get_topic_tag_link(); // Page or single post } elseif (is_page() || is_single()) { $base = get_permalink(); // Forum archive } elseif (bbp_is_forum_archive()) { $base = bbp_get_forums_url(); // Topic archive } elseif (bbp_is_topic_archive()) { $base = bbp_get_topics_url(); // Default } else { $base = get_permalink((int) $r['post_parent']); } // Use pagination base $base = trailingslashit($base) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/'); // Unpretty pagination } else { $base = add_query_arg('paged', '%#%'); } // Pagination settings with filter $bbp_topic_pagination = apply_filters('bbp_topic_pagination', array('base' => $base, 'format' => '', 'total' => $r['posts_per_page'] === $bbp->topic_query->found_posts ? 1 : ceil((int) $bbp->topic_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->topic_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1)); // Add pagination to query object $bbp->topic_query->pagination_links = paginate_links($bbp_topic_pagination); // Remove first page from pagination $bbp->topic_query->pagination_links = str_replace($wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links); } // Return object return apply_filters('pg_get_user_unread', $bbp->topic_query->have_posts(), $bbp->topic_query); } //if no unread return bbp_has_topics(); // default query }