bbp_close_topic( int $topic_id )

Closes 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_close_topic( $topic_id = 0 ) {

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

	// Bail if already closed
	if ( bbp_get_closed_status_id() === $topic->post_status )
		return false;

	// Execute pre close code
	do_action( 'bbp_close_topic', $topic_id );

	// Add pre close status
	add_post_meta( $topic_id, '_bbp_status', $topic->post_status );

	// Set closed status
	$topic->post_status = bbp_get_closed_status_id();

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

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

	// Execute post close code
	do_action( 'bbp_closed_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.