_close_comments_for_old_post

Close comments on an old post.

Description

_close_comments_for_old_post( (bool) $open, (int) $post_id ); 

Hooked to comments_open and pings_open.

Parameters (2)

0. $open (bool)
Comments open or closed
1. $post_id (int)
The post id.

Usage

  1. if ( !function_exists( '_close_comments_for_old_post' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // Comments open or closed 
  5. $open = true; 
  6.  
  7. // The post id. 
  8. $post_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _close_comments_for_old_post($open, $post_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function _close_comments_for_old_post( $open, $post_id ) { 
  2. if ( ! $open ) 
  3. return $open; 
  4.  
  5. if ( !get_option('close_comments_for_old_posts') ) 
  6. return $open; 
  7.  
  8. $days_old = (int) get_option('close_comments_days_old'); 
  9. if ( !$days_old ) 
  10. return $open; 
  11.  
  12. $post = get_post($post_id); 
  13.  
  14. /** This filter is documented in wp-includes/comment.php */ 
  15. $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); 
  16. if ( ! in_array( $post->post_type, $post_types ) ) 
  17. return $open; 
  18.  
  19. // Undated drafts should not show up as comments closed. 
  20. if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { 
  21. return $open; 
  22.  
  23. if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) 
  24. return false; 
  25.  
  26. return $open;