get_default_comment_status

Gets the default comment status for a post type.

Description

(string) get_default_comment_status( (string) $post_type = 'post', (string) $comment_type = 'comment' ); 

Returns (string)

Expected return value is 'open' or 'closed'.

Parameters (2)

0. $post_type — Optional. (string) => 'post'
Post type. Default post..
1. $comment_type — Optional. (string) => 'comment'
Comment type. Default comment..

Usage

  1. if ( !function_exists( 'get_default_comment_status' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // Optional. Post type. Default 'post'. 
  5. $post_type = 'post'; 
  6.  
  7. // Optional. Comment type. Default 'comment'. 
  8. $comment_type = 'comment'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_default_comment_status($post_type, $comment_type); 
  12.  

Defined (1)

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

/wp-includes/comment.php  
  1. function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) { 
  2. switch ( $comment_type ) { 
  3. case 'pingback' : 
  4. case 'trackback' : 
  5. $supports = 'trackbacks'; 
  6. $option = 'ping'; 
  7. break; 
  8. default : 
  9. $supports = 'comments'; 
  10. $option = 'comment'; 
  11.  
  12. // Set the status. 
  13. if ( 'page' === $post_type ) { 
  14. $status = 'closed'; 
  15. } elseif ( post_type_supports( $post_type, $supports ) ) { 
  16. $status = get_option( "default_{$option}_status" ); 
  17. } else { 
  18. $status = 'closed'; 
  19.  
  20. /** 
  21. * Filters the default comment status for the given post type. 
  22. * @since 4.3.0 
  23. * @param string $status Default status for the given post type,  
  24. * either 'open' or 'closed'. 
  25. * @param string $post_type Post type. Default is `post`. 
  26. * @param string $comment_type Type of comment. Default is `comment`. 
  27. */ 
  28. return apply_filters( 'get_default_comment_status' , $status, $post_type, $comment_type );