bbp_unspam_topic

Unspams a topic.

Description

bbp_unspam_topic( (int) $topic_id = 0 ); 

Parameters (1)

0. $topic_id — Optional. (int)
The topic id.

Usage

  1. if ( !function_exists( 'bbp_unspam_topic' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/topics/functions.php'; 
  3.  
  4. // The topic id. 
  5. $topic_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_unspam_topic($topic_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/topics/functions.php  
  1. function bbp_unspam_topic( $topic_id = 0 ) { 
  2.  
  3. // Get the topic 
  4. $topic = bbp_get_topic( $topic_id ); 
  5. if ( empty( $topic ) ) 
  6. return $topic; 
  7.  
  8. // Bail if already not spam 
  9. if ( bbp_get_spam_status_id() !== $topic->post_status ) 
  10. return false; 
  11.  
  12. // Execute pre unspam code 
  13. do_action( 'bbp_unspam_topic', $topic_id ); 
  14.  
  15. /** Untrash Replies *******************************************************/ 
  16.  
  17. // Get the replies that were not previously trashed 
  18. $pre_spammed_replies = get_post_meta( $topic_id, '_bbp_pre_spammed_replies', true ); 
  19.  
  20. // There are replies to untrash 
  21. if ( !empty( $pre_spammed_replies ) ) { 
  22.  
  23. // Maybe reverse the trashed replies array 
  24. if ( is_array( $pre_spammed_replies ) ) 
  25. $pre_spammed_replies = array_reverse( $pre_spammed_replies ); 
  26.  
  27. // Loop through replies 
  28. foreach ( (array) $pre_spammed_replies as $reply ) { 
  29. wp_untrash_post( $reply ); 
  30.  
  31. /** Topic Tags ************************************************************/ 
  32.  
  33. // Get pre-spam topic tags 
  34. $terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true ); 
  35.  
  36. // Topic had tags before it was spammed 
  37. if ( !empty( $terms ) ) { 
  38.  
  39. // Set the tax_input of the topic 
  40. $topic->tax_input = array( bbp_get_topic_tag_tax_id() => $terms ); 
  41.  
  42. // Delete pre-spam topic tag meta 
  43. delete_post_meta( $topic_id, '_bbp_spam_topic_tags' ); 
  44.  
  45. /** Topic Status **********************************************************/ 
  46.  
  47. // Get pre spam status 
  48. $topic_status = get_post_meta( $topic_id, '_bbp_spam_meta_status', true ); 
  49.  
  50. // If no previous status, default to publish 
  51. if ( empty( $topic_status ) ) { 
  52. $topic_status = bbp_get_public_status_id(); 
  53.  
  54. // Set post status to pre spam 
  55. $topic->post_status = $topic_status; 
  56.  
  57. // Delete pre spam meta 
  58. delete_post_meta( $topic_id, '_bbp_spam_meta_status' ); 
  59.  
  60. // No revisions 
  61. remove_action( 'pre_post_update', 'wp_save_post_revision' ); 
  62.  
  63. // Update the topic 
  64. $topic_id = wp_update_post( $topic ); 
  65.  
  66. // Execute post unspam code 
  67. do_action( 'bbp_unspammed_topic', $topic_id ); 
  68.  
  69. // Return topic_id 
  70. return $topic_id;