/** * Handles the front end edit reply submission * * @param string $action The requested action to compare this function to * @uses bbp_add_error() To add an error message * @uses bbp_get_reply() To get the reply * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses bbp_is_reply_anonymous() To check if the reply was by an anonymous user * @uses current_user_can() To check if the current user can edit that reply * @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 remove_filter() To remove kses filters if needed * @uses esc_attr() For sanitization * @uses apply_filters() Calls 'bbp_edit_reply_pre_title' with the title and * reply id * @uses apply_filters() Calls 'bbp_edit_reply_pre_content' with the content * reply id * @uses wp_set_post_terms() To set the topic tags * @uses bbp_has_errors() To get the {@link WP_Error} errors * @uses wp_save_post_revision() To save a reply revision * @uses bbp_update_reply_revision_log() To update the reply revision log * @uses wp_update_post() To update the reply * @uses bbp_get_reply_topic_id() To get the reply topic id * @uses bbp_get_topic_forum_id() To get the topic forum id * @uses bbp_get_reply_to() To get the reply to id * @uses do_action() Calls 'bbp_edit_reply' with the reply id, topic id, forum * id, anonymous data, reply author, bool true (for edit), * and the reply to id * @uses bbp_get_reply_url() To get the paginated url to the reply * @uses wp_safe_redirect() To redirect to the reply url * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error * message */ function bbp_edit_reply_handler($action = '') { // Bail if action is not bbp-edit-reply if ('bbp-edit-reply' !== $action) { return; } // Define local variable(s) $revisions_removed = false; $reply = $reply_id = $reply_author = $topic_id = $forum_id = $anonymous_data = 0; $reply_title = $reply_content = $reply_edit_reason = $terms = ''; /** Reply *****************************************************************/ // Reply id was not passed if (empty($_POST['bbp_reply_id'])) { bbp_add_error('bbp_edit_reply_id', __('<strong>ERROR</strong>: Reply ID not found.', 'bbpress')); return; // Reply id was passed } elseif (is_numeric($_POST['bbp_reply_id'])) { $reply_id = (int) $_POST['bbp_reply_id']; $reply = bbp_get_reply($reply_id); } // Nonce check if (!bbp_verify_nonce_request('bbp-edit-reply_' . $reply_id)) { bbp_add_error('bbp_edit_reply_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; } // Reply does not exist if (empty($reply)) { bbp_add_error('bbp_edit_reply_not_found', __('<strong>ERROR</strong>: The reply you want to edit was not found.', 'bbpress')); return; // Reply exists } else { // Check users ability to create new reply if (!bbp_is_reply_anonymous($reply_id)) { // User cannot edit this reply if (!current_user_can('edit_reply', $reply_id)) { bbp_add_error('bbp_edit_reply_permissions', __('<strong>ERROR</strong>: You do not have permission to edit that reply.', 'bbpress')); return; } // Set reply author $reply_author = bbp_get_reply_author_id($reply_id); // It is an anonymous post } else { // Filter anonymous data $anonymous_data = bbp_filter_anonymous_post_data(); } } // 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_reply']) && wp_create_nonce('bbp-unfiltered-html-reply_' . $reply_id) === $_POST['_bbp_unfiltered_html_reply']) { remove_filter('bbp_edit_reply_pre_title', 'wp_filter_kses'); remove_filter('bbp_edit_reply_pre_content', 'bbp_encode_bad', 10); remove_filter('bbp_edit_reply_pre_content', 'bbp_filter_kses', 30); } /** Reply Topic ***********************************************************/ $topic_id = bbp_get_reply_topic_id($reply_id); /** Topic Forum ***********************************************************/ $forum_id = bbp_get_topic_forum_id($topic_id); // Forum exists if (!empty($forum_id) && $forum_id !== bbp_get_reply_forum_id($reply_id)) { // Forum is a category if (bbp_is_forum_category($forum_id)) { bbp_add_error('bbp_edit_reply_forum_category', __('<strong>ERROR</strong>: This forum is a category. No replies can be created in this forum.', '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_reply_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new replies.', '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_reply_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies 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_reply_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress')); } } } } /** Reply Title ***********************************************************/ if (!empty($_POST['bbp_reply_title'])) { $reply_title = esc_attr(strip_tags($_POST['bbp_reply_title'])); } // Filter and sanitize $reply_title = apply_filters('bbp_edit_reply_pre_title', $reply_title, $reply_id); /** Reply Content *********************************************************/ if (!empty($_POST['bbp_reply_content'])) { $reply_content = $_POST['bbp_reply_content']; } // Filter and sanitize $reply_content = apply_filters('bbp_edit_reply_pre_content', $reply_content, $reply_id); // No reply content if (empty($reply_content)) { bbp_add_error('bbp_edit_reply_content', __('<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress')); } /** Reply Blacklist *******************************************************/ if (!bbp_check_for_blacklist($anonymous_data, $reply_author, $reply_title, $reply_content)) { bbp_add_error('bbp_reply_blacklist', __('<strong>ERROR</strong>: Your reply cannot be edited at this time.', 'bbpress')); } /** Reply Status **********************************************************/ // Maybe put into moderation if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) { // Set post status to pending if public if (bbp_get_public_status_id() === $reply->post_status) { $reply_status = bbp_get_pending_status_id(); } // Use existing post_status } else { $reply_status = $reply->post_status; } /** Reply To **************************************************************/ // Handle Reply To of the reply; $_REQUEST for non-JS submissions if (isset($_REQUEST['bbp_reply_to'])) { $reply_to = bbp_validate_reply_to($_REQUEST['bbp_reply_to']); } /** Topic Tags ************************************************************/ // Either replace terms if (bbp_allow_topic_tags() && current_user_can('assign_topic_tags') && !empty($_POST['bbp_topic_tags'])) { $terms = esc_attr(strip_tags($_POST['bbp_topic_tags'])); // ...or remove them. } elseif (isset($_POST['bbp_topic_tags'])) { $terms = ''; // Existing terms } else { $terms = bbp_get_topic_tag_names($topic_id); } /** Additional Actions (Before Save) **************************************/ do_action('bbp_edit_reply_pre_extras', $reply_id); // Bail if errors if (bbp_has_errors()) { return; } /** No Errors *************************************************************/ // Add the content of the form to $reply_data as an array // Just in time manipulation of reply data before being edited $reply_data = apply_filters('bbp_edit_reply_pre_insert', array('ID' => $reply_id, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_status' => $reply_status, 'post_parent' => $topic_id, 'post_author' => $reply_author, 'post_type' => bbp_get_reply_post_type())); // Toggle revisions to avoid duplicates if (post_type_supports(bbp_get_reply_post_type(), 'revisions')) { $revisions_removed = true; remove_post_type_support(bbp_get_reply_post_type(), 'revisions'); } // Insert topic $reply_id = wp_update_post($reply_data); // Toggle revisions back on if (true === $revisions_removed) { $revisions_removed = false; add_post_type_support(bbp_get_reply_post_type(), 'revisions'); } /** Topic Tags ************************************************************/ // Just in time manipulation of reply terms before being edited $terms = apply_filters('bbp_edit_reply_pre_set_terms', $terms, $topic_id, $reply_id); // Insert terms $terms = wp_set_post_terms($topic_id, $terms, bbp_get_topic_tag_tax_id(), false); // Term error if (is_wp_error($terms)) { bbp_add_error('bbp_reply_tags', __('<strong>ERROR</strong>: There was a problem adding the tags to the topic.', 'bbpress')); } /** Revisions *************************************************************/ // Revision Reason if (!empty($_POST['bbp_reply_edit_reason'])) { $reply_edit_reason = esc_attr(strip_tags($_POST['bbp_reply_edit_reason'])); } // Update revision log if (!empty($_POST['bbp_log_reply_edit']) && "1" === $_POST['bbp_log_reply_edit']) { $revision_id = wp_save_post_revision($reply_id); if (!empty($revision_id)) { bbp_update_reply_revision_log(array('reply_id' => $reply_id, 'revision_id' => $revision_id, 'author_id' => bbp_get_current_user_id(), 'reason' => $reply_edit_reason)); } } /** No Errors *************************************************************/ if (!empty($reply_id) && !is_wp_error($reply_id)) { // Update counts, etc... do_action('bbp_edit_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, true, $reply_to); /** Additional Actions (After Save) ***********************************/ do_action('bbp_edit_reply_post_extras', $reply_id); /** Redirect **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // Get the reply URL $reply_url = bbp_get_reply_url($reply_id, $redirect_to); // Allow to be filtered $reply_url = apply_filters('bbp_edit_reply_redirect_to', $reply_url, $redirect_to); /** Successful Edit ***************************************************/ // Redirect back to new reply wp_safe_redirect($reply_url); // For good measure exit; /** Errors ****************************************************************/ } else { $append_error = is_wp_error($reply_id) && $reply_id->get_error_message() ? $reply_id->get_error_message() . ' ' : ''; bbp_add_error('bbp_reply_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress')); } }
/** * Return a breadcrumb ( forum -> topic -> reply ) * * @since bbPress (r2589) * * @param string $sep Separator. Defaults to '←' * @param bool $current_page Include the current item * @param bool $root Include the root page if one exists * * @uses get_post() To get the post * @uses bbp_get_forum_permalink() To get the forum link * @uses bbp_get_topic_permalink() To get the topic link * @uses bbp_get_reply_permalink() To get the reply link * @uses get_permalink() To get the permalink * @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_forum_title() To get the forum title * @uses bbp_get_topic_title() To get the topic title * @uses bbp_get_reply_title() To get the reply title * @uses get_the_title() To get the title * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs * @return string Breadcrumbs */ function bbp_get_breadcrumb($args = array()) { // Turn off breadcrumbs if (apply_filters('bbp_no_breadcrumb', is_front_page())) { return; } // Define variables $front_id = $root_id = 0; $ancestors = $crumbs = $tag_data = array(); $pre_root_text = $pre_front_text = $pre_current_text = ''; $pre_include_root = $pre_include_home = $pre_include_current = true; /** Home Text *********************************************************/ // No custom home text if (empty($args['home_text'])) { // Set home text to page title $front_id = get_option('page_on_front'); if (!empty($front_id)) { $pre_front_text = get_the_title($front_id); // Default to 'Home' } else { $pre_front_text = __('Home', 'bbpress'); } } /** Root Text *********************************************************/ // No custom root text if (empty($args['root_text'])) { $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_id = $page->ID; } $pre_root_text = bbp_get_forum_archive_title(); } /** Includes **********************************************************/ // Root slug is also the front page if (!empty($front_id) && $front_id == $root_id) { $pre_include_root = false; } // Don't show root if viewing forum archive if (bbp_is_forum_archive()) { $pre_include_root = false; } // Don't show root if viewing page in place of forum archive if (!empty($root_id) && ((is_single() || is_page()) && $root_id == get_the_ID())) { $pre_include_root = false; } /** Current Text ******************************************************/ // Forum archive if (bbp_is_forum_archive()) { $pre_current_text = bbp_get_forum_archive_title(); // Topic archive } elseif (bbp_is_topic_archive()) { $pre_current_text = bbp_get_topic_archive_title(); // View } elseif (bbp_is_single_view()) { $pre_current_text = bbp_get_view_title(); // Single Forum } elseif (bbp_is_single_forum()) { $pre_current_text = bbp_get_forum_title(); // Single Topic } elseif (bbp_is_single_topic()) { $pre_current_text = bbp_get_topic_title(); // Single Topic } elseif (bbp_is_single_reply()) { $pre_current_text = bbp_get_reply_title(); // Topic Tag (or theme compat topic tag) } elseif (bbp_is_topic_tag() || get_query_var('bbp_topic_tag') && !bbp_is_topic_tag_edit()) { // Always include the tag name $tag_data[] = bbp_get_topic_tag_name(); // If capable, include a link to edit the tag if (current_user_can('manage_topic_tags')) { $tag_data[] = '<a href="' . bbp_get_topic_tag_edit_link() . '" class="bbp-edit-topic-tag-link">' . __('(Edit)', 'bbpress') . '</a>'; } // Implode the results of the tag data $pre_current_text = sprintf(__('Topic Tag: %s', 'bbpress'), implode(' ', $tag_data)); // Edit Topic Tag } elseif (bbp_is_topic_tag_edit()) { $pre_current_text = __('Edit', 'bbpress'); // Single } else { $pre_current_text = get_the_title(); } /** Parse Args ********************************************************/ // Parse args $defaults = array('before' => '<div class="bbp-breadcrumb"><p>', 'after' => '</p></div>', 'sep' => __('›', 'bbpress'), 'pad_sep' => 1, 'include_home' => $pre_include_home, 'home_text' => $pre_front_text, 'include_root' => $pre_include_root, 'root_text' => $pre_root_text, 'include_current' => $pre_include_current, 'current_text' => $pre_current_text); $r = bbp_parse_args($args, $defaults, 'get_breadcrumb'); extract($r); /** Ancestors *********************************************************/ // Get post ancestors if (is_page() || is_single() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit()) { $ancestors = array_reverse(get_post_ancestors(get_the_ID())); } // Do we want to include a link to home? if (!empty($include_home) || empty($home_text)) { $crumbs[] = '<a href="' . trailingslashit(home_url()) . '" class="bbp-breadcrumb-home">' . $home_text . '</a>'; } // Do we want to include a link to the forum root? if (!empty($include_root) || empty($root_text)) { // Page exists at root slug path, so use its permalink $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_url = get_permalink($page->ID); // Use the root slug } else { $root_url = get_post_type_archive_link(bbp_get_forum_post_type()); } // Add the breadcrumb $crumbs[] = '<a href="' . $root_url . '" class="bbp-breadcrumb-root">' . $root_text . '</a>'; } // Ancestors exist if (!empty($ancestors)) { // Loop through parents foreach ((array) $ancestors as $parent_id) { // Parents $parent = get_post($parent_id); // Switch through post_type to ensure correct filters are applied switch ($parent->post_type) { // Forum case bbp_get_forum_post_type(): $crumbs[] = '<a href="' . bbp_get_forum_permalink($parent->ID) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title($parent->ID) . '</a>'; break; // Topic // Topic case bbp_get_topic_post_type(): $crumbs[] = '<a href="' . bbp_get_topic_permalink($parent->ID) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title($parent->ID) . '</a>'; break; // Reply (Note: not in most themes) // Reply (Note: not in most themes) case bbp_get_reply_post_type(): $crumbs[] = '<a href="' . bbp_get_reply_permalink($parent->ID) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title($parent->ID) . '</a>'; break; // WordPress Post/Page/Other // WordPress Post/Page/Other default: $crumbs[] = '<a href="' . get_permalink($parent->ID) . '" class="bbp-breadcrumb-item">' . get_the_title($parent->ID) . '</a>'; break; } } // Edit topic tag } elseif (bbp_is_topic_tag_edit()) { $crumbs[] = '<a href="' . get_term_link(bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id()) . '" class="bbp-breadcrumb-topic-tag">' . sprintf(__('Topic Tag: %s', 'bbpress'), bbp_get_topic_tag_name()) . '</a>'; } /** Current ***********************************************************/ // Add current page to breadcrumb if (!empty($include_current) || empty($pre_current_text)) { $crumbs[] = '<span class="bbp-breadcrumb-current">' . $current_text . '</span>'; } /** Separator *********************************************************/ // Wrap the separator in a span before padding and filter if (!empty($sep)) { $sep = '<span class="bbp-breadcrumb-separator">' . $sep . '</span>'; } // Pad the separator if (!empty($pad_sep)) { $sep = str_pad($sep, strlen($sep) + (int) $pad_sep * 2, ' ', STR_PAD_BOTH); } /** Finish Up *********************************************************/ // Filter the separator and breadcrumb $sep = apply_filters('bbp_breadcrumb_separator', $sep); $crumbs = apply_filters('bbp_breadcrumbs', $crumbs); // Build the trail $trail = !empty($crumbs) ? $before . implode($sep, $crumbs) . $after : ''; return apply_filters('bbp_get_breadcrumb', $trail, $crumbs, $r); }
/** * Get the forum statistics * * @since 2.0.0 bbPress (r2769) * @since 2.6.0 bbPress (r6055) Introduced the `count_pending_topics` and * `count_pending_replies` arguments. * * @param array $args Optional. The function supports these arguments (all * default to true): * - count_users: Count users? * - count_forums: Count forums? * - count_topics: Count topics? If set to false, private, spammed and trashed * topics are also not counted. * - count_pending_topics: Count pending topics? (only counted if the current * user has edit_others_topics cap) * - count_private_topics: Count private topics? (only counted if the current * user has read_private_topics cap) * - count_spammed_topics: Count spammed topics? (only counted if the current * user has edit_others_topics cap) * - count_trashed_topics: Count trashed topics? (only counted if the current * user has view_trash cap) * - count_replies: Count replies? If set to false, private, spammed and * trashed replies are also not counted. * - count_pending_replies: Count pending replies? (only counted if the current * user has edit_others_replies cap) * - count_private_replies: Count private replies? (only counted if the current * user has read_private_replies cap) * - count_spammed_replies: Count spammed replies? (only counted if the current * user has edit_others_replies cap) * - count_trashed_replies: Count trashed replies? (only counted if the current * user has view_trash cap) * - count_tags: Count tags? If set to false, empty tags are also not counted * - count_empty_tags: Count empty tags? * @uses bbp_get_total_users() To count the number of registered users * @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 wp_count_posts() To count the number of forums, topics and replies * @uses wp_count_terms() To count the number of topic tags * @uses current_user_can() To check if the user is capable of doing things * @uses number_format_i18n() To format the number * @uses apply_filters() Calls 'bbp_get_statistics' with the statistics and args * @return object Walked forum tree */ function bbp_get_statistics($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('count_users' => true, 'count_forums' => true, 'count_topics' => true, 'count_pending_topics' => true, 'count_private_topics' => true, 'count_spammed_topics' => true, 'count_trashed_topics' => true, 'count_replies' => true, 'count_pending_replies' => true, 'count_private_replies' => true, 'count_spammed_replies' => true, 'count_trashed_replies' => true, 'count_tags' => true, 'count_empty_tags' => true), 'get_statistics'); // Defaults $user_count = 0; $forum_count = 0; $topic_count = 0; $topic_count_hidden = 0; $reply_count = 0; $reply_count_hidden = 0; $topic_tag_count = 0; $empty_topic_tag_count = 0; // Users if (!empty($r['count_users'])) { $user_count = bbp_get_total_users(); } // Forums if (!empty($r['count_forums'])) { $forum_count = wp_count_posts(bbp_get_forum_post_type())->publish; } // Post statuses $pending = bbp_get_pending_status_id(); $private = bbp_get_private_status_id(); $spam = bbp_get_spam_status_id(); $trash = bbp_get_trash_status_id(); $closed = bbp_get_closed_status_id(); // Topics if (!empty($r['count_topics'])) { $all_topics = wp_count_posts(bbp_get_topic_post_type()); // Published (publish + closed) $topic_count = $all_topics->publish + $all_topics->{$closed}; if (current_user_can('read_private_topics') || current_user_can('edit_others_topics') || current_user_can('view_trash')) { // Declare empty arrays $topics = $topic_titles = array(); // Pending $topics['pending'] = !empty($r['count_pending_topics']) && current_user_can('edit_others_topics') ? (int) $all_topics->{$pending} : 0; // Private $topics['private'] = !empty($r['count_private_topics']) && current_user_can('read_private_topics') ? (int) $all_topics->{$private} : 0; // Spam $topics['spammed'] = !empty($r['count_spammed_topics']) && current_user_can('edit_others_topics') ? (int) $all_topics->{$spam} : 0; // Trash $topics['trashed'] = !empty($r['count_trashed_topics']) && current_user_can('view_trash') ? (int) $all_topics->{$trash} : 0; // Total hidden (private + spam + trash) $topic_count_hidden = $topics['pending'] + $topics['private'] + $topics['spammed'] + $topics['trashed']; // Generate the hidden topic count's title attribute $topic_titles[] = !empty($topics['pending']) ? sprintf(__('Pending: %s', 'bbpress'), number_format_i18n($topics['pending'])) : ''; $topic_titles[] = !empty($topics['private']) ? sprintf(__('Private: %s', 'bbpress'), number_format_i18n($topics['private'])) : ''; $topic_titles[] = !empty($topics['spammed']) ? sprintf(__('Spammed: %s', 'bbpress'), number_format_i18n($topics['spammed'])) : ''; $topic_titles[] = !empty($topics['trashed']) ? sprintf(__('Trashed: %s', 'bbpress'), number_format_i18n($topics['trashed'])) : ''; // Compile the hidden topic title $hidden_topic_title = implode(' | ', array_filter($topic_titles)); } } // Replies if (!empty($r['count_replies'])) { $all_replies = wp_count_posts(bbp_get_reply_post_type()); // Published $reply_count = $all_replies->publish; if (current_user_can('read_private_replies') || current_user_can('edit_others_replies') || current_user_can('view_trash')) { // Declare empty arrays $replies = $reply_titles = array(); // Pending $replies['pending'] = !empty($r['count_pending_replies']) && current_user_can('edit_others_replies') ? (int) $all_replies->{$pending} : 0; // Private $replies['private'] = !empty($r['count_private_replies']) && current_user_can('read_private_replies') ? (int) $all_replies->{$private} : 0; // Spam $replies['spammed'] = !empty($r['count_spammed_replies']) && current_user_can('edit_others_replies') ? (int) $all_replies->{$spam} : 0; // Trash $replies['trashed'] = !empty($r['count_trashed_replies']) && current_user_can('view_trash') ? (int) $all_replies->{$trash} : 0; // Total hidden (private + spam + trash) $reply_count_hidden = $replies['pending'] + $replies['private'] + $replies['spammed'] + $replies['trashed']; // Generate the hidden topic count's title attribute $reply_titles[] = !empty($replies['pending']) ? sprintf(__('Pending: %s', 'bbpress'), number_format_i18n($replies['pending'])) : ''; $reply_titles[] = !empty($replies['private']) ? sprintf(__('Private: %s', 'bbpress'), number_format_i18n($replies['private'])) : ''; $reply_titles[] = !empty($replies['spammed']) ? sprintf(__('Spammed: %s', 'bbpress'), number_format_i18n($replies['spammed'])) : ''; $reply_titles[] = !empty($replies['trashed']) ? sprintf(__('Trashed: %s', 'bbpress'), number_format_i18n($replies['trashed'])) : ''; // Compile the hidden replies title $hidden_reply_title = implode(' | ', array_filter($reply_titles)); } } // Topic Tags if (!empty($r['count_tags']) && bbp_allow_topic_tags()) { // Get the count $topic_tag_count = wp_count_terms(bbp_get_topic_tag_tax_id(), array('hide_empty' => true)); // Empty tags if (!empty($r['count_empty_tags']) && current_user_can('edit_topic_tags')) { $empty_topic_tag_count = wp_count_terms(bbp_get_topic_tag_tax_id()) - $topic_tag_count; } } // Tally the tallies $statistics = array_map('number_format_i18n', array_map('absint', compact('user_count', 'forum_count', 'topic_count', 'topic_count_hidden', 'reply_count', 'reply_count_hidden', 'topic_tag_count', 'empty_topic_tag_count'))); // Add the hidden (topic/reply) count title attribute strings because we // don't need to run the math functions on these (see above) $statistics['hidden_topic_title'] = isset($hidden_topic_title) ? $hidden_topic_title : ''; $statistics['hidden_reply_title'] = isset($hidden_reply_title) ? $hidden_reply_title : ''; return apply_filters('bbp_get_statistics', $statistics, $r); }
/** * Unspams a topic * * @since bbPress (r2740) * * @param int $topic_id Topic id * @uses wp_get_single_post() To get the topic * @uses do_action() Calls 'bbp_unspam_topic' with the topic id * @uses get_post_meta() To get the previous status * @uses delete_post_meta() To delete the previous status meta * @uses wp_insert_post() To update the topic with the new status * @uses do_action() Calls 'bbp_unspammed_topic' with the topic id * @return mixed False or {@link WP_Error} on failure, topic id on success */ function bbp_unspam_topic($topic_id = 0) { // Get the topic if (!($topic = wp_get_single_post($topic_id, ARRAY_A))) { return $topic; } // Bail if already not spam if (bbp_get_spam_status_id() != $topic['post_status']) { return false; } // Execute pre unspam code do_action('bbp_unspam_topic', $topic_id); // Get pre spam status $topic_status = get_post_meta($topic_id, '_bbp_spam_meta_status', true); // Set post status to pre spam $topic['post_status'] = $topic_status; // Delete pre spam meta delete_post_meta($topic_id, '_bbp_spam_meta_status'); // No revisions remove_action('pre_post_update', 'wp_save_post_revision'); // Get pre-spam topic tags $terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true); // Topic had tags before it was spammed if (!empty($terms)) { // Set the tax_input of the topic $topic['tax_input'] = array(bbp_get_topic_tag_tax_id() => $terms); // Delete pre-spam topic tag meta delete_post_meta($topic_id, '_bbp_spam_topic_tags'); } // Update the topic $topic_id = wp_insert_post($topic); // Execute post unspam code do_action('bbp_unspammed_topic', $topic_id); // Return topic_id return $topic_id; }
/** * Process the user's bbPress topic selections when the post is saved */ function process_topic_option($post_ID, $post) { /** Don't process on AJAX-based auto-drafts */ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } /** Don't process on initial page load auto drafts */ if ($post->post_status == 'auto-draft') { return; } /** Only process for post types we specify */ if (!in_array($post->post_type, apply_filters('bbppt_eligible_post_types', array('post', 'page')))) { return; } // TODO: combine existing topic and draft settings branches if (isset($_POST['bbpress_topic'])) { /** * Post was created through the full post editor form * Check the POST for settings */ if (!empty($_POST['bbpress_topic']['enabled'])) { $bbppt_options = $_POST['bbpress_topic']; $create_topic = true; $use_defaults = isset($bbppt_options['use_defaults']); bbppt_debug('Processing a topic for regular post ' . $post_ID . ' with the following settings: ' . print_r($bbppt_options, true)); bbppt_debug('Creating topic?: ' . $create_topic . '; using defaults?: ' . $use_defaults); } else { $create_topic = false; $bbppt_options = array(); bbppt_debug('NOT creating a topic for regular post ' . $post_ID); } } else { if (get_post_meta($post_ID, 'bbpress_discussion_topic_id', true)) { /** * If post has an existing topic, use its settings */ $bbppt_options = $this->get_topic_options_for_post($post_ID); $create_topic = !empty($bbppt_options['enabled']); $use_defaults = !empty($bbppt_options['use_defaults']); bbppt_debug('Processing topic for existing post ' . $post_ID . ' with the following settings: ' . print_r($bbppt_options, true)); bbppt_debug('Creating topic?: ' . $create_topic . '; using defaults?: ' . $use_defaults); } else { if ($this->has_draft_settings($post)) { /** * If the post has draft settings saved, use draft settings */ $bbppt_options = $this->get_draft_settings($post); $create_topic = !empty($bbppt_options['enabled']); $use_defaults = !empty($bbppt_options['use_defaults']); bbppt_debug('Processing a topic for draft post ' . $post_ID . ' with the following settings: ' . print_r($bbppt_options, true)); bbppt_debug('Creating topic?: ' . $create_topic . '; using defaults?: ' . $use_defaults); } else { /** * Post was created through some other means (including XML-RPC) - use defaults */ $bbppt_options = get_option('bbpress_discussion_defaults'); $create_topic = !empty($bbppt_options['enabled']); $use_defaults = true; $bbppt_options['use_defaults'] = $use_defaults; bbppt_debug('Processing a topic for unattended post ' . $post_ID . ' with the following settings: ' . print_r($bbppt_options, true)); bbppt_debug('Creating topic?: ' . $create_topic . '; using defaults?: ' . $use_defaults); } } } /** If post is saved as a draft, store selected settings for publication later */ if (in_array($post->post_status, apply_filters('bbppt_draft_post_status', array('draft', 'future')))) { $this->set_draft_settings($bbppt_options, $post); return; } /** Only process further when the post is published */ if (!in_array($post->post_status, apply_filters('bbppt_eligible_post_status', array('publish', 'private')))) { return; } /** * The user requested to use a bbPress topic for discussion */ if ($create_topic) { if (!function_exists('bbp_has_forums')) { ?> <br /><p><?php _e('bbPress Topics for Posts cannot process this request because it cannot detect your bbPress setup.', 'bbpress-post-topics'); ?> </p><?php return; } $topic_slug = isset($bbppt_options['slug']) ? $bbppt_options['slug'] : ''; $topic_forum = isset($bbppt_options['forum_id']) ? (int) $bbppt_options['forum_id'] : 0; if (!$use_defaults) { $topic_display = isset($bbppt_options['display']) ? $bbppt_options['display'] : 'topic'; /** Store extra data for xreplies, as well as any custom display formats */ $topic_display_extras = apply_filters('bbppt_store_display_extras', $bbppt_options['display-extras'], $post); } if (!empty($topic_slug)) { /** if user has selected an existing topic */ if (is_numeric($topic_slug)) { $topic = bbp_get_topic((int) $topic_slug); } else { $topic = bbppt_get_topic_by_slug($topic_slug); } if ($topic == null) { // return an error of some kind wp_die(__('There was an error with your selected topic.', 'bbpress-post-topics'), __('Error Locating bbPress Topic', 'bbpress-post-topics')); } else { $topic_ID = $topic->ID; update_post_meta($post_ID, 'use_bbpress_discussion_topic', true); update_post_meta($post_ID, 'bbpress_discussion_topic_id', $topic_ID); /** Update topic with tags from the post */ if (!empty($bbppt_options['copy_tags'])) { $post_tags = wp_get_post_tags($post_ID); $post_tags = array_map(create_function('$term', 'return $term->name;'), $post_tags); wp_set_post_terms($topic_ID, join(',', $post_tags), bbp_get_topic_tag_tax_id(), true); update_post_meta($post_ID, 'bbpress_discussion_tags_copied', time()); } /** Export comments from the post to the new bbPress topic */ if (!empty($bbppt_options['copy_comments'])) { bbppt_import_comments($post_ID, $topic_ID); update_post_meta($post_ID, 'bbpress_discussion_comments_copied', time()); } if ($use_defaults) { update_post_meta($post_ID, 'bbpress_discussion_use_defaults', true); } else { delete_post_meta($post_ID, 'bbpress_discussion_use_defaults'); update_post_meta($post_ID, 'bbpress_discussion_display_format', $topic_display); update_post_meta($post_ID, 'bbpress_discussion_display_extras', $topic_display_extras); } } do_action('bbppt_topic_assigned', $post_ID, $topic_ID); } else { if ($topic_forum != 0) { /** if user has opted to create a new topic */ $topic_ID = $this->build_new_topic($post, $topic_forum); if (!$topic_ID) { // return an error of some kind wp_die(__('There was an error creating a new topic.', 'bbpress-post-topics'), __('Error Creating bbPress Topic', 'bbpress-post-topics')); } else { update_post_meta($post_ID, 'use_bbpress_discussion_topic', true); update_post_meta($post_ID, 'bbpress_discussion_topic_id', $topic_ID); /** Update topic with tags from the post */ if ($bbppt_options['copy_tags']) { $post_tags = wp_get_post_tags($post_ID); $post_tags = array_map(create_function('$term', 'return $term->name;'), $post_tags); wp_set_post_terms($topic_ID, join(',', $post_tags), bbp_get_topic_tag_tax_id(), false); update_post_meta($post_ID, 'bbpress_discussion_tags_copied', time()); } /** Export comments from the post to the new bbPress topic */ if ($bbppt_options['copy_comments']) { bbppt_import_comments($post_ID, $topic_ID); update_post_meta($post_ID, 'bbpress_discussion_comments_copied', time()); } if ($use_defaults) { update_post_meta($post_ID, 'bbpress_discussion_use_defaults', true); } else { update_post_meta($post_ID, 'bbpress_discussion_display_format', $topic_display); update_post_meta($post_ID, 'bbpress_discussion_display_extras', $topic_display_extras); } } do_action('bbppt_topic_created', $post_ID, $topic_ID); } } } else { delete_post_meta($post_ID, 'use_bbpress_discussion_topic'); delete_post_meta($post_ID, 'bbpress_discussion_topic_id'); delete_post_meta($post_ID, 'bbpress_discussion_use_defaults'); delete_post_meta($post_ID, 'bbpress_discussion_display_format'); delete_post_meta($post_ID, 'bbpress_discussion_display_extras'); delete_post_meta($post_ID, 'bbpress_discussion_tags_copied'); delete_post_meta($post_ID, 'bbpress_discussion_comments_copied'); } $this->delete_draft_settings($post); do_action('bbppt_topic_associated', $post_ID, $topic_ID); }
/** * Return value of topic tags field * * @since bbPress (r2976) * * @uses bbp_is_topic_edit() To check if it's the topic edit page * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags * @return string Value of topic tags field */ function bbp_get_form_topic_tags() { // Get _POST data if (bbp_is_post_request() && isset($_POST['bbp_topic_tags'])) { $topic_tags = $_POST['bbp_topic_tags']; // Get edit data } elseif (bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_edit() || bbp_is_reply_edit()) { // Determine the topic id based on the post type switch (get_post_type()) { // Post is a topic case bbp_get_topic_post_type(): $topic_id = get_the_ID(); break; // Post is a reply // Post is a reply case bbp_get_reply_post_type(): $topic_id = bbp_get_reply_topic_id(get_the_ID()); break; } // Topic exists if (!empty($topic_id)) { // Topic is spammed so display pre-spam terms if (bbp_is_topic_spam($topic_id)) { // Get pre-spam terms $new_terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true); // If terms exist, explode them and compile the return value if (empty($new_terms)) { $new_terms = ''; } // Topic is not spam so get real terms } else { $terms = array_filter((array) get_the_terms($topic_id, bbp_get_topic_tag_tax_id())); // Loop through them foreach ($terms as $term) { $new_terms[] = $term->name; } } // Define local variable(s) } else { $new_terms = ''; } // Set the return value $topic_tags = !empty($new_terms) ? implode(', ', $new_terms) : ''; // No data } else { $topic_tags = ''; } return apply_filters('bbp_get_form_topic_tags', esc_attr($topic_tags)); }
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); }
/** * Get topic tags for a specific topic ID * * @since bbPress (r4165) * * @param int $topic_id * @param string $sep * @return string */ function bbp_get_topic_tag_names($topic_id = 0, $sep = ', ') { $topic_id = bbp_get_topic_id($topic_id); $topic_tags = array_filter((array) get_the_terms($topic_id, bbp_get_topic_tag_tax_id())); $terms = array(); foreach ($topic_tags as $term) { $terms[] = $term->name; } $terms = !empty($terms) ? implode($sep, $terms) : ''; return apply_filters('bbp_get_topic_tags', $terms, $topic_id); }
/** * Handle any terms submitted with a post flagged as spam * * @since bbPress (r3308) * * @param string $terms Comma-separated list of terms * @param int $topic_id * @param int $reply_id * * @uses bbp_get_reply_id() To get the reply_id * @uses bbp_get_topic_id() To get the topic_id * @uses wp_get_object_terms() To a post's current terms * @uses update_post_meta() To add spam terms to post meta * * @return array Array of existing topic terms */ public function filter_post_terms($terms = '', $topic_id = 0, $reply_id = 0) { // Validate the reply_id and topic_id $reply_id = bbp_get_reply_id($reply_id); $topic_id = bbp_get_topic_id($topic_id); // Get any pre-existing terms $existing_terms = wp_get_object_terms($topic_id, bbp_get_topic_tag_tax_id(), array('fields' => 'names')); // Save the terms for later in case the reply gets hammed if (!empty($terms)) { update_post_meta($reply_id, '_bbp_akismet_spam_terms', $terms); } // Keep the topic tags the same for now return $existing_terms; }
<div class="entry-content"> <?php get_the_content() ? the_content() : wpautop(esc_html__('This is a collection of tags that are currently popular on our forums.', 'bbpress')); ?> <div id="bbpress-forums"> <?php bbp_breadcrumb(); ?> <div id="bbp-topic-hot-tags"> <?php wp_tag_cloud(array('smallest' => 9, 'largest' => 38, 'number' => 80, 'taxonomy' => bbp_get_topic_tag_tax_id())); ?> </div> </div> </div> </div><!-- #bbp-topic-tags --> <?php } ?> <?php do_action('bbp_after_main_content'); ?>
/** * Get topic tags for a specific topic ID * * @since 2.6.0 bbPress (r5836) * * @param int $topic_id * * @return string */ function bbp_get_topic_tags($topic_id = 0) { $topic_id = bbp_get_topic_id($topic_id); $terms = (array) get_the_terms($topic_id, bbp_get_topic_tag_tax_id()); $topic_tags = array_filter($terms); return apply_filters('bbp_get_topic_tags', $topic_tags, $topic_id); }
/** * Filter the query for topic tags * * @since bbPress (r3637) * * @param array $args * @return array */ public function display_topics_of_tag_query($args = array()) { $args['tax_query'] = array(array('taxonomy' => bbp_get_topic_tag_tax_id(), 'field' => 'id', 'terms' => bbpress()->current_topic_tag_id)); return $args; }
/** * Register bbPress-specific rewrite rules for uri's that are not * setup for us by way of custom post types or taxonomies. This includes: * - Front-end editing * - Topic views * - User profiles * * @since bbPress (r2688) * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in * $wp_rewrite->rules */ public static function generate_rewrite_rules($wp_rewrite) { // Slugs $view_slug = bbp_get_view_slug(); $user_slug = bbp_get_user_slug(); // Unique rewrite ID's $edit_id = bbp_get_edit_rewrite_id(); $view_id = bbp_get_view_rewrite_id(); $user_id = bbp_get_user_rewrite_id(); $favs_id = bbp_get_user_favorites_rewrite_id(); $subs_id = bbp_get_user_subscriptions_rewrite_id(); $tops_id = bbp_get_user_topics_rewrite_id(); $reps_id = bbp_get_user_replies_rewrite_id(); // Rewrite rule matches used repeatedly below $root_rule = '/([^/]+)/?$'; $edit_rule = '/([^/]+)/edit/?$'; $feed_rule = '/([^/]+)/feed/?$'; $page_rule = '/([^/]+)/page/?([0-9]{1,})/?$'; // User profile rules $tops_rule = '/([^/]+)/topics/?$'; $reps_rule = '/([^/]+)/replies/?$'; $favs_rule = '/([^/]+)/' . bbp_get_user_favorites_slug() . '/?$'; $subs_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/?$'; $tops_page_rule = '/([^/]+)/topics/page/?([0-9]{1,})/?$'; $reps_page_rule = '/([^/]+)/replies/page/?([0-9]{1,})/?$'; $favs_page_rule = '/([^/]+)/' . bbp_get_user_favorites_slug() . '/page/?([0-9]{1,})/?$'; $subs_page_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/page/?([0-9]{1,})/?$'; // New bbPress specific rules to merge with existing that are not // handled automatically by custom post types or taxonomy types $bbp_rules = array(bbp_get_forum_slug() . $edit_rule => 'index.php?' . bbp_get_forum_post_type() . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', bbp_get_topic_slug() . $edit_rule => 'index.php?' . bbp_get_topic_post_type() . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', bbp_get_reply_slug() . $edit_rule => 'index.php?' . bbp_get_reply_post_type() . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', bbp_get_topic_tag_tax_slug() . $edit_rule => 'index.php?' . bbp_get_topic_tag_tax_id() . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', $user_slug . $tops_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $tops_id . '=1&paged=' . $wp_rewrite->preg_index(2), $user_slug . $reps_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $reps_id . '=1&paged=' . $wp_rewrite->preg_index(2), $user_slug . $favs_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $favs_id . '=1&paged=' . $wp_rewrite->preg_index(2), $user_slug . $subs_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $subs_id . '=1&paged=' . $wp_rewrite->preg_index(2), $user_slug . $tops_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $tops_id . '=1', $user_slug . $reps_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $reps_id . '=1', $user_slug . $favs_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $favs_id . '=1', $user_slug . $subs_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $subs_id . '=1', $user_slug . $edit_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1) . '&' . $edit_id . '=1', $user_slug . $root_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index(1), $view_slug . $page_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2), $view_slug . $feed_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index(1) . '&feed=' . $wp_rewrite->preg_index(2), $view_slug . $root_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index(1)); // Merge bbPress rules with existing $wp_rewrite->rules = array_merge($bbp_rules, $wp_rewrite->rules); // Return merged rules return $wp_rewrite; }
/** * Can the current user see a specific UI element? * * Used when registering post-types and taxonomies to decide if 'show_ui' should * be set to true or false. Also used for fine-grained control over which admin * sections are visible under what conditions. * * This function is in bbp-core-caps.php rather than in /bbp-admin so that it * can be used during the bbp_register_post_types action. * * @since bbPress (r3944) * * @uses current_user_can() To check the 'moderate' capability * @uses bbp_get_forum_post_type() * @uses bbp_get_topic_post_type() * @uses bbp_get_reply_post_type() * @uses bbp_get_topic_tag_tax_id() * @uses is_plugin_active() * @uses is_super_admin() * @return bool Results of current_user_can( 'moderate' ) check. */ function bbp_current_user_can_see($component = '') { // Define local variable $retval = false; // Which component are we checking UI visibility for? switch ($component) { /** Everywhere ********************************************************/ case bbp_get_forum_post_type(): // Forums // Forums case bbp_get_topic_post_type(): // Topics // Topics case bbp_get_reply_post_type(): // Replies // Replies case bbp_get_topic_tag_tax_id(): // Topic-Tags $retval = current_user_can('moderate'); break; /** Admin Exclusive ***************************************************/ /** Admin Exclusive ***************************************************/ case 'bbp_settings_buddypress': // BuddyPress Extension $retval = is_plugin_active('buddypress/bp-loader.php') && defined('BP_VERSION') && is_super_admin(); break; case 'bbp_settings_akismet': // Akismet Extension $retval = is_plugin_active('akismet/akismet.php') && defined('AKISMET_VERSION') && is_super_admin(); break; case 'bbp_tools_page': // Tools Page // Tools Page case 'bbp_tools_repair_page': // Tools - Repair Page // Tools - Repair Page case 'bbp_tools_import_page': // Tools - Import Page // Tools - Import Page case 'bbp_tools_reset_page': // Tools - Reset Page // Tools - Reset Page case 'bbp_settings?page': // Settings Page // Settings Page case 'bbp_settings_main': // Settings - General // Settings - General case 'bbp_settings_theme_compat': // Settings - Theme compat // Settings - Theme compat case 'bbp_settings_root_slugs': // Settings - Root slugs // Settings - Root slugs case 'bbp_settings_single_slugs': // Settings - Single slugs // Settings - Single slugs case 'bbp_settings_per_page': // Settings - Single slugs // Settings - Single slugs case 'bbp_settings_per_page_rss': // Settings - Single slugs // Settings - Single slugs default: // Anything else $retval = current_user_can(bbpress()->admin->minimum_capability); break; } return (bool) apply_filters('bbp_current_user_can_see', (bool) $retval, $component); }
/** * Add bbPress-specific rewrite rules for uri's that are not * setup for us by way of custom post types or taxonomies. This includes: * - Front-end editing * - Topic views * - User profiles * * @since bbPress (r2688) * @todo Extract into an API */ public static function add_rewrite_rules() { /** Setup *************************************************************/ // Add rules to top or bottom? $priority = 'top'; // Single Slugs $forum_slug = bbp_get_forum_slug(); $topic_slug = bbp_get_topic_slug(); $reply_slug = bbp_get_reply_slug(); $ttag_slug = bbp_get_topic_tag_tax_slug(); // Archive Slugs $user_slug = bbp_get_user_slug(); $view_slug = bbp_get_view_slug(); $search_slug = bbp_get_search_slug(); $topic_archive_slug = bbp_get_topic_archive_slug(); $reply_archive_slug = bbp_get_reply_archive_slug(); // Tertiary Slugs $feed_slug = 'feed'; $edit_slug = 'edit'; $paged_slug = bbp_get_paged_slug(); $user_favs_slug = bbp_get_user_favorites_slug(); $user_subs_slug = bbp_get_user_subscriptions_slug(); // Unique rewrite ID's $feed_id = 'feed'; $edit_id = bbp_get_edit_rewrite_id(); $view_id = bbp_get_view_rewrite_id(); $paged_id = bbp_get_paged_rewrite_id(); $search_id = bbp_get_search_rewrite_id(); $user_id = bbp_get_user_rewrite_id(); $user_favs_id = bbp_get_user_favorites_rewrite_id(); $user_subs_id = bbp_get_user_subscriptions_rewrite_id(); $user_tops_id = bbp_get_user_topics_rewrite_id(); $user_reps_id = bbp_get_user_replies_rewrite_id(); // Rewrite rule matches used repeatedly below $root_rule = '/([^/]+)/?$'; $feed_rule = '/([^/]+)/' . $feed_slug . '/?$'; $edit_rule = '/([^/]+)/' . $edit_slug . '/?$'; $paged_rule = '/([^/]+)/' . $paged_slug . '/?([0-9]{1,})/?$'; // Search rules (without slug check) $search_root_rule = '/?$'; $search_paged_rule = '/' . $paged_slug . '/?([0-9]{1,})/?$'; /** Add ***************************************************************/ // User profile rules $tops_rule = '/([^/]+)/' . $topic_archive_slug . '/?$'; $reps_rule = '/([^/]+)/' . $reply_archive_slug . '/?$'; $favs_rule = '/([^/]+)/' . $user_favs_slug . '/?$'; $subs_rule = '/([^/]+)/' . $user_subs_slug . '/?$'; $tops_paged_rule = '/([^/]+)/' . $topic_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$'; $reps_paged_rule = '/([^/]+)/' . $reply_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$'; $favs_paged_rule = '/([^/]+)/' . $user_favs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$'; $subs_paged_rule = '/([^/]+)/' . $user_subs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$'; // Edit Forum|Topic|Reply|Topic-tag add_rewrite_rule($forum_slug . $edit_rule, 'index.php?' . bbp_get_forum_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority); add_rewrite_rule($topic_slug . $edit_rule, 'index.php?' . bbp_get_topic_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority); add_rewrite_rule($reply_slug . $edit_rule, 'index.php?' . bbp_get_reply_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority); add_rewrite_rule($ttag_slug . $edit_rule, 'index.php?' . bbp_get_topic_tag_tax_id() . '=$matches[1]&' . $edit_id . '=1', $priority); // User Pagination|Edit|View add_rewrite_rule($user_slug . $tops_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1&' . $paged_id . '=$matches[2]', $priority); add_rewrite_rule($user_slug . $reps_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1&' . $paged_id . '=$matches[2]', $priority); add_rewrite_rule($user_slug . $favs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1&' . $paged_id . '=$matches[2]', $priority); add_rewrite_rule($user_slug . $subs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1&' . $paged_id . '=$matches[2]', $priority); add_rewrite_rule($user_slug . $tops_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1', $priority); add_rewrite_rule($user_slug . $reps_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1', $priority); add_rewrite_rule($user_slug . $favs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1', $priority); add_rewrite_rule($user_slug . $subs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1', $priority); add_rewrite_rule($user_slug . $edit_rule, 'index.php?' . $user_id . '=$matches[1]&' . $edit_id . '=1', $priority); add_rewrite_rule($user_slug . $root_rule, 'index.php?' . $user_id . '=$matches[1]', $priority); // Topic-View Pagination|Feed|View add_rewrite_rule($view_slug . $paged_rule, 'index.php?' . $view_id . '=$matches[1]&' . $paged_id . '=$matches[2]', $priority); add_rewrite_rule($view_slug . $feed_rule, 'index.php?' . $view_id . '=$matches[1]&' . $feed_id . '=$matches[2]', $priority); add_rewrite_rule($view_slug . $root_rule, 'index.php?' . $view_id . '=$matches[1]', $priority); // Search All add_rewrite_rule($search_slug . $search_paged_rule, 'index.php?' . $paged_id . '=$matches[1]', $priority); add_rewrite_rule($search_slug . $search_root_rule, 'index.php?' . $search_id, $priority); }
/** * Get the topic edit template * * @since bbPress (r3311) * * @uses bbp_get_topic_tag_tax_id() * @uses bbp_get_query_template() * @return string Path to template file */ function bbp_get_topic_tag_edit_template() { $tt_slug = bbp_get_topic_tag_slug(); $tt_id = bbp_get_topic_tag_tax_id(); $templates = array('taxonomy-' . $tt_slug . '-edit.php', 'taxonomy-' . $tt_id . '-edit.php'); return bbp_get_query_template('topic_tag_edit', $templates); }
/** * bbPress Dashboard Right Now Widget * * Adds a dashboard widget with forum statistics * * @since 2.0.0 bbPress (r2770) * * @deprecated 2.6.0 bbPress (r5268) * * @uses bbp_get_version() To get the current bbPress version * @uses bbp_get_statistics() To get the forum statistics * @uses current_user_can() To check if the user is capable of doing things * @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 get_admin_url() To get the administration url * @uses add_query_arg() To add custom args to the url * @uses do_action() Calls 'bbp_dashboard_widget_right_now_content_table_end' * below the content table * @uses do_action() Calls 'bbp_dashboard_widget_right_now_table_end' * below the discussion table * @uses do_action() Calls 'bbp_dashboard_widget_right_now_discussion_table_end' * below the discussion table * @uses do_action() Calls 'bbp_dashboard_widget_right_now_end' below the widget */ function bbp_dashboard_widget_right_now() { // Get the statistics $r = bbp_get_statistics(); ?> <div class="table table_content"> <p class="sub"><?php esc_html_e('Discussion', 'bbpress'); ?> </p> <table> <tr class="first"> <?php $num = $r['forum_count']; $text = _n('Forum', 'Forums', $r['forum_count'], 'bbpress'); if (current_user_can('publish_forums')) { $link = add_query_arg(array('post_type' => bbp_get_forum_post_type()), get_admin_url(null, 'edit.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a href="' . esc_url($link) . '">' . $text . '</a>'; } ?> <td class="first b b-forums"><?php echo $num; ?> </td> <td class="t forums"><?php echo $text; ?> </td> </tr> <tr> <?php $num = $r['topic_count']; $text = _n('Topic', 'Topics', $r['topic_count'], 'bbpress'); if (current_user_can('publish_topics')) { $link = add_query_arg(array('post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a href="' . esc_url($link) . '">' . $text . '</a>'; } ?> <td class="first b b-topics"><?php echo $num; ?> </td> <td class="t topics"><?php echo $text; ?> </td> </tr> <tr> <?php $num = $r['reply_count']; $text = _n('Reply', 'Replies', $r['reply_count'], 'bbpress'); if (current_user_can('publish_replies')) { $link = add_query_arg(array('post_type' => bbp_get_reply_post_type()), get_admin_url(null, 'edit.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a href="' . esc_url($link) . '">' . $text . '</a>'; } ?> <td class="first b b-replies"><?php echo $num; ?> </td> <td class="t replies"><?php echo $text; ?> </td> </tr> <?php if (bbp_allow_topic_tags()) { ?> <tr> <?php $num = $r['topic_tag_count']; $text = _n('Topic Tag', 'Topic Tags', $r['topic_tag_count'], 'bbpress'); if (current_user_can('manage_topic_tags')) { $link = add_query_arg(array('taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit-tags.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a href="' . esc_url($link) . '">' . $text . '</a>'; } ?> <td class="first b b-topic_tags"><span class="total-count"><?php echo $num; ?> </span></td> <td class="t topic_tags"><?php echo $text; ?> </td> </tr> <?php } ?> <?php do_action('bbp_dashboard_widget_right_now_content_table_end'); ?> </table> </div> <div class="table table_discussion"> <p class="sub"><?php esc_html_e('Users & Moderation', 'bbpress'); ?> </p> <table> <tr class="first"> <?php $num = $r['user_count']; $text = _n('User', 'Users', $r['user_count'], 'bbpress'); if (current_user_can('edit_users')) { $link = get_admin_url(null, 'users.php'); $num = '<a href="' . $link . '">' . $num . '</a>'; $text = '<a href="' . $link . '">' . $text . '</a>'; } ?> <td class="b b-users"><span class="total-count"><?php echo $num; ?> </span></td> <td class="last t users"><?php echo $text; ?> </td> </tr> <?php if (isset($r['topic_count_hidden'])) { ?> <tr> <?php $num = $r['topic_count_hidden']; $text = _n('Hidden Topic', 'Hidden Topics', $r['topic_count_hidden'], 'bbpress'); $link = add_query_arg(array('post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit.php')); if ('0' !== $num) { $link = add_query_arg(array('post_status' => bbp_get_spam_status_id()), $link); } $num = '<a href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_topic_title']) . '">' . $num . '</a>'; $text = '<a class="waiting" href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_topic_title']) . '">' . $text . '</a>'; ?> <td class="b b-hidden-topics"><?php echo $num; ?> </td> <td class="last t hidden-replies"><?php echo $text; ?> </td> </tr> <?php } ?> <?php if (isset($r['reply_count_hidden'])) { ?> <tr> <?php $num = $r['reply_count_hidden']; $text = _n('Hidden Reply', 'Hidden Replies', $r['reply_count_hidden'], 'bbpress'); $link = add_query_arg(array('post_type' => bbp_get_reply_post_type()), get_admin_url(null, 'edit.php')); if ('0' !== $num) { $link = add_query_arg(array('post_status' => bbp_get_spam_status_id()), $link); } $num = '<a href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_reply_title']) . '">' . $num . '</a>'; $text = '<a class="waiting" href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_reply_title']) . '">' . $text . '</a>'; ?> <td class="b b-hidden-replies"><?php echo $num; ?> </td> <td class="last t hidden-replies"><?php echo $text; ?> </td> </tr> <?php } ?> <?php if (bbp_allow_topic_tags() && isset($r['empty_topic_tag_count'])) { ?> <tr> <?php $num = $r['empty_topic_tag_count']; $text = _n('Empty Topic Tag', 'Empty Topic Tags', $r['empty_topic_tag_count'], 'bbpress'); $link = add_query_arg(array('taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit-tags.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a class="waiting" href="' . esc_url($link) . '">' . $text . '</a>'; ?> <td class="b b-hidden-topic-tags"><?php echo $num; ?> </td> <td class="last t hidden-topic-tags"><?php echo $text; ?> </td> </tr> <?php } ?> <?php do_action('bbp_dashboard_widget_right_now_discussion_table_end'); ?> </table> </div> <?php do_action('bbp_dashboard_widget_right_now_table_end'); ?> <div class="versions"> <span id="wp-version-message"> <?php printf(__('You are using <span class="b">bbPress %s</span>.', 'bbpress'), bbp_get_version()); ?> </span> </div> <br class="clear" /> <?php do_action('bbp_dashboard_widget_right_now_end'); }
/** * Return the description of the current tag * * @since 2.0.0 bbPress (r3109) * * @uses get_term_by() * @uses get_queried_object() * @uses get_query_var() * @uses apply_filters() * @param array $args before|after|tag * * @return string Term Name */ function bbp_get_topic_tag_description($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('before' => '<div class="bbp-topic-tag-description"><p>', 'after' => '</p></div>', 'tag' => ''), 'get_topic_tag_description'); // Get the term if (!empty($r['tag'])) { $term = get_term_by('slug', $r['tag'], bbp_get_topic_tag_tax_id()); } else { $tag = get_query_var('term'); $r['tag'] = $tag; $term = get_queried_object(); } // Add before and after if description exists if (!empty($term->description)) { $retval = $r['before'] . $term->description . $r['after']; // No description, no HTML } else { $retval = ''; } return apply_filters('bbp_get_topic_tag_description', $retval, $r, $args, $tag, $term); }
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 }