WordPress.org

Make WordPress Core

Ticket #20262: 20262.diff

File 20262.diff, 908 bytes (added by solarissmoke, 2 years ago)

Only close comments on published posts

  • wp-includes/comment.php

     
    19721972 * @return object 
    19731973 */ 
    19741974function _close_comments_for_old_posts( $posts, $query ) { 
    1975         if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) 
     1975        if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) || $posts[0]->post_status != 'publish' ) 
    19761976                return $posts; 
    19771977 
    19781978        $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); 
     
    20132013                return $open; 
    20142014 
    20152015        $post = get_post($post_id); 
     2016         
     2017        if( $post->post_status != 'publish' ) 
     2018                return $open; 
    20162019 
    20172020        $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); 
    20182021        if ( ! in_array( $post->post_type, $post_types ) )