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
3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 | 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.