bbp_spam_topic_replies( int $topic_id )
Trash replies to a topic when it’s marked as spam
Description Description
Usually you’ll want to do this before the topic itself is marked as spam.
Parameters Parameters
- $topic_id
-
(Required)
Source Source
File: includes/topics/functions.php
function bbp_spam_topic_replies( $topic_id = 0 ) { // Validation $topic_id = bbp_get_topic_id( $topic_id ); // Topic is being spammed, so its replies are trashed $replies = new WP_Query( array( 'fields' => 'id=>parent', 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'post_parent' => $topic_id, '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 ) ); if ( ! empty( $replies->posts ) ) { // Prevent debug notices $pre_spammed_replies = array(); // Loop through replies, trash them, and add them to array foreach ( $replies->posts as $reply ) { wp_trash_post( $reply->ID ); $pre_spammed_replies[] = $reply->ID; } // Set a post_meta entry of the replies that were trashed by this action. // This is so we can possibly untrash them, without untrashing replies // that were purposefully trashed before. update_post_meta( $topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies ); // Reset the global post data after looping through the above WP_Query wp_reset_postdata(); } }
Changelog Changelog
Version | Description |
---|---|
2.6.0 | Introduced. |