WordPress.org

Make WordPress Core

Ticket #20262: 20262.3.diff

File 20262.3.diff, 1.6 KB (added by rachelbaker, 5 years ago)
  • src/wp-includes/comment.php

     
    30523052 * @return array
    30533053 */
    30543054function _close_comments_for_old_posts( $posts, $query ) {
    3055         if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) )
     3055        if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) || $posts[0]->post_status !== 'publish' ) {
    30563056                return $posts;
     3057        }
    30573058
    30583059        /**
    30593060         * Filter the list of post types to automatically close comments for.
     
    30893090 * @return bool $open
    30903091 */
    30913092function _close_comments_for_old_post( $open, $post_id ) {
    3092         if ( ! $open )
     3093        if ( ! $open ) {
    30933094                return $open;
     3095        }
    30943096
    3095         if ( !get_option('close_comments_for_old_posts') )
     3097        if ( ! get_option('close_comments_for_old_posts' ) ) {
    30963098                return $open;
     3099        }
    30973100
    30983101        $days_old = (int) get_option('close_comments_days_old');
    3099         if ( !$days_old )
     3102        if ( !$days_old ) {
    31003103                return $open;
     3104        }
    31013105
    31023106        $post = get_post($post_id);
     3107
     3108        if ( $post->post_status !== 'publish' ) {
     3109                return $open;
     3110        }
    31033111
    31043112        /** This filter is documented in wp-includes/comment.php */
    31053113        $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
    3106         if ( ! in_array( $post->post_type, $post_types ) )
     3114        if ( ! in_array( $post->post_type, $post_types ) ) {
    31073115                return $open;
     3116        }
    31083117
    3109         if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
     3118        if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
    31103119                return false;
     3120        }
    31113121
    31123122        return $open;
    31133123}