comments_open

Whether the current post is open for comments.

Description

comments_open( (null) $post_id = null ); 

Parameters (1)

0. $post_id — Optional. (null) => null
Post ID or WP_Post object. Default current post.

Usage

  1. if ( !function_exists( 'comments_open' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment-template.php'; 
  3.  
  4. // Post ID or WP_Post object. Default current post. 
  5. $post_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = comments_open($post_id); 
  9.  

Defined (1)

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

/wp-includes/comment-template.php  
  1. function comments_open( $post_id = null ) { 
  2.  
  3. $_post = get_post($post_id); 
  4.  
  5. $open = ( 'open' == $_post->comment_status ); 
  6.  
  7. /** 
  8. * Filters whether the current post is open for comments. 
  9. * @since 2.5.0 
  10. * @param bool $open Whether the current post is open for comments. 
  11. * @param int|WP_Post $post_id The post ID or WP_Post object. 
  12. */ 
  13. return apply_filters( 'comments_open', $open, $post_id );