/** * @covers ::bbp_is_forum_category */ public function test_bbp_is_forum_category() { $f = $this->factory->forum->create_many(2); bbp_normalize_forum($f[0]); $categorize_meta = get_post_meta($f[0], '_bbp_forum_type', true); $this->assertSame('forum', $categorize_meta); $forum = bbp_is_forum_category($f[0]); $this->assertFalse($forum); bbp_categorize_forum($f[1]); $categorize_meta = get_post_meta($f[1], '_bbp_forum_type', true); $this->assertSame('category', $categorize_meta); $forum = bbp_is_forum_category($f[1]); $this->assertTrue($forum); $f = $this->factory->forum->create(array('forum_meta' => array('forum_type' => 'category'))); $forum = bbp_is_forum_category($f); $this->assertTrue($forum); }
<ul id="forums-list-<?php bbp_forum_id(); ?> " class="bbp-forums"> <li class="bbp-body"> <?php while (bbp_forums()) { bbp_the_forum(); ?> <?php if (bbp_is_forum_category() && !bbp_get_forum_parent_id()) { ?> <div class="vwbb-forum-cat-section"> <div class="vwbb-forum-cat-head"> <ul class="forum-titles clearfix"> <li class="bbp-forum-info"><?php bbp_forum_title(); ?> </li> <li class="normal bbp-forum-topic-count"><?php _e('Topics', 'bbpress'); ?> / <?php bbp_show_lead_topic() ? _e('Replies', 'bbpress') : _e('Posts', 'bbpress'); ?>
function st_bbp_list_forums($args = '') { // Define used variables $output = $sub_forums = $topic_count = $reply_count = $counts = ''; $i = 0; $count = array(); // Defaults and arguments $defaults = array('before' => '<ul class="bbp-forums-list">', 'after' => '</ul>', 'link_before' => '<li class="bbp-forum">', 'link_after' => '</li>', 'count_before' => ' (', 'count_after' => ')', 'count_sep' => ', ', 'separator' => ', ', 'forum_id' => '', 'show_topic_count' => true, 'show_reply_count' => true, 'show_freshness_link' => true); $r = bbp_parse_args($args, $defaults, 'list_forums'); extract($r, EXTR_SKIP); // Bail if there are no subforums if (!bbp_get_forum_subforum_count($forum_id)) { return; } // Loop through forums and create a list $sub_forums = bbp_forum_get_subforums($forum_id); if (!empty($sub_forums)) { // Total count (for separator) $total_subs = count($sub_forums); foreach ($sub_forums as $sub_forum) { $i++; // Separator count // Get forum details $count = array(); $show_sep = $total_subs > $i ? $separator : ''; $permalink = bbp_get_forum_permalink($sub_forum->ID); $title = bbp_get_forum_title($sub_forum->ID); $description = bbp_get_forum_content($sub_forum->ID); // Show topic count if (!empty($show_topic_count) && !bbp_is_forum_category($sub_forum->ID)) { $count['topic'] = bbp_get_forum_topic_count($sub_forum->ID); } // Show reply count if (!empty($show_reply_count) && !bbp_is_forum_category($sub_forum->ID)) { $count['reply'] = bbp_get_forum_reply_count($sub_forum->ID); } // Counts to show if (!empty($count)) { $counts = $count_before . implode($count_sep, $count) . $count_after; } if (!empty($show_freshness_link)) { $freshness_link = "<div class='freshness-forum-link'>" . st_get_last_poster_block($sub_forum->ID) . "</div>"; } // Build this sub forums link if ($i % 2) { $class = "odd-forum-row"; } else { $class = "even-forum-row"; } $output .= "<li class='{$class}'><ul>" . $link_before . '<div class="bbp-forum-title-container"><a href="' . $permalink . '" class="bbp-forum-link">' . $title . '</a><p class="bbp-forum-description">' . $description . '</p></div>' . $counts . $freshness_link . $link_after . "</ul></li>"; } // Output the list echo apply_filters('bbp_list_forums', $before . $output . $after, $args); } }
/** * @see Walker::start_el() * * @since bbPress (r2746) * * @param string $output Passed by reference. Used to append additional * content. * @param object $_post Post data object. * @param int $depth Depth of post in reference to parent posts. Used * for padding. * @param array $args Uses 'selected' argument for selected post to set * selected HTML attribute for option element. * @param int $current_object_id * @uses bbp_is_forum_category() To check if the forum is a category * @uses current_user_can() To check if the current user can post in * closed forums * @uses bbp_is_forum_closed() To check if the forum is closed * @uses apply_filters() Calls 'bbp_walker_dropdown_post_title' with the * title, output, post, depth and args */ public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) { $pad = str_repeat(' ', (int) $depth * 3); $output .= '<option class="level-' . (int) $depth . '"'; // Disable the <option> if: // - we're told to do so // - the post type is a forum // - the forum is a category // - forum is closed if (true === $args['disable_categories'] && bbp_get_forum_post_type() === $object->post_type && (bbp_is_forum_category($object->ID) || !current_user_can('edit_forum', $object->ID) && bbp_is_forum_closed($object->ID))) { $output .= ' disabled="disabled" value=""'; } else { $output .= ' value="' . (int) $object->ID . '"' . selected($args['selected'], $object->ID, false); } $output .= '>'; $title = apply_filters('bbp_walker_dropdown_post_title', $object->post_title, $output, $object, $depth, $args); $output .= $pad . esc_html($title); $output .= "</option>\n"; }
bbpress()->forum_query = clone $temp_query; } else { bbp_get_template_part('loop', 'single-forum'); $bbp_forums_noheader = 1; /* This prevents the header part to be printed again on next post in the loop */ } ?> </li><!-- .bbp-body --> <?php /* Prints the footer only if : - it's a category - or if it's the last forum of a no-parent forum list - or if the next forum in the loop is a category */ if (bbp_is_forum_category() or bbpress()->forum_query->current_post + 1 == bbpress()->forum_query->post_count or bbp_is_forum_category(bbpress()->forum_query->posts[bbpress()->forum_query->current_post + 1]->ID)) { ?> <li class="bbp-footer"> <div class="tr"> <p class="td colspan4"> </p> </div><!-- .tr --> </li><!-- .bbp-footer --> </ul><!-- .forums-directory --> <?php unset($bbp_forums_noheader); /* Needed if we have 2+ no-parent forums with at least 1 category between them */
if (bbp_is_forum_category()) { echo 'bbp-forum-is-category'; } ?> list-group-item bbp-body"> <ul id="bbp-forum-<?php bbp_forum_id(); ?> " <?php bbp_forum_class(); ?> > <li class="bbp-forum-info"> <span class="pull-left ipt_kb_bbpress_forum_icon"> <?php if (bbp_is_forum_category()) { ?> <span class="glyphicon ipt-icon-folder-open"></span> <?php } else { ?> <span class="glyphicon ipt-icon-file4"></span> <?php } ?> </span> <?php ipt_kb_bbp_forum_title_in_list(); ?> <?php ipt_kb_bbp_forum_description_in_list();
/** * 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')); } }
/** * 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')); } }
protected function get_views() { global $post; $views = array(); if (bbp_is_forum_category() && bbp_has_forums()) { $views['all'] = '<a class="current bbp-forum-title" href="' . bbp_get_forum_permalink() . '">' . __('All', 'bbpresskr') . '</a>'; while (bbp_forums()) { bbp_the_forum(); $views[] = '<a class="bbp-forum-title" href="' . bbp_get_forum_permalink() . '">' . bbp_get_forum_title() . '</a>'; } } else { $forum_id = bbp_get_forum_id(); $forum = get_post($forum_id); if ($forum->post_parent && bbp_has_forums(array('post_parent' => $forum->post_parent))) { $views['all'] = '<a class="bbp-forum-title" href="' . bbp_get_forum_permalink($forum->post_parent) . '">' . __('All', 'bbpresskr') . '</a>'; while (bbp_forums()) { bbp_the_forum(); $current = $forum_id == $post->ID ? ' current' : ''; $views[$post->post_name] = '<a class="bbp-forum-title' . $current . '" href="' . bbp_get_forum_permalink() . '">' . bbp_get_forum_title() . '</a>'; } } } return $views; }
/** * Post new topic by email handler. * * For bbPress, the logic in this method is the same as {@link bbp_new_topic_handler()}. * It's duplicated because bbPress doesn't utilize hooks for verifying topics. * * @todo No fancy support for topic tags, subscriptions yet. Will probably need shortcodes. * * @param array $data { * An array of arguments. * * @type array $headers Email headers. * @type string $content The email body content. * @type string $subject The email subject line. * @type int $user_id The user ID who sent the email. * @type bool $is_html Whether the email content is HTML or not. * @type int $i The email message number. * } * @param array $params Parsed paramaters from the email address querystring. * See {@link BP_Reply_By_Email_Parser::get_parameters()}. * @return array|object Array of the parsed item on success. WP_Error object * on failure. */ private function post_new_topic($data, $params) { //private function post_new_topic( $connection, $i, $headers, $params, $body, $topic_author ) { /** SETUP DATA ***************************************************/ $i = $data['i']; $topic_author = $data['user_id']; $forum_id = $params[$this->forum_id_param]; /* current email is a bbPress new topic, let's proceed! */ // let RBE know that we're in the process of rendering a bbP new topic // BuddyPress group new topic if (!empty($params[$this->item_id_param])) { bp_rbe_log('Message #' . $i . ': this is a bbPress group forum new topic'); // bbPress } else { bp_rbe_log('Message #' . $i . ': this is a bbPress new topic'); } // other variables $anonymous_data = 0; /** GROUP PERMISSIONS ********************************************/ // posting from a BP group if (!empty($params[$this->item_id_param])) { global $bp; // set group ID and cache it in global for later use // $bp->rbe->temp->group_id gets passed to the set_group_id() method later on $group_id = $bp->rbe->temp->group_id = $params[$this->item_id_param]; // get all group member data for the user in one swoop! $group_member_data = bp_rbe_get_group_member_info($topic_author, $group_id); // user is not a member of the group anymore if (empty($group_member_data)) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_not_group_member' ); return new WP_Error('user_not_group_member', '', $data); } // user is banned from group if ((int) $group_member_data->is_banned == 1) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_banned_from_group' ); return new WP_Error('user_banned_from_group', '', $data); } // override groups_get_current_group() with our cached group ID add_filter('groups_get_current_group', array($this, 'set_group_id')); // temporarily add some GES filters here add_filter('bp_ass_activity_notification_subject', 'wp_specialchars_decode'); add_filter('bp_ass_activity_notification_content', 'wp_specialchars_decode'); } /** TOPIC / FORUM PERMISSIONS ************************************/ // Allow member to pass default cap checks. // The reason why we keep the user_can() checks below is b/c bbPress // plugins may disable cap access for a specific user if they have hooked into // the 'bbp_map_meta_caps' filter. add_filter('bbp_map_meta_caps', array($this, 'map_forum_meta_caps'), 5, 4); // User cannot create topics if (!user_can($topic_author, 'publish_topics')) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_permissions' ); return new WP_Error('bbp_topic_permissions', '', $data); } // Forum is a category if (bbp_is_forum_category($forum_id)) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_category' ); //bbp_add_error( 'bbp_edit_topic_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No topics can be created in this forum.', 'bbpress' ) ); return new WP_Error('bbp_edit_topic_forum_category', '', $data); // Forum is not a category } else { // Forum is closed and user cannot access if (bbp_is_forum_closed($forum_id) && !user_can($topic_author, 'edit_forum')) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_closed' ); //bbp_add_error( 'bbp_edit_topic_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress' ) ); return new WP_Error('bbp_edit_topic_forum_closed', '', $data); } // Forum is private and user cannot access if (bbp_is_forum_private($forum_id)) { if (!user_can($topic_author, 'read_private_forums')) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_private' ); //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' ) ); return new WP_Error('bbp_edit_topic_forum_private', '', $data); } } // Forum is hidden and user cannot access if (bbp_is_forum_hidden($forum_id)) { if (!user_can($topic_author, 'read_hidden_forums')) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_hidden' ); //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' ) ); return new WP_Error('bbp_edit_topic_forum_hidden', '', $data); } } } /** UNFILTERED HTML **********************************************/ // Remove wp_filter_kses filters from title and content for capable users if (user_can($topic_author, 'unfiltered_html')) { remove_filter('bbp_new_topic_pre_title', 'wp_filter_kses'); remove_filter('bbp_new_topic_pre_content', 'wp_filter_kses'); } /** TOPIC DATA ***************************************************/ $topic_content = $data['content']; $topic_title = $data['subject']; bp_rbe_log('Message #' . $i . ': body contents - ' . $topic_content); bp_rbe_log('Subject - ' . $topic_title); if (empty($topic_content) || empty($topic_title)) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_new_forum_topic_empty' ); return new WP_Error('bbp_new_forum_topic_empty', '', $data); } // Filter and sanitize $topic_title = apply_filters('bbp_new_topic_pre_title', $topic_title); $topic_content = apply_filters('bbp_new_topic_pre_content', $topic_content); /** Topic Tags ****************************************************/ /* TODO if ( bbp_allow_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 ); } */ /** TOPIC MODERATION *********************************************/ // Post Flooding if (!bbp_check_for_flood($anonymous_data, $topic_author)) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_flood' ); //bbp_add_error( 'bbp_reply_flood', __( '<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress' ) ); return new WP_Error('bbp_topic_flood', '', $data); } // Topic Duplicate if (!bbp_check_for_duplicate(array('post_type' => bbp_get_topic_post_type(), 'post_author' => $topic_author, 'post_content' => $topic_content, 'anonymous_data' => $anonymous_data))) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_duplicate' ); return new WP_Error('bbp_topic_duplicate', '', $data); } // Topic Blacklist if (!bbp_check_for_blacklist($anonymous_data, $topic_author, $topic_title, $topic_content)) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_blacklist' ); return new WP_Error('bbp_topic_blacklist', '', $data); } // Topic Status // Maybe put into moderation if (!bbp_check_for_moderation($anonymous_data, $topic_author, $topic_title, $topic_content)) { $topic_status = bbp_get_pending_status_id(); // Default } else { $topic_status = bbp_get_public_status_id(); } /** POSTING TIME! ************************************************/ // bbP hook before save do_action('bbp_new_topic_pre_extras', $forum_id); // Setup reply data $topic_data = apply_filters('bbp_new_topic_pre_insert', array('post_author' => $topic_author, 'post_title' => $topic_title, 'post_content' => $topic_content, 'post_status' => $topic_status, 'post_parent' => $forum_id, 'post_type' => bbp_get_topic_post_type(), 'comment_status' => 'closed')); // Insert topic $topic_id = wp_insert_post($topic_data); // Topic posted! if (!is_wp_error($topic_id)) { // more internal logging bp_rbe_log('Message #' . $i . ': bbPress topic successfully posted!'); // Problem posting } else { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_error' ); return new WP_Error('bbp_topic_error', '', $data); } /** AFTER POSTING ************************************************/ // stuff that needs to happen after a bbP topic is posted occurs here... bbP // should preferably do the following at the 'bbp_new_reply' hook, until then // do what bbP does inline. // Trash Check //////////////////////////////////////////////////// // If the forum is trash, or the topic_status is switched to // trash, trash it properly if (get_post_field('post_status', $forum_id) == bbp_get_trash_status_id() || $topic_data['post_status'] == bbp_get_trash_status_id()) { // Trash the reply wp_trash_post($topic_id); } // Spam Check ///////////////////////////////////////////////////// // If reply or topic are spam, officially spam this reply if ($topic_data['post_status'] == bbp_get_spam_status_id()) { add_post_meta($topic_id, '_bbp_spam_meta_status', bbp_get_public_status_id()); } // Reply By Email ///////////////////////////////////////////////// // Add a RBE marker to the post's meta // Could potentially show that post was made via email on the frontend add_post_meta($topic_id, 'bp_rbe', 1); /** POST HOOKS ***************************************************/ // RBE Custom Hooks /////////////////////////////////////////////// // change activity action add_filter('bbp_before_record_activity_parse_args', array($this, 'change_activity_action')); // add RBE's special activity hook add_action('bp_activity_after_save', array($this, 'activity_rbe_hook')); // bbPress Topic Hooks //////////////////////////////////////////// do_action('bbp_new_topic', $topic_id, $forum_id, $anonymous_data, $topic_author); do_action('bbp_new_topic_post_extras', $topic_id); return array('bbp_topic_id' => $topic_id); }
/** * @group canonical * @covers ::bbp_insert_forum */ public function test_bbp_insert_forum() { $c = $this->factory->forum->create(array('post_title' => 'Category 1', 'post_content' => 'Content of Category 1', 'forum_meta' => array('forum_type' => 'category', 'status' => 'open'))); $f = $this->factory->forum->create(array('post_title' => 'Forum 1', 'post_content' => 'Content of Forum 1', 'post_parent' => $c, 'forum_meta' => array('forum_id' => $c, 'forum_type' => 'forum', 'status' => 'open'))); $now = time(); $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100); $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f))); $r = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Get the category. $category = bbp_get_forum($c); // Get the forum. $forum = bbp_get_forum($f); // Category post. $this->assertSame('Category 1', bbp_get_forum_title($c)); $this->assertSame('Content of Category 1', bbp_get_forum_content($c)); $this->assertSame('open', bbp_get_forum_status($c)); $this->assertSame('category', bbp_get_forum_type($c)); $this->assertTrue(bbp_is_forum($c)); $this->assertTrue(bbp_is_forum_category($c)); $this->assertTrue(bbp_is_forum_open($c)); $this->assertTrue(bbp_is_forum_public($c)); $this->assertFalse(bbp_is_forum_closed($c)); $this->assertFalse(bbp_is_forum_hidden($c)); $this->assertFalse(bbp_is_forum_private($c)); $this->assertSame(0, bbp_get_forum_parent_id($c)); $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $category->post_name, $category->guid); // Forum post. $this->assertSame('Forum 1', bbp_get_forum_title($f)); $this->assertSame('Content of Forum 1', bbp_get_forum_content($f)); $this->assertSame('open', bbp_get_forum_status($f)); $this->assertSame('forum', bbp_get_forum_type($f)); $this->assertTrue(bbp_is_forum($f)); $this->assertTrue(bbp_is_forum_open($f)); $this->assertTrue(bbp_is_forum_public($f)); $this->assertFalse(bbp_is_forum_closed($f)); $this->assertFalse(bbp_is_forum_hidden($f)); $this->assertFalse(bbp_is_forum_private($f)); $this->assertSame($c, bbp_get_forum_parent_id($f)); $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $category->post_name . '/' . $forum->post_name, $forum->guid); // Category meta. $this->assertSame(1, bbp_get_forum_subforum_count($c, true)); $this->assertSame(0, bbp_get_forum_topic_count($c, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($c, true, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($c, true)); $this->assertSame(0, bbp_get_forum_reply_count($c, false, true)); $this->assertSame(1, bbp_get_forum_reply_count($c, true, true)); $this->assertSame(0, bbp_get_forum_post_count($c, false, true)); $this->assertSame(2, bbp_get_forum_post_count($c, true, true)); $this->assertSame($t, bbp_get_forum_last_topic_id($c)); $this->assertSame($r, bbp_get_forum_last_reply_id($c)); $this->assertSame($r, bbp_get_forum_last_active_id($c)); $this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($c)); // Forum meta. $this->assertSame(0, bbp_get_forum_subforum_count($f, true)); $this->assertSame(1, bbp_get_forum_topic_count($f, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($f, true, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($f, true)); $this->assertSame(1, bbp_get_forum_reply_count($f, false, true)); $this->assertSame(1, bbp_get_forum_reply_count($f, true, true)); $this->assertSame(2, bbp_get_forum_post_count($f, false, true)); $this->assertSame(2, bbp_get_forum_post_count($f, true, true)); $this->assertSame($t, bbp_get_forum_last_topic_id($f)); $this->assertSame($r, bbp_get_forum_last_reply_id($f)); $this->assertSame($r, bbp_get_forum_last_active_id($f)); $this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($f)); }
function custom_list_forums($args = '') { // Define used variables global $rpg_settingsg; global $rpg_settingsf; $output = $sub_forums = $topic_count = $reply_count = $counts = ''; $i = 0; $count = array(); // Parse arguments against default values $r = bbp_parse_args($args, array('before' => '<ul class="bbp-forums-list">', 'after' => '</ul>', 'link_before' => '<li class="bbp-forum">', 'link_after' => '</li>', 'count_before' => ' (', 'count_after' => ')', 'count_sep' => ', ', 'separator' => '<br> ', 'forum_id' => '', 'show_topic_count' => true, 'show_reply_count' => true), 'listb_forums'); // Loop through forums and create a list $sub_forums = bbp_forum_get_subforums($r['forum_id']); if (!empty($sub_forums)) { // Total count (for separator) $total_subs = count($sub_forums); foreach ($sub_forums as $sub_forum) { $i++; // Separator count // Get forum details $count = array(); $show_sep = $total_subs > $i ? $r['separator'] : ''; $permalink = bbp_get_forum_permalink($sub_forum->ID); $title = bbp_get_forum_title($sub_forum->ID); $content = bbp_get_forum_content($sub_forum->ID); if ($rpg_settingsg['activate_descriptions'] == true) { $content = bbp_get_forum_content($sub_forum->ID); } else { $content = ''; } // Show topic count if (!empty($r['show_topic_count']) && !bbp_is_forum_category($sub_forum->ID)) { $count['topic'] = bbp_get_forum_topic_count($sub_forum->ID); } // Show reply count if (!empty($r['show_reply_count']) && !bbp_is_forum_category($sub_forum->ID)) { $count['reply'] = bbp_get_forum_reply_count($sub_forum->ID); } // Counts to show if (!empty($count)) { $counts = $r['count_before'] . implode($r['count_sep'], $count) . $r['count_after']; } if ($rpg_settingsg['hide_counts'] == true) { $counts = ''; } //Build this sub forums link if (bbp_is_forum_private($sub_forum->ID)) { if (!current_user_can('read_private_forums')) { if (!$rpg_settingsf['redirect_page']) { $link = '/home'; } else { $link = $rpg_settingsf['redirect_page']; } $output .= $r['before'] . $r['link_before'] . '<a href="' . $link . '" class="bbp-forum-link">' . $title . $counts . '</a>' . $show_sep . $r['link_after'] . '<div class="bbp-forum-content">' . $content . '</div>' . $r['after']; } else { $output .= $r['before'] . $r['link_before'] . '<a href="' . esc_url($permalink) . '" class="bbp-forum-link">' . $title . $counts . '</a>' . $show_sep . $r['link_after'] . '<div class="bbp-forum-content">' . $content . '</div>' . $r['after']; } } else { $output .= $r['before'] . $r['link_before'] . '<a href="' . esc_url($permalink) . '" class="bbp-forum-link">' . $title . $counts . '</a>' . $show_sep . $r['link_after'] . '<div class="bbp-forum-content">' . $content . '</div>' . $r['after']; } } //Output the list return $output; } }
/** * Return a fancy description of the current forum, including total * topics, total replies, and last activity. * * @since Boss 1.0.0 * * @param mixed $args This function supports these arguments: * - forum_id: Forum id * - before: Before the text * - after: After the text * - size: Size of the avatar * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_forum_topic_count() To get the forum topic count * @uses bbp_get_forum_reply_count() To get the forum reply count * @uses bbp_get_forum_freshness_link() To get the forum freshness link * @uses bbp_get_forum_last_active_id() To get the forum last active id * @uses bbp_get_author_link() To get the author link * @uses add_filter() To add the 'view all' filter back * @uses apply_filters() Calls 'bbp_get_single_forum_description' with * the description and args * @return string Filtered forum description */ function buddyboss_bbp_get_single_forum_description($args = '') { // Parse arguments against default values $r = bbp_parse_args($args, array('forum_id' => 0, 'before' => '<div class="bbp-template-notice info"><p class="bbp-forum-description">', 'after' => '</p></div>', 'size' => 14, 'feed' => true), 'get_single_forum_description'); // Validate forum_id $forum_id = bbp_get_forum_id($r['forum_id']); // Unhook the 'view all' query var adder remove_filter('bbp_get_forum_permalink', 'bbp_add_view_all'); // Get some forum data $tc_int = bbp_get_forum_topic_count($forum_id, false); $rc_int = bbp_get_forum_reply_count($forum_id, false); $topic_count = bbp_get_forum_topic_count($forum_id); $reply_count = bbp_get_forum_reply_count($forum_id); $last_active = bbp_get_forum_last_active_id($forum_id); // Has replies if (!empty($reply_count)) { $reply_text = sprintf(_n('%s reply', '%s replies', $rc_int, 'boss'), $reply_count); } // Forum has active data if (!empty($last_active)) { $topic_text = bbp_get_forum_topics_link($forum_id); $time_since = bbp_get_forum_freshness_link($forum_id); $last_updated_by = bbp_get_author_link(array('post_id' => $last_active, 'size' => $r['size'])); // Forum has no last active data } else { $topic_text = sprintf(_n('%s topic', '%s topics', $tc_int, 'boss'), $topic_count); } // Forum has active data if (!empty($last_active)) { if (!empty($reply_count)) { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('<span class="post-num">%1$s and %2$s</span> <span class="last-activity">Last updated by %3$s %4$s</span>', 'boss'), $topic_text, $reply_text, $last_updated_by, $time_since); } else { $retstr = sprintf(__('<span class="post-num">%1$s and %2$s</span> <span class="last-activity">Last updated by %3$s %4$s<span>', 'boss'), $topic_text, $reply_text, $last_updated_by, $time_since); } } else { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('<span class="post-num">%1$s</span> <span class="last-activity">Last updated by %2$s %3$s</span>', 'boss'), $topic_text, $last_updated_by, $time_since); } else { $retstr = sprintf(__('<span class="post-num">%1$s</span> <span class="last-activity">Last updated by %2$s %3$s</span>', 'boss'), $topic_text, $last_updated_by, $time_since); } } // Forum has no last active data } else { if (!empty($reply_count)) { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('<span class="post-num">%1$s and %2$s</span>', 'boss'), $topic_text, $reply_text); } else { $retstr = sprintf(__('<span class="post-num">%1$s and %2$s</span>', 'boss'), $topic_text, $reply_text); } } else { if (!empty($topic_count)) { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('<span class="post-num">%1$s</span>', 'boss'), $topic_text); } else { $retstr = sprintf(__('<span class="post-num">%1$s</span>', 'boss'), $topic_text); } } else { $retstr = __('<span class="post-num">0 topics and 0 posts</span>', 'boss'); } } } // Add feeds //$feed_links = ( !empty( $r['feed'] ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : ''; // Add the 'view all' filter back add_filter('bbp_get_forum_permalink', 'bbp_add_view_all'); // Combine the elements together $retstr = $r['before'] . $retstr . $r['after']; // Return filtered result return apply_filters('bbp_get_single_forum_description', $retstr, $r); }
/** * Handle the saving of core forum metadata (Status, Visibility, and Type) * * @since 2.1.0 bbPress (r3678) * * @param int $forum_id * @uses bbp_is_forum_closed() To check if forum is closed * @uses bbp_close_forum() To close forum * @uses bbp_open_forum() To open forum * @uses bbp_is_forum_category() To check if forum is a category * @uses bbp_categorize_forum() To turn forum into a category * @uses bbp_normalize_forum() To turn category into forum * @uses bbp_get_public_status_id() To get the public status ID * @uses bbp_get_private_status_id() To get the private status ID * @uses bbp_get_hidden_status_id() To get the hidden status ID * @uses bbp_get_forum_visibility() To get the forums visibility * @uses bbp_hide_forum() To hide a forum * @uses bbp_privatize_forum() To make a forum private * @uses bbp_publicize_forum() To make a forum public * @return If forum ID is empty */ function bbp_save_forum_extras($forum_id = 0) { // Validate the forum ID $forum_id = bbp_get_forum_id($forum_id); // Bail if forum ID is empty if (empty($forum_id) || !bbp_is_forum($forum_id)) { return; } /** Forum Status **********************************************************/ if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) { if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) { bbp_close_forum($forum_id); } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_open($forum_id, false)) { bbp_open_forum($forum_id); } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) { bbp_open_forum($forum_id); } } /** Forum Type ************************************************************/ if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) { if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) { bbp_categorize_forum($forum_id); } elseif ('forum' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) { bbp_normalize_forum($forum_id); } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) { bbp_normalize_forum($forum_id); } } /** Forum Visibility ******************************************************/ if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array_keys(bbp_get_forum_visibilities()))) { // Get forums current visibility $old_visibility = bbp_get_forum_visibility($forum_id); // Sanitize the new visibility $new_visibility = sanitize_key($_POST['bbp_forum_visibility']); // What is the new forum visibility setting? switch ($new_visibility) { // Hidden case bbp_get_hidden_status_id(): bbp_hide_forum($forum_id, $old_visibility); break; // Private // Private case bbp_get_private_status_id(): bbp_privatize_forum($forum_id, $old_visibility); break; // Publish (default) // Publish (default) case bbp_get_public_status_id(): default: bbp_publicize_forum($forum_id, $old_visibility); break; } /** * Allow custom forum visibility save actions * * @since 2.6.0 bbPress (r5855) * * @param int $forum_id The forum ID * @param string $old_visibility The current forum visibility * @param string $new_visibility The new forum visibility */ do_action('bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility); } }
/** * Return a fancy description of the current forum, including total * topics, total replies, and last activity. * * @since bbPress (r2860) * * @param mixed $args This function supports these arguments: * - forum_id: Forum id * - before: Before the text * - after: After the text * - size: Size of the avatar * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_forum_topic_count() To get the forum topic count * @uses bbp_get_forum_reply_count() To get the forum reply count * @uses bbp_get_forum_subforum_count() To get the forum subforum count * @uses bbp_get_forum_freshness_link() To get the forum freshness link * @uses bbp_get_forum_last_active_id() To get the forum last active id * @uses bbp_get_author_link() To get the author link * @uses add_filter() To add the 'view all' filter back * @uses apply_filters() Calls 'bbp_get_single_forum_description' with * the description and args * @return string Filtered forum description */ function bbp_get_single_forum_description($args = '') { // Default arguments $defaults = array('forum_id' => 0, 'before' => '<div class="bbp-template-notice info"><p class="bbp-forum-description">', 'after' => '</p></div>', 'size' => 14, 'feed' => true); $r = bbp_parse_args($args, $defaults, 'get_single_forum_description'); extract($r); // Validate forum_id $forum_id = bbp_get_forum_id($forum_id); // Unhook the 'view all' query var adder remove_filter('bbp_get_forum_permalink', 'bbp_add_view_all'); // Get some forum data $topic_count = bbp_get_forum_topic_count($forum_id); $reply_count = bbp_get_forum_reply_count($forum_id); $last_active = bbp_get_forum_last_active_id($forum_id); // Has replies if (!empty($reply_count)) { $reply_text = sprintf(_n('%s reply', '%s replies', $reply_count, 'bbpress'), $reply_count); } // Forum has active data if (!empty($last_active)) { $topic_text = bbp_get_forum_topics_link($forum_id); $time_since = bbp_get_forum_freshness_link($forum_id); $last_updated_by = bbp_get_author_link(array('post_id' => $last_active, 'size' => $size)); // Forum has no last active data } else { $topic_text = sprintf(_n('%s topic', '%s topics', $topic_count, 'bbpress'), $topic_count); } // Forum has active data if (!empty($last_active)) { if (!empty($reply_count)) { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('This category contains %1$s and %2$s, and was last updated by %3$s %4$s.', 'bbpress'), $topic_text, $reply_text, $last_updated_by, $time_since); } else { $retstr = sprintf(__('This forum contains %1$s and %2$s, and was last updated by %3$s %4$s.', 'bbpress'), $topic_text, $reply_text, $last_updated_by, $time_since); } } else { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('This category contains %1$s, and was last updated by %2$s %3$s.', 'bbpress'), $topic_text, $last_updated_by, $time_since); } else { $retstr = sprintf(__('This forum contains %1$s, and was last updated by %2$s %3$s.', 'bbpress'), $topic_text, $last_updated_by, $time_since); } } // Forum has no last active data } else { if (!empty($reply_count)) { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('This category contains %1$s and %2$s.', 'bbpress'), $topic_text, $reply_text); } else { $retstr = sprintf(__('This forum contains %1$s and %2$s.', 'bbpress'), $topic_text, $reply_text); } } else { if (!empty($topic_count)) { if (bbp_is_forum_category($forum_id)) { $retstr = sprintf(__('This category contains %1$s.', 'bbpress'), $topic_text); } else { $retstr = sprintf(__('This forum contains %1$s.', 'bbpress'), $topic_text); } } else { $retstr = __('This forum is empty.', 'bbpress'); } } } // Add feeds //$feed_links = ( !empty( $feed ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : ''; // Add the 'view all' filter back add_filter('bbp_get_forum_permalink', 'bbp_add_view_all'); // Combine the elements together $retstr = $before . $retstr . $after; // Return filtered result return apply_filters('bbp_get_single_forum_description', $retstr, $args); }
/** * Bump the total topic count of a forum * * @since 2.1.0 bbPress (r3825) * * @param int $forum_id Optional. Forum id. * @param int $difference Optional. Default 1 * @param bool $update_ancestors Optional. Default true * @uses bbp_get_forum_id() To get the forum id * @uses update_post_meta() To update the forum's topic count meta * @uses apply_filters() Calls 'bbp_bump_forum_reply_count' with the topic * count, forum id, and difference * @return int Forum topic count */ function bbp_bump_forum_reply_count($forum_id = 0, $difference = 1, $update_ancestors = true) { // Bail if no bump if (empty($difference)) { return false; } // Get some counts $forum_id = bbp_get_forum_id($forum_id); $topic_count = bbp_get_forum_reply_count($forum_id, false, true); $total_reply_count = bbp_get_forum_reply_count($forum_id, true, true); $difference = (int) $difference; // Update this forum id update_post_meta($forum_id, '_bbp_reply_count', (int) ($topic_count + $difference)); update_post_meta($forum_id, '_bbp_total_reply_count', (int) ($total_reply_count + $difference)); // Check for ancestors if (true === $update_ancestors) { // Get post ancestors $forum = get_post($forum_id); $ancestors = get_post_ancestors($forum); // If has ancestors, loop through them... if (!empty($ancestors)) { foreach ((array) $ancestors as $parent_forum_id) { // Only update reply count when an ancestor is not a category. if (!bbp_is_forum_category($parent_forum_id)) { $parent_reply_count = bbp_get_forum_reply_count($parent_forum_id, false, true); update_post_meta($parent_forum_id, '_bbp_reply_count', (int) ($parent_reply_count + $difference)); } // Update the total reply count. $parent_total_reply_count = bbp_get_forum_reply_count($parent_forum_id, true, true); update_post_meta($parent_forum_id, '_bbp_total_reply_count', (int) ($parent_total_reply_count + $difference)); } } } $forum_reply_count = (int) ($total_reply_count + $difference); return (int) apply_filters('bbp_bump_forum_reply_count', $forum_reply_count, $forum_id, $difference, $update_ancestors); }
function ipt_kb_bbp_forum_description_in_list($forum_id = 0) { do_action('bbp_theme_before_forum_description'); ?> <div class="bbp-forum-content <?php echo bbp_is_forum_category($forum_id) ? 'text-primary' : 'text-muted'; ?> "><?php bbp_forum_content($forum_id); ?> </div> <?php do_action('bbp_theme_after_forum_description'); ?> <?php }
<?php if ( bbp_has_forums() ) : ?> <?php bbp_get_template_part( 'loop', 'forums' ); ?> <?php endif; ?> <?php if ( !bbp_is_forum_category() && bbp_has_topics() ) : ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'loop', 'topics' ); ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php elseif ( !bbp_is_forum_category() ) : ?> <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php endif; ?> <?php endif; ?> <?php do_action( 'bbp_template_after_single_forum' ); ?> </div>
/** * Handle the saving of core forum metadata (Status, Visibility, and Type) * * @since bbPress (r3678) * @param int $forum_id * @uses bbp_is_forum_closed() To check if forum is closed * @uses bbp_close_forum() To close forum * @uses bbp_open_forum() To open forum * @uses bbp_is_forum_category() To check if forum is a category * @uses bbp_categorize_forum() To turn forum into a category * @uses bbp_normalize_forum() To turn category into forum * @uses bbp_get_public_status_id() To get the public status ID * @uses bbp_get_private_status_id() To get the private status ID * @uses bbp_get_hidden_status_id() To get the hidden status ID * @uses bbp_get_forum_visibility() To get the forums visibility * @uses bbp_hide_forum() To hide a forum * @uses bbp_privatize_forum() To make a forum private * @uses bbp_publicize_forum() To make a forum public * @return If forum ID is empty */ function bbp_save_forum_extras($forum_id = 0) { // Validate the forum ID $forum_id = bbp_get_forum_id($forum_id); // Bail if forum ID is empty if (empty($forum_id) || !bbp_is_forum($forum_id)) { return; } /** Forum Status ******************************************************/ if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) { if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) { bbp_close_forum($forum_id); } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) { bbp_open_forum($forum_id); } } /** Forum Type ********************************************************/ if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) { if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) { bbp_categorize_forum($forum_id); } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) { bbp_normalize_forum($forum_id); } } /** Forum Visibility **************************************************/ if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array(bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id()))) { // Get forums current visibility $visibility = bbp_get_forum_visibility($forum_id); // What is the new forum visibility setting? switch ($_POST['bbp_forum_visibility']) { // Hidden case bbp_get_hidden_status_id(): bbp_hide_forum($forum_id, $visibility); break; // Private // Private case bbp_get_private_status_id(): bbp_privatize_forum($forum_id, $visibility); break; // Publish (default) // Publish (default) case bbp_get_public_status_id(): default: bbp_publicize_forum($forum_id, $visibility); break; } } }
/** * @see Walker::start_el() * * @since bbPress (r2746) * * @param string $output Passed by reference. Used to append additional * content. * @param object $_post Post data object. * @param int $depth Depth of post in reference to parent posts. Used * for padding. * @param array $args Uses 'selected' argument for selected post to set * selected HTML attribute for option element. * @uses bbp_is_forum_category() To check if the forum is a category * @uses current_user_can() To check if the current user can post in * closed forums * @uses bbp_is_forum_closed() To check if the forum is closed * @uses apply_filters() Calls 'bbp_walker_dropdown_post_title' with the * title, output, post, depth and args */ public function start_el(&$output, $_post, $depth, $args) { $pad = str_repeat(' ', $depth * 3); $output .= "\t<option class=\"level-{$depth}\""; // Disable the <option> if we're told to do so, the post type is bbp_forum and the forum is a category or is closed if (true == $args['disable_categories'] && $_post->post_type == bbp_get_forum_post_type() && (bbp_is_forum_category($_post->ID) || !current_user_can('edit_forum', $_post->ID) && bbp_is_forum_closed($_post->ID))) { $output .= ' disabled="disabled" value=""'; } else { $output .= ' value="' . $_post->ID . '"' . selected($args['selected'], $_post->ID, false); } $output .= '>'; $title = esc_html($_post->post_title); $title = apply_filters('bbp_walker_dropdown_post_title', $_post->post_title, $output, $_post, $depth, $args); $output .= $pad . $title; $output .= "</option>\n"; }
?> <?php bbp_get_template_part('loop', 'topics'); ?> <?php bbp_get_template_part('pagination', 'topics'); ?> <?php bbp_get_template_part('form', 'topic'); ?> <?php } elseif (!bbp_is_forum_category()) { ?> <?php bbp_get_template_part('feedback', 'no-topics'); ?> <?php bbp_get_template_part('form', 'topic'); ?> <?php } ?>
function wm_section_heading($args = array()) { //Helper variables global $post, $page, $paged, $wp_query; if (!isset($paged)) { $paged = 0; } if (!isset($page)) { $page = 0; } $paginated = max($paged, $page); $blog_page_id = get_option('page_for_posts'); $page_id = is_home() ? $blog_page_id : null; $disable_heading = false; if (function_exists('wma_meta_option') && wma_meta_option('disable-heading', $page_id) || !function_exists('wma_meta_option') && is_front_page()) { $disable_heading = true; } //WooCommerce support $wc_shop = false; if (class_exists('WooCommerce')) { if (is_woocommerce() || is_cart() || is_checkout()) { $wc_shop = true; } if (is_shop()) { $page_id = wc_get_page_id('shop'); } } //Requirements check if (is_home() && !$blog_page_id || $disable_heading) { return; } $output = ''; $defaults = array('addons' => '', 'class' => 'main-heading entry-header wrap clearfix', 'link' => get_permalink($page_id), 'page_id' => $page_id, 'paged' => array($paginated, $paged, $page), 'output' => "\r\n\r\n" . '<header id="main-heading" class="{class}">' . "\r\n" . apply_filters('wmhook_section_inner_wrappers', '') . '<{tag} class="entry-title"' . wm_schema_org('name') . '>{title}</{tag}>{addons}' . apply_filters('wmhook_section_inner_wrappers_close', '') . "\r\n" . '</header>' . "\r\n", 'tag' => 'h1', 'title' => 2 > $paginated ? get_the_title($page_id) : '<a href="' . get_permalink($page_id) . '">' . get_the_title($page_id) . '</a>'); //Link on tax, category and tag archive if (is_tax() || is_category() || is_tag()) { global $wp_query; $term = $wp_query->get_queried_object(); $defaults['link'] = get_term_link($term); } elseif (is_archive()) { $defaults['link'] = ''; } $defaults = apply_filters('wmhook_wm_section_heading_defaults', $defaults); $args = wp_parse_args($args, $defaults); //Preparing output //Archives if (is_day()) { $args['title'] = sprintf(__('Daily Archives: <strong>%s</strong>', 'mustang'), get_the_date()); } elseif (is_month()) { $args['title'] = sprintf(__('Monthly Archives: <strong>%s</strong>', 'mustang'), get_the_date(_x('F Y', 'monthly archives date format', 'mustang'))); } elseif (is_year()) { $args['title'] = sprintf(__('Yearly Archives: <strong>%s</strong>', 'mustang'), get_the_date(_x('Y', 'yearly archives date format', 'mustang'))); } elseif (is_category()) { $args['title'] = sprintf(__('Category Archives: <strong>%s</strong>', 'mustang'), single_cat_title('', false)); } elseif (is_tag()) { $args['title'] = sprintf(__('Tag Archives: <strong>%s</strong>', 'mustang'), single_tag_title('', false)); } elseif (is_search()) { $args['title'] = sprintf(__('Search Results for: <strong>%s</strong>', 'mustang'), get_search_query()); } elseif (is_author()) { $author = get_userdata(get_query_var('author')); $args['title'] = sprintf(__('<strong>%s</strong> archives', 'mustang'), $author->display_name); } elseif (is_tax()) { $args['title'] = single_term_title('', false); } elseif (is_archive()) { $args['title'] = __('Archives', 'mustang'); } if (is_category() || is_tag() || is_tax()) { $term_description = term_description(); if (!empty($term_description)) { $args['addons'] .= sprintf('<div class="taxonomy-description" title="%2$s">%1$s</div>', $term_description, esc_attr(sprintf('Description of "%s"', single_term_title('', false)))); } } //Single post if (is_singular('post') && $blog_page_id) { $args['title'] = '<a href="' . get_permalink($blog_page_id) . '">' . get_the_title($blog_page_id) . '</a>'; $args['class'] = str_replace(' entry-header', '', $args['class']); $args['output'] = str_replace(' class="entry-title"', '', $args['output']); } //Parted article / pagination suffix if (!(is_singular('post') && $blog_page_id)) { if (1 < $args['paged'][2]) { $args['title'] = '<a href="' . $args['link'] . '">' . $args['title'] . '</a>' . wm_paginated_suffix('small'); } elseif (1 < $args['paged'][1]) { $args['title'] .= wm_paginated_suffix('small'); } } //404 page if (is_404()) { $args['title'] = __('Error 404', 'mustang'); } //bbPress support if (class_exists('bbPress')) { if (bbp_is_forum_archive()) { $args['title'] = sprintf(__('%s forums', 'mustang'), get_bloginfo('name')); } if (bbp_is_single_forum() && !bbp_is_forum_category()) { $args['title'] = sprintf(__('Forum: %s', 'mustang'), $args['title']); } if (bbp_is_single_topic()) { $args['title'] = sprintf(__('Topic: %s', 'mustang'), $args['title']); } } //WooCommerce support if ($wc_shop && !is_tax()) { $args['title'] = 2 > $paginated ? get_the_title($page_id) : '<a href="' . get_permalink($page_id) . '">' . get_the_title($page_id) . '</a>'; if (is_search()) { $args['title'] .= sprintf(__(' / Results for: <strong>%s</strong>', 'mustang'), get_search_query()); } } //Addons $widget_area_atts = apply_filters('wmhook_wm_section_heading_widget_area_atts', array('max_widgets_count' => 2, 'sidebar' => 'main-heading-widgets')); $widget_area = ''; if (function_exists('wma_sidebar')) { $widget_area = wma_sidebar($widget_area_atts); } if ($widget_area) { $args['addons'] .= '<div class="main-heading-widgets">' . $widget_area . '</div>'; $args['class'] .= ' has-widgets'; } //Filter processed $args $args = apply_filters('wmhook_wm_section_heading_args', $args); //Generating output HTML $replacements = array('{addons}' => do_shortcode($args['addons']), '{class}' => esc_attr($args['class']), '{tag}' => esc_attr($args['tag']), '{title}' => do_shortcode($args['title'])); $output = strtr($args['output'], $replacements); //Output echo apply_filters('wmhook_wm_section_heading_output', $output); }
/** * Recaches the last post in every topic and forum * * @since 2.0.0 bbPress (r3040) * * @uses wpdb::query() To run our recount sql queries * @uses is_wp_error() To check if the executed query returned {@link WP_Error} * @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_public_status_id() To get the public status id * @uses bbp_is_forum_category() To check if the forum is a ategory * @uses bbp_update_forum() To update the forums forum id * @return array An array of the status code and the message */ function bbp_admin_repair_freshness() { // Define variables $bbp_db = bbp_db(); $statement = __('Recomputing latest post in every topic and forum… %s', 'bbpress'); $result = __('Failed!', 'bbpress'); // First, delete everything. if (is_wp_error($bbp_db->query("DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );"))) { return array(1, sprintf($statement, $result)); } // Post types and status $fpt = bbp_get_forum_post_type(); $tpt = bbp_get_topic_post_type(); $rpt = bbp_get_reply_post_type(); $pps = bbp_get_public_status_id(); // Next, give all the topics with replies the ID their last reply. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `topic`.`ID`, '_bbp_last_reply_id', MAX( `reply`.`ID` )\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`\n\t\t\tWHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'\n\t\t\tGROUP BY `topic`.`ID` );"))) { return array(2, sprintf($statement, $result)); } // For any remaining topics, give a reply ID of 0. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_reply_id', 0\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply`\n\t\t\tON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_reply_id'\n\t\t\tWHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );"))) { return array(3, sprintf($statement, $result)); } // Now we give all the forums with topics the ID their last topic. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `forum`.`ID`, '_bbp_last_topic_id', `topic`.`ID`\n\t\t\tFROM `{$bbp_db->posts}` AS `forum` INNER JOIN `{$bbp_db->posts}` AS `topic` ON `forum`.`ID` = `topic`.`post_parent`\n\t\t\tWHERE `topic`.`post_status` = '{$pps}' AND `forum`.`post_type` = '{$fpt}' AND `topic`.`post_type` = '{$tpt}'\n\t\t\tGROUP BY `forum`.`ID` );"))) { return array(4, sprintf($statement, $result)); } // For any remaining forums, give a topic ID of 0. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_topic_id', 0\n\t\t\tFROM `{$bbp_db->posts}` AS `forum` LEFT JOIN `{$bbp_db->postmeta}` AS `topic`\n\t\t\tON `forum`.`ID` = `topic`.`post_id` AND `topic`.`meta_key` = '_bbp_last_topic_id'\n\t\t\tWHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );"))) { return array(5, sprintf($statement, $result)); } // After that, we give all the topics with replies the ID their last reply (again, this time for a different reason). if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `topic`.`ID`, '_bbp_last_active_id', MAX( `reply`.`ID` )\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`\n\t\t\tWHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'\n\t\t\tGROUP BY `topic`.`ID` );"))) { return array(6, sprintf($statement, $result)); } // For any remaining topics, give a reply ID of themself. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_active_id', `ID`\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply`\n\t\t\tON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id'\n\t\t\tWHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );"))) { return array(7, sprintf($statement, $result)); } // Give topics with replies their last update time. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` )\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`\n\t\t\tWHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'\n\t\t\tGROUP BY `topic`.`ID` );"))) { return array(8, sprintf($statement, $result)); } // Give topics without replies their last update time. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_active_time', `post_date`\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply`\n\t\t\tON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time'\n\t\t\tWHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );"))) { return array(9, sprintf($statement, $result)); } // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database. $forums = $bbp_db->get_col("SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft';"); if (is_wp_error($forums)) { return array(10, sprintf($statement, $result)); } // Loop through forums foreach ($forums as $forum_id) { if (!bbp_is_forum_category($forum_id)) { bbp_update_forum(array('forum_id' => $forum_id)); } } // Loop through categories when forums are done foreach ($forums as $forum_id) { if (bbp_is_forum_category($forum_id)) { bbp_update_forum(array('forum_id' => $forum_id)); } } // Complete results return array(0, sprintf($statement, __('Complete!', 'bbpress'))); }
<?php if (bbp_allow_search()) { ?> <?php bbp_get_template_part('form', 'search'); ?> <?php } ?> <?php bbp_get_template_part('form', 'topic'); ?> <?php if (!bbp_is_forum_category() && bbp_has_topics()) { ?> <?php bbp_get_template_part('loop', 'topics'); ?> <?php bbp_get_template_part('pagination', 'topics'); ?> <?php } ?>