Skip to:
Content

bbPress.org

Changeset 8038


Ignore:
Timestamp:
10/15/2026 11:08:10 PM (10 days ago)
Author:
johnjamesjacoby
Message:

Moderation: Preserve pending post dates.

Set the GMT date when WordPress inserts pending topics and replies so later status-only updates do not replace the original post date. This moves the WordPress.org safeguard into bbPress and keeps REST editing behavior consistent with the stored date invariant.

Add regression coverage for topic and reply status changes and update the existing REST expectations.

In branches/2.6, for 2.6.21.

Fixes #3744.

Location:
branches/2.6
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/CHANGELOG.md

    r8028 r8038  
    1313Development for the next bbPress release is in progress. See the active
    1414[Trac milestones](https://bbpress.trac.wordpress.org/roadmap) for planned work.
     15
     16### Fixed
     17
     18- Preserved the original date of pending topics and replies across status changes.
    1519
    1620## 2.6.20 - 2026-10-15
  • branches/2.6/src/includes/common/functions.php

    r8017 r8038  
    262262
    263263        return $retval;
     264}
     265
     266/**
     267 * Set the GMT date for pending topics and replies.
     268 *
     269 * WordPress leaves the GMT date empty for pending posts, which can cause a
     270 * later status change to replace the original post date.
     271 *
     272 * @since 2.6.21 bbPress
     273 *
     274 * @param array $data Post data
     275 * @return array Filtered post data
     276 */
     277function bbp_set_pending_post_date_gmt( $data = array() ) {
     278        if (
     279                isset( $data['post_type'], $data['post_status'], $data['post_date'], $data['post_date_gmt'] )
     280                && in_array( $data['post_type'], array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ), true )
     281                && ( bbp_get_pending_status_id() === $data['post_status'] )
     282                && ( '0000-00-00 00:00:00' === $data['post_date_gmt'] )
     283        ) {
     284                $data['post_date_gmt'] = get_gmt_from_date( $data['post_date'] );
     285        }
     286
     287        return $data;
    264288}
    265289
  • branches/2.6/src/includes/core/filters.php

    r8013 r8038  
    5959add_filter( 'rest_request_before_callbacks', 'bbp_filter_rest_user_discovery',          10, 3 );
    6060
    61 // Filter WordPress post data for forums and anonymous posts
     61// Filter WordPress post data for forums, pending dates, and anonymous posts
    6262add_filter( 'wp_insert_post_data', 'bbp_filter_admin_forum_post_data', 20, 2 );
     63add_filter( 'wp_insert_post_data', 'bbp_set_pending_post_date_gmt',     25    );
    6364add_filter( 'wp_insert_post_data', 'bbp_fix_post_author',              30, 2 );
    6465
  • branches/2.6/tests/phpunit/testcases/common/functions.php

    r7998 r8038  
    635635                        'This test has not been implemented yet.'
    636636                );
     637        }
     638
     639        /**
     640         * @covers ::bbp_set_pending_post_date_gmt
     641         */
     642        public function test_bbp_set_pending_post_date_gmt_preserves_dates_on_status_change() {
     643                $forum_id = $this->factory->forum->create();
     644                $topic_id = $this->factory->topic->create( array(
     645                        'post_parent' => $forum_id,
     646                        'post_status' => bbp_get_pending_status_id(),
     647                        'post_date'   => '2020-01-01 00:00:00',
     648                        'topic_meta'  => array( 'forum_id' => $forum_id ),
     649                ) );
     650                $reply_id = $this->factory->reply->create( array(
     651                        'post_parent' => $topic_id,
     652                        'post_status' => bbp_get_pending_status_id(),
     653                        'post_date'   => '2020-01-02 00:00:00',
     654                        'reply_meta'  => array(
     655                                'forum_id' => $forum_id,
     656                                'topic_id' => $topic_id,
     657                        ),
     658                ) );
     659
     660                foreach ( array( $topic_id, $reply_id ) as $post_id ) {
     661                        $post_date = get_post_field( 'post_date', $post_id );
     662                        $this->assertSame( get_gmt_from_date( $post_date ), get_post_field( 'post_date_gmt', $post_id ) );
     663
     664                        wp_update_post( array(
     665                                'ID'          => $post_id,
     666                                'post_status' => bbp_get_spam_status_id(),
     667                        ) );
     668
     669                        $this->assertSame( $post_date, get_post_field( 'post_date', $post_id ) );
     670                }
    637671        }
    638672
  • branches/2.6/tests/phpunit/testcases/common/rest.php

    r8017 r8038  
    10951095
    10961096        /**
    1097          * A pending topic's zero GMT date must not lock out its recent author.
     1097         * A pending topic's GMT date must not lock out its recent author.
    10981098         *
    10991099         * @covers BBP_REST_Posts_Controller::update_item_permissions_check
    … …  
    11081108                bbp_set_user_role( $user_id, bbp_get_participant_role() );
    11091109
    1110                 $this->assertSame( '0000-00-00 00:00:00', get_post_field( 'post_date_gmt', $topic_id ) );
     1110                $this->assertSame( get_gmt_from_date( get_post_field( 'post_date', $topic_id ) ), get_post_field( 'post_date_gmt', $topic_id ) );
    11111111                $response = $this->update_item( bbp_get_topic_post_type(), $topic_id, $user_id, array( 'content' => 'Pending revision.' ) );
    11121112
    … …  
    11941194                bbp_set_user_role( $user_id, bbp_get_participant_role() );
    11951195
    1196                 $this->assertSame( '0000-00-00 00:00:00', get_post_field( 'post_date_gmt', $reply_id ) );
     1196                $this->assertSame( get_gmt_from_date( get_post_field( 'post_date', $reply_id ) ), get_post_field( 'post_date_gmt', $reply_id ) );
    11971197                $response = $this->update_item( bbp_get_reply_post_type(), $reply_id, $user_id, array( 'content' => 'Pending reply revision.' ) );
    11981198
Note: See TracChangeset for help on using the changeset viewer.