bbp_close_topic( int $topic_id )

Closes a topic

Description

Parameters

$topic_id

(Required) Topic id

Return

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

Source

File: bp-forums/topics/functions.php

2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
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.