Make WordPress Core

Changeset 38959


Ignore:
Timestamp:
10/26/2016 02:47:09 PM (10 years ago)
Author:
SergeyBiryukov
Message:

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

Props jipmoors.
Fixes #38514.

File:
1 edited

Legend:

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

    r38845 r38959  
    21672167        if ( null === $post_id )
    21682168                $post_id = get_the_ID();
     2169
     2170        // Exit the function when comments for the post are closed.
     2171        if ( ! comments_open( $post_id ) ) {
     2172                /**
     2173                 * Fires after the comment form if comments are closed.
     2174                 *
     2175                 * @since 3.0.0
     2176                 */
     2177                do_action( 'comment_form_comments_closed' );
     2178
     2179                return;
     2180        }
    21692181
    21702182        $commenter = wp_get_current_commenter();
     
    22532265        $args = array_merge( $defaults, $args );
    22542266
    2255         if ( comments_open( $post_id ) ) : ?>
     2267        /**
     2268         * Fires before the comment form.
     2269         *
     2270         * @since 3.0.0
     2271         */
     2272        do_action( 'comment_form_before' );
     2273        ?>
     2274        <div id="respond" class="comment-respond">
    22562275                <?php
    2257                 /**
    2258                  * Fires before the comment form.
    2259                  *
    2260                  * @since 3.0.0
    2261                  */
    2262                 do_action( 'comment_form_before' );
    2263                 ?>
    2264                 <div id="respond" class="comment-respond">
    2265                         <?php
    2266                         echo $args['title_reply_before'];
    2267 
    2268                         comment_form_title( $args['title_reply'], $args['title_reply_to'] );
    2269 
    2270                         echo $args['cancel_reply_before'];
    2271 
    2272                         cancel_comment_reply_link( $args['cancel_reply_link'] );
    2273 
    2274                         echo $args['cancel_reply_after'];
    2275 
    2276                         echo $args['title_reply_after'];
    2277 
    2278                         if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) :
    2279                                 echo $args['must_log_in'];
     2276                echo $args['title_reply_before'];
     2277
     2278                comment_form_title( $args['title_reply'], $args['title_reply_to'] );
     2279
     2280                echo $args['cancel_reply_before'];
     2281
     2282                cancel_comment_reply_link( $args['cancel_reply_link'] );
     2283
     2284                echo $args['cancel_reply_after'];
     2285
     2286                echo $args['title_reply_after'];
     2287
     2288                if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) :
     2289                        echo $args['must_log_in'];
     2290                        /**
     2291                         * Fires after the HTML-formatted 'must log in after' message in the comment form.
     2292                         *
     2293                         * @since 3.0.0
     2294                         */
     2295                        do_action( 'comment_form_must_log_in_after' );
     2296                else : ?>
     2297                        <form action="<?php echo esc_url( $args['action'] ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>>
     2298                                <?php
    22802299                                /**
    2281                                  * Fires after the HTML-formatted 'must log in after' message in the comment form.
     2300                                 * Fires at the top of the comment form, inside the form tag.
    22822301                                 *
    22832302                                 * @since 3.0.0
    22842303                                 */
    2285                                 do_action( 'comment_form_must_log_in_after' );
    2286                         else : ?>
    2287                                 <form action="<?php echo esc_url( $args['action'] ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>>
    2288                                         <?php
     2304                                do_action( 'comment_form_top' );
     2305
     2306                                if ( is_user_logged_in() ) :
    22892307                                        /**
    2290                                          * Fires at the top of the comment form, inside the form tag.
     2308                                         * Filters the 'logged in' message for the comment form for display.
    22912309                                         *
    22922310                                         * @since 3.0.0
     2311                                         *
     2312                                         * @param string $args_logged_in The logged-in-as HTML-formatted message.
     2313                                         * @param array  $commenter      An array containing the comment author's
     2314                                         *                               username, email, and URL.
     2315                                         * @param string $user_identity  If the commenter is a registered user,
     2316                                         *                               the display name, blank otherwise.
    22932317                                         */
    2294                                         do_action( 'comment_form_top' );
    2295 
    2296                                         if ( is_user_logged_in() ) :
     2318                                        echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
     2319
     2320                                        /**
     2321                                         * Fires after the is_user_logged_in() check in the comment form.
     2322                                         *
     2323                                         * @since 3.0.0
     2324                                         *
     2325                                         * @param array  $commenter     An array containing the comment author's
     2326                                         *                              username, email, and URL.
     2327                                         * @param string $user_identity If the commenter is a registered user,
     2328                                         *                              the display name, blank otherwise.
     2329                                         */
     2330                                        do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
     2331
     2332                                else :
     2333
     2334                                        echo $args['comment_notes_before'];
     2335
     2336                                endif;
     2337
     2338                                // Prepare an array of all fields, including the textarea
     2339                                $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields'];
     2340
     2341                                /**
     2342                                 * Filters the comment form fields, including the textarea.
     2343                                 *
     2344                                 * @since 4.4.0
     2345                                 *
     2346                                 * @param array $comment_fields The comment fields.
     2347                                 */
     2348                                $comment_fields = apply_filters( 'comment_form_fields', $comment_fields );
     2349
     2350                                // Get an array of field names, excluding the textarea
     2351                                $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) );
     2352
     2353                                // Get the first and the last field name, excluding the textarea
     2354                                $first_field = reset( $comment_field_keys );
     2355                                $last_field  = end( $comment_field_keys );
     2356
     2357                                foreach ( $comment_fields as $name => $field ) {
     2358
     2359                                        if ( 'comment' === $name ) {
     2360
    22972361                                                /**
    2298                                                  * Filters the 'logged in' message for the comment form for display.
     2362                                                 * Filters the content of the comment textarea field for display.
    22992363                                                 *
    23002364                                                 * @since 3.0.0
    23012365                                                 *
    2302                                                  * @param string $args_logged_in The logged-in-as HTML-formatted message.
    2303                                                  * @param array  $commenter      An array containing the comment author's
    2304                                                  *                               username, email, and URL.
    2305                                                  * @param string $user_identity  If the commenter is a registered user,
    2306                                                  *                               the display name, blank otherwise.
     2366                                                 * @param string $args_comment_field The content of the comment textarea field.
    23072367                                                 */
    2308                                                 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
     2368                                                echo apply_filters( 'comment_form_field_comment', $field );
     2369
     2370                                                echo $args['comment_notes_after'];
     2371
     2372                                        } elseif ( ! is_user_logged_in() ) {
     2373
     2374                                                if ( $first_field === $name ) {
     2375                                                        /**
     2376                                                         * Fires before the comment fields in the comment form, excluding the textarea.
     2377                                                         *
     2378                                                         * @since 3.0.0
     2379                                                         */
     2380                                                        do_action( 'comment_form_before_fields' );
     2381                                                }
    23092382
    23102383                                                /**
    2311                                                  * Fires after the is_user_logged_in() check in the comment form.
     2384                                                 * Filters a comment form field for display.
     2385                                                 *
     2386                                                 * The dynamic portion of the filter hook, `$name`, refers to the name
     2387                                                 * of the comment form field. Such as 'author', 'email', or 'url'.
    23122388                                                 *
    23132389                                                 * @since 3.0.0
    23142390                                                 *
    2315                                                  * @param array  $commenter     An array containing the comment author's
    2316                                                  *                              username, email, and URL.
    2317                                                  * @param string $user_identity If the commenter is a registered user,
    2318                                                  *                              the display name, blank otherwise.
     2391                                                 * @param string $field The HTML-formatted output of the comment form field.
    23192392                                                 */
    2320                                                 do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
    2321 
    2322                                         else :
    2323 
    2324                                                 echo $args['comment_notes_before'];
    2325 
    2326                                         endif;
    2327 
    2328                                         // Prepare an array of all fields, including the textarea
    2329                                         $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields'];
    2330 
    2331                                         /**
    2332                                          * Filters the comment form fields, including the textarea.
    2333                                          *
    2334                                          * @since 4.4.0
    2335                                          *
    2336                                          * @param array $comment_fields The comment fields.
    2337                                          */
    2338                                         $comment_fields = apply_filters( 'comment_form_fields', $comment_fields );
    2339 
    2340                                         // Get an array of field names, excluding the textarea
    2341                                         $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) );
    2342 
    2343                                         // Get the first and the last field name, excluding the textarea
    2344                                         $first_field = reset( $comment_field_keys );
    2345                                         $last_field  = end( $comment_field_keys );
    2346 
    2347                                         foreach ( $comment_fields as $name => $field ) {
    2348 
    2349                                                 if ( 'comment' === $name ) {
    2350 
     2393                                                echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
     2394
     2395                                                if ( $last_field === $name ) {
    23512396                                                        /**
    2352                                                          * Filters the content of the comment textarea field for display.
     2397                                                         * Fires after the comment fields in the comment form, excluding the textarea.
    23532398                                                         *
    23542399                                                         * @since 3.0.0
    2355                                                          *
    2356                                                          * @param string $args_comment_field The content of the comment textarea field.
    23572400                                                         */
    2358                                                         echo apply_filters( 'comment_form_field_comment', $field );
    2359 
    2360                                                         echo $args['comment_notes_after'];
    2361 
    2362                                                 } elseif ( ! is_user_logged_in() ) {
    2363 
    2364                                                         if ( $first_field === $name ) {
    2365                                                                 /**
    2366                                                                  * Fires before the comment fields in the comment form, excluding the textarea.
    2367                                                                  *
    2368                                                                  * @since 3.0.0
    2369                                                                  */
    2370                                                                 do_action( 'comment_form_before_fields' );
    2371                                                         }
    2372 
    2373                                                         /**
    2374                                                          * Filters a comment form field for display.
    2375                                                          *
    2376                                                          * The dynamic portion of the filter hook, `$name`, refers to the name
    2377                                                          * of the comment form field. Such as 'author', 'email', or 'url'.
    2378                                                          *
    2379                                                          * @since 3.0.0
    2380                                                          *
    2381                                                          * @param string $field The HTML-formatted output of the comment form field.
    2382                                                          */
    2383                                                         echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
    2384 
    2385                                                         if ( $last_field === $name ) {
    2386                                                                 /**
    2387                                                                  * Fires after the comment fields in the comment form, excluding the textarea.
    2388                                                                  *
    2389                                                                  * @since 3.0.0
    2390                                                                  */
    2391                                                                 do_action( 'comment_form_after_fields' );
    2392                                                         }
     2401                                                        do_action( 'comment_form_after_fields' );
    23932402                                                }
    23942403                                        }
    2395 
    2396                                         $submit_button = sprintf(
    2397                                                 $args['submit_button'],
    2398                                                 esc_attr( $args['name_submit'] ),
    2399                                                 esc_attr( $args['id_submit'] ),
    2400                                                 esc_attr( $args['class_submit'] ),
    2401                                                 esc_attr( $args['label_submit'] )
    2402                                         );
    2403 
    2404                                         /**
    2405                                          * Filters the submit button for the comment form to display.
    2406                                          *
    2407                                          * @since 4.2.0
    2408                                          *
    2409                                          * @param string $submit_button HTML markup for the submit button.
    2410                                          * @param array  $args          Arguments passed to `comment_form()`.
    2411                                          */
    2412                                         $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
    2413 
    2414                                         $submit_field = sprintf(
    2415                                                 $args['submit_field'],
    2416                                                 $submit_button,
    2417                                                 get_comment_id_fields( $post_id )
    2418                                         );
    2419 
    2420                                         /**
    2421                                          * Filters the submit field for the comment form to display.
    2422                                          *
    2423                                          * The submit field includes the submit button, hidden fields for the
    2424                                          * comment form, and any wrapper markup.
    2425                                          *
    2426                                          * @since 4.2.0
    2427                                          *
    2428                                          * @param string $submit_field HTML markup for the submit field.
    2429                                          * @param array  $args         Arguments passed to comment_form().
    2430                                          */
    2431                                         echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
    2432 
    2433                                         /**
    2434                                          * Fires at the bottom of the comment form, inside the closing </form> tag.
    2435                                          *
    2436                                          * @since 1.5.0
    2437                                          *
    2438                                          * @param int $post_id The post ID.
    2439                                          */
    2440                                         do_action( 'comment_form', $post_id );
    2441                                         ?>
    2442                                 </form>
    2443                         <?php endif; ?>
    2444                 </div><!-- #respond -->
    2445                 <?php
    2446                 /**
    2447                  * Fires after the comment form.
    2448                  *
    2449                  * @since 3.0.0
    2450                  */
    2451                 do_action( 'comment_form_after' );
    2452         else :
    2453                 /**
    2454                  * Fires after the comment form if comments are closed.
    2455                  *
    2456                  * @since 3.0.0
    2457                  */
    2458                 do_action( 'comment_form_comments_closed' );
    2459         endif;
    2460 }
     2404                                }
     2405
     2406                                $submit_button = sprintf(
     2407                                        $args['submit_button'],
     2408                                        esc_attr( $args['name_submit'] ),
     2409                                        esc_attr( $args['id_submit'] ),
     2410                                        esc_attr( $args['class_submit'] ),
     2411                                        esc_attr( $args['label_submit'] )
     2412                                );
     2413
     2414                                /**
     2415                                 * Filters the submit button for the comment form to display.
     2416                                 *
     2417                                 * @since 4.2.0
     2418                                 *
     2419                                 * @param string $submit_button HTML markup for the submit button.
     2420                                 * @param array  $args          Arguments passed to `comment_form()`.
     2421                                 */
     2422                                $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
     2423
     2424                                $submit_field = sprintf(
     2425                                        $args['submit_field'],
     2426                                        $submit_button,
     2427                                        get_comment_id_fields( $post_id )
     2428                                );
     2429
     2430                                /**
     2431                                 * Filters the submit field for the comment form to display.
     2432                                 *
     2433                                 * The submit field includes the submit button, hidden fields for the
     2434                                 * comment form, and any wrapper markup.
     2435                                 *
     2436                                 * @since 4.2.0
     2437                                 *
     2438                                 * @param string $submit_field HTML markup for the submit field.
     2439                                 * @param array  $args         Arguments passed to comment_form().
     2440                                 */
     2441                                echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
     2442
     2443                                /**
     2444                                 * Fires at the bottom of the comment form, inside the closing </form> tag.
     2445                                 *
     2446                                 * @since 1.5.0
     2447                                 *
     2448                                 * @param int $post_id The post ID.
     2449                                 */
     2450                                do_action( 'comment_form', $post_id );
     2451                                ?>
     2452                        </form>
     2453                <?php endif; ?>
     2454        </div><!-- #respond -->
     2455        <?php
     2456
     2457        /**
     2458         * Fires after the comment form.
     2459         *
     2460         * @since 3.0.0
     2461         */
     2462        do_action( 'comment_form_after' );
     2463}
Note: See TracChangeset for help on using the changeset viewer.