WordPress.org

Make WordPress Core

Ticket #8177: 8177.diff

File 8177.diff, 3.2 KB (added by DD32, 9 years ago)
  • wp-includes/comment.php

     
    15801591 * @return object
    15811592 */
    15821593function _close_comments_for_old_posts( $posts ) {
    1583         if ( empty($posts) || !is_singular() || !get_option('close_comments_for_old_posts') )
     1594        if ( empty($posts) || !get_option('close_comments_for_old_posts') )
    15841595                return $posts;
    15851596
    15861597        $days_old = (int) get_option('close_comments_days_old');
    15871598        if ( !$days_old )
    15881599                return $posts;
    15891600
    1590         if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) ) {
    1591                 $posts[0]->comment_status = 'closed';
    1592                 $posts[0]->ping_status = 'closed';
     1601        $num_posts = count($posts);
     1602        for ( $i = 0; $i < $num_posts; $i++) {
     1603                if ( time() - strtotime( $posts[$i]->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) ) {
     1604                        $posts[$i]->comment_status = 'closed';
     1605                        $posts[$i]->ping_status = 'closed';
     1606                }
    15931607        }
    15941608
    15951609        return $posts;
     
    16241638        return $open;
    16251639}
    16261640
    1627 ?>
     1641/**
     1642 * Close comments/pings on attachments if the parent's comments are closed.  Hooked to the_posts.
     1643 *
     1644 * @access private
     1645 * @since 2.8.0
     1646 *
     1647 * @param object $posts Post data object.
     1648 * @return object
     1649 */
     1650function _close_comments_for_attachments( $posts ) {
     1651
     1652        foreach ( (array)$posts as $key => $post ) {
     1653                if ( 'attachment' != $post->post_type || 0 == $post->post_parent || $post->post_parent == $post->ID )
     1654                        continue;
     1655                $parent = get_post($post->post_parent);
     1656                $posts[ $key ]->comment_status = $parent->comment_status;
     1657                $posts[ $key ]->ping_status = $parent->ping_status;
     1658        }
     1659
     1660        return $posts;
     1661}
     1662
     1663/**
     1664 * Close comments/pings on attachment if parents comments/pings are closed.  Hooked to comments_open and pings_open.
     1665 *
     1666 * @access private
     1667 * @since 2.8.0
     1668 *
     1669 * @param bool $open Comments open or closed
     1670 * @param int $post_id Post ID
     1671 * @return bool $open
     1672 */
     1673function _close_comments_for_attachment( $open, $post_id) {
     1674        if ( ! $open )
     1675                return $open;
     1676
     1677        $post = get_post( $post_id );
     1678
     1679        if ( 'attachment' != $post->post_type || 0 == $post->post_parent )
     1680                return $open;
     1681
     1682        $parent = get_post( $post->post_parent );
     1683
     1684        if ( ! $parent )
     1685                return $open;
     1686
     1687        if ( 'comments_open' == current_filter() )
     1688                $open = ( 'open' == $parent->comment_status );
     1689        else //pings
     1690                $open = ( 'open' == $parent->ping_status );
     1691       
     1692        return $open;
     1693}
     1694
     1695?>
     1696 No newline at end of file
  • wp-includes/default-filters.php

     
    158158add_filter( 'the_posts', '_close_comments_for_old_posts' );
    159159add_filter( 'comments_open', '_close_comments_for_old_post', 10, 2 );
    160160add_filter( 'pings_open', '_close_comments_for_old_post', 10, 2 );
     161add_filter( 'the_posts', '_close_comments_for_attachments' );
     162add_filter( 'comments_open', '_close_comments_for_attachment', 10, 2 );
     163add_filter( 'pings_open', '_close_comments_for_attachment', 10, 2 );
    161164add_filter( 'editable_slug', 'urldecode' );
    162165
    163166// Atom SSL support