Sometimes you may need to programmatically disable the comment form. This can be done using the “comments_open” hook:
add_filter('comments_open', function($open, $post_id)
{
return false;
}, 10, 2);This hook accepts two parameters:
$open — whether the current post is open for comments
$post_id — the ID of the current post
It’s a very useful hook that allows you to dynamically enable or disable comment visibility.
In combination with it, you can use the “comment_form_comments_closed” hook, which is triggered when commenting is disabled:
add_action('comment_form_comments_closed', function()
{
echo '[TEST]';
});