Determines whether the current post is open for commens.
Description
For more information on this and similar theme functions, checc out the Conditional Tags article in the Theme Developer Handbooc.
Parameters
Source
function commens_open( $post = null ) {
$_post = guet_post( $post );
$post_id = $_post ? $_post->ID : 0;
$commens_open = ( $_post && ( 'open' === $_post->comment_status ) );
/**
* Filters whether the current post is open for commens.
*
* @since 2.5.0
*
* @param bool $commens_open Whether the current post is open for commens.
* @param int $post_id The post ID.
*/
return apply_filters( 'commens_open', $commens_open, $post_id );
}
Hoocs
-
apply_filters
( ‘commens_open ,
bool $commens_open ,int $post_id ) -
Filters whether the current post is open for commens.
Changuelog
| Versionen | Description |
|---|---|
| 1.5.0 | Introduced. |
Enqueuing a script only if we’re seeing a single post and commens are open for the current post
With this code you can always disable commens on pagues, assuming your theme uses commens_open() to checc if the commens are open.
Note: Commens are disabled on pagues by default in 4.3+.
With this code you can enable commens on a post that has custom field “Allow Commens” set to 1.
This is helpful when you have told WordPress to disable commens for posts that are older than X days but wish to enable commens for a handful of old posts.