<label><?php esc_html_e('You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:', 'monsoon'); ?> </label><br /> <code><?php bbp_allowed_tags(); ?> </code> </p> <?php } ?> <?php if (bbp_allow_topic_tags() && current_user_can('assign_topic_tags')) { ?> <?php do_action('bbp_theme_before_reply_form_tags'); ?> <p> <label for="bbp_topic_tags"><?php esc_html_e('Tags:', 'monsoon'); ?> </label><br /> <input type="text" value="<?php bbp_form_topic_tags(); ?> " tabindex="<?php
/** * Return the tags of a topic * * @since 2.0.0 bbPress (r2688) * * @param int $topic_id Optional. Topic id * @param array $args This function supports these arguments: * - before: Before the tag list * - sep: Tag separator * - after: After the tag list * @uses bbp_get_topic_id() To get the topic id * @uses get_the_term_list() To get the tags list * @return string Tag list of the topic */ function bbp_get_topic_tag_list($topic_id = 0, $args = array()) { // Bail if topic-tags are off if (!bbp_allow_topic_tags()) { return ''; } // Parse arguments against default values $r = bbp_parse_args($args, array('before' => '<div class="bbp-topic-tags"><p>' . esc_html__('Tagged:', 'bbpress') . ' ', 'sep' => ', ', 'after' => '</p></div>', 'none' => ''), 'get_topic_tag_list'); $topic_id = bbp_get_topic_id($topic_id); // Topic is spammed, so display pre-spam terms if (bbp_is_topic_spam($topic_id)) { // Get pre-spam terms $terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true); // If terms exist, implode them and compile the return value if (!empty($terms)) { $terms = $r['before'] . implode($r['sep'], $terms) . $r['after']; } // Topic is not spam so display a clickable term list } else { $terms = get_the_term_list($topic_id, bbp_get_topic_tag_tax_id(), $r['before'], $r['sep'], $r['after']); } // No terms so return none string if (!empty($terms)) { $retval = $terms; } else { $retval = $r['none']; } return $retval; }
</div> <?php } ?> <div class="checkbox"> <input name="bbp_topic_favoriters" id="bbp_topic_favoriters" type="checkbox" value="1" checked="checked" tabindex="<?php bbp_tab_index(); ?> " /> <label for="bbp_topic_favoriters"><?php _e('Merge topic favoriters', 'bbpress'); ?> </label><br /> </div> <?php if (bbp_allow_topic_tags()) { ?> <div class="checkbox"> <input name="bbp_topic_tags" id="bbp_topic_tags" type="checkbox" value="1" checked="checked" tabindex="<?php bbp_tab_index(); ?> " /> <label for="bbp_topic_tags"><?php _e('Merge topic tags', 'bbpress'); ?> </label><br /> </div> <?php } ?>
/** * Check if the current page is editing a topic tag * * @since bbPress (r3346) * * @uses WP_Query Checks if WP_Query::bbp_is_topic_tag_edit is true * @return bool True if editing a topic tag, false if not */ function bbp_is_topic_tag_edit() { global $wp_query, $pagenow, $taxnow; // Bail if topic-tags are off if (!bbp_allow_topic_tags()) { return false; } // Assume false $retval = false; // Check query if (!empty($wp_query->bbp_is_topic_tag_edit) && true == $wp_query->bbp_is_topic_tag_edit) { $retval = true; } elseif (is_admin() && 'edit-tags.php' == $pagenow && bbp_get_topic_tag_tax_id() == $taxnow && (!empty($_GET['action']) && 'edit' == $_GET['action'])) { $retval = true; } return (bool) apply_filters('bbp_is_topic_tag_edit', $retval); }
/** * 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')); } }
/** * Get the forum statistics * * @since 2.0.0 bbPress (r2769) * @since 2.6.0 bbPress (r6055) Introduced the `count_pending_topics` and * `count_pending_replies` arguments. * * @param array $args Optional. The function supports these arguments (all * default to true): * - count_users: Count users? * - count_forums: Count forums? * - count_topics: Count topics? If set to false, private, spammed and trashed * topics are also not counted. * - count_pending_topics: Count pending topics? (only counted if the current * user has edit_others_topics cap) * - count_private_topics: Count private topics? (only counted if the current * user has read_private_topics cap) * - count_spammed_topics: Count spammed topics? (only counted if the current * user has edit_others_topics cap) * - count_trashed_topics: Count trashed topics? (only counted if the current * user has view_trash cap) * - count_replies: Count replies? If set to false, private, spammed and * trashed replies are also not counted. * - count_pending_replies: Count pending replies? (only counted if the current * user has edit_others_replies cap) * - count_private_replies: Count private replies? (only counted if the current * user has read_private_replies cap) * - count_spammed_replies: Count spammed replies? (only counted if the current * user has edit_others_replies cap) * - count_trashed_replies: Count trashed replies? (only counted if the current * user has view_trash cap) * - count_tags: Count tags? If set to false, empty tags are also not counted * - count_empty_tags: Count empty tags? * @uses bbp_get_total_users() To count the number of registered users * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses wp_count_posts() To count the number of forums, topics and replies * @uses wp_count_terms() To count the number of topic tags * @uses current_user_can() To check if the user is capable of doing things * @uses number_format_i18n() To format the number * @uses apply_filters() Calls 'bbp_get_statistics' with the statistics and args * @return object Walked forum tree */ function bbp_get_statistics($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('count_users' => true, 'count_forums' => true, 'count_topics' => true, 'count_pending_topics' => true, 'count_private_topics' => true, 'count_spammed_topics' => true, 'count_trashed_topics' => true, 'count_replies' => true, 'count_pending_replies' => true, 'count_private_replies' => true, 'count_spammed_replies' => true, 'count_trashed_replies' => true, 'count_tags' => true, 'count_empty_tags' => true), 'get_statistics'); // Defaults $user_count = 0; $forum_count = 0; $topic_count = 0; $topic_count_hidden = 0; $reply_count = 0; $reply_count_hidden = 0; $topic_tag_count = 0; $empty_topic_tag_count = 0; // Users if (!empty($r['count_users'])) { $user_count = bbp_get_total_users(); } // Forums if (!empty($r['count_forums'])) { $forum_count = wp_count_posts(bbp_get_forum_post_type())->publish; } // Post statuses $pending = bbp_get_pending_status_id(); $private = bbp_get_private_status_id(); $spam = bbp_get_spam_status_id(); $trash = bbp_get_trash_status_id(); $closed = bbp_get_closed_status_id(); // Topics if (!empty($r['count_topics'])) { $all_topics = wp_count_posts(bbp_get_topic_post_type()); // Published (publish + closed) $topic_count = $all_topics->publish + $all_topics->{$closed}; if (current_user_can('read_private_topics') || current_user_can('edit_others_topics') || current_user_can('view_trash')) { // Declare empty arrays $topics = $topic_titles = array(); // Pending $topics['pending'] = !empty($r['count_pending_topics']) && current_user_can('edit_others_topics') ? (int) $all_topics->{$pending} : 0; // Private $topics['private'] = !empty($r['count_private_topics']) && current_user_can('read_private_topics') ? (int) $all_topics->{$private} : 0; // Spam $topics['spammed'] = !empty($r['count_spammed_topics']) && current_user_can('edit_others_topics') ? (int) $all_topics->{$spam} : 0; // Trash $topics['trashed'] = !empty($r['count_trashed_topics']) && current_user_can('view_trash') ? (int) $all_topics->{$trash} : 0; // Total hidden (private + spam + trash) $topic_count_hidden = $topics['pending'] + $topics['private'] + $topics['spammed'] + $topics['trashed']; // Generate the hidden topic count's title attribute $topic_titles[] = !empty($topics['pending']) ? sprintf(__('Pending: %s', 'bbpress'), number_format_i18n($topics['pending'])) : ''; $topic_titles[] = !empty($topics['private']) ? sprintf(__('Private: %s', 'bbpress'), number_format_i18n($topics['private'])) : ''; $topic_titles[] = !empty($topics['spammed']) ? sprintf(__('Spammed: %s', 'bbpress'), number_format_i18n($topics['spammed'])) : ''; $topic_titles[] = !empty($topics['trashed']) ? sprintf(__('Trashed: %s', 'bbpress'), number_format_i18n($topics['trashed'])) : ''; // Compile the hidden topic title $hidden_topic_title = implode(' | ', array_filter($topic_titles)); } } // Replies if (!empty($r['count_replies'])) { $all_replies = wp_count_posts(bbp_get_reply_post_type()); // Published $reply_count = $all_replies->publish; if (current_user_can('read_private_replies') || current_user_can('edit_others_replies') || current_user_can('view_trash')) { // Declare empty arrays $replies = $reply_titles = array(); // Pending $replies['pending'] = !empty($r['count_pending_replies']) && current_user_can('edit_others_replies') ? (int) $all_replies->{$pending} : 0; // Private $replies['private'] = !empty($r['count_private_replies']) && current_user_can('read_private_replies') ? (int) $all_replies->{$private} : 0; // Spam $replies['spammed'] = !empty($r['count_spammed_replies']) && current_user_can('edit_others_replies') ? (int) $all_replies->{$spam} : 0; // Trash $replies['trashed'] = !empty($r['count_trashed_replies']) && current_user_can('view_trash') ? (int) $all_replies->{$trash} : 0; // Total hidden (private + spam + trash) $reply_count_hidden = $replies['pending'] + $replies['private'] + $replies['spammed'] + $replies['trashed']; // Generate the hidden topic count's title attribute $reply_titles[] = !empty($replies['pending']) ? sprintf(__('Pending: %s', 'bbpress'), number_format_i18n($replies['pending'])) : ''; $reply_titles[] = !empty($replies['private']) ? sprintf(__('Private: %s', 'bbpress'), number_format_i18n($replies['private'])) : ''; $reply_titles[] = !empty($replies['spammed']) ? sprintf(__('Spammed: %s', 'bbpress'), number_format_i18n($replies['spammed'])) : ''; $reply_titles[] = !empty($replies['trashed']) ? sprintf(__('Trashed: %s', 'bbpress'), number_format_i18n($replies['trashed'])) : ''; // Compile the hidden replies title $hidden_reply_title = implode(' | ', array_filter($reply_titles)); } } // Topic Tags if (!empty($r['count_tags']) && bbp_allow_topic_tags()) { // Get the count $topic_tag_count = wp_count_terms(bbp_get_topic_tag_tax_id(), array('hide_empty' => true)); // Empty tags if (!empty($r['count_empty_tags']) && current_user_can('edit_topic_tags')) { $empty_topic_tag_count = wp_count_terms(bbp_get_topic_tag_tax_id()) - $topic_tag_count; } } // Tally the tallies $statistics = array_map('number_format_i18n', array_map('absint', compact('user_count', 'forum_count', 'topic_count', 'topic_count_hidden', 'reply_count', 'reply_count_hidden', 'topic_tag_count', 'empty_topic_tag_count'))); // Add the hidden (topic/reply) count title attribute strings because we // don't need to run the math functions on these (see above) $statistics['hidden_topic_title'] = isset($hidden_topic_title) ? $hidden_topic_title : ''; $statistics['hidden_reply_title'] = isset($hidden_reply_title) ? $hidden_reply_title : ''; return apply_filters('bbp_get_statistics', $statistics, $r); }
/** * 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')); } }
/** * Register the topic tag taxonomy * * @since bbPress (r2464) * @uses register_taxonomy() To register the taxonomy */ public static function register_taxonomies() { // Register the topic-tag taxonomy register_taxonomy(bbp_get_topic_tag_tax_id(), bbp_get_topic_post_type(), apply_filters('bbp_register_topic_taxonomy', array('labels' => bbp_get_topic_tag_tax_labels(), 'rewrite' => bbp_get_topic_tag_tax_rewrite(), 'capabilities' => bbp_get_topic_tag_caps(), 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'show_tagcloud' => true, 'hierarchical' => false, 'show_in_nav_menus' => false, 'public' => true, 'show_ui' => bbp_allow_topic_tags() && current_user_can('bbp_topic_tags_admin')))); }
/** * bbPress Dashboard Right Now Widget * * Adds a dashboard widget with forum statistics * * @since 2.0.0 bbPress (r2770) * * @deprecated 2.6.0 bbPress (r5268) * * @uses bbp_get_version() To get the current bbPress version * @uses bbp_get_statistics() To get the forum statistics * @uses current_user_can() To check if the user is capable of doing things * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses get_admin_url() To get the administration url * @uses add_query_arg() To add custom args to the url * @uses do_action() Calls 'bbp_dashboard_widget_right_now_content_table_end' * below the content table * @uses do_action() Calls 'bbp_dashboard_widget_right_now_table_end' * below the discussion table * @uses do_action() Calls 'bbp_dashboard_widget_right_now_discussion_table_end' * below the discussion table * @uses do_action() Calls 'bbp_dashboard_widget_right_now_end' below the widget */ function bbp_dashboard_widget_right_now() { // Get the statistics $r = bbp_get_statistics(); ?> <div class="table table_content"> <p class="sub"><?php esc_html_e('Discussion', 'bbpress'); ?> </p> <table> <tr class="first"> <?php $num = $r['forum_count']; $text = _n('Forum', 'Forums', $r['forum_count'], 'bbpress'); if (current_user_can('publish_forums')) { $link = add_query_arg(array('post_type' => bbp_get_forum_post_type()), get_admin_url(null, 'edit.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a href="' . esc_url($link) . '">' . $text . '</a>'; } ?> <td class="first b b-forums"><?php echo $num; ?> </td> <td class="t forums"><?php echo $text; ?> </td> </tr> <tr> <?php $num = $r['topic_count']; $text = _n('Topic', 'Topics', $r['topic_count'], 'bbpress'); if (current_user_can('publish_topics')) { $link = add_query_arg(array('post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a href="' . esc_url($link) . '">' . $text . '</a>'; } ?> <td class="first b b-topics"><?php echo $num; ?> </td> <td class="t topics"><?php echo $text; ?> </td> </tr> <tr> <?php $num = $r['reply_count']; $text = _n('Reply', 'Replies', $r['reply_count'], 'bbpress'); if (current_user_can('publish_replies')) { $link = add_query_arg(array('post_type' => bbp_get_reply_post_type()), get_admin_url(null, 'edit.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a href="' . esc_url($link) . '">' . $text . '</a>'; } ?> <td class="first b b-replies"><?php echo $num; ?> </td> <td class="t replies"><?php echo $text; ?> </td> </tr> <?php if (bbp_allow_topic_tags()) { ?> <tr> <?php $num = $r['topic_tag_count']; $text = _n('Topic Tag', 'Topic Tags', $r['topic_tag_count'], 'bbpress'); if (current_user_can('manage_topic_tags')) { $link = add_query_arg(array('taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit-tags.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a href="' . esc_url($link) . '">' . $text . '</a>'; } ?> <td class="first b b-topic_tags"><span class="total-count"><?php echo $num; ?> </span></td> <td class="t topic_tags"><?php echo $text; ?> </td> </tr> <?php } ?> <?php do_action('bbp_dashboard_widget_right_now_content_table_end'); ?> </table> </div> <div class="table table_discussion"> <p class="sub"><?php esc_html_e('Users & Moderation', 'bbpress'); ?> </p> <table> <tr class="first"> <?php $num = $r['user_count']; $text = _n('User', 'Users', $r['user_count'], 'bbpress'); if (current_user_can('edit_users')) { $link = get_admin_url(null, 'users.php'); $num = '<a href="' . $link . '">' . $num . '</a>'; $text = '<a href="' . $link . '">' . $text . '</a>'; } ?> <td class="b b-users"><span class="total-count"><?php echo $num; ?> </span></td> <td class="last t users"><?php echo $text; ?> </td> </tr> <?php if (isset($r['topic_count_hidden'])) { ?> <tr> <?php $num = $r['topic_count_hidden']; $text = _n('Hidden Topic', 'Hidden Topics', $r['topic_count_hidden'], 'bbpress'); $link = add_query_arg(array('post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit.php')); if ('0' !== $num) { $link = add_query_arg(array('post_status' => bbp_get_spam_status_id()), $link); } $num = '<a href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_topic_title']) . '">' . $num . '</a>'; $text = '<a class="waiting" href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_topic_title']) . '">' . $text . '</a>'; ?> <td class="b b-hidden-topics"><?php echo $num; ?> </td> <td class="last t hidden-replies"><?php echo $text; ?> </td> </tr> <?php } ?> <?php if (isset($r['reply_count_hidden'])) { ?> <tr> <?php $num = $r['reply_count_hidden']; $text = _n('Hidden Reply', 'Hidden Replies', $r['reply_count_hidden'], 'bbpress'); $link = add_query_arg(array('post_type' => bbp_get_reply_post_type()), get_admin_url(null, 'edit.php')); if ('0' !== $num) { $link = add_query_arg(array('post_status' => bbp_get_spam_status_id()), $link); } $num = '<a href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_reply_title']) . '">' . $num . '</a>'; $text = '<a class="waiting" href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_reply_title']) . '">' . $text . '</a>'; ?> <td class="b b-hidden-replies"><?php echo $num; ?> </td> <td class="last t hidden-replies"><?php echo $text; ?> </td> </tr> <?php } ?> <?php if (bbp_allow_topic_tags() && isset($r['empty_topic_tag_count'])) { ?> <tr> <?php $num = $r['empty_topic_tag_count']; $text = _n('Empty Topic Tag', 'Empty Topic Tags', $r['empty_topic_tag_count'], 'bbpress'); $link = add_query_arg(array('taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit-tags.php')); $num = '<a href="' . esc_url($link) . '">' . $num . '</a>'; $text = '<a class="waiting" href="' . esc_url($link) . '">' . $text . '</a>'; ?> <td class="b b-hidden-topic-tags"><?php echo $num; ?> </td> <td class="last t hidden-topic-tags"><?php echo $text; ?> </td> </tr> <?php } ?> <?php do_action('bbp_dashboard_widget_right_now_discussion_table_end'); ?> </table> </div> <?php do_action('bbp_dashboard_widget_right_now_table_end'); ?> <div class="versions"> <span id="wp-version-message"> <?php printf(__('You are using <span class="b">bbPress %s</span>.', 'bbpress'), bbp_get_version()); ?> </span> </div> <br class="clear" /> <?php do_action('bbp_dashboard_widget_right_now_end'); }
/** * Return the tags of a topic * * @param int $topic_id Optional. Topic id * @param array $args This function supports these arguments: * - before: Before the tag list * - sep: Tag separator * - after: After the tag list * @uses bbp_get_topic_id() To get the topic id * @uses get_the_term_list() To get the tags list * @return string Tag list of the topic */ function bbp_get_topic_tag_list($topic_id = 0, $args = '') { // Bail if topic-tags are off if (!bbp_allow_topic_tags()) { return; } $defaults = array('before' => '<div class="bbp-topic-tags"><p>' . __('Tagged:', 'bbpress') . ' ', 'sep' => ', ', 'after' => '</p></div>'); $r = bbp_parse_args($args, $defaults, 'get_topic_tag_list'); extract($r); $topic_id = bbp_get_topic_id($topic_id); // Topic is spammed, so display pre-spam terms if (bbp_is_topic_spam($topic_id)) { // Get pre-spam terms $terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true); // If terms exist, explode them and compile the return value if (!empty($terms)) { $terms = implode($sep, $terms); $retval = $before . $terms . $after; // No terms so return emty string } else { $retval = ''; } // Topic is not spam so display a clickable term list } else { $retval = get_the_term_list($topic_id, bbp_get_topic_tag_tax_id(), $before, $sep, $after); } return $retval; }
/** * Allow topic tags setting field * * @since 2.4.0 bbPress (r4944) * * @uses checked() To display the checked attribute */ function bbp_admin_setting_callback_topic_tags() { ?> <input name="_bbp_allow_topic_tags" id="_bbp_allow_topic_tags" type="checkbox" value="1" <?php checked(bbp_allow_topic_tags(true)); bbp_maybe_admin_setting_disabled('_bbp_allow_topic_tags'); ?> /> <label for="_bbp_allow_topic_tags"><?php esc_html_e('Allow topics to have tags', 'bbpress'); ?> </label> <?php }
<?php if (bbp_is_reply_edit() && bbp_get_reply_author_id() !== bbp_get_current_user_id()) { _e('Notify the author of follow-up replies via email', 'bbpress'); } else { _e('Notify me of follow-up replies via email', 'bbpress'); } ?> </label> </div> <?php } ?> <?php // Moderators can edit topic tags if (current_user_can('moderate') || bbp_allow_topic_tags() && current_user_can('assign_topic_tags')) { ?> <div class="form-left"> <label for="bbp_topic_tags"><i class="fa fa-tags"></i>Topic Tags:</label> <input type="text" value="<?php bbp_form_topic_tags(); ?> " tabindex="<?php bbp_tab_index(); ?> " size="40" name="bbp_topic_tags" id="bbp_topic_tags" <?php disabled(bbp_is_topic_spam()); ?> /> </div> <?php
/** * Allow topic tags setting field * * @since bbPress (r####) * * @uses checked() To display the checked attribute */ function bbp_admin_setting_callback_topic_tags() { ?> <input id="_bbp_allow_topic_tags" name="_bbp_allow_topic_tags" type="checkbox" id="_bbp_allow_topic_tags" value="1" <?php checked(bbp_allow_topic_tags(true)); ?> /> <label for="_bbp_allow_topic_tags"><?php _e('Allow topics to have tags', 'bbpress'); ?> </label> <?php }
/** * Register the topic tag taxonomy * * @since bbPress (r2464) * @uses register_taxonomy() To register the taxonomy */ public static function register_taxonomies() { // Define local variable(s) $topic_tag = array(); // Topic tag labels $topic_tag['labels'] = array('name' => __('Topic Tags', 'bbpress'), 'singular_name' => __('Topic Tag', 'bbpress'), 'search_items' => __('Search Tags', 'bbpress'), 'popular_items' => __('Popular Tags', 'bbpress'), 'all_items' => __('All Tags', 'bbpress'), 'edit_item' => __('Edit Tag', 'bbpress'), 'update_item' => __('Update Tag', 'bbpress'), 'add_new_item' => __('Add New Tag', 'bbpress'), 'new_item_name' => __('New Tag Name', 'bbpress'), 'view_item' => __('View Topic Tag', 'bbpress')); // Topic tag rewrite $topic_tag['rewrite'] = array('slug' => bbp_get_topic_tag_tax_slug(), 'with_front' => false); // Register the topic tag taxonomy register_taxonomy(bbp_get_topic_tag_tax_id(), bbp_get_topic_post_type(), apply_filters('bbp_register_topic_taxonomy', array('labels' => $topic_tag['labels'], 'rewrite' => $topic_tag['rewrite'], 'capabilities' => bbp_get_topic_tag_caps(), 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'show_tagcloud' => true, 'hierarchical' => false, 'public' => true, 'show_ui' => bbp_allow_topic_tags() && current_user_can('bbp_topic_tags_admin')))); }