确定当前帖子是否已打开以供评论。
原型
comments_open( int|WP_Post $post_id = null )
描述
有关此功能和类似主题功能的更多信息,请查看Theme Developer Handbook中的Conditional Tags文章。
参数
$post_id
(int|WP_Post)
(Optional)
发布ID或WP_Post对象。默认当前帖子。
返回值
(bool)
如果评论是公开的,则为真。
源文件
路径:wp-includes/comment-template.php
<?php
...
function comments_open( $post_id = null ) {
$_post = get_post($post_id);
$post_id = $_post ? $_post->ID : 0;
$open = ( '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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/comments_open/