WordPress.org

Make WordPress Core

Ticket #20262: 20262.2.diff

File 20262.2.diff, 1.6 KB (added by MikeHansenMe, 6 years ago)
  • src/wp-includes/comment.php

     
    27972797 * @return object
    27982798 */
    27992799function _close_comments_for_old_posts( $posts, $query ) {
    2800         if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) )
     2800        if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) || $posts[0]->post_status != 'publish' ) {
    28012801                return $posts;
     2802        }
    28022803
    28032804        /**
    28042805         * Filter the list of post types to automatically close comments for.
     
    28342835 * @return bool $open
    28352836 */
    28362837function _close_comments_for_old_post( $open, $post_id ) {
    2837         if ( ! $open )
     2838        if ( ! $open ) {
    28382839                return $open;
     2840        }
    28392841
    2840         if ( !get_option('close_comments_for_old_posts') )
     2842        if ( !get_option('close_comments_for_old_posts') ) {
    28412843                return $open;
     2844        }
    28422845
    28432846        $days_old = (int) get_option('close_comments_days_old');
    2844         if ( !$days_old )
     2847        if ( !$days_old ) {
    28452848                return $open;
     2849        }
    28462850
    28472851        $post = get_post($post_id);
     2852       
     2853        if( $post->post_status != 'publish' ) {
     2854                return $open;
     2855        }
    28482856
    28492857        /** This filter is documented in wp-includes/comment.php */
    28502858        $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
    2851         if ( ! in_array( $post->post_type, $post_types ) )
     2859        if ( ! in_array( $post->post_type, $post_types ) ) {
    28522860                return $open;
     2861        }
    28532862
    2854         if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
     2863        if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
    28552864                return false;
     2865        }
    28562866
    28572867        return $open;
    28582868}