bbp_unspam_topic( int $topic_id )
Unspams a topic
Description
Parameters
- $topic_id
-
(Required) Topic id
Return
(mixed) False or WP_Error on failure, topic id on success
Source
File: bp-forums/topics/functions.php
3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 | function bbp_unspam_topic( $topic_id = 0 ) { // Get the topic $topic = bbp_get_topic( $topic_id ); if ( empty ( $topic ) ) return $topic ; // Bail if already not spam if ( bbp_get_spam_status_id() !== $topic ->post_status ) return false; // Execute pre unspam code do_action( 'bbp_unspam_topic' , $topic_id ); /** Untrash Replies *******************************************************/ // Get the replies that were not previously trashed $pre_spammed_replies = get_post_meta( $topic_id , '_bbp_pre_spammed_replies' , true ); // There are replies to untrash if ( ! empty ( $pre_spammed_replies ) ) { // Maybe reverse the trashed replies array if ( is_array ( $pre_spammed_replies ) ) $pre_spammed_replies = array_reverse ( $pre_spammed_replies ); // Loop through replies foreach ( ( array ) $pre_spammed_replies as $reply ) { wp_untrash_post( $reply ); } } /** Topic Tags ************************************************************/ // Get pre-spam topic tags $terms = get_post_meta( $topic_id , '_bbp_spam_topic_tags' , true ); // Topic had tags before it was spammed if ( ! empty ( $terms ) ) { // Set the tax_input of the topic $topic ->tax_input = array ( bbp_get_topic_tag_tax_id() => $terms ); // Delete pre-spam topic tag meta delete_post_meta( $topic_id , '_bbp_spam_topic_tags' ); } /** Topic Status **********************************************************/ // Get pre spam status $topic_status = get_post_meta( $topic_id , '_bbp_spam_meta_status' , true ); // If no previous status, default to publish if ( empty ( $topic_status ) ) { $topic_status = bbp_get_public_status_id(); } // Set post status to pre spam $topic ->post_status = $topic_status ; // Delete pre spam meta delete_post_meta( $topic_id , '_bbp_spam_meta_status' ); // No revisions remove_action( 'pre_post_update' , 'wp_save_post_revision' ); // Update the topic $topic_id = wp_update_post( $topic ); // Execute post unspam code do_action( 'bbp_unspammed_topic' , $topic_id ); // Return topic_id return $topic_id ; } |
Changelog
Version | Description |
---|---|
bbPress (r2740) | 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.