Ticket #8177: 8177.diff
File 8177.diff, 3.2 KB (added by , 16 years ago) |
---|
-
wp-includes/comment.php
1580 1591 * @return object 1581 1592 */ 1582 1593 function _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') ) 1584 1595 return $posts; 1585 1596 1586 1597 $days_old = (int) get_option('close_comments_days_old'); 1587 1598 if ( !$days_old ) 1588 1599 return $posts; 1589 1600 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 } 1593 1607 } 1594 1608 1595 1609 return $posts; … … 1624 1638 return $open; 1625 1639 } 1626 1640 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 */ 1650 function _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 */ 1673 function _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
158 158 add_filter( 'the_posts', '_close_comments_for_old_posts' ); 159 159 add_filter( 'comments_open', '_close_comments_for_old_post', 10, 2 ); 160 160 add_filter( 'pings_open', '_close_comments_for_old_post', 10, 2 ); 161 add_filter( 'the_posts', '_close_comments_for_attachments' ); 162 add_filter( 'comments_open', '_close_comments_for_attachment', 10, 2 ); 163 add_filter( 'pings_open', '_close_comments_for_attachment', 10, 2 ); 161 164 add_filter( 'editable_slug', 'urldecode' ); 162 165 163 166 // Atom SSL support