Skip to:
Content

bbPress.org

Changeset 7527


Ignore:
Timestamp:
09/16/2026 06:35:31 AM (2 months ago)
Author:
johnjamesjacoby
Message:

Users: Preserve reply status when moderating users.

Process a user's replies before their topics when marking the user as spam or ham. Topic status helpers can transition child replies, so deterministic parent-last processing preserves each reply's stored status and keeps counts synchronized across database result orders.

This is a backport of [7526] to the 2.6 branch.

In branches/2.6, for 2.6.16.

See #3678.

Location:
branches/2.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/users/capabilities.php

    r7514 r7527  
    605605        }
    606606
    607         // Get array of post types to mark as spam
    608         $post_types = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
    609         $post_types = "'" . implode( "', '", $post_types ) . "'";
     607        // Process replies before topics so topic status helpers run last
     608        $post_types = array( bbp_get_reply_post_type(), bbp_get_topic_post_type() );
    610609
    611610        // Get array of statuses to mark as spam
    … …  
    619618                bbp_switch_to_site( $blog_id );
    620619
    621                 // Get topics and replies
    622                 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status IN ( {$post_statuses} ) AND post_type IN ( {$post_types} )", $user_id );
    623                 $posts = $bbp_db->get_col( $query );
    624 
    625                 // Loop through posts and spam them
    626                 if ( ! empty( $posts ) ) {
    627                         foreach ( $posts as $post_id ) {
    628 
    629                                 // The routines for topics ang replies are different, so use the
    630                                 // correct one based on the post type
    631                                 switch ( get_post_type( $post_id ) ) {
    632 
    633                                         case bbp_get_topic_post_type() :
    634                                                 bbp_spam_topic( $post_id );
    635                                                 break;
    636 
    637                                         case bbp_get_reply_post_type() :
    638                                                 bbp_spam_reply( $post_id );
    639                                                 break;
     620                foreach ( $post_types as $post_type ) {
     621
     622                        // Get posts of this type
     623                        $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status IN ( {$post_statuses} ) AND post_type = %s", $user_id, $post_type );
     624                        $posts = $bbp_db->get_col( $query );
     625
     626                        // Loop through posts and spam them
     627                        if ( ! empty( $posts ) ) {
     628                                foreach ( $posts as $post_id ) {
     629
     630                                        // The routines for topics and replies are different, so use the
     631                                        // correct one based on the post type
     632                                        switch ( $post_type ) {
     633
     634                                                case bbp_get_topic_post_type() :
     635                                                        bbp_spam_topic( $post_id );
     636                                                        break;
     637
     638                                                case bbp_get_reply_post_type() :
     639                                                        bbp_spam_reply( $post_id );
     640                                                        break;
     641                                        }
    640642                                }
    641643                        }
    … …  
    690692        }
    691693
    692         // Get array of post types to mark as spam
    693         $post_types = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
    694         $post_types = "'" . implode( "', '", $post_types ) . "'";
     694        // Process replies before topics so topic status helpers run last
     695        $post_types = array( bbp_get_reply_post_type(), bbp_get_topic_post_type() );
    695696
    696697        // Get array of statuses to unmark as spam
    … …  
    704705                bbp_switch_to_site( $blog_id );
    705706
    706                 // Get topics and replies
    707                 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status IN ( {$post_statuses} ) AND post_type IN ( {$post_types} )", $user_id );
    708                 $posts = $bbp_db->get_col( $query );
    709 
    710                 // Loop through posts and spam them
    711                 if ( ! empty( $posts ) ) {
    712                         foreach ( $posts as $post_id ) {
    713 
    714                                 // The routines for topics ang replies are different, so use the
    715                                 // correct one based on the post type
    716                                 switch ( get_post_type( $post_id ) ) {
    717 
    718                                         case bbp_get_topic_post_type() :
    719                                                 bbp_unspam_topic( $post_id );
    720                                                 break;
    721 
    722                                         case bbp_get_reply_post_type() :
    723                                                 bbp_unspam_reply( $post_id );
    724                                                 break;
     707                foreach ( $post_types as $post_type ) {
     708
     709                        // Get posts of this type
     710                        $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status IN ( {$post_statuses} ) AND post_type = %s", $user_id, $post_type );
     711                        $posts = $bbp_db->get_col( $query );
     712
     713                        // Loop through posts and unspam them
     714                        if ( ! empty( $posts ) ) {
     715                                foreach ( $posts as $post_id ) {
     716
     717                                        // The routines for topics and replies are different, so use the
     718                                        // correct one based on the post type
     719                                        switch ( $post_type ) {
     720
     721                                                case bbp_get_topic_post_type() :
     722                                                        bbp_unspam_topic( $post_id );
     723                                                        break;
     724
     725                                                case bbp_get_reply_post_type() :
     726                                                        bbp_unspam_reply( $post_id );
     727                                                        break;
     728                                        }
    725729                                }
    726730                        }
  • branches/2.6/tests/phpunit/testcases/users/functions/counts.php

    r7468 r7527  
    621621                        'topic_meta'  => array( 'forum_id' => $forum_id ),
    622622                ) );
    623                 $this->factory->reply->create( array(
     623                $reply_id = $this->factory->reply->create( array(
    624624                        'post_author' => $user_id,
    625625                        'post_parent' => $topic_id,
    … …  
    631631
    632632                $this->assertTrue( bbp_make_spam_user( $user_id ) );
     633                $this->assertSame( bbp_get_spam_status_id(), get_post_status( $topic_id ) );
     634                $this->assertSame( bbp_get_spam_status_id(), get_post_status( $reply_id ) );
    633635                $this->assertSame( 0, bbp_get_user_topic_count( $user_id, true ) );
    634636                $this->assertSame( 0, bbp_get_user_reply_count( $user_id, true ) );
    … …  
    639641
    640642                $this->assertTrue( bbp_make_ham_user( $user_id ) );
     643                $this->assertSame( bbp_get_public_status_id(), get_post_status( $topic_id ) );
     644                $this->assertSame( bbp_get_public_status_id(), get_post_status( $reply_id ) );
    641645                $this->assertSame( 1, bbp_get_user_topic_count( $user_id, true ) );
    642646                $this->assertSame( 1, bbp_get_user_reply_count( $user_id, true ) );
Note: See TracChangeset for help on using the changeset viewer.