Make WordPress Core


Ignore:
Timestamp:
10/11/2022 03:43:04 PM (19 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r54134 r54488  
    23252325    $post = get_post( $post );
    23262326
    2327     $post_id = $post ? $post->ID : get_the_ID();
    2328 
    2329     // Exit the function when comments for the post are closed.
    2330     if ( ! comments_open( $post_id ) ) {
     2327    // Exit the function if the post is invalid or comments are closed.
     2328    if ( ! $post || ! comments_open( $post ) ) {
    23312329        /**
    23322330         * Fires after the comment form if comments are closed.
     2331         *
     2332         * For backward compatibility, this action also fires if comment_form()
     2333         * is called with an invalid post object or ID.
    23332334         *
    23342335         * @since 3.0.0
     
    23392340    }
    23402341
     2342    $post_id       = $post->ID;
    23412343    $commenter     = wp_get_current_commenter();
    23422344    $user          = wp_get_current_user();
Note: See TracChangeset for help on using the changeset viewer.