Skip to:
Content

bbPress.org

Changeset 7526


Ignore:
Timestamp:
09/16/2026 06:34:30 AM (5 days 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.

In trunk, for 2.7.

See #3678.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/users/capabilities.php

    r7515 r7526  
    607607        }
    608608
    609         // Get array of post types to mark as spam
    610         $post_types = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
    611         $post_types = "'" . implode( "', '", $post_types ) . "'";
     609        // Process replies before topics so topic status helpers run last
     610        $post_types = array( bbp_get_reply_post_type(), bbp_get_topic_post_type() );
    612611
    613612        // Get array of statuses to mark as spam
     
    621620                bbp_switch_to_site( $blog_id );
    622621
    623                 // Get topics and replies
    624                 $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 );
    625                 $posts = $bbp_db->get_col( $query );
    626 
    627                 // Loop through posts and spam them
    628                 if ( ! empty( $posts ) ) {
    629                         foreach ( $posts as $post_id ) {
    630 
    631                                 // The routines for topics ang replies are different, so use the
    632                                 // correct one based on the post type
    633                                 switch ( get_post_type( $post_id ) ) {
    634 
    635                                         case bbp_get_topic_post_type() :
    636                                                 bbp_spam_topic( $post_id );
    637                                                 break;
    638 
    639                                         case bbp_get_reply_post_type() :
    640                                                 bbp_spam_reply( $post_id );
    641                                                 break;
     622                foreach ( $post_types as $post_type ) {
     623
     624                        // Get posts of this type
     625                        $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 );
     626                        $posts = $bbp_db->get_col( $query );
     627
     628                        // Loop through posts and spam them
     629                        if ( ! empty( $posts ) ) {
     630                                foreach ( $posts as $post_id ) {
     631
     632                                        // The routines for topics and replies are different, so use the
     633                                        // correct one based on the post type
     634                                        switch ( $post_type ) {
     635
     636                                                case bbp_get_topic_post_type() :
     637                                                        bbp_spam_topic( $post_id );
     638                                                        break;
     639
     640                                                case bbp_get_reply_post_type() :
     641                                                        bbp_spam_reply( $post_id );
     642                                                        break;
     643                                        }
    642644                                }
    643645                        }
     
    692694        }
    693695
    694         // Get array of post types to mark as spam
    695         $post_types = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
    696         $post_types = "'" . implode( "', '", $post_types ) . "'";
     696        // Process replies before topics so topic status helpers run last
     697        $post_types = array( bbp_get_reply_post_type(), bbp_get_topic_post_type() );
    697698
    698699        // Get array of statuses to unmark as spam
     
    706707                bbp_switch_to_site( $blog_id );
    707708
    708                 // Get topics and replies
    709                 $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 );
    710                 $posts = $bbp_db->get_col( $query );
    711 
    712                 // Loop through posts and spam them
    713                 if ( ! empty( $posts ) ) {
    714                         foreach ( $posts as $post_id ) {
    715 
    716                                 // The routines for topics ang replies are different, so use the
    717                                 // correct one based on the post type
    718                                 switch ( get_post_type( $post_id ) ) {
    719 
    720                                         case bbp_get_topic_post_type() :
    721                                                 bbp_unspam_topic( $post_id );
    722                                                 break;
    723 
    724                                         case bbp_get_reply_post_type() :
    725                                                 bbp_unspam_reply( $post_id );
    726                                                 break;
     709                foreach ( $post_types as $post_type ) {
     710
     711                        // Get posts of this type
     712                        $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 );
     713                        $posts = $bbp_db->get_col( $query );
     714
     715                        // Loop through posts and unspam them
     716                        if ( ! empty( $posts ) ) {
     717                                foreach ( $posts as $post_id ) {
     718
     719                                        // The routines for topics and replies are different, so use the
     720                                        // correct one based on the post type
     721                                        switch ( $post_type ) {
     722
     723                                                case bbp_get_topic_post_type() :
     724                                                        bbp_unspam_topic( $post_id );
     725                                                        break;
     726
     727                                                case bbp_get_reply_post_type() :
     728                                                        bbp_unspam_reply( $post_id );
     729                                                        break;
     730                                        }
    727731                                }
    728732                        }
  • trunk/tests/phpunit/testcases/users/functions/counts.php

    r7467 r7526  
    622622                        'topic_meta'  => array( 'forum_id' => $forum_id ),
    623623                ) );
    624                 $this->factory->reply->create( array(
     624                $reply_id = $this->factory->reply->create( array(
    625625                        'post_author' => $user_id,
    626626                        'post_parent' => $topic_id,
     
    632632
    633633                $this->assertTrue( bbp_make_spam_user( $user_id ) );
     634                $this->assertSame( bbp_get_spam_status_id(), get_post_status( $topic_id ) );
     635                $this->assertSame( bbp_get_spam_status_id(), get_post_status( $reply_id ) );
    634636                $this->assertSame( 0, bbp_get_user_topic_count( $user_id, true ) );
    635637                $this->assertSame( 0, bbp_get_user_reply_count( $user_id, true ) );
     
    640642
    641643                $this->assertTrue( bbp_make_ham_user( $user_id ) );
     644                $this->assertSame( bbp_get_public_status_id(), get_post_status( $topic_id ) );
     645                $this->assertSame( bbp_get_public_status_id(), get_post_status( $reply_id ) );
    642646                $this->assertSame( 1, bbp_get_user_topic_count( $user_id, true ) );
    643647                $this->assertSame( 1, bbp_get_user_reply_count( $user_id, true ) );
Note: See TracChangeset for help on using the changeset viewer.