WordPress.org

Make WordPress Core

Changeset 35475


Ignore:
Timestamp:
10/31/2015 08:12:16 PM (5 years ago)
Author:
wonderboymusic
Message:

Comments: don't auto-close comments on draft posts.

Adds unit tests.

Props solarissmoke, MikeHansenMe, nacin, rachelbaker.
Fixes #20262.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-functions.php

    r35435 r35475  
    25932593        return $open;
    25942594
     2595    // Undated drafts should not show up as comments closed.
     2596    if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
     2597        return $open;
     2598    }
     2599
    25952600    if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
    25962601        return false;
  • trunk/tests/phpunit/tests/comment.php

    r35350 r35475  
    568568        return $email_sent_when_comment_approved || $email_sent_when_comment_added;
    569569    }
     570
     571    public function test_close_comments_for_old_post() {
     572        update_option( 'close_comments_for_old_posts', true );
     573        // Close comments more than one day old.
     574        update_option( 'close_comments_days_old', 1 );
     575
     576        $old_date = strtotime( '-25 hours' );
     577        $old_post_id = self::factory()->post->create( array( 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $old_date ) ) );
     578
     579        $old_post_comment_status = _close_comments_for_old_post( true, $old_post_id );
     580        $this->assertFalse( $old_post_comment_status );
     581
     582        $new_post_comment_status = _close_comments_for_old_post( true, self::$post_id );
     583        $this->assertTrue( $new_post_comment_status );
     584    }
     585
     586    public function test_close_comments_for_old_post_undated_draft() {
     587        $draft_id = self::factory()->post->create( array( 'post_status' => 'draft', 'post_type' => 'post' ) );
     588        $draft_comment_status = _close_comments_for_old_post( true, $draft_id );
     589
     590        $this->assertTrue( $draft_comment_status );
     591    }
    570592}
Note: See TracChangeset for help on using the changeset viewer.