bbp_unspam_topic( int $topic_id )

Unspams a topic

Description

Parameters

$topic_id

(int) (Required) Topic id

Return

(mixed) False or WP_Error on failure, topic id on success

Source

File: bp-forums/topics/functions.php

function bbp_unspam_topic( $topic_id = 0 ) {

	// Get the topic
	$topic = bbp_get_topic( $topic_id );
	if ( empty( $topic ) )
		return $topic;

	// Bail if already not spam
	if ( bbp_get_spam_status_id() !== $topic->post_status )
		return false;

	// Execute pre unspam code
	do_action( 'bbp_unspam_topic', $topic_id );

	/** Untrash Replies *******************************************************/

	// Get the replies that were not previously trashed
	$pre_spammed_replies = get_post_meta( $topic_id, '_bbp_pre_spammed_replies', true );

	// There are replies to untrash
	if ( !empty( $pre_spammed_replies ) ) {

		// Maybe reverse the trashed replies array
		if ( is_array( $pre_spammed_replies ) )
			$pre_spammed_replies = array_reverse( $pre_spammed_replies );

		// Loop through replies
		foreach ( (array) $pre_spammed_replies as $reply ) {
			wp_untrash_post( $reply );
		}
	}

	/** Topic Tags ************************************************************/

	// Get pre-spam topic tags
	$terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true );

	// Topic had tags before it was spammed
	if ( !empty( $terms ) ) {

		// Set the tax_input of the topic
		$topic->tax_input = array( bbp_get_topic_tag_tax_id() => $terms );

		// Delete pre-spam topic tag meta
		delete_post_meta( $topic_id, '_bbp_spam_topic_tags' );
	}

	/** Topic Status **********************************************************/

	// Get pre spam status
	$topic_status = get_post_meta( $topic_id, '_bbp_spam_meta_status', true );

	// If no previous status, default to publish
	if ( empty( $topic_status ) ) {
		$topic_status = bbp_get_public_status_id();
	}

	// Set post status to pre spam
	$topic->post_status = $topic_status;

	// Delete pre spam meta
	delete_post_meta( $topic_id, '_bbp_spam_meta_status' );

	// No revisions
	remove_action( 'pre_post_update', 'wp_save_post_revision' );

	// Update the topic
	$topic_id = wp_update_post( $topic );

	// Execute post unspam code
	do_action( 'bbp_unspammed_topic', $topic_id );

	// Return topic_id
	return $topic_id;
}

Changelog

Changelog
Version Description
bbPress (r2740) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.