mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
Comments: Return early from comment_form()
if an invalid post ID is passed.
If an invalid post ID is passed to the function, `comments_open()` should return `false`, and no comment form be displayed. This commit restores the previous behavior that was unintentionally changed when standardizing on the `$post` parameter name. Follow-up to [53715]. Props peterwilsoncc. Fixes #56243. Built from https://develop.svn.wordpress.org/trunk@54488 git-svn-id: http://core.svn.wordpress.org/trunk@54047 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
dd2cc423ef
commit
2fc21e6b79
@ -2324,13 +2324,14 @@ function wp_list_comments( $args = array(), $comments = null ) {
|
|||||||
function comment_form( $args = array(), $post = null ) {
|
function comment_form( $args = array(), $post = null ) {
|
||||||
$post = get_post( $post );
|
$post = get_post( $post );
|
||||||
|
|
||||||
$post_id = $post ? $post->ID : get_the_ID();
|
// Exit the function if the post is invalid or comments are closed.
|
||||||
|
if ( ! $post || ! comments_open( $post ) ) {
|
||||||
// Exit the function when comments for the post are closed.
|
|
||||||
if ( ! comments_open( $post_id ) ) {
|
|
||||||
/**
|
/**
|
||||||
* Fires after the comment form if comments are closed.
|
* Fires after the comment form if comments are closed.
|
||||||
*
|
*
|
||||||
|
* For backward compatibility, this action also fires if comment_form()
|
||||||
|
* is called with an invalid post object or ID.
|
||||||
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
do_action( 'comment_form_comments_closed' );
|
do_action( 'comment_form_comments_closed' );
|
||||||
@ -2338,6 +2339,7 @@ function comment_form( $args = array(), $post = null ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$post_id = $post->ID;
|
||||||
$commenter = wp_get_current_commenter();
|
$commenter = wp_get_current_commenter();
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
$user_identity = $user->exists() ? $user->display_name : '';
|
$user_identity = $user->exists() ? $user->display_name : '';
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.1-beta3-54487';
|
$wp_version = '6.1-beta3-54488';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user