/wp-content/plugins/bbpress/includes/topics/functions.php
PHP | 3431 lines | 1394 code | 698 blank | 1339 comment | 356 complexity | db1f3a9066c61ae7b7a6d0cdf08ac377 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * bbPress Topic Functions
- *
- * @package bbPress
- * @subpackage Functions
- */
- // Exit if accessed directly
- if ( !defined( 'ABSPATH' ) ) exit;
- /** Insert ********************************************************************/
- /**
- * A wrapper for wp_insert_post() that also includes the necessary meta values
- * for the topic to function properly.
- *
- * @since bbPress (r3349)
- *
- * @uses bbp_parse_args()
- * @uses bbp_get_topic_post_type()
- * @uses wp_insert_post()
- * @uses update_post_meta()
- *
- * @param array $topic_data Forum post data
- * @param arrap $topic_meta Forum meta data
- */
- function bbp_insert_topic( $topic_data = array(), $topic_meta = array() ) {
- // Parse arguments against default values
- $topic_data = bbp_parse_args( $topic_data, array(
- 'post_parent' => 0, // forum ID
- 'post_status' => bbp_get_public_status_id(),
- 'post_type' => bbp_get_topic_post_type(),
- 'post_author' => bbp_get_current_user_id(),
- 'post_password' => '',
- 'post_content' => '',
- 'post_title' => '',
- 'comment_status' => 'closed',
- 'menu_order' => 0,
- ), 'insert_topic' );
- // Insert topic
- $topic_id = wp_insert_post( $topic_data );
- // Bail if no topic was added
- if ( empty( $topic_id ) )
- return false;
- // Parse arguments against default values
- $topic_meta = bbp_parse_args( $topic_meta, array(
- 'author_ip' => bbp_current_author_ip(),
- 'forum_id' => 0,
- 'topic_id' => $topic_id,
- 'voice_count' => 1,
- 'reply_count' => 0,
- 'reply_count_hidden' => 0,
- 'last_reply_id' => 0,
- 'last_active_id' => $topic_id,
- 'last_active_time' => get_post_field( 'post_date', $topic_id, 'db' ),
- ), 'insert_topic_meta' );
- // Insert topic meta
- foreach ( $topic_meta as $meta_key => $meta_value )
- update_post_meta( $topic_id, '_bbp_' . $meta_key, $meta_value );
- // Update the forum
- $forum_id = bbp_get_topic_forum_id( $topic_id );
- if ( !empty( $forum_id ) )
- bbp_update_forum( array( 'forum_id' => $forum_id ) );
- // Return new topic ID
- return $topic_id;
- }
- /** Post Form Handlers ********************************************************/
- /**
- * Handles the front end topic submission
- *
- * @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 referer
- * @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 topic
- * @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 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 bbp_check_for_flood() To check for flooding
- * @uses bbp_check_for_duplicate() To check for duplicates
- * @uses bbp_get_topic_post_type() To get the topic post type
- * @uses remove_filter() To remove kses filters if needed
- * @uses apply_filters() Calls 'bbp_new_topic_pre_title' with the content
- * @uses apply_filters() Calls 'bbp_new_topic_pre_content' with the content
- * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors
- * @uses wp_insert_post() To insert the topic
- * @uses do_action() Calls 'bbp_new_topic' with the topic id, forum id,
- * anonymous data and reply author
- * @uses bbp_stick_topic() To stick or super stick the topic
- * @uses bbp_unstick_topic() To unstick the topic
- * @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_new_topic_handler( $action = '' ) {
- // Bail if action is not bbp-new-topic
- if ( 'bbp-new-topic' !== $action )
- return;
- // Nonce check
- if ( ! bbp_verify_nonce_request( 'bbp-new-topic' ) ) {
- bbp_add_error( 'bbp_new_topic_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
- return;
- }
- // Define local variable(s)
- $view_all = false;
- $forum_id = $topic_author = $anonymous_data = 0;
- $topic_title = $topic_content = '';
- $terms = array( bbp_get_topic_tag_tax_id() => array() );
- /** Topic 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 topics
- if ( !current_user_can( 'publish_topics' ) ) {
- bbp_add_error( 'bbp_topic_permissions', __( '<strong>ERROR</strong>: You do not have permission to create new topics.', 'bbpress' ) );
- return;
- }
- // Topic author is current user
- $topic_author = bbp_get_current_user_id();
- }
- // 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_new' ) == $_POST['_bbp_unfiltered_html_topic'] ) {
- remove_filter( 'bbp_new_topic_pre_title', 'wp_filter_kses' );
- remove_filter( 'bbp_new_topic_pre_content', 'bbp_encode_bad', 10 );
- remove_filter( 'bbp_new_topic_pre_content', 'bbp_filter_kses', 30 );
- }
- /** 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_new_topic_pre_title', $topic_title );
- // No topic title
- if ( empty( $topic_title ) )
- bbp_add_error( 'bbp_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_new_topic_pre_content', $topic_content );
- // No topic content
- if ( empty( $topic_content ) )
- bbp_add_error( 'bbp_topic_content', __( '<strong>ERROR</strong>: Your topic cannot be empty.', 'bbpress' ) );
- /** 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'];
- }
- // Forum exists
- if ( !empty( $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 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_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 Flooding ********************************************************/
- if ( !bbp_check_for_flood( $anonymous_data, $topic_author ) )
- bbp_add_error( 'bbp_topic_flood', __( '<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress' ) );
- /** 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 ) ) )
- bbp_add_error( 'bbp_topic_duplicate', __( '<strong>ERROR</strong>: Duplicate topic detected; it looks as though you’ve already said that!', '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 created at this time.', 'bbpress' ) );
- /** 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 to published
- } else {
- $topic_status = bbp_get_public_status_id();
- }
- /** Topic Tags ************************************************************/
- if ( bbp_allow_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 );
- }
- /** Additional Actions (Before Save) **************************************/
- do_action( 'bbp_new_topic_pre_extras', $forum_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 created
- $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(),
- 'tax_input' => $terms,
- 'comment_status' => 'closed'
- ) );
- // Insert topic
- $topic_id = wp_insert_post( $topic_data );
- /** No Errors *************************************************************/
- if ( !empty( $topic_id ) && !is_wp_error( $topic_id ) ) {
- /** 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 );
- // Force view=all
- $view_all = true;
- }
- /** 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() );
- // Force view=all
- $view_all = true;
- }
- /** Update counts, etc... *********************************************/
- do_action( 'bbp_new_topic', $topic_id, $forum_id, $anonymous_data, $topic_author );
- /** Stickies **********************************************************/
- // Sticky check after 'bbp_new_topic' action so forum ID meta is set
- if ( !empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array( 'stick', 'super', 'unstick' ) ) ) {
- // What's the haps?
- switch ( $_POST['bbp_stick_topic'] ) {
- // Sticky in this forum
- case 'stick' :
- bbp_stick_topic( $topic_id );
- break;
- // Super sticky in all forums
- case 'super' :
- bbp_stick_topic( $topic_id, true );
- break;
- // We can avoid this as it is a new topic
- case 'unstick' :
- default :
- break;
- }
- }
- /** Additional Actions (After Save) ***********************************/
- do_action( 'bbp_new_topic_post_extras', $topic_id );
- /** Redirect **********************************************************/
- // Redirect to
- $redirect_to = bbp_get_redirect_to();
- // Get the topic URL
- $redirect_url = bbp_get_topic_permalink( $topic_id, $redirect_to );
- // Add view all?
- if ( bbp_get_view_all() || !empty( $view_all ) ) {
- // User can moderate, so redirect to topic with view all set
- if ( current_user_can( 'moderate' ) ) {
- $redirect_url = bbp_add_view_all( $redirect_url );
- // User cannot moderate, so redirect to forum
- } else {
- $redirect_url = bbp_get_forum_permalink( $forum_id );
- }
- }
- // Allow to be filtered
- $redirect_url = apply_filters( 'bbp_new_topic_redirect_to', $redirect_url, $redirect_to, $topic_id );
- /** Successful Save ***************************************************/
- // Redirect back to new topic
- wp_safe_redirect( $redirect_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, 'bbpress' ) );
- }
- }
- /**
- * Handles the front end edit topic submission
- *
- * @param string $action The requested action to compare this function to
- * @uses bbp_add_error() To add an error message
- * @uses bbp_get_topic() To get the topic
- * @uses bbp_verify_nonce_request() To verify the nonce and check the request
- * @uses bbp_is_topic_anonymous() To check if topic is by an anonymous user
- * @uses current_user_can() To check if the current user can edit the topic
- * @uses bbp_filter_anonymous_post_data() To filter anonymous data
- * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
- * @uses esc_attr() For sanitization
- * @uses bbp_is_forum_category() To check if the forum is a category
- * @uses bbp_is_forum_closed() To check if the forum is closed
- * @uses bbp_is_forum_private() To check if the forum is private
- * @uses remove_filter() To remove kses filters if needed
- * @uses apply_filters() Calls 'bbp_edit_topic_pre_title' with the title and
- * topic id
- * @uses apply_filters() Calls 'bbp_edit_topic_pre_content' with the content
- * and topic id
- * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors
- * @uses wp_save_post_revision() To save a topic revision
- * @uses bbp_update_topic_revision_log() To update the topic revision log
- * @uses bbp_stick_topic() To stick or super stick the topic
- * @uses bbp_unstick_topic() To unstick the topic
- * @uses wp_update_post() To update the topic
- * @uses do_action() Calls 'bbp_edit_topic' with the topic id, forum id,
- * anonymous data and reply author
- * @uses bbp_move_topic_handler() To handle movement of a topic from one forum
- * to another
- * @uses bbp_get_topic_permalink() To get the topic permalink
- * @uses wp_safe_redirect() To redirect to the topic link
- * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error
- * messages
- */
- function bbp_edit_topic_handler( $action = '' ) {
- // Bail if action is not bbp-edit-topic
- if ( 'bbp-edit-topic' !== $action )
- return;
- // Define local variable(s)
- $revisions_removed = false;
- $topic = $topic_id = $topic_author = $forum_id = $anonymous_data = 0;
- $topic_title = $topic_content = $topic_edit_reason = '';
- /** Topic *****************************************************************/
- // Topic id was not passed
- if ( empty( $_POST['bbp_topic_id'] ) ) {
- bbp_add_error( 'bbp_edit_topic_id', __( '<strong>ERROR</strong>: Topic ID not found.', 'bbpress' ) );
- return;
- // Topic id was passed
- } elseif ( is_numeric( $_POST['bbp_topic_id'] ) ) {
- $topic_id = (int) $_POST['bbp_topic_id'];
- $topic = bbp_get_topic( $topic_id );
- }
- // Topic does not exist
- if ( empty( $topic ) ) {
- bbp_add_error( 'bbp_edit_topic_not_found', __( '<strong>ERROR</strong>: The topic you want to edit was not found.', 'bbpress' ) );
- return;
- // Topic exists
- } else {
- // Check users ability to create new topic
- if ( ! bbp_is_topic_anonymous( $topic_id ) ) {
- // User cannot edit this topic
- if ( !current_user_can( 'edit_topic', $topic_id ) ) {
- bbp_add_error( 'bbp_edit_topic_permissions', __( '<strong>ERROR</strong>: You do not have permission to edit that topic.', 'bbpress' ) );
- }
- // Set topic author
- $topic_author = bbp_get_topic_author_id( $topic_id );
- // It is an anonymous post
- } else {
- // Filter anonymous data
- $anonymous_data = bbp_filter_anonymous_post_data( array(), true );
- }
- }
- // Nonce check
- if ( ! bbp_verify_nonce_request( 'bbp-edit-topic_' . $topic_id ) ) {
- bbp_add_error( 'bbp_edit_topic_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
- return;
- }
- // Remove kses filters from title and content for capable users and if the nonce is verified
- if ( current_user_can( 'unfiltered_html' ) && !empty( $_POST['_bbp_unfiltered_html_topic'] ) && ( wp_create_nonce( 'bbp-unfiltered-html-topic_' . $topic_id ) == $_POST['_bbp_unfiltered_html_topic'] ) ) {
- remove_filter( 'bbp_edit_topic_pre_title', 'wp_filter_kses' );
- remove_filter( 'bbp_edit_topic_pre_content', 'bbp_encode_bad', 10 );
- remove_filter( 'bbp_edit_topic_pre_content', 'bbp_filter_kses', 30 );
- }
- /** Topic Forum ***********************************************************/
- // Forum id was not passed
- if ( empty( $_POST['bbp_forum_id'] ) ) {
- bbp_add_error( 'bbp_topic_forum_id', __( '<strong>ERROR</strong>: Forum ID is missing.', 'bbpress' ) );
- // Forum id was passed
- } elseif ( is_numeric( $_POST['bbp_forum_id'] ) ) {
- $forum_id = (int) $_POST['bbp_forum_id'];
- }
- // Current forum this topic is in
- $current_forum_id = bbp_get_topic_forum_id( $topic_id );
- // Forum exists
- if ( !empty( $forum_id ) && ( $forum_id !== $current_forum_id ) ) {
- // Forum is a category
- if ( bbp_is_forum_category( $forum_id ) ) {
- bbp_add_error( 'bbp_edit_topic_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No topics can be created in it.', 'bbpress' ) );
- // Forum is not a category
- } else {
- // Forum is closed and user cannot access
- if ( bbp_is_forum_closed( $forum_id ) && !current_user_can( 'edit_forum', $forum_id ) ) {
- bbp_add_error( 'bbp_edit_topic_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress' ) );
- }
- // Forum is private and user cannot access
- if ( bbp_is_forum_private( $forum_id ) ) {
- if ( !current_user_can( 'read_private_forums' ) ) {
- bbp_add_error( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
- }
- // Forum is hidden and user cannot access
- } elseif ( bbp_is_forum_hidden( $forum_id ) ) {
- if ( !current_user_can( 'read_hidden_forums' ) ) {
- bbp_add_error( 'bbp_edit_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
- }
- }
- }
- }
- /** Topic Title ***********************************************************/
- if ( !empty( $_POST['bbp_topic_title'] ) )
- $topic_title = esc_attr( strip_tags( $_POST['bbp_topic_title'] ) );
- // Filter and sanitize
- $topic_title = apply_filters( 'bbp_edit_topic_pre_title', $topic_title, $topic_id );
- // No topic title
- if ( empty( $topic_title ) )
- bbp_add_error( 'bbp_edit_topic_title', __( '<strong>ERROR</strong>: Your topic needs a title.', 'bbpress' ) );
- /** Topic Content *********************************************************/
- if ( !empty( $_POST['bbp_topic_content'] ) )
- $topic_content = $_POST['bbp_topic_content'];
- // Filter and sanitize
- $topic_content = apply_filters( 'bbp_edit_topic_pre_content', $topic_content, $topic_id );
- // No topic content
- if ( empty( $topic_content ) )
- bbp_add_error( 'bbp_edit_topic_content', __( '<strong>ERROR</strong>: Your topic cannot be empty.', 'bbpress' ) );
- /** Topic Blacklist *******************************************************/
- if ( !bbp_check_for_blacklist( $anonymous_data, $topic_author, $topic_title, $topic_content ) )
- bbp_add_error( 'bbp_topic_blacklist', __( '<strong>ERROR</strong>: Your topic cannot be edited at this time.', 'bbpress' ) );
- /** Topic Status **********************************************************/
- // Maybe put into moderation
- if ( !bbp_check_for_moderation( $anonymous_data, $topic_author, $topic_title, $topic_content ) ) {
- // Set post status to pending if public or closed
- if ( in_array( $topic->post_status, array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ) ) {
- $topic_status = bbp_get_pending_status_id();
- }
- // 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 /* Is edit */ );
- /** 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( 'stick', 'super', 'unstick' ) ) ) {
- // What's the dilly?
- switch ( $_POST['bbp_stick_topic'] ) {
- // Sticky in forum
- case 'stick' :
- bbp_stick_topic( $topic_id );
- break;
- // Sticky in all forums
- case 'super' :
- bbp_stick_topic( $topic_id, true );
- break;
- // 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' ) );
- }
- }
- /**
- * Handle all the extra meta stuff from posting a new topic
- *
- * @param int $topic_id Optional. Topic id
- * @param int $forum_id Optional. Forum id
- * @param bool|array $anonymous_data Optional logged-out user data.
- * @param int $author_id Author id
- * @param bool $is_edit Optional. Is the post being edited? Defaults to false.
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_forum_id() To get the forum id
- * @uses bbp_get_current_user_id() To get the current user id
- * @yses bbp_get_topic_forum_id() To get the topic forum id
- * @uses update_post_meta() To update the topic metas
- * @uses set_transient() To update the flood check transient for the ip
- * @uses bbp_update_user_last_posted() To update the users last posted time
- * @uses bbp_is_subscriptions_active() To check if the subscriptions feature is
- * activated or not
- * @uses bbp_is_user_subscribed() To check if the user is subscribed
- * @uses bbp_remove_user_subscription() To remove the user's subscription
- * @uses bbp_add_user_subscription() To add the user's subscription
- * @uses bbp_update_topic_forum_id() To update the topic's forum id
- * @uses bbp_update_topic_topic_id() To update the topic's topic id
- * @uses bbp_update_topic_last_reply_id() To update the last reply id topic meta
- * @uses bbp_update_topic_last_active_id() To update the topic last active id
- * @uses bbp_update_topic_last_active_time() To update the last active topic meta
- * @uses bbp_update_topic_reply_count() To update the topic reply count
- * @uses bbp_update_topic_reply_count_hidden() To udpate the topic hidden reply count
- * @uses bbp_update_topic_voice_count() To update the topic voice count
- * @uses bbp_update_topic_walker() To udpate the topic's ancestors
- */
- function bbp_update_topic( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false ) {
- // Validate the ID's passed from 'bbp_new_topic' action
- $topic_id = bbp_get_topic_id( $topic_id );
- $forum_id = bbp_get_forum_id( $forum_id );
- // Bail if there is no topic
- if ( empty( $topic_id ) )
- return;
- // Check author_id
- if ( empty( $author_id ) )
- $author_id = bbp_get_current_user_id();
- // Check forum_id
- if ( empty( $forum_id ) )
- $forum_id = bbp_get_topic_forum_id( $topic_id );
- // If anonymous post, store name, email, website and ip in post_meta.
- // It expects anonymous_data to be sanitized.
- // Check bbp_filter_anonymous_post_data() for sanitization.
- if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) {
- // Parse arguments against default values
- $r = bbp_parse_args( $anonymous_data, array(
- 'bbp_anonymous_name' => '',
- 'bbp_anonymous_email' => '',
- 'bbp_anonymous_website' => '',
- ), 'update_topic' );
- // Update all anonymous metas
- foreach( $r as $anon_key => $anon_value ) {
- update_post_meta( $topic_id, '_' . $anon_key, (string) $anon_value, false );
- }
- // Set transient for throttle check (only on new, not edit)
- if ( empty( $is_edit ) ) {
- set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time() );
- }
- } else {
- if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) {
- bbp_update_user_last_posted( $author_id );
- }
- }
- // Handle Subscription Checkbox
- if ( bbp_is_subscriptions_active() && !empty( $author_id ) ) {
- $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
- $subscheck = ( !empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' == $_POST['bbp_topic_subscription'] ) ) ? true : false;
- // Subscribed and unsubscribing
- if ( true == $subscribed && false == $subscheck ) {
- bbp_remove_user_subscription( $author_id, $topic_id );
- // Subscribing
- } elseif ( false == $subscribed && true == $subscheck ) {
- bbp_add_user_subscription( $author_id, $topic_id );
- }
- }
- // Forum topic meta
- bbp_update_topic_forum_id( $topic_id, $forum_id );
- bbp_update_topic_topic_id( $topic_id, $topic_id );
- // Update associated topic values if this is a new topic
- if ( empty( $is_edit ) ) {
- // Update poster IP if not editing
- update_post_meta( $topic_id, '_bbp_author_ip', bbp_current_author_ip(), false );
- // Last active time
- $last_active = current_time( 'mysql' );
- // Reply topic meta
- bbp_update_topic_last_reply_id ( $topic_id, 0 );
- bbp_update_topic_last_active_id ( $topic_id, $topic_id );
- bbp_update_topic_last_active_time ( $topic_id, $last_active );
- bbp_update_topic_reply_count ( $topic_id, 0 );
- bbp_update_topic_reply_count_hidden ( $topic_id, 0 );
- bbp_update_topic_voice_count ( $topic_id );
- // Walk up ancestors and do the dirty work
- bbp_update_topic_walker( $topic_id, $last_active, $forum_id, 0, false );
- }
- }
- /**
- * Walks up the post_parent tree from the current topic_id, and updates the
- * counts of forums above it. This calls a few internal functions that all run
- * manual queries against the database to get their results. As such, this
- * function can be costly to run but is necessary to keep everything accurate.
- *
- * @since bbPress (r2800)
- * @param int $topic_id Topic id
- * @param string $last_active_time Optional. Last active time
- * @param int $forum_id Optional. Forum id
- * @param int $reply_id Optional. Reply id
- * @param bool $refresh Reset all the previous parameters? Defaults to true.
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_topic_forum_id() To get the topic forum id
- * @uses get_post_ancestors() To get the topic's ancestors
- * @uses bbp_is_forum() To check if the ancestor is a forum
- * @uses bbp_update_forum() To update the forum
- */
- function bbp_update_topic_walker( $topic_id, $last_active_time = '', $forum_id = 0, $reply_id = 0, $refresh = true ) {
- // Validate topic_id
- $topic_id = bbp_get_topic_id( $topic_id );
- // Define local variable(s)
- $active_id = 0;
- // Topic was passed
- if ( !empty( $topic_id ) ) {
- // Get the forum ID if none was passed
- if ( empty( $forum_id ) ) {
- $forum_id = bbp_get_topic_forum_id( $topic_id );
- }
- // Set the active_id based on topic_id/reply_id
- $active_id = empty( $reply_id ) ? $topic_id : $reply_id;
- }
- // Get topic ancestors
- $ancestors = array_values( array_unique( array_merge( array( $forum_id ), (array) get_post_ancestors( $topic_id ) ) ) );
- // Topic status
- $topic_status = get_post_status( $topic_id );
- // If we want a full refresh, unset any of the possibly passed variables
- if ( true == $refresh ) {
- $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
- $topic_status = bbp_get_public_status_id();
- }
- // Loop through ancestors
- if ( !empty( $ancestors ) ) {
- foreach ( $ancestors as $ancestor ) {
- // If ancestor is a forum, update counts
- if ( bbp_is_forum( $ancestor ) ) {
- // Update the forum
- bbp_update_forum( array(
- 'forum_id' => $ancestor,
- 'last_topic_id' => $topic_id,
- 'last_reply_id' => $reply_id,
- 'last_active_id' => $active_id,
- 'last_active_time' => 0,
- 'last_active_status' => $topic_status
- ) );
- }
- }
- }
- }
- /**
- * Handle the moving of a topic from one forum to another. This includes walking
- * up the old and new branches and updating the counts.
- *
- * @param int $topic_id Topic id
- * @param int $old_forum_id Old forum id
- * @param int $new_forum_id New forum id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_forum_id() To get the forum id
- * @uses bbp_get_stickies() To get the old forums sticky topics
- * @uses delete_post_meta() To delete the forum sticky meta
- * @uses update_post_meta() To update the old forum sticky meta
- * @uses bbp_stick_topic() To stick the topic in the new forum
- * @uses bbp_get_reply_post_type() To get the reply post type
- * @uses bbp_get_all_child_ids() To get the public child ids
- * @uses bbp_update_reply_forum_id() To update the reply forum id
- * @uses bbp_update_topic_forum_id() To update the topic forum id
- * @uses get_post_ancestors() To get the topic's ancestors
- * @uses bbp_is_forum() To check if the ancestor is a forum
- * @uses bbp_update_forum() To update the forum
- */
- function bbp_move_topic_handler( $topic_id, $old_forum_id, $new_forum_id ) {
- // Validate parameters
- $topic_id = bbp_get_topic_id( $topic_id );
- $old_forum_id = bbp_get_forum_id( $old_forum_id );
- $new_forum_id = bbp_get_forum_id( $new_forum_id );
- // Update topic forum's ID
- bbp_update_topic_forum_id( $topic_id, $new_forum_id );
- /** Stickies **************************************************************/
- // Get forum stickies
- $old_stickies = bbp_get_stickies( $old_forum_id );
- // Only proceed if stickies are found
- if ( !empty( $old_stickies ) ) {
- // Define local variables
- $updated_stickies = array();
- // Loop through stickies of forum and add misses to the updated array
- foreach ( (array) $old_stickies as $sticky_topic_id ) {
- if ( $topic_id != $sticky_topic_id ) {
- $updated_stickies[] = $sticky_topic_id;
- }
- }
- // If stickies are different, update or delete them
- if ( $updated_stickies != $old_stickies ) {
- // No more stickies so delete the meta
- if ( empty( $updated_stickies ) ) {
- delete_post_meta( $old_forum_id, '_bbp_sticky_topics' );
- // Still stickies so update the meta
- } else {
- update_post_meta( $old_forum_id, '_bbp_sticky_topics', $updated_stickies );
- }
- // Topic was sticky, so restick in new forum
- bbp_stick_topic( $topic_id );
- }
- }
- /** Topic Replies *********************************************************/
- // Get the topics replies
- $replies = bbp_get_all_child_ids( $topic_id, bbp_get_reply_post_type() );
- // Update the forum_id of all replies in the topic
- foreach ( $replies as $reply_id ) {
- bbp_update_reply_forum_id( $reply_id, $new_forum_id );
- }
- /** Old forum_id **********************************************************/
- // Get topic ancestors
- $old_forum_ancestors = array_values( array_unique( array_merge( array( $old_forum_id ), (array) get_post_ancestors( $old_forum_id ) ) ) );
- // Loop through ancestors and update them
- if ( !empty( $old_forum_ancestors ) ) {
- foreach ( $old_forum_ancestors as $ancestor ) {
- if ( bbp_is_forum( $ancestor ) ) {
- bbp_update_forum( array(
- 'forum_id' => $ancestor,
- ) );
- }
- }
- }
- /** New forum_id **********************************************************/
- // Make sure we're not walking twice
- if ( !in_array( $new_forum_id, $old_forum_ancestors ) ) {
- // Get topic ancestors
- $new_forum_ancestors = array_values( array_unique( array_merge( array( $new_forum_id ), (array) get_post_ancestors( $new_forum_id ) ) ) );
- // Make sure we're not walking twice
- $new_forum_ancestors = array_diff( $new_forum_ancestors, $old_forum_ancestors );
- // Loop through ancestors and update them
- if ( !empty( $new_forum_ancestors ) ) {
- foreach ( $new_forum_ancestors as $ancestor ) {
- if ( bbp_is_forum( $ancestor ) ) {
- bbp_update_forum( array(
- 'forum_id' => $ancestor,
- ) );
- }
- }
- }
- }
- }
- /**
- * Merge topic handler
- *
- * Handles the front end merge topic submission
- *
- * @since bbPress (r2756)
- *
- * @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 topics
- * @uses bbp_verify_nonce_request() To verify the nonce and check the request
- * @uses current_user_can() To check if the current user can edit the topics
- * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
- * @uses do_action() Calls 'bbp_merge_topic' with the destination and source
- * topic ids
- * @uses bbp_get_topic_subscribers() To get the source topic subscribers
- * @uses bbp_add_user_subscription() To add the user subscription
- * @uses bbp_remove_user_subscription() To remove the user subscription
- * @uses bbp_get_topic_favoriters() To get the source topic favoriters
- * @uses bbp_add_user_favorite() To add the user favorite
- * @uses bbp_remove_user_favorite() To remove the user favorite
- * @uses wp_get_post_terms() To get the source topic tags
- * @uses wp_set_post_terms() To set the topic tags
- * @uses wp_delete_object_term_relationships() To delete the topic tags
- * @uses bbp_open_topic() To open the topic
- * @uses bbp_unstick_topic() To unstick the topic
- * @uses bbp_get_reply_post_type() To get the reply post type
- * @uses get_posts() To get the replies
- * @uses wp_update_post() To update the topic
- * @uses bbp_update_reply_topic_id() To update the reply topic id
- * @uses bbp_get_topic_forum_id() To get the topic forum id
- * @uses bbp_update_reply_forum_id() To update the reply forum id
- * @uses do_action() Calls 'bbp_merged_topic_reply' with the reply id and
- * destination topic id
- * @uses do_action() Calls 'bbp_merged_topic' with the destination and source
- * topic ids and source topic's forum id
- * @uses bbp_get_topic_permalink() To get the topic permalink
- * @uses wp_safe_redirect() To redirect to the topic link
- */
- function bbp_merge_topic_handler( $action = '' ) {
- // Bail if action is not bbp-merge-topic
- if ( 'bbp-merge-topic' !== $action )
- return;
- // Define local variable(s)
- $source_topic_id = $destination_topic_id = 0;
- $source_topic = $destination_topic = 0;
- $subscribers = $favoriters = $replies = array();
- /** Source Topic **********************************************************/
- // Topic id
- if ( empty( $_POST['bbp_topic_id'] ) ) {
- bbp_add_error( 'bbp_merge_topic_source_id', __( '<strong>ERROR</strong>: Topic ID not found.', 'bbpress' ) );
- } else {
- $source_topic_id = (int) $_POST['bbp_topic_id'];
- }
- // Nonce check
- if ( ! bbp_verify_nonce_request( 'bbp-merge-topic_' . $source_topic_id ) ) {
- bbp_add_error( 'bbp_merge_topic_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
- return;
- // Source topic not found
- } elseif ( !$source_topic = bbp_get_topic( $source_topic_id ) ) {
- bbp_add_error( 'bbp_merge_topic_source_not_found', __( '<strong>ERROR</strong>: The topic you want to merge was not found.', 'bbpress' ) );
- return;
- }
- // Cannot edit source topic
- if ( !current_user_can( 'edit_topic', $source_topic->ID ) ) {
- bbp_add_error( 'bbp_merge_topic_source_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the source topic.', 'bbpress' ) );
- return;
- }
- /** Destination Topic *****************************************************/
- // Topic id
- if ( empty( $_POST['bbp_destination_topic'] ) )
- bbp_add_error( 'bbp_merge_topic_destination_id', __( '<strong>ERROR</strong>: Destination topic ID not found.', 'bbpress' ) );
- else
- $destination_topic_id = (int) $_POST['bbp_destination_topic'];
- // Destination topic not found
- if ( !$destination_topic = bbp_get_topic( $destination_topic_id ) )
- bbp_add_error( 'bbp_merge_topic_destination_not_found', __( '<strong>ERROR</strong>: The topic you want to merge to was not found.', 'bbpress' ) );
- // Cannot edit destination topic
- if ( !current_user_can( 'edit_topic', $destination_topic->ID ) )
- bbp_add_error( 'bbp_merge_topic_destination_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the destination topic.', 'bbpress' ) );
- // Bail if errors
- if ( bbp_has_errors() )
- return;
- /** No Errors *************************************************************/
- // Update counts, etc...
- do_action( 'bbp_merge_topic', $destination_topic->ID, $source_topic->ID );
- /** Date Check ************************************************************/
- // Check if the destination topic is older than the source topic
- if ( strtotime( $source_topic->post_date ) < strtotime( $destination_topic->post_date ) ) {
- // Set destination topic post_date to 1 second before source topic
- $destination_post_date = date( 'Y-m-d H:i:s', strtotime( $source_topic->post_date ) - 1 );
- $postarr = array(
- 'ID' => $destination_topic_id,
- 'post_date' => $destination_post_date,
- 'post_date_gmt' => get_gmt_from_date( $destination_post_date )
- );
- // Update destination topic
- wp_update_post( $postarr );
- }
- /** Subscriptions *********************************************************/
- // Get subscribers from source topic
- $subscribers = bbp_get_topic_subscribers( $source_topic->ID );
- // Remove the topic from everybody's subscriptions
- if ( !empty( $subscribers ) ) {
- // Loop through each user
- foreach ( (array) $subscribers as $subscriber ) {
- // Shift the subscriber if told to
- if ( !empty( $_POST['bbp_topic_subscribers'] ) && ( 1 == $_POST['bbp_topic_subscribers'] ) && bbp_is_subscriptions_active() )
- bbp_add_user_subscription( $subscriber, $destination_topic->ID );
- // Remove old subscription
- bbp_remove_user_subscription( $subscriber, $source_topic->ID );
- }
- }
- /** Favorites *************************************************************/
- // Get favoriters from source topic
- $favoriters = bbp_get_topic_favoriters( $source_topic->ID );
- // Remove the topic from everybody's favorites
- if ( !empty( $favoriters ) ) {
- // Loop through each user
- foreach ( (array) $favoriters as $favoriter ) {
- // Shift the favoriter if told to
- if ( !empty( $_POST['bbp_topic_favoriters'] ) && 1 == $_POST['bbp_topic_favoriters'] )
- bbp_add_user_favorite( $favoriter, $destination_topic->ID );
- // Remove old favorite
- bbp_remove_user_favorite( $favoriter, $source_topic->ID );
- }
- }
- /** Tags ******************************************************************/
- // Get the source topic tags
- $source_topic_tags = wp_get_post_terms( $source_topic->ID, bbp_get_topic_tag_tax_id(), array( 'fields' => 'names' ) );
- // Tags to possibly merge
- if ( !empty( $source_topic_tags ) && !is_wp_error( $source_topic_tags ) ) {
- // Shift the tags if told to
- if ( !empty( $_POST['bbp_topic_tags'] ) && ( 1 == $_POST['bbp_topic_tags'] ) )
- wp_set_post_terms( $destination_topic->ID, $source_topic_tags, bbp_get_topic_tag_tax_id(), true );
- // Delete the tags from the source topic
- wp_delete_object_term_relationships( $source_topic->ID, bbp_get_topic_tag_tax_id() );
- }
- /** Source Topic **********************************************************/
- // Status
- bbp_open_topic( $source_topic->ID );
- // Sticky
- bbp_unstick_topic( $source_topic->ID );
- // Get the replies of the source topic
- $replies = (array) get_posts( array(
- 'post_parent' => $source_topic->ID,
- 'post_type' => bbp_get_reply_post_type(),
- 'posts_per_page' => -1,
- 'order' => 'ASC'
- ) );
- // Prepend the source topic to its replies array for processing
- array_unshift( $replies, $source_topic );
- if ( !empty( $replies ) ) {
- /** Merge Replies *****************************************************/
- // Change the post_parent of each reply to the destination topic id
- foreach ( $replies as $reply ) {
- $postarr = array(
- 'ID' => $reply->ID,
- 'post_title' => sprintf( __( 'Reply To: %s', 'bbpress' ), $destination_topic->post_title ),
- 'post_name' => false,
- 'post_type' => bbp_get_reply_post_type(),
- 'post_parent' => $destination_topic->ID,
- 'guid' => ''
- );
- wp_update_post( $postarr );
- // Adjust reply meta values
- bbp_update_reply_topic_id( $reply->ID, $destination_topic->ID );
- bbp_update_reply_forum_id( $reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) );
- // Do additional actions per merged reply
- do_action( 'bbp_merged_topic_reply', $reply->ID, $destination_topic->ID );
- }
- }
- /** Successful Merge ******************************************************/
- // Update topic's last meta data
- bbp_update_topic_last_reply_id ( $destination_topic->ID );
- bbp_update_topic_last_active_id ( $destination_topic->ID );
- bbp_update_topic_last_active_time( $destination_topic->ID );
- // Send the post parent of the source topic as it has been shifted
- // (possibly to a new forum) so we need to update the counts of the
- // old forum as well as the new one
- do_action( 'bbp_merged_topic', $destination_topic->ID, $source_topic->ID, $source_topic->post_parent );
- // Redirect back to new topic
- wp_safe_redirect( bbp_get_topic_permalink( $destination_topic->ID ) );
- // For good measure
- exit();
- }
- /**
- * Fix counts on topic merge
- *
- * When a topic is merged, update the counts of source and destination topic
- * and their forums.
- *
- * @since bbPress (r2756)
- *
- * @param int $destination_topic_id Destination topic id
- * @param int $source_topic_id Source topic id
- * @param int $source_topic_forum Source topic's forum id
- * @uses bbp_update_forum_topic_count() To update the forum topic counts
- * @uses bbp_update_forum_reply_count() To update the forum reply counts
- * @uses bbp_update_topic_reply_count() To update the topic reply counts
- * @uses bbp_update_topic_voice_count() To update the topic voice counts
- * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
- * count
- * @uses do_action() Calls 'bbp_merge_topic_count' with the destination topic
- * id, source topic id & source topic forum id
- */
- function bbp_merge_topic_count( $destination_topic_id, $source_topic_id, $source_topic_forum_id ) {
- /** Source Topic **********************************************************/
- // Forum Topic Counts
- bbp_update_forum_topic_count( $source_topic_forum_id );
- // Forum Reply Counts
- bbp_update_forum_reply_count( $source_topic_forum_id );
- /** Destination Topic *****************************************************/
- // Topic Reply Counts
- bbp_update_topic_reply_count( $destination_topic_id );
- // Topic Hidden Reply Counts
- bbp_update_topic_reply_count_hidden( $destination_topic_id );
- // Topic Voice Counts
- bbp_update_topic_voice_count( $destination_topic_id );
- do_action( 'bbp_merge_topic_count', $destination_topic_id, $source_topic_id, $source_topic_forum_id );
- }
- /**
- * Split topic handler
- *
- * Handles the front end split topic submission
- *
- * @since bbPress (r2756)
- *
- * @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_get_topic() To get the topics
- * @uses bbp_verify_nonce_request() To verify the nonce and check the request
- * @uses current_user_can() To check if the current user can edit the topics
- * @uses bbp_get_topic_post_type() To get the topic post type
- * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
- * @uses do_action() Calls 'bbp_pre_split_topic' with the from reply id, source
- * and destination topic ids
- * @uses bbp_get_topic_subscribers() To get the source topic subscribers
- * @uses bbp_add_user_subscription() To add the user subscription
- * @uses bbp_get_topic_favoriters() To get the source topic favoriters
- * @uses bbp_add_user_favorite() To add the user favorite
- * @uses…
Large files files are truncated, but you can click here to view the full file