function maybe_add_robots() { global $post; if (is_singular() && bbp_is_topic($post->ID) && bbp_is_topic_closed($post->ID) && time() - get_post_time('U', true, $post) > YEAR_IN_SECONDS) { echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; } }
<?php bbp_reply_form_fields(); ?> </fieldset> <?php do_action('bbp_theme_after_reply_form'); ?> </form> </div> <?php } elseif (bbp_is_topic_closed()) { ?> <div id="no-reply-<?php bbp_topic_id(); ?> " class="bbp-no-reply"> <div class="bbp-template-notice"> <p><?php printf(esc_html__('The topic ‘%s’ is closed to new replies.', 'monsoon'), bbp_get_topic_title()); ?> </p> </div> </div> <?php
/** * Is the topic open to new replies? * * @since 2.0.0 bbPress (r2727) * * @uses bbp_get_topic_status() * * @param int $topic_id Optional. Topic id * @uses bbp_is_topic_closed() To check if the topic is closed * @return bool True if open, false if closed. */ function bbp_is_topic_open($topic_id = 0) { return !bbp_is_topic_closed($topic_id); }
/** * Handles the front end reply submission * * @since bbPress (r2574) * * @param string $action The requested action to compare this function to * @uses bbp_add_error() To add an error message * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses bbp_is_anonymous() To check if an anonymous post is being made * @uses current_user_can() To check if the current user can publish replies * @uses bbp_get_current_user_id() To get the current user id * @uses bbp_filter_anonymous_post_data() To filter anonymous data * @uses bbp_set_current_anonymous_user_data() To set the anonymous user * cookies * @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 bbp_check_for_flood() To check for flooding * @uses bbp_check_for_duplicate() To check for duplicates * @uses apply_filters() Calls 'bbp_new_reply_pre_title' with the title * @uses apply_filters() Calls 'bbp_new_reply_pre_content' with the content * @uses bbp_get_reply_post_type() To get the reply post type * @uses wp_set_post_terms() To set the topic tags * @uses wp_insert_post() To insert the reply * @uses do_action() Calls 'bbp_new_reply' with the reply id, topic id, forum * id, anonymous data, reply author, edit (false), 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_new_reply_handler($action = '') { // Bail if action is not bbp-new-reply if ('bbp-new-reply' !== $action) { return; } // Nonce check if (!bbp_verify_nonce_request('bbp-new-reply')) { bbp_add_error('bbp_new_reply_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; } // Define local variable(s) $topic_id = $forum_id = $reply_author = $anonymous_data = $reply_to = 0; $reply_title = $reply_content = $terms = ''; /** Reply Author **********************************************************/ // User is anonymous if (bbp_is_anonymous()) { // Filter anonymous data $anonymous_data = bbp_filter_anonymous_post_data(); // Anonymous data checks out, so set cookies, etc... if (!empty($anonymous_data) && is_array($anonymous_data)) { bbp_set_current_anonymous_user_data($anonymous_data); } // User is logged in } else { // User cannot create replies if (!current_user_can('publish_replies')) { bbp_add_error('bbp_reply_permissions', __('<strong>ERROR</strong>: You do not have permission to reply.', 'bbpress')); } // Reply author is current user $reply_author = bbp_get_current_user_id(); } /** Topic ID **************************************************************/ // Topic id was not passed if (empty($_POST['bbp_topic_id'])) { bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID is missing.', 'bbpress')); // Topic id is not a number } elseif (!is_numeric($_POST['bbp_topic_id'])) { bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID must be a number.', 'bbpress')); // Topic id might be valid } else { // Get the topic id $posted_topic_id = intval($_POST['bbp_topic_id']); // Topic id is a negative number if (0 > $posted_topic_id) { bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID cannot be a negative number.', 'bbpress')); // Topic does not exist } elseif (!bbp_get_topic($posted_topic_id)) { bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic does not exist.', 'bbpress')); // Use the POST'ed topic id } else { $topic_id = $posted_topic_id; } } /** Forum ID **************************************************************/ // Try to use the forum id of the topic if (!isset($_POST['bbp_forum_id']) && !empty($topic_id)) { $forum_id = bbp_get_topic_forum_id($topic_id); // Error check the POST'ed forum id } elseif (isset($_POST['bbp_forum_id'])) { // Empty Forum id was passed if (empty($_POST['bbp_forum_id'])) { bbp_add_error('bbp_reply_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress')); // Forum id is not a number } elseif (!is_numeric($_POST['bbp_forum_id'])) { bbp_add_error('bbp_reply_forum_id', __('<strong>ERROR</strong>: Forum ID must be a number.', 'bbpress')); // Forum id might be valid } else { // Get the forum id $posted_forum_id = intval($_POST['bbp_forum_id']); // Forum id is empty if (0 === $posted_forum_id) { bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress')); // Forum id is a negative number } elseif (0 > $posted_forum_id) { bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID cannot be a negative number.', 'bbpress')); // Forum does not exist } elseif (!bbp_get_forum($posted_forum_id)) { bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum does not exist.', 'bbpress')); // Use the POST'ed forum id } else { $forum_id = $posted_forum_id; } } } // Forum exists if (!empty($forum_id)) { // Forum is a category if (bbp_is_forum_category($forum_id)) { bbp_add_error('bbp_new_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_new_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_new_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_new_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')); } } } } /** Unfiltered HTML *******************************************************/ // 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_' . $topic_id) === $_POST['_bbp_unfiltered_html_reply']) { remove_filter('bbp_new_reply_pre_title', 'wp_filter_kses'); remove_filter('bbp_new_reply_pre_content', 'bbp_encode_bad', 10); remove_filter('bbp_new_reply_pre_content', 'bbp_filter_kses', 30); } /** 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_new_reply_pre_title', $reply_title); /** Reply Content *********************************************************/ if (!empty($_POST['bbp_reply_content'])) { $reply_content = $_POST['bbp_reply_content']; } // Filter and sanitize $reply_content = apply_filters('bbp_new_reply_pre_content', $reply_content); // No reply content if (empty($reply_content)) { bbp_add_error('bbp_reply_content', __('<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress')); } /** Reply Flooding ********************************************************/ if (!bbp_check_for_flood($anonymous_data, $reply_author)) { bbp_add_error('bbp_reply_flood', __('<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress')); } /** Reply Duplicate *******************************************************/ if (!bbp_check_for_duplicate(array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data))) { bbp_add_error('bbp_reply_duplicate', __('<strong>ERROR</strong>: Duplicate reply detected; it looks as though you’ve already said that!', '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 created at this time.', 'bbpress')); } /** Reply Status **********************************************************/ // Maybe put into moderation if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) { $reply_status = bbp_get_pending_status_id(); // Default } else { $reply_status = bbp_get_public_status_id(); } /** 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 Closed **********************************************************/ // If topic is closed, moderators can still reply if (bbp_is_topic_closed($topic_id) && !current_user_can('moderate')) { bbp_add_error('bbp_reply_topic_closed', __('<strong>ERROR</strong>: Topic is closed.', 'bbpress')); } /** 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_new_reply_pre_extras', $topic_id, $forum_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 created $reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_status' => $reply_status, 'post_parent' => $topic_id, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => bbp_get_topic_reply_count($topic_id, false) + 1)); // Insert reply $reply_id = wp_insert_post($reply_data); /** No Errors *************************************************************/ // Check for missing reply_id or error if (!empty($reply_id) && !is_wp_error($reply_id)) { /** Topic Tags ********************************************************/ // Just in time manipulation of reply terms before being edited $terms = apply_filters('bbp_new_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')); } /** Trash Check *******************************************************/ // If this reply starts as trash, add it to pre_trashed_replies // for the topic, so it is properly restored. if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] === bbp_get_trash_status_id()) { // Trash the reply wp_trash_post($reply_id); // Only add to pre-trashed array if topic is trashed if (bbp_is_topic_trash($topic_id)) { // Get pre_trashed_replies for topic $pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true); // Add this reply to the end of the existing replies $pre_trashed_replies[] = $reply_id; // Update the pre_trashed_reply post meta update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies); } /** Spam Check ********************************************************/ // If reply or topic are spam, officially spam this reply } elseif (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] === bbp_get_spam_status_id()) { add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id()); // Only add to pre-spammed array if topic is spam if (bbp_is_topic_spam($topic_id)) { // Get pre_spammed_replies for topic $pre_spammed_replies = get_post_meta($topic_id, '_bbp_pre_spammed_replies', true); // Add this reply to the end of the existing replies $pre_spammed_replies[] = $reply_id; // Update the pre_spammed_replies post meta update_post_meta($topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies); } } /** Update counts, etc... *********************************************/ do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to); /** Additional Actions (After Save) ***********************************/ do_action('bbp_new_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_new_reply_redirect_to', $reply_url, $redirect_to, $reply_id); /** Successful Save ***************************************************/ // 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')); } }
function bbp_user_can_comment() { return bbpresskr()->forum_option('use_comments') && bbp_current_user_can_access_create_reply_form() && !bbp_is_topic_closed() && !bbp_is_forum_closed(); }
/** * Display Topic Status * -------------------------------------------------------------------------------------------*/ function aq_display_topic_status($topic_id = 0) { $topic_id = $topic_id ? $topic_id : bbp_get_topic_id(); $statuses = array(1, 2, 3); $status_id = get_post_meta($topic_id, '_bbps_topic_status', true); echo '<div class="aq-topic-status">'; if (bbp_is_topic_sticky()) { echo '<span class="sticky">Sticky</span>'; } elseif (in_array($status_id, $statuses)) { if ($status_id == 1) { echo '<span class="not-resolved">Not Resolved</span>'; } if ($status_id == 2) { echo '<span class="resolved">Resolved</span>'; } if ($status_id == 3) { echo '<span class="in-progress">In Progress</span>'; } } elseif (bbp_is_topic_closed()) { echo '<span class="sticky">Sticky</span>'; } else { echo '<span class="in-progress">In Progress</span>'; } echo '</div>'; }
</div> <?php do_action( 'bbp_theme_after_reply_form_submit_wrapper' ); ?> </div> <?php bbp_reply_form_fields(); ?> </fieldset> <?php do_action( 'bbp_theme_after_reply_form' ); ?> </form> </div> <?php elseif ( bbp_is_topic_closed() ) : ?> <div id="no-reply-<?php bbp_topic_id(); ?>" class="bbp-no-reply"> <div class="bbp-template-notice"> <p><?php printf( __( 'The topic ‘%s’ is closed to new replies.', 'bbpress' ), bbp_get_topic_title() ); ?></p> </div> </div> <?php elseif ( bbp_is_forum_closed( bbp_get_topic_forum_id() ) ) : ?> <div id="no-reply-<?php bbp_topic_id(); ?>" class="bbp-no-reply"> <div class="bbp-template-notice"> <p><?php printf( __( 'The forum ‘%s’ is closed to new topics and replies.', 'bbpress' ), bbp_get_forum_title( bbp_get_topic_forum_id() ) ); ?></p> </div> </div>
/** * Increase the total topic count of a forum by one. * * @since 2.6.0 bbPress (r6036) * * @param int $forum_id The forum id. * * @uses bbp_is_topic() To get the topic id * @uses bbp_get_topic_forum_id() To get the topics forum id * @uses bbp_is_topic_published() To get the topics published status * @uses bbp_is_topic_closed() To get the topics closed status * @uses bbp_increase_forum_topic_count_hidden() To increase the forums hidden * topic count by 1 * @uses bbp_bump_forum_topic_count() To bump the forum topic count * * @return void */ function bbp_increase_forum_topic_count($forum_id = 0) { // Bail early if no id is passed. if (empty($forum_id)) { return; } // If it's a topic, get the forum id. if (bbp_is_topic($forum_id)) { $topic_id = $forum_id; $forum_id = bbp_get_topic_forum_id($topic_id); // If this is a new, unpublished, topic, increase hidden count and bail. if ('bbp_new_topic' === current_filter() && (!bbp_is_topic_published($topic_id) && !bbp_is_topic_closed($topic_id))) { bbp_increase_forum_topic_count_hidden($forum_id); return; } } bbp_bump_forum_topic_count($forum_id); }