Skip to:
Content

bbPress.org

Changeset 4674


Ignore:
Timestamp:
12/31/2012 02:44:33 PM (9 years ago)
Author:
johnjamesjacoby
Message:

When spamming a topic, save the currently published replies in topic meta and trash them. This prevents rogue replies from appearing in user profiles and searches that have no live parent topic.

Also add similar logic to new reply handler, to add reply to topic meta if replying to a previously spammed topic. This is rare, as the ability is restricted to capable users, but must be done to keep meta synchronized.

Location:
trunk/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/replies/functions.php

    r4657 r4674  
    300300            // Update the pre_trashed_reply post meta
    301301            update_post_meta( $topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies );
     302
     303        /** Spam Check ********************************************************/
     304
     305        // If reply or topic are spam, officially spam this reply
     306        } elseif ( bbp_is_topic_spam( $topic_id ) || ( $reply_data['post_status'] == bbp_get_spam_status_id() ) ) {
     307            add_post_meta( $reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id() );
     308
     309            // Get pre_trashed_replies for topic
     310            $pre_spammed_replies = get_post_meta( $topic_id, '_bbp_pre_spammed_replies', true );
     311
     312            // Add this reply to the end of the existing replies
     313            $pre_spammed_replies[] = $reply_id;
     314
     315            // Update the pre_trashed_reply post meta
     316            update_post_meta( $topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies );
    302317        }
    303 
    304         /** Spam Check ********************************************************/
    305 
    306         // If reply or topic are spam, officially spam this reply
    307         if ( bbp_is_topic_spam( $topic_id ) || ( $reply_data['post_status'] == bbp_get_spam_status_id() ) )
    308             add_post_meta( $reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id() );
    309318
    310319        /** Update counts, etc... *********************************************/
  • trunk/includes/topics/functions.php

    r4657 r4674  
    26912691    do_action( 'bbp_spam_topic', $topic_id );
    26922692
     2693    /** Trash Replies *********************************************************/
     2694
     2695    // Topic is being spammed, so its replies are trashed
     2696    $replies = new WP_Query( array(
     2697        'suppress_filters' => true,
     2698        'post_type'        => bbp_get_reply_post_type(),
     2699        'post_status'      => bbp_get_public_status_id(),
     2700        'post_parent'      => $topic_id,
     2701        'posts_per_page'   => -1,
     2702        'nopaging'         => true,
     2703        'fields'           => 'id=>parent'
     2704    ) );
     2705
     2706    if ( !empty( $replies->posts ) ) {
     2707
     2708        // Prevent debug notices
     2709        $pre_spammed_replies = array();
     2710
     2711        // Loop through replies, trash them, and add them to array
     2712        foreach ( $replies->posts as $reply ) {
     2713            wp_trash_post( $reply->ID );
     2714            $pre_spammed_replies[] = $reply->ID;
     2715        }
     2716
     2717        // Set a post_meta entry of the replies that were trashed by this action.
     2718        // This is so we can possibly untrash them, without untrashing replies
     2719        // that were purposefully trashed before.
     2720        update_post_meta( $topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies );
     2721
     2722        // Reset the $post global
     2723        wp_reset_postdata();
     2724    }
     2725
     2726    // Cleanup
     2727    unset( $replies );
     2728
     2729    /** Topic Tags ************************************************************/
     2730
    26932731    // Add the original post status as post meta for future restoration
    26942732    add_post_meta( $topic_id, '_bbp_spam_meta_status', $topic['post_status'] );
     
    27622800    do_action( 'bbp_unspam_topic', $topic_id );
    27632801
     2802    /** Untrash Replies *******************************************************/
     2803
     2804    // Get the replies that were not previously trashed
     2805    $pre_spammed_replies = get_post_meta( $topic_id, '_bbp_pre_spammed_replies', true );
     2806
     2807    // There are replies to untrash
     2808    if ( !empty( $pre_spammed_replies ) ) {
     2809
     2810        // Maybe reverse the trashed replies array
     2811        if ( is_array( $pre_spammed_replies ) )
     2812            $pre_spammed_replies = array_reverse( $pre_spammed_replies );
     2813
     2814        // Loop through replies
     2815        foreach ( (array) $pre_spammed_replies as $reply ) {
     2816            wp_untrash_post( $reply );
     2817        }
     2818    }
     2819
     2820    /** Topic Tags ************************************************************/
     2821
     2822    // Get pre-spam topic tags
     2823    $terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true );
     2824
     2825    // Topic had tags before it was spammed
     2826    if ( !empty( $terms ) ) {
     2827
     2828        // Set the tax_input of the topic
     2829        $topic['tax_input'] = array( bbp_get_topic_tag_tax_id() => $terms );
     2830
     2831        // Delete pre-spam topic tag meta
     2832        delete_post_meta( $topic_id, '_bbp_spam_topic_tags' );
     2833    }
     2834
     2835    /** Topic Status **********************************************************/
     2836
    27642837    // Get pre spam status
    27652838    $topic_status = get_post_meta( $topic_id, '_bbp_spam_meta_status', true );
     
    27732846    // No revisions
    27742847    remove_action( 'pre_post_update', 'wp_save_post_revision' );
    2775 
    2776     // Get pre-spam topic tags
    2777     $terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true );
    2778 
    2779     // Topic had tags before it was spammed
    2780     if ( !empty( $terms ) ) {
    2781 
    2782         // Set the tax_input of the topic
    2783         $topic['tax_input'] = array( bbp_get_topic_tag_tax_id() => $terms );
    2784 
    2785         // Delete pre-spam topic tag meta
    2786         delete_post_meta( $topic_id, '_bbp_spam_topic_tags' );
    2787     }
    27882848
    27892849    // Update the topic
Note: See TracChangeset for help on using the changeset viewer.