bbp_trash_forum_topics( int $forum_id )
Trash all topics inside a forum
Description Description
Parameters Parameters
- $forum_id
-
(Required)
Return Return
(If) forum is not valid
Source Source
File: includes/forums/functions.php
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 = 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( 'fields' => 'id=>parent', 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $forum_id, 'post_status' => $post_stati, 'posts_per_page' => -1, // Performance 'nopaging' => true, 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'ignore_sticky_posts' => true, 'no_found_rows' => true ) ); // 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 Changelog
Version | Description |
---|---|
2.1.0 | Introduced. |