函数原型
comments_open( int|WP_Post $post = null ): bool
函数描述
Determines whether the current post is open for comments.
是否弃用
未弃用
函数参数
-
$post
int|WP_Post
Optional - Post ID or WP_Post object. Default current post.
Default:
null
函数返回值
bool True if the comments are open.
函数位置
File: wp-includes/comment-template.php.
函数源码
function comments_open( $post = null ) {
$_post = get_post( $post );
$post_id = $_post ? $_post->ID : 0;
$open = ( $_post && ( 'open' === $_post->comment_status ) );
/**
* Filters whether the current post is open for comments.
*
* @since 2.5.0
*
* @param bool $open Whether the current post is open for comments.
* @param int $post_id The post ID.
*/
return apply_filters( 'comments_open', $open, $post_id );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |

