Comments: In `comment_form()`, bail early if comments for the post are closed.

Props jipmoors.
Fixes #38514.

git-svn-id: https://develop.svn.wordpress.org/trunk@38959 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2016-10-26 14:47:09 +00:00
parent 573912fcfd
commit 509a314de8
1 changed files with 166 additions and 163 deletions

View File

@ -2167,6 +2167,18 @@ function comment_form( $args = array(), $post_id = null ) {
if ( null === $post_id )
$post_id = get_the_ID();
// Exit the function when comments for the post are closed.
if ( ! comments_open( $post_id ) ) {
/**
* Fires after the comment form if comments are closed.
*
* @since 3.0.0
*/
do_action( 'comment_form_comments_closed' );
return;
}
$commenter = wp_get_current_commenter();
$user = wp_get_current_user();
$user_identity = $user->exists() ? $user->display_name : '';
@ -2252,8 +2264,6 @@ function comment_form( $args = array(), $post_id = null ) {
// Ensure that the filtered args contain all required default values.
$args = array_merge( $defaults, $args );
if ( comments_open( $post_id ) ) : ?>
<?php
/**
* Fires before the comment form.
*
@ -2443,18 +2453,11 @@ function comment_form( $args = array(), $post_id = null ) {
<?php endif; ?>
</div><!-- #respond -->
<?php
/**
* Fires after the comment form.
*
* @since 3.0.0
*/
do_action( 'comment_form_after' );
else :
/**
* Fires after the comment form if comments are closed.
*
* @since 3.0.0
*/
do_action( 'comment_form_comments_closed' );
endif;
}