bbp_close_topic( int $topic_id )
Closes a topic
Description Description
Parameters Parameters
- $topic_id
-
(Required) Topic id
Return Return
(mixed) False or WP_Error on failure, topic id on success
Source Source
File: includes/topics/functions.php
function bbp_close_topic( $topic_id = 0 ) {
// Get topic
$topic = bbp_get_topic( $topic_id );
if ( empty( $topic ) ) {
return $topic;
}
// Get previous topic status meta
$status = bbp_get_closed_status_id();
$topic_status = get_post_meta( $topic_id, '_bbp_status', true );
// Bail if already closed and topic status meta exists
if ( $status === $topic->post_status && ! empty( $topic_status ) ) {
return false;
}
// Set status meta public
$topic_status = $topic->post_status;
// Execute pre close code
do_action( 'bbp_close_topic', $topic_id );
// Add pre close status
add_post_meta( $topic_id, '_bbp_status', $topic_status );
// Set closed status
$topic->post_status = $status;
// Toggle revisions off as we are not altering content
if ( post_type_supports( bbp_get_topic_post_type(), 'revisions' ) ) {
$revisions_removed = true;
remove_post_type_support( bbp_get_topic_post_type(), 'revisions' );
}
// Update topic
$topic_id = wp_update_post( $topic );
// Toggle revisions back on
if ( true === $revisions_removed ) {
$revisions_removed = false;
add_post_type_support( bbp_get_topic_post_type(), 'revisions' );
}
// Execute post close code
do_action( 'bbp_closed_topic', $topic_id );
// Return topic_id
return $topic_id;
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |