Changeset 46088 for trunk/src/wp-includes/comment-template.php
- Timestamp:
- 09/10/2019 07:22:07 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r45932 r46088 2275 2275 $html_req = ( $req ? " required='required'" : '' ); 2276 2276 $html5 = 'html5' === $args['format']; 2277 $fields = array( 2278 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . 2279 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $html_req . ' /></p>', 2280 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . 2281 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $html_req . ' /></p>', 2282 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . 2283 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', 2277 2278 $fields = array( 2279 'author' => sprintf( 2280 '<p class="comment-form-author">%s %s</p>', 2281 sprintf( 2282 '<label for="author">%s%s</label>', 2283 __( 'Name' ), 2284 ( $req ? ' <span class="required">*</span>' : '' ) 2285 ), 2286 sprintf( 2287 '<input id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />', 2288 esc_attr( $commenter['comment_author'] ), 2289 $html_req 2290 ) 2291 ), 2292 'email' => sprintf( 2293 '<p class="comment-form-email">%s %s</p>', 2294 sprintf( 2295 '<label for="email">%s%s</label>', 2296 __( 'Email' ), 2297 ( $req ? ' <span class="required">*</span>' : '' ) 2298 ), 2299 sprintf( 2300 '<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes"%s />', 2301 ( $html5 ? 'type="email"' : 'type="text"' ), 2302 esc_attr( $commenter['comment_author_email'] ), 2303 $html_req 2304 ) 2305 ), 2306 'url' => sprintf( 2307 '<p class="comment-form-url">%s %s</p>', 2308 sprintf( 2309 '<label for="url">%s</label>', 2310 __( 'Website' ) 2311 ), 2312 sprintf( 2313 '<input id="url" name="url" %s value="%s" size="30" maxlength="200" />', 2314 ( $html5 ? 'type="url"' : 'type="text"' ), 2315 esc_attr( $commenter['comment_author_url'] ) 2316 ) 2317 ), 2284 2318 ); 2285 2319 2286 2320 if ( has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ) && get_option( 'show_comments_cookies_opt_in' ) ) { 2287 $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"'; 2288 $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . 2289 '<label for="wp-comment-cookies-consent">' . __( 'Save my name, email, and website in this browser for the next time I comment.' ) . '</label></p>'; 2321 $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"'; 2322 2323 $fields['cookies'] = sprintf( 2324 '<p class="comment-form-cookies-consent">%s %s</p>', 2325 sprintf( 2326 '<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"%s />', 2327 $consent 2328 ), 2329 sprintf( 2330 '<label for="wp-comment-cookies-consent">%s</label>', 2331 __( 'Save my name, email, and website in this browser for the next time I comment.' ) 2332 ) 2333 ); 2290 2334 2291 2335 // Ensure that the passed fields include cookies consent. … … 2308 2352 * @param string[] $fields Array of the default comment fields. 2309 2353 */ 2310 $fields = apply_filters( 'comment_form_default_fields', $fields ); 2354 $fields = apply_filters( 'comment_form_default_fields', $fields ); 2355 2311 2356 $defaults = array( 2312 2357 'fields' => $fields, 2313 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>', 2314 /** This filter is documented in wp-includes/link-template.php */ 2315 'must_log_in' => '<p class="must-log-in">' . sprintf( 2316 /* translators: %s: Login URL. */ 2317 __( 'You must be <a href="%s">logged in</a> to post a comment.' ), 2318 wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) 2319 ) . '</p>', 2320 /** This filter is documented in wp-includes/link-template.php */ 2321 'logged_in_as' => '<p class="logged-in-as">' . sprintf( 2322 /* translators: 1: Edit user link, 2: Accessibility text, 3: User name, 4: Logout URL. */ 2323 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), 2324 get_edit_user_link(), 2325 /* translators: %s: User name. */ 2326 esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), 2327 $user_identity, 2328 wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) 2329 ) . '</p>', 2330 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>' . ( $req ? $required_text : '' ) . '</p>', 2358 'comment_field' => sprintf( 2359 '<p class="comment-form-comment">%s %s</p>', 2360 sprintf( 2361 '<label for="comment">%s</label>', 2362 _x( 'Comment', 'noun' ) 2363 ), 2364 '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea>' 2365 ), 2366 'must_log_in' => sprintf( 2367 '<p class="must-log-in">%s</p>', 2368 sprintf( 2369 /* translators: %s: Login URL. */ 2370 __( 'You must be <a href="%s">logged in</a> to post a comment.' ), 2371 /** This filter is documented in wp-includes/link-template.php */ 2372 wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) 2373 ) 2374 ), 2375 'logged_in_as' => sprintf( 2376 '<p class="logged-in-as">%s</p>', 2377 sprintf( 2378 /* translators: 1: Edit user link, 2: Accessibility text, 3: User name, 4: Logout URL. */ 2379 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), 2380 get_edit_user_link(), 2381 /* translators: %s: User name. */ 2382 esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), 2383 $user_identity, 2384 /** This filter is documented in wp-includes/link-template.php */ 2385 wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) 2386 ) 2387 ), 2388 'comment_notes_before' => sprintf( 2389 '<p class="comment-notes">%s%s</p>', 2390 sprintf( 2391 '<span id="email-notes">%s</span>', 2392 __( 'Your email address will not be published.' ) 2393 ), 2394 ( $req ? $required_text : '' ) 2395 ), 2331 2396 'comment_notes_after' => '', 2332 2397 'action' => site_url( '/wp-comments-post.php' ), … … 2386 2451 2387 2452 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) : 2453 2388 2454 echo $args['must_log_in']; 2389 2455 /** … … 2393 2459 */ 2394 2460 do_action( 'comment_form_must_log_in_after' ); 2461 2395 2462 else : 2396 ?> 2397 <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' : ''; ?>> 2398 <?php 2463 2464 printf( 2465 '<form action="%s" method="post" id="%s" class="%s"%s>', 2466 esc_url( $args['action'] ), 2467 esc_attr( $args['id_form'] ), 2468 esc_attr( $args['class_form'] ), 2469 ( $html5 ? ' novalidate' : '' ) 2470 ); 2471 2472 /** 2473 * Fires at the top of the comment form, inside the form tag. 2474 * 2475 * @since 3.0.0 2476 */ 2477 do_action( 'comment_form_top' ); 2478 2479 if ( is_user_logged_in() ) : 2480 2399 2481 /** 2400 * Fi res at the top of the comment form, inside the form tag.2482 * Filters the 'logged in' message for the comment form for display. 2401 2483 * 2402 2484 * @since 3.0.0 2485 * 2486 * @param string $args_logged_in The logged-in-as HTML-formatted message. 2487 * @param array $commenter An array containing the comment author's 2488 * username, email, and URL. 2489 * @param string $user_identity If the commenter is a registered user, 2490 * the display name, blank otherwise. 2403 2491 */ 2404 do_action( 'comment_form_top' ); 2405 2406 if ( is_user_logged_in() ) : 2492 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); 2493 2494 /** 2495 * Fires after the is_user_logged_in() check in the comment form. 2496 * 2497 * @since 3.0.0 2498 * 2499 * @param array $commenter An array containing the comment author's 2500 * username, email, and URL. 2501 * @param string $user_identity If the commenter is a registered user, 2502 * the display name, blank otherwise. 2503 */ 2504 do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); 2505 2506 else : 2507 2508 echo $args['comment_notes_before']; 2509 2510 endif; 2511 2512 // Prepare an array of all fields, including the textarea 2513 $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields']; 2514 2515 /** 2516 * Filters the comment form fields, including the textarea. 2517 * 2518 * @since 4.4.0 2519 * 2520 * @param array $comment_fields The comment fields. 2521 */ 2522 $comment_fields = apply_filters( 'comment_form_fields', $comment_fields ); 2523 2524 // Get an array of field names, excluding the textarea 2525 $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) ); 2526 2527 // Get the first and the last field name, excluding the textarea 2528 $first_field = reset( $comment_field_keys ); 2529 $last_field = end( $comment_field_keys ); 2530 2531 foreach ( $comment_fields as $name => $field ) { 2532 2533 if ( 'comment' === $name ) { 2534 2407 2535 /** 2408 * Filters the 'logged in' message for the comment formfor display.2536 * Filters the content of the comment textarea field for display. 2409 2537 * 2410 2538 * @since 3.0.0 2411 2539 * 2412 * @param string $args_logged_in The logged-in-as HTML-formatted message. 2413 * @param array $commenter An array containing the comment author's 2414 * username, email, and URL. 2415 * @param string $user_identity If the commenter is a registered user, 2416 * the display name, blank otherwise. 2540 * @param string $args_comment_field The content of the comment textarea field. 2417 2541 */ 2418 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); 2542 echo apply_filters( 'comment_form_field_comment', $field ); 2543 2544 echo $args['comment_notes_after']; 2545 2546 } elseif ( ! is_user_logged_in() ) { 2547 2548 if ( $first_field === $name ) { 2549 /** 2550 * Fires before the comment fields in the comment form, excluding the textarea. 2551 * 2552 * @since 3.0.0 2553 */ 2554 do_action( 'comment_form_before_fields' ); 2555 } 2419 2556 2420 2557 /** 2421 * Fires after the is_user_logged_in() check in the comment form. 2558 * Filters a comment form field for display. 2559 * 2560 * The dynamic portion of the filter hook, `$name`, refers to the name 2561 * of the comment form field. Such as 'author', 'email', or 'url'. 2422 2562 * 2423 2563 * @since 3.0.0 2424 2564 * 2425 * @param array $commenter An array containing the comment author's 2426 * username, email, and URL. 2427 * @param string $user_identity If the commenter is a registered user, 2428 * the display name, blank otherwise. 2565 * @param string $field The HTML-formatted output of the comment form field. 2429 2566 */ 2430 do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); 2431 2432 else : 2433 2434 echo $args['comment_notes_before']; 2435 2436 endif; 2437 2438 // Prepare an array of all fields, including the textarea 2439 $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields']; 2440 2441 /** 2442 * Filters the comment form fields, including the textarea. 2443 * 2444 * @since 4.4.0 2445 * 2446 * @param array $comment_fields The comment fields. 2447 */ 2448 $comment_fields = apply_filters( 'comment_form_fields', $comment_fields ); 2449 2450 // Get an array of field names, excluding the textarea 2451 $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) ); 2452 2453 // Get the first and the last field name, excluding the textarea 2454 $first_field = reset( $comment_field_keys ); 2455 $last_field = end( $comment_field_keys ); 2456 2457 foreach ( $comment_fields as $name => $field ) { 2458 2459 if ( 'comment' === $name ) { 2460 2567 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; 2568 2569 if ( $last_field === $name ) { 2461 2570 /** 2462 * Fi lters the content of the comment textarea field for display.2571 * Fires after the comment fields in the comment form, excluding the textarea. 2463 2572 * 2464 2573 * @since 3.0.0 2465 *2466 * @param string $args_comment_field The content of the comment textarea field.2467 2574 */ 2468 echo apply_filters( 'comment_form_field_comment', $field ); 2469 2470 echo $args['comment_notes_after']; 2471 2472 } elseif ( ! is_user_logged_in() ) { 2473 2474 if ( $first_field === $name ) { 2475 /** 2476 * Fires before the comment fields in the comment form, excluding the textarea. 2477 * 2478 * @since 3.0.0 2479 */ 2480 do_action( 'comment_form_before_fields' ); 2481 } 2482 2483 /** 2484 * Filters a comment form field for display. 2485 * 2486 * The dynamic portion of the filter hook, `$name`, refers to the name 2487 * of the comment form field. Such as 'author', 'email', or 'url'. 2488 * 2489 * @since 3.0.0 2490 * 2491 * @param string $field The HTML-formatted output of the comment form field. 2492 */ 2493 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; 2494 2495 if ( $last_field === $name ) { 2496 /** 2497 * Fires after the comment fields in the comment form, excluding the textarea. 2498 * 2499 * @since 3.0.0 2500 */ 2501 do_action( 'comment_form_after_fields' ); 2502 } 2575 do_action( 'comment_form_after_fields' ); 2503 2576 } 2504 2577 } 2505 2506 $submit_button = sprintf( 2507 $args['submit_button'], 2508 esc_attr( $args['name_submit'] ), 2509 esc_attr( $args['id_submit'] ), 2510 esc_attr( $args['class_submit'] ), 2511 esc_attr( $args['label_submit'] ) 2512 ); 2513 2514 /** 2515 * Filters the submit button for the comment form to display. 2516 * 2517 * @since 4.2.0 2518 * 2519 * @param string $submit_button HTML markup for the submit button. 2520 * @param array $args Arguments passed to comment_form(). 2521 */ 2522 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args ); 2523 2524 $submit_field = sprintf( 2525 $args['submit_field'], 2526 $submit_button, 2527 get_comment_id_fields( $post_id ) 2528 ); 2529 2530 /** 2531 * Filters the submit field for the comment form to display. 2532 * 2533 * The submit field includes the submit button, hidden fields for the 2534 * comment form, and any wrapper markup. 2535 * 2536 * @since 4.2.0 2537 * 2538 * @param string $submit_field HTML markup for the submit field. 2539 * @param array $args Arguments passed to comment_form(). 2540 */ 2541 echo apply_filters( 'comment_form_submit_field', $submit_field, $args ); 2542 2543 /** 2544 * Fires at the bottom of the comment form, inside the closing </form> tag. 2545 * 2546 * @since 1.5.0 2547 * 2548 * @param int $post_id The post ID. 2549 */ 2550 do_action( 'comment_form', $post_id ); 2551 ?> 2552 </form> 2553 <?php endif; ?> 2578 } 2579 2580 $submit_button = sprintf( 2581 $args['submit_button'], 2582 esc_attr( $args['name_submit'] ), 2583 esc_attr( $args['id_submit'] ), 2584 esc_attr( $args['class_submit'] ), 2585 esc_attr( $args['label_submit'] ) 2586 ); 2587 2588 /** 2589 * Filters the submit button for the comment form to display. 2590 * 2591 * @since 4.2.0 2592 * 2593 * @param string $submit_button HTML markup for the submit button. 2594 * @param array $args Arguments passed to comment_form(). 2595 */ 2596 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args ); 2597 2598 $submit_field = sprintf( 2599 $args['submit_field'], 2600 $submit_button, 2601 get_comment_id_fields( $post_id ) 2602 ); 2603 2604 /** 2605 * Filters the submit field for the comment form to display. 2606 * 2607 * The submit field includes the submit button, hidden fields for the 2608 * comment form, and any wrapper markup. 2609 * 2610 * @since 4.2.0 2611 * 2612 * @param string $submit_field HTML markup for the submit field. 2613 * @param array $args Arguments passed to comment_form(). 2614 */ 2615 echo apply_filters( 'comment_form_submit_field', $submit_field, $args ); 2616 2617 /** 2618 * Fires at the bottom of the comment form, inside the closing </form> tag. 2619 * 2620 * @since 1.5.0 2621 * 2622 * @param int $post_id The post ID. 2623 */ 2624 do_action( 'comment_form', $post_id ); 2625 2626 echo '</form>'; 2627 2628 endif; 2629 ?> 2554 2630 </div><!-- #respond --> 2555 2631 <?php
Note: See TracChangeset
for help on using the changeset viewer.