bbp_trash_forum_topics( int $forum_id )
Trash all topics inside a forum
Description
Parameters
- $forum_id
-
(Required)
Return
(If) forum is not valid
Source
File: bp-forums/forums/functions.php
2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 | function bbp_trash_forum_topics( $forum_id = 0 ) { // Validate forum ID $forum_id = bbp_get_forum_id( $forum_id ); if ( empty ( $forum_id ) ) return ; // Allowed post statuses to pre-trash $post_stati = implode( ',' , array ( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_pending_status_id() ) ); // Forum is being trashed, so its topics and replies are trashed too $topics = new WP_Query( array ( 'suppress_filters' => true, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $forum_id , 'post_status' => $post_stati , 'posts_per_page' => -1, 'nopaging' => true, 'fields' => 'id=>parent' ) ); // Loop through and trash child topics. Topic replies will get trashed by // the bbp_trash_topic() action. if ( ! empty ( $topics ->posts ) ) { // Prevent debug notices $pre_trashed_topics = array (); // Loop through topics, trash them, and add them to array foreach ( $topics ->posts as $topic ) { wp_trash_post( $topic ->ID, true ); $pre_trashed_topics [] = $topic ->ID; } // Set a post_meta entry of the topics that were trashed by this action. // This is so we can possibly untrash them, without untrashing topics // that were purposefully trashed before. update_post_meta( $forum_id , '_bbp_pre_trashed_topics' , $pre_trashed_topics ); // Reset the $post global wp_reset_postdata(); } // Cleanup unset( $topics ); } |
Changelog
Version | Description |
---|---|
bbPress (r3668) | 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.