bbp_delete_topic( $topic_id )
Called before deleting a topic.
Description
This function is supplemental to the actual topic deletion which is handled by WordPress core API functions. It is used to clean up after a topic that is being deleted.
Source
File: bp-forums/topics/functions.php
function bbp_delete_topic( $topic_id = 0 ) { // Validate topic ID $topic_id = bbp_get_topic_id( $topic_id ); if ( empty( $topic_id ) || !bbp_is_topic( $topic_id ) ) return false; do_action( 'bbp_delete_topic', $topic_id ); // Topic is being permanently deleted, so its replies gotta go too // Note that we get all post statuses here $replies = new WP_Query( array( 'suppress_filters' => true, 'post_type' => bbp_get_reply_post_type(), 'post_status' => array_keys( get_post_stati() ), 'post_parent' => $topic_id, 'posts_per_page' => -1, 'nopaging' => true, 'fields' => 'id=>parent' ) ); // Loop through and delete child replies if ( ! empty( $replies->posts ) ) { foreach ( $replies->posts as $reply ) { wp_delete_post( $reply->ID, true ); } // Reset the $post global wp_reset_postdata(); } // Cleanup unset( $replies ); }
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.