273 * |
275 * |
274 * @param string $comment_author_IP The comment author's IP address. |
276 * @param string $comment_author_IP The comment author's IP address. |
275 * @param int $comment_ID The comment ID. |
277 * @param int $comment_ID The comment ID. |
276 * @param WP_Comment $comment The comment object. |
278 * @param WP_Comment $comment The comment object. |
277 */ |
279 */ |
278 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment ); |
280 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
279 } |
281 } |
280 |
282 |
281 /** |
283 /** |
282 * Display the IP address of the author of the current comment. |
284 * Displays the IP address of the author of the current comment. |
283 * |
285 * |
284 * @since 0.71 |
286 * @since 0.71 |
285 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
287 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
286 * |
288 * |
287 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address. |
289 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address. |
288 * Default current comment. |
290 * Default current comment. |
289 */ |
291 */ |
290 function comment_author_IP( $comment_ID = 0 ) { |
292 function comment_author_IP( $comment_ID = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
291 echo esc_html( get_comment_author_IP( $comment_ID ) ); |
293 echo esc_html( get_comment_author_IP( $comment_ID ) ); |
292 } |
294 } |
293 |
295 |
294 /** |
296 /** |
295 * Retrieve the url of the author of the current comment. |
297 * Retrieves the URL of the author of the current comment, not linked. |
296 * |
298 * |
297 * @since 1.5.0 |
299 * @since 1.5.0 |
298 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
300 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
299 * |
301 * |
300 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL. |
302 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL. |
301 * Default current comment. |
303 * Default current comment. |
302 * @return string Comment author URL. |
304 * @return string Comment author URL, if provided, an empty string otherwise. |
303 */ |
305 */ |
304 function get_comment_author_url( $comment_ID = 0 ) { |
306 function get_comment_author_url( $comment_ID = 0 ) { |
305 $comment = get_comment( $comment_ID ); |
307 $comment = get_comment( $comment_ID ); |
306 $url = ''; |
308 $url = ''; |
307 $id = 0; |
309 $id = 0; |
|
310 |
308 if ( ! empty( $comment ) ) { |
311 if ( ! empty( $comment ) ) { |
309 $author_url = ( 'http://' == $comment->comment_author_url ) ? '' : $comment->comment_author_url; |
312 $author_url = ( 'http://' === $comment->comment_author_url ) ? '' : $comment->comment_author_url; |
310 $url = esc_url( $author_url, array( 'http', 'https' ) ); |
313 $url = esc_url( $author_url, array( 'http', 'https' ) ); |
311 $id = $comment->comment_ID; |
314 $id = $comment->comment_ID; |
312 } |
315 } |
313 |
316 |
314 /** |
317 /** |
523 * |
529 * |
524 * @since 2.7.0 |
530 * @since 2.7.0 |
525 * |
531 * |
526 * @param string[] $classes An array of comment classes. |
532 * @param string[] $classes An array of comment classes. |
527 * @param string $class A comma-separated list of additional classes added to the list. |
533 * @param string $class A comma-separated list of additional classes added to the list. |
528 * @param int $comment_id The comment id. |
534 * @param int $comment_id The comment ID. |
529 * @param WP_Comment $comment The comment object. |
535 * @param WP_Comment $comment The comment object. |
530 * @param int|WP_Post $post_id The post ID or WP_Post object. |
536 * @param int|WP_Post $post_id The post ID or WP_Post object. |
531 */ |
537 */ |
532 return apply_filters( 'comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id ); |
538 return apply_filters( 'comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id ); |
533 } |
539 } |
534 |
540 |
535 /** |
541 /** |
536 * Retrieve the comment date of the current comment. |
542 * Retrieves the comment date of the current comment. |
537 * |
543 * |
538 * @since 1.5.0 |
544 * @since 1.5.0 |
539 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
545 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
540 * |
546 * |
541 * @param string $d Optional. The format of the date. Default user's setting. |
547 * @param string $format Optional. The format of the date. Default user's setting. |
542 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the date. |
548 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the date. |
543 * Default current comment. |
549 * Default current comment. |
544 * @return string The comment's date. |
550 * @return string The comment's date. |
545 */ |
551 */ |
546 function get_comment_date( $d = '', $comment_ID = 0 ) { |
552 function get_comment_date( $format = '', $comment_ID = 0 ) { |
547 $comment = get_comment( $comment_ID ); |
553 $comment = get_comment( $comment_ID ); |
548 if ( '' == $d ) { |
554 |
549 $date = mysql2date( get_option( 'date_format' ), $comment->comment_date ); |
555 $_format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
550 } else { |
556 |
551 $date = mysql2date( $d, $comment->comment_date ); |
557 $date = mysql2date( $_format, $comment->comment_date ); |
552 } |
558 |
553 /** |
559 /** |
554 * Filters the returned comment date. |
560 * Filters the returned comment date. |
555 * |
561 * |
556 * @since 1.5.0 |
562 * @since 1.5.0 |
557 * |
563 * |
558 * @param string|int $date Formatted date string or Unix timestamp. |
564 * @param string|int $date Formatted date string or Unix timestamp. |
559 * @param string $d The format of the date. |
565 * @param string $format The format of the date. |
560 * @param WP_Comment $comment The comment object. |
566 * @param WP_Comment $comment The comment object. |
561 */ |
567 */ |
562 return apply_filters( 'get_comment_date', $date, $d, $comment ); |
568 return apply_filters( 'get_comment_date', $date, $format, $comment ); |
563 } |
569 } |
564 |
570 |
565 /** |
571 /** |
566 * Display the comment date of the current comment. |
572 * Displays the comment date of the current comment. |
567 * |
573 * |
568 * @since 0.71 |
574 * @since 0.71 |
569 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
575 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
570 * |
576 * |
571 * @param string $d Optional. The format of the date. Default user's settings. |
577 * @param string $format Optional. The format of the date. Default user's settings. |
572 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date. |
578 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date. |
573 * Default current comment. |
579 * Default current comment. |
574 */ |
580 */ |
575 function comment_date( $d = '', $comment_ID = 0 ) { |
581 function comment_date( $format = '', $comment_ID = 0 ) { |
576 echo get_comment_date( $d, $comment_ID ); |
582 echo get_comment_date( $format, $comment_ID ); |
577 } |
583 } |
578 |
584 |
579 /** |
585 /** |
580 * Retrieve the excerpt of the current comment. |
586 * Retrieves the excerpt of the given comment. |
581 * |
587 * |
582 * Will cut each word and only output the first 20 words with '…' at the end. |
588 * Returns a maximum of 20 words with an ellipsis appended if necessary. |
583 * If the word count is less than 20, then no truncating is done and no '…' |
|
584 * will appear. |
|
585 * |
589 * |
586 * @since 1.5.0 |
590 * @since 1.5.0 |
587 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
591 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
588 * |
592 * |
589 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt. |
593 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt. |
590 * Default current comment. |
594 * Default current comment. |
591 * @return string The maybe truncated comment with 20 words or less. |
595 * @return string The possibly truncated comment excerpt. |
592 */ |
596 */ |
593 function get_comment_excerpt( $comment_ID = 0 ) { |
597 function get_comment_excerpt( $comment_ID = 0 ) { |
594 $comment = get_comment( $comment_ID ); |
598 $comment = get_comment( $comment_ID ); |
595 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); |
599 |
596 $words = explode( ' ', $comment_text ); |
600 if ( ! post_password_required( $comment->comment_post_ID ) ) { |
597 |
601 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); |
598 /** |
602 } else { |
599 * Filters the amount of words used in the comment excerpt. |
603 $comment_text = __( 'Password protected' ); |
|
604 } |
|
605 |
|
606 /* translators: Maximum number of words used in a comment excerpt. */ |
|
607 $comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) ); |
|
608 |
|
609 /** |
|
610 * Filters the maximum number of words used in the comment excerpt. |
600 * |
611 * |
601 * @since 4.4.0 |
612 * @since 4.4.0 |
602 * |
613 * |
603 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. |
614 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. |
604 */ |
615 */ |
605 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 ); |
616 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length ); |
606 |
617 |
607 $use_ellipsis = count( $words ) > $comment_excerpt_length; |
618 $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' ); |
608 if ( $use_ellipsis ) { |
619 |
609 $words = array_slice( $words, 0, $comment_excerpt_length ); |
|
610 } |
|
611 |
|
612 $excerpt = trim( join( ' ', $words ) ); |
|
613 if ( $use_ellipsis ) { |
|
614 $excerpt .= '…'; |
|
615 } |
|
616 /** |
620 /** |
617 * Filters the retrieved comment excerpt. |
621 * Filters the retrieved comment excerpt. |
618 * |
622 * |
619 * @since 1.5.0 |
623 * @since 1.5.0 |
620 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
624 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
867 */ |
871 */ |
868 return apply_filters( 'get_comments_number', $count, $post_id ); |
872 return apply_filters( 'get_comments_number', $count, $post_id ); |
869 } |
873 } |
870 |
874 |
871 /** |
875 /** |
872 * Display the language string for the number of comments the current post has. |
876 * Displays the language string for the number of comments the current post has. |
873 * |
877 * |
874 * @since 0.71 |
878 * @since 0.71 |
875 * |
879 * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`. |
876 * @param string $zero Optional. Text for no comments. Default false. |
880 * |
877 * @param string $one Optional. Text for one comment. Default false. |
881 * @param string $zero Optional. Text for no comments. Default false. |
878 * @param string $more Optional. Text for more than one comment. Default false. |
882 * @param string $one Optional. Text for one comment. Default false. |
879 * @param string $deprecated Not used. |
883 * @param string $more Optional. Text for more than one comment. Default false. |
880 */ |
884 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. |
881 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { |
885 */ |
882 if ( ! empty( $deprecated ) ) { |
886 function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) { |
883 _deprecated_argument( __FUNCTION__, '1.3.0' ); |
887 echo get_comments_number_text( $zero, $one, $more, $post_id ); |
884 } |
888 } |
885 echo get_comments_number_text( $zero, $one, $more ); |
889 |
886 } |
890 /** |
887 |
891 * Displays the language string for the number of comments the current post has. |
888 /** |
|
889 * Display the language string for the number of comments the current post has. |
|
890 * |
892 * |
891 * @since 4.0.0 |
893 * @since 4.0.0 |
892 * |
894 * @since 5.4.0 Added the `$post_id` parameter to allow using the function outside of the loop. |
893 * @param string $zero Optional. Text for no comments. Default false. |
895 * |
894 * @param string $one Optional. Text for one comment. Default false. |
896 * @param string $zero Optional. Text for no comments. Default false. |
895 * @param string $more Optional. Text for more than one comment. Default false. |
897 * @param string $one Optional. Text for one comment. Default false. |
896 */ |
898 * @param string $more Optional. Text for more than one comment. Default false. |
897 function get_comments_number_text( $zero = false, $one = false, $more = false ) { |
899 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. |
898 $number = get_comments_number(); |
900 * @return string Language string for the number of comments a post has. |
|
901 */ |
|
902 function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) { |
|
903 $number = get_comments_number( $post_id ); |
899 |
904 |
900 if ( $number > 1 ) { |
905 if ( $number > 1 ) { |
901 if ( false === $more ) { |
906 if ( false === $more ) { |
902 /* translators: %s: number of comments */ |
907 /* translators: %s: Number of comments. */ |
903 $output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) ); |
908 $output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) ); |
904 } else { |
909 } else { |
905 // % Comments |
910 // % Comments |
906 /* translators: If comment number in your language requires declension, |
911 /* |
|
912 * translators: If comment number in your language requires declension, |
907 * translate this to 'on'. Do not translate into your own language. |
913 * translate this to 'on'. Do not translate into your own language. |
908 */ |
914 */ |
909 if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) { |
915 if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) { |
910 $text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more ); |
916 $text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more ); |
911 $text = preg_replace( '/&.+?;/', '', $text ); // Kill entities |
917 $text = preg_replace( '/&.+?;/', '', $text ); // Kill entities. |
912 $text = trim( strip_tags( $text ), '% ' ); |
918 $text = trim( strip_tags( $text ), '% ' ); |
913 |
919 |
914 // Replace '% Comments' with a proper plural form |
920 // Replace '% Comments' with a proper plural form. |
915 if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) { |
921 if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) { |
916 /* translators: %s: number of comments */ |
922 /* translators: %s: Number of comments. */ |
917 $new_text = _n( '%s Comment', '%s Comments', $number ); |
923 $new_text = _n( '%s Comment', '%s Comments', $number ); |
918 $new_text = trim( sprintf( $new_text, '' ) ); |
924 $new_text = trim( sprintf( $new_text, '' ) ); |
919 |
925 |
920 $more = str_replace( $text, $new_text, $more ); |
926 $more = str_replace( $text, $new_text, $more ); |
921 if ( false === strpos( $more, '%' ) ) { |
927 if ( false === strpos( $more, '%' ) ) { |
997 * @since 1.2.0 |
1020 * @since 1.2.0 |
998 * |
1021 * |
999 * @see Walker_Comment::comment() |
1022 * @see Walker_Comment::comment() |
1000 * |
1023 * |
1001 * @param string $comment_text Text of the current comment. |
1024 * @param string $comment_text Text of the current comment. |
1002 * @param WP_Comment|null $comment The comment object. |
1025 * @param WP_Comment|null $comment The comment object. Null if not found. |
1003 * @param array $args An array of arguments. |
1026 * @param array $args An array of arguments. |
1004 */ |
1027 */ |
1005 echo apply_filters( 'comment_text', $comment_text, $comment, $args ); |
1028 echo apply_filters( 'comment_text', $comment_text, $comment, $args ); |
1006 } |
1029 } |
1007 |
1030 |
1008 /** |
1031 /** |
1009 * Retrieve the comment time of the current comment. |
1032 * Retrieves the comment time of the current comment. |
1010 * |
1033 * |
1011 * @since 1.5.0 |
1034 * @since 1.5.0 |
1012 * |
1035 * |
1013 * @param string $d Optional. The format of the time. Default user's settings. |
1036 * @param string $format Optional. The format of the time. Default user's settings. |
1014 * @param bool $gmt Optional. Whether to use the GMT date. Default false. |
1037 * @param bool $gmt Optional. Whether to use the GMT date. Default false. |
1015 * @param bool $translate Optional. Whether to translate the time (for use in feeds). |
1038 * @param bool $translate Optional. Whether to translate the time (for use in feeds). |
1016 * Default true. |
1039 * Default true. |
1017 * @return string The formatted time. |
1040 * @return string The formatted time. |
1018 */ |
1041 */ |
1019 function get_comment_time( $d = '', $gmt = false, $translate = true ) { |
1042 function get_comment_time( $format = '', $gmt = false, $translate = true ) { |
1020 $comment = get_comment(); |
1043 $comment = get_comment(); |
1021 |
1044 |
1022 $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date; |
1045 $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date; |
1023 if ( '' == $d ) { |
1046 |
1024 $date = mysql2date( get_option( 'time_format' ), $comment_date, $translate ); |
1047 $_format = ! empty( $format ) ? $format : get_option( 'time_format' ); |
1025 } else { |
1048 |
1026 $date = mysql2date( $d, $comment_date, $translate ); |
1049 $date = mysql2date( $_format, $comment_date, $translate ); |
1027 } |
|
1028 |
1050 |
1029 /** |
1051 /** |
1030 * Filters the returned comment time. |
1052 * Filters the returned comment time. |
1031 * |
1053 * |
1032 * @since 1.5.0 |
1054 * @since 1.5.0 |
1033 * |
1055 * |
1034 * @param string|int $date The comment time, formatted as a date string or Unix timestamp. |
1056 * @param string|int $date The comment time, formatted as a date string or Unix timestamp. |
1035 * @param string $d Date format. |
1057 * @param string $format Date format. |
1036 * @param bool $gmt Whether the GMT date is in use. |
1058 * @param bool $gmt Whether the GMT date is in use. |
1037 * @param bool $translate Whether the time is translated. |
1059 * @param bool $translate Whether the time is translated. |
1038 * @param WP_Comment $comment The comment object. |
1060 * @param WP_Comment $comment The comment object. |
1039 */ |
1061 */ |
1040 return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment ); |
1062 return apply_filters( 'get_comment_time', $date, $format, $gmt, $translate, $comment ); |
1041 } |
1063 } |
1042 |
1064 |
1043 /** |
1065 /** |
1044 * Display the comment time of the current comment. |
1066 * Displays the comment time of the current comment. |
1045 * |
1067 * |
1046 * @since 0.71 |
1068 * @since 0.71 |
1047 * |
1069 * |
1048 * @param string $d Optional. The format of the time. Default user's settings. |
1070 * @param string $format Optional. The format of the time. Default user's settings. |
1049 */ |
1071 */ |
1050 function comment_time( $d = '' ) { |
1072 function comment_time( $format = '' ) { |
1051 echo get_comment_time( $d ); |
1073 echo get_comment_time( $format ); |
1052 } |
1074 } |
1053 |
1075 |
1054 /** |
1076 /** |
1055 * Retrieve the comment type of the current comment. |
1077 * Retrieves the comment type of the current comment. |
1056 * |
1078 * |
1057 * @since 1.5.0 |
1079 * @since 1.5.0 |
1058 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
1080 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
1059 * |
1081 * |
1060 * @param int|WP_Comment $comment_ID Optional. WP_Comment or ID of the comment for which to get the type. |
1082 * @param int|WP_Comment $comment_ID Optional. WP_Comment or ID of the comment for which to get the type. |
1061 * Default current comment. |
1083 * Default current comment. |
1062 * @return string The comment type. |
1084 * @return string The comment type. |
1063 */ |
1085 */ |
1064 function get_comment_type( $comment_ID = 0 ) { |
1086 function get_comment_type( $comment_ID = 0 ) { |
1065 $comment = get_comment( $comment_ID ); |
1087 $comment = get_comment( $comment_ID ); |
1066 if ( '' == $comment->comment_type ) { |
1088 |
|
1089 if ( '' === $comment->comment_type ) { |
1067 $comment->comment_type = 'comment'; |
1090 $comment->comment_type = 'comment'; |
1068 } |
1091 } |
1069 |
1092 |
1070 /** |
1093 /** |
1071 * Filters the returned comment type. |
1094 * Filters the returned comment type. |
1525 * @param false|string $more Optional. String to display when there are more than one comment. Default false. |
1550 * @param false|string $more Optional. String to display when there are more than one comment. Default false. |
1526 * @param string $css_class Optional. CSS class to use for comments. Default empty. |
1551 * @param string $css_class Optional. CSS class to use for comments. Default empty. |
1527 * @param false|string $none Optional. String to display when comments have been turned off. Default false. |
1552 * @param false|string $none Optional. String to display when comments have been turned off. Default false. |
1528 */ |
1553 */ |
1529 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { |
1554 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { |
1530 $id = get_the_ID(); |
1555 $post_id = get_the_ID(); |
1531 $title = get_the_title(); |
1556 $post_title = get_the_title(); |
1532 $number = get_comments_number( $id ); |
1557 $number = get_comments_number( $post_id ); |
1533 |
1558 |
1534 if ( false === $zero ) { |
1559 if ( false === $zero ) { |
1535 /* translators: %s: post title */ |
1560 /* translators: %s: Post title. */ |
1536 $zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $title ); |
1561 $zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $post_title ); |
1537 } |
1562 } |
1538 |
1563 |
1539 if ( false === $one ) { |
1564 if ( false === $one ) { |
1540 /* translators: %s: post title */ |
1565 /* translators: %s: Post title. */ |
1541 $one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $title ); |
1566 $one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $post_title ); |
1542 } |
1567 } |
1543 |
1568 |
1544 if ( false === $more ) { |
1569 if ( false === $more ) { |
1545 /* translators: 1: number of comments, 2: post title */ |
1570 /* translators: 1: Number of comments, 2: Post title. */ |
1546 $more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number ); |
1571 $more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number ); |
1547 $more = sprintf( $more, number_format_i18n( $number ), $title ); |
1572 $more = sprintf( $more, number_format_i18n( $number ), $post_title ); |
1548 } |
1573 } |
1549 |
1574 |
1550 if ( false === $none ) { |
1575 if ( false === $none ) { |
1551 /* translators: %s: post title */ |
1576 /* translators: %s: Post title. */ |
1552 $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title ); |
1577 $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $post_title ); |
1553 } |
1578 } |
1554 |
1579 |
1555 if ( 0 == $number && ! comments_open() && ! pings_open() ) { |
1580 if ( 0 == $number && ! comments_open() && ! pings_open() ) { |
1556 echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>'; |
1581 echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>'; |
1557 return; |
1582 return; |
1859 */ |
1889 */ |
1860 return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text ); |
1890 return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text ); |
1861 } |
1891 } |
1862 |
1892 |
1863 /** |
1893 /** |
1864 * Display HTML content for cancel comment reply link. |
1894 * Displays HTML content for cancel comment reply link. |
1865 * |
1895 * |
1866 * @since 2.7.0 |
1896 * @since 2.7.0 |
1867 * |
1897 * |
1868 * @param string $text Optional. Text to display for cancel reply link. Default empty. |
1898 * @param string $text Optional. Text to display for cancel reply link. If empty, |
|
1899 * defaults to 'Click here to cancel reply'. Default empty. |
1869 */ |
1900 */ |
1870 function cancel_comment_reply_link( $text = '' ) { |
1901 function cancel_comment_reply_link( $text = '' ) { |
1871 echo get_cancel_comment_reply_link( $text ); |
1902 echo get_cancel_comment_reply_link( $text ); |
1872 } |
1903 } |
1873 |
1904 |
1874 /** |
1905 /** |
1875 * Retrieve hidden input HTML for replying to comments. |
1906 * Retrieves hidden input HTML for replying to comments. |
1876 * |
1907 * |
1877 * @since 3.0.0 |
1908 * @since 3.0.0 |
1878 * |
1909 * |
1879 * @param int $id Optional. Post ID. Default current post ID. |
1910 * @param int $post_id Optional. Post ID. Defaults to the current post ID. |
1880 * @return string Hidden input HTML for replying to comments |
1911 * @return string Hidden input HTML for replying to comments. |
1881 */ |
1912 */ |
1882 function get_comment_id_fields( $id = 0 ) { |
1913 function get_comment_id_fields( $post_id = 0 ) { |
1883 if ( empty( $id ) ) { |
1914 if ( empty( $post_id ) ) { |
1884 $id = get_the_ID(); |
1915 $post_id = get_the_ID(); |
1885 } |
1916 } |
1886 |
1917 |
1887 $replytoid = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0; |
1918 $reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0; |
1888 $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n"; |
1919 $result = "<input type='hidden' name='comment_post_ID' value='$post_id' id='comment_post_ID' />\n"; |
1889 $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n"; |
1920 $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$reply_to_id' />\n"; |
1890 |
1921 |
1891 /** |
1922 /** |
1892 * Filters the returned comment id fields. |
1923 * Filters the returned comment ID fields. |
1893 * |
1924 * |
1894 * @since 3.0.0 |
1925 * @since 3.0.0 |
1895 * |
1926 * |
1896 * @param string $result The HTML-formatted hidden id field comment elements. |
1927 * @param string $result The HTML-formatted hidden ID field comment elements. |
1897 * @param int $id The post ID. |
1928 * @param int $post_id The post ID. |
1898 * @param int $replytoid The id of the comment being replied to. |
1929 * @param int $reply_to_id The ID of the comment being replied to. |
1899 */ |
1930 */ |
1900 return apply_filters( 'comment_id_fields', $result, $id, $replytoid ); |
1931 return apply_filters( 'comment_id_fields', $result, $post_id, $reply_to_id ); |
1901 } |
1932 } |
1902 |
1933 |
1903 /** |
1934 /** |
1904 * Output hidden input HTML for replying to comments. |
1935 * Outputs hidden input HTML for replying to comments. |
|
1936 * |
|
1937 * Adds two hidden inputs to the comment form to identify the `comment_post_ID` |
|
1938 * and `comment_parent` values for threaded comments. |
|
1939 * |
|
1940 * This tag must be within the `<form>` section of the `comments.php` template. |
1905 * |
1941 * |
1906 * @since 2.7.0 |
1942 * @since 2.7.0 |
1907 * |
1943 * |
1908 * @param int $id Optional. Post ID. Default current post ID. |
1944 * @see get_comment_id_fields() |
1909 */ |
1945 * |
1910 function comment_id_fields( $id = 0 ) { |
1946 * @param int $post_id Optional. Post ID. Defaults to the current post ID. |
1911 echo get_comment_id_fields( $id ); |
1947 */ |
1912 } |
1948 function comment_id_fields( $post_id = 0 ) { |
1913 |
1949 echo get_comment_id_fields( $post_id ); |
1914 /** |
1950 } |
1915 * Display text based on comment reply status. |
1951 |
|
1952 /** |
|
1953 * Displays text based on comment reply status. |
1916 * |
1954 * |
1917 * Only affects users with JavaScript disabled. |
1955 * Only affects users with JavaScript disabled. |
1918 * |
1956 * |
1919 * @internal The $comment global must be present to allow template tags access to the current |
1957 * @internal The $comment global must be present to allow template tags access to the current |
1920 * comment. See https://core.trac.wordpress.org/changeset/36512. |
1958 * comment. See https://core.trac.wordpress.org/changeset/36512. |
1921 * |
1959 * |
1922 * @since 2.7.0 |
1960 * @since 2.7.0 |
1923 * |
1961 * |
1924 * @global WP_Comment $comment Current comment. |
1962 * @global WP_Comment $comment Global comment object. |
1925 * |
1963 * |
1926 * @param string $noreplytext Optional. Text to display when not replying to a comment. |
1964 * @param string $no_reply_text Optional. Text to display when not replying to a comment. |
1927 * Default false. |
1965 * Default false. |
1928 * @param string $replytext Optional. Text to display when replying to a comment. |
1966 * @param string $reply_text Optional. Text to display when replying to a comment. |
1929 * Default false. Accepts "%s" for the author of the comment |
1967 * Default false. Accepts "%s" for the author of the comment |
1930 * being replied to. |
1968 * being replied to. |
1931 * @param string $linktoparent Optional. Boolean to control making the author's name a link |
1969 * @param string $link_to_parent Optional. Boolean to control making the author's name a link |
1932 * to their comment. Default true. |
1970 * to their comment. Default true. |
1933 */ |
1971 */ |
1934 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) { |
1972 function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true ) { |
1935 global $comment; |
1973 global $comment; |
1936 |
1974 |
1937 if ( false === $noreplytext ) { |
1975 if ( false === $no_reply_text ) { |
1938 $noreplytext = __( 'Leave a Reply' ); |
1976 $no_reply_text = __( 'Leave a Reply' ); |
1939 } |
1977 } |
1940 if ( false === $replytext ) { |
1978 |
1941 $replytext = __( 'Leave a Reply to %s' ); |
1979 if ( false === $reply_text ) { |
1942 } |
1980 /* translators: %s: Author of the comment being replied to. */ |
1943 |
1981 $reply_text = __( 'Leave a Reply to %s' ); |
1944 $replytoid = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0; |
1982 } |
1945 |
1983 |
1946 if ( 0 == $replytoid ) { |
1984 $reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0; |
1947 echo $noreplytext; |
1985 |
|
1986 if ( 0 == $reply_to_id ) { |
|
1987 echo $no_reply_text; |
1948 } else { |
1988 } else { |
1949 // Sets the global so that template tags can be used in the comment form. |
1989 // Sets the global so that template tags can be used in the comment form. |
1950 $comment = get_comment( $replytoid ); |
1990 $comment = get_comment( $reply_to_id ); |
1951 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>' : get_comment_author( $comment ); |
1991 |
1952 printf( $replytext, $author ); |
1992 if ( $link_to_parent ) { |
1953 } |
1993 $author = '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>'; |
1954 } |
1994 } else { |
1955 |
1995 $author = get_comment_author( $comment ); |
1956 /** |
1996 } |
1957 * List comments. |
1997 |
|
1998 printf( $reply_text, $author ); |
|
1999 } |
|
2000 } |
|
2001 |
|
2002 /** |
|
2003 * Displays a list of comments. |
1958 * |
2004 * |
1959 * Used in the comments.php template to list comments for a particular post. |
2005 * Used in the comments.php template to list comments for a particular post. |
1960 * |
2006 * |
1961 * @since 2.7.0 |
2007 * @since 2.7.0 |
1962 * |
2008 * |
1963 * @see WP_Query->comments |
2009 * @see WP_Query->comments |
1964 * |
2010 * |
1965 * @global WP_Query $wp_query |
2011 * @global WP_Query $wp_query WordPress Query object. |
1966 * @global int $comment_alt |
2012 * @global int $comment_alt |
1967 * @global int $comment_depth |
2013 * @global int $comment_depth |
1968 * @global int $comment_thread_alt |
2014 * @global int $comment_thread_alt |
1969 * @global bool $overridden_cpage |
2015 * @global bool $overridden_cpage |
1970 * @global bool $in_comment_loop |
2016 * @global bool $in_comment_loop |
1971 * |
2017 * |
1972 * @param string|array $args { |
2018 * @param string|array $args { |
1973 * Optional. Formatting options. |
2019 * Optional. Formatting options. |
1974 * |
2020 * |
1975 * @type object $walker Instance of a Walker class to list comments. Default null. |
2021 * @type object $walker Instance of a Walker class to list comments. Default null. |
1976 * @type int $max_depth The maximum comments depth. Default empty. |
2022 * @type int $max_depth The maximum comments depth. Default empty. |
1977 * @type string $style The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'. |
2023 * @type string $style The style of list ordering. Accepts 'ul', 'ol', or 'div'. |
1978 * @type string $callback Callback function to use. Default null. |
2024 * 'div' will result in no additional list markup. Default 'ul'. |
1979 * @type string $end-callback Callback function to use at the end. Default null. |
2025 * @type callable $callback Callback function to use. Default null. |
1980 * @type string $type Type of comments to list. |
2026 * @type callable $end-callback Callback function to use at the end. Default null. |
1981 * Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'. |
2027 * @type string $type Type of comments to list. Accepts 'all', 'comment', |
1982 * @type int $page Page ID to list comments for. Default empty. |
2028 * 'pingback', 'trackback', 'pings'. Default 'all'. |
1983 * @type int $per_page Number of comments to list per page. Default empty. |
2029 * @type int $page Page ID to list comments for. Default empty. |
1984 * @type int $avatar_size Height and width dimensions of the avatar size. Default 32. |
2030 * @type int $per_page Number of comments to list per page. Default empty. |
1985 * @type bool $reverse_top_level Ordering of the listed comments. If true, will display newest comments first. |
2031 * @type int $avatar_size Height and width dimensions of the avatar size. Default 32. |
1986 * @type bool $reverse_children Whether to reverse child comments in the list. Default null. |
2032 * @type bool $reverse_top_level Ordering of the listed comments. If true, will display |
1987 * @type string $format How to format the comments list. |
2033 * newest comments first. Default null. |
1988 * Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'. |
2034 * @type bool $reverse_children Whether to reverse child comments in the list. Default null. |
1989 * @type bool $short_ping Whether to output short pings. Default false. |
2035 * @type string $format How to format the comments list. Accepts 'html5', 'xhtml'. |
1990 * @type bool $echo Whether to echo the output or return it. Default true. |
2036 * Default 'html5' if the theme supports it. |
|
2037 * @type bool $short_ping Whether to output short pings. Default false. |
|
2038 * @type bool $echo Whether to echo the output or return it. Default true. |
1991 * } |
2039 * } |
1992 * @param array $comments Optional. Array of WP_Comment objects. |
2040 * @param WP_Comment[] $comments Optional. Array of WP_Comment objects. |
|
2041 * @return void|string Void if 'echo' argument is true, or no comments to list. |
|
2042 * Otherwise, HTML list of comments. |
1993 */ |
2043 */ |
1994 function wp_list_comments( $args = array(), $comments = null ) { |
2044 function wp_list_comments( $args = array(), $comments = null ) { |
1995 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; |
2045 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; |
1996 |
2046 |
1997 $in_comment_loop = true; |
2047 $in_comment_loop = true; |
1998 |
2048 |
1999 $comment_alt = $comment_thread_alt = 0; |
2049 $comment_alt = 0; |
2000 $comment_depth = 1; |
2050 $comment_thread_alt = 0; |
|
2051 $comment_depth = 1; |
2001 |
2052 |
2002 $defaults = array( |
2053 $defaults = array( |
2003 'walker' => null, |
2054 'walker' => null, |
2004 'max_depth' => '', |
2055 'max_depth' => '', |
2005 'style' => 'ul', |
2056 'style' => 'ul', |
2014 'format' => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml', |
2065 'format' => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml', |
2015 'short_ping' => false, |
2066 'short_ping' => false, |
2016 'echo' => true, |
2067 'echo' => true, |
2017 ); |
2068 ); |
2018 |
2069 |
2019 $r = wp_parse_args( $args, $defaults ); |
2070 $parsed_args = wp_parse_args( $args, $defaults ); |
2020 |
2071 |
2021 /** |
2072 /** |
2022 * Filters the arguments used in retrieving the comment list. |
2073 * Filters the arguments used in retrieving the comment list. |
2023 * |
2074 * |
2024 * @since 4.0.0 |
2075 * @since 4.0.0 |
2025 * |
2076 * |
2026 * @see wp_list_comments() |
2077 * @see wp_list_comments() |
2027 * |
2078 * |
2028 * @param array $r An array of arguments for displaying comments. |
2079 * @param array $parsed_args An array of arguments for displaying comments. |
2029 */ |
2080 */ |
2030 $r = apply_filters( 'wp_list_comments_args', $r ); |
2081 $parsed_args = apply_filters( 'wp_list_comments_args', $parsed_args ); |
2031 |
2082 |
2032 // Figure out what comments we'll be looping through ($_comments) |
2083 // Figure out what comments we'll be looping through ($_comments). |
2033 if ( null !== $comments ) { |
2084 if ( null !== $comments ) { |
2034 $comments = (array) $comments; |
2085 $comments = (array) $comments; |
2035 if ( empty( $comments ) ) { |
2086 if ( empty( $comments ) ) { |
2036 return; |
2087 return; |
2037 } |
2088 } |
2038 if ( 'all' != $r['type'] ) { |
2089 if ( 'all' !== $parsed_args['type'] ) { |
2039 $comments_by_type = separate_comments( $comments ); |
2090 $comments_by_type = separate_comments( $comments ); |
2040 if ( empty( $comments_by_type[ $r['type'] ] ) ) { |
2091 if ( empty( $comments_by_type[ $parsed_args['type'] ] ) ) { |
2041 return; |
2092 return; |
2042 } |
2093 } |
2043 $_comments = $comments_by_type[ $r['type'] ]; |
2094 $_comments = $comments_by_type[ $parsed_args['type'] ]; |
2044 } else { |
2095 } else { |
2045 $_comments = $comments; |
2096 $_comments = $comments; |
2046 } |
2097 } |
2047 } else { |
2098 } else { |
2048 /* |
2099 /* |
2049 * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query, |
2100 * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query, |
2050 * perform a separate comment query and allow Walker_Comment to paginate. |
2101 * perform a separate comment query and allow Walker_Comment to paginate. |
2051 */ |
2102 */ |
2052 if ( $r['page'] || $r['per_page'] ) { |
2103 if ( $parsed_args['page'] || $parsed_args['per_page'] ) { |
2053 $current_cpage = get_query_var( 'cpage' ); |
2104 $current_cpage = get_query_var( 'cpage' ); |
2054 if ( ! $current_cpage ) { |
2105 if ( ! $current_cpage ) { |
2055 $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages; |
2106 $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages; |
2056 } |
2107 } |
2057 |
2108 |
2058 $current_per_page = get_query_var( 'comments_per_page' ); |
2109 $current_per_page = get_query_var( 'comments_per_page' ); |
2059 if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) { |
2110 if ( $parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page ) { |
2060 $comment_args = array( |
2111 $comment_args = array( |
2061 'post_id' => get_the_ID(), |
2112 'post_id' => get_the_ID(), |
2062 'orderby' => 'comment_date_gmt', |
2113 'orderby' => 'comment_date_gmt', |
2063 'order' => 'ASC', |
2114 'order' => 'ASC', |
2064 'status' => 'approve', |
2115 'status' => 'approve', |
2065 ); |
2116 ); |
2066 |
2117 |
2067 if ( is_user_logged_in() ) { |
2118 if ( is_user_logged_in() ) { |
2068 $comment_args['include_unapproved'] = get_current_user_id(); |
2119 $comment_args['include_unapproved'] = array( get_current_user_id() ); |
2069 } else { |
2120 } else { |
2070 $unapproved_email = wp_get_unapproved_comment_author_email(); |
2121 $unapproved_email = wp_get_unapproved_comment_author_email(); |
2071 |
2122 |
2072 if ( $unapproved_email ) { |
2123 if ( $unapproved_email ) { |
2073 $comment_args['include_unapproved'] = array( $unapproved_email ); |
2124 $comment_args['include_unapproved'] = array( $unapproved_email ); |
2074 } |
2125 } |
2075 } |
2126 } |
2076 |
2127 |
2077 $comments = get_comments( $comment_args ); |
2128 $comments = get_comments( $comment_args ); |
2078 |
2129 |
2079 if ( 'all' != $r['type'] ) { |
2130 if ( 'all' !== $parsed_args['type'] ) { |
2080 $comments_by_type = separate_comments( $comments ); |
2131 $comments_by_type = separate_comments( $comments ); |
2081 if ( empty( $comments_by_type[ $r['type'] ] ) ) { |
2132 if ( empty( $comments_by_type[ $parsed_args['type'] ] ) ) { |
2082 return; |
2133 return; |
2083 } |
2134 } |
2084 |
2135 |
2085 $_comments = $comments_by_type[ $r['type'] ]; |
2136 $_comments = $comments_by_type[ $parsed_args['type'] ]; |
2086 } else { |
2137 } else { |
2087 $_comments = $comments; |
2138 $_comments = $comments; |
2088 } |
2139 } |
2089 } |
2140 } |
2090 |
2141 |
2091 // Otherwise, fall back on the comments from `$wp_query->comments`. |
2142 // Otherwise, fall back on the comments from `$wp_query->comments`. |
2092 } else { |
2143 } else { |
2093 if ( empty( $wp_query->comments ) ) { |
2144 if ( empty( $wp_query->comments ) ) { |
2094 return; |
2145 return; |
2095 } |
2146 } |
2096 if ( 'all' != $r['type'] ) { |
2147 if ( 'all' !== $parsed_args['type'] ) { |
2097 if ( empty( $wp_query->comments_by_type ) ) { |
2148 if ( empty( $wp_query->comments_by_type ) ) { |
2098 $wp_query->comments_by_type = separate_comments( $wp_query->comments ); |
2149 $wp_query->comments_by_type = separate_comments( $wp_query->comments ); |
2099 } |
2150 } |
2100 if ( empty( $wp_query->comments_by_type[ $r['type'] ] ) ) { |
2151 if ( empty( $wp_query->comments_by_type[ $parsed_args['type'] ] ) ) { |
2101 return; |
2152 return; |
2102 } |
2153 } |
2103 $_comments = $wp_query->comments_by_type[ $r['type'] ]; |
2154 $_comments = $wp_query->comments_by_type[ $parsed_args['type'] ]; |
2104 } else { |
2155 } else { |
2105 $_comments = $wp_query->comments; |
2156 $_comments = $wp_query->comments; |
2106 } |
2157 } |
2107 |
2158 |
2108 if ( $wp_query->max_num_comment_pages ) { |
2159 if ( $wp_query->max_num_comment_pages ) { |
2109 $default_comments_page = get_option( 'default_comments_page' ); |
2160 $default_comments_page = get_option( 'default_comments_page' ); |
2110 $cpage = get_query_var( 'cpage' ); |
2161 $cpage = get_query_var( 'cpage' ); |
2111 if ( 'newest' === $default_comments_page ) { |
2162 if ( 'newest' === $default_comments_page ) { |
2112 $r['cpage'] = $cpage; |
2163 $parsed_args['cpage'] = $cpage; |
2113 |
2164 |
2114 /* |
2165 /* |
2115 * When first page shows oldest comments, post permalink is the same as |
2166 * When first page shows oldest comments, post permalink is the same as |
2116 * the comment permalink. |
2167 * the comment permalink. |
2117 */ |
2168 */ |
2118 } elseif ( $cpage == 1 ) { |
2169 } elseif ( 1 == $cpage ) { |
2119 $r['cpage'] = ''; |
2170 $parsed_args['cpage'] = ''; |
2120 } else { |
2171 } else { |
2121 $r['cpage'] = $cpage; |
2172 $parsed_args['cpage'] = $cpage; |
2122 } |
2173 } |
2123 |
2174 |
2124 $r['page'] = 0; |
2175 $parsed_args['page'] = 0; |
2125 $r['per_page'] = 0; |
2176 $parsed_args['per_page'] = 0; |
2126 } |
2177 } |
2127 } |
2178 } |
2128 } |
2179 } |
2129 |
2180 |
2130 if ( '' === $r['per_page'] && get_option( 'page_comments' ) ) { |
2181 if ( '' === $parsed_args['per_page'] && get_option( 'page_comments' ) ) { |
2131 $r['per_page'] = get_query_var( 'comments_per_page' ); |
2182 $parsed_args['per_page'] = get_query_var( 'comments_per_page' ); |
2132 } |
2183 } |
2133 |
2184 |
2134 if ( empty( $r['per_page'] ) ) { |
2185 if ( empty( $parsed_args['per_page'] ) ) { |
2135 $r['per_page'] = 0; |
2186 $parsed_args['per_page'] = 0; |
2136 $r['page'] = 0; |
2187 $parsed_args['page'] = 0; |
2137 } |
2188 } |
2138 |
2189 |
2139 if ( '' === $r['max_depth'] ) { |
2190 if ( '' === $parsed_args['max_depth'] ) { |
2140 if ( get_option( 'thread_comments' ) ) { |
2191 if ( get_option( 'thread_comments' ) ) { |
2141 $r['max_depth'] = get_option( 'thread_comments_depth' ); |
2192 $parsed_args['max_depth'] = get_option( 'thread_comments_depth' ); |
2142 } else { |
2193 } else { |
2143 $r['max_depth'] = -1; |
2194 $parsed_args['max_depth'] = -1; |
2144 } |
2195 } |
2145 } |
2196 } |
2146 |
2197 |
2147 if ( '' === $r['page'] ) { |
2198 if ( '' === $parsed_args['page'] ) { |
2148 if ( empty( $overridden_cpage ) ) { |
2199 if ( empty( $overridden_cpage ) ) { |
2149 $r['page'] = get_query_var( 'cpage' ); |
2200 $parsed_args['page'] = get_query_var( 'cpage' ); |
2150 } else { |
2201 } else { |
2151 $threaded = ( -1 != $r['max_depth'] ); |
2202 $threaded = ( -1 != $parsed_args['max_depth'] ); |
2152 $r['page'] = ( 'newest' == get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $r['per_page'], $threaded ) : 1; |
2203 $parsed_args['page'] = ( 'newest' === get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $parsed_args['per_page'], $threaded ) : 1; |
2153 set_query_var( 'cpage', $r['page'] ); |
2204 set_query_var( 'cpage', $parsed_args['page'] ); |
2154 } |
2205 } |
2155 } |
2206 } |
2156 // Validation check |
2207 // Validation check. |
2157 $r['page'] = intval( $r['page'] ); |
2208 $parsed_args['page'] = intval( $parsed_args['page'] ); |
2158 if ( 0 == $r['page'] && 0 != $r['per_page'] ) { |
2209 if ( 0 == $parsed_args['page'] && 0 != $parsed_args['per_page'] ) { |
2159 $r['page'] = 1; |
2210 $parsed_args['page'] = 1; |
2160 } |
2211 } |
2161 |
2212 |
2162 if ( null === $r['reverse_top_level'] ) { |
2213 if ( null === $parsed_args['reverse_top_level'] ) { |
2163 $r['reverse_top_level'] = ( 'desc' == get_option( 'comment_order' ) ); |
2214 $parsed_args['reverse_top_level'] = ( 'desc' === get_option( 'comment_order' ) ); |
2164 } |
2215 } |
2165 |
2216 |
2166 wp_queue_comments_for_comment_meta_lazyload( $_comments ); |
2217 wp_queue_comments_for_comment_meta_lazyload( $_comments ); |
2167 |
2218 |
2168 if ( empty( $r['walker'] ) ) { |
2219 if ( empty( $parsed_args['walker'] ) ) { |
2169 $walker = new Walker_Comment; |
2220 $walker = new Walker_Comment; |
2170 } else { |
2221 } else { |
2171 $walker = $r['walker']; |
2222 $walker = $parsed_args['walker']; |
2172 } |
2223 } |
2173 |
2224 |
2174 $output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r ); |
2225 $output = $walker->paged_walk( $_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args ); |
2175 |
2226 |
2176 $in_comment_loop = false; |
2227 $in_comment_loop = false; |
2177 |
2228 |
2178 if ( $r['echo'] ) { |
2229 if ( $parsed_args['echo'] ) { |
2179 echo $output; |
2230 echo $output; |
2180 } else { |
2231 } else { |
2181 return $output; |
2232 return $output; |
2182 } |
2233 } |
2183 } |
2234 } |
2273 } |
2326 } |
2274 |
2327 |
2275 $req = get_option( 'require_name_email' ); |
2328 $req = get_option( 'require_name_email' ); |
2276 $html_req = ( $req ? " required='required'" : '' ); |
2329 $html_req = ( $req ? " required='required'" : '' ); |
2277 $html5 = 'html5' === $args['format']; |
2330 $html5 = 'html5' === $args['format']; |
2278 $fields = array( |
2331 |
2279 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2332 $fields = array( |
2280 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $html_req . ' /></p>', |
2333 'author' => sprintf( |
2281 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2334 '<p class="comment-form-author">%s %s</p>', |
2282 '<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>', |
2335 sprintf( |
2283 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . |
2336 '<label for="author">%s%s</label>', |
2284 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', |
2337 __( 'Name' ), |
|
2338 ( $req ? ' <span class="required">*</span>' : '' ) |
|
2339 ), |
|
2340 sprintf( |
|
2341 '<input id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />', |
|
2342 esc_attr( $commenter['comment_author'] ), |
|
2343 $html_req |
|
2344 ) |
|
2345 ), |
|
2346 'email' => sprintf( |
|
2347 '<p class="comment-form-email">%s %s</p>', |
|
2348 sprintf( |
|
2349 '<label for="email">%s%s</label>', |
|
2350 __( 'Email' ), |
|
2351 ( $req ? ' <span class="required">*</span>' : '' ) |
|
2352 ), |
|
2353 sprintf( |
|
2354 '<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes"%s />', |
|
2355 ( $html5 ? 'type="email"' : 'type="text"' ), |
|
2356 esc_attr( $commenter['comment_author_email'] ), |
|
2357 $html_req |
|
2358 ) |
|
2359 ), |
|
2360 'url' => sprintf( |
|
2361 '<p class="comment-form-url">%s %s</p>', |
|
2362 sprintf( |
|
2363 '<label for="url">%s</label>', |
|
2364 __( 'Website' ) |
|
2365 ), |
|
2366 sprintf( |
|
2367 '<input id="url" name="url" %s value="%s" size="30" maxlength="200" />', |
|
2368 ( $html5 ? 'type="url"' : 'type="text"' ), |
|
2369 esc_attr( $commenter['comment_author_url'] ) |
|
2370 ) |
|
2371 ), |
2285 ); |
2372 ); |
2286 |
2373 |
2287 if ( has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ) && get_option( 'show_comments_cookies_opt_in' ) ) { |
2374 if ( has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ) && get_option( 'show_comments_cookies_opt_in' ) ) { |
2288 $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"'; |
2375 $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"'; |
2289 $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . |
2376 |
2290 '<label for="wp-comment-cookies-consent">' . __( 'Save my name, email, and website in this browser for the next time I comment.' ) . '</label></p>'; |
2377 $fields['cookies'] = sprintf( |
|
2378 '<p class="comment-form-cookies-consent">%s %s</p>', |
|
2379 sprintf( |
|
2380 '<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"%s />', |
|
2381 $consent |
|
2382 ), |
|
2383 sprintf( |
|
2384 '<label for="wp-comment-cookies-consent">%s</label>', |
|
2385 __( 'Save my name, email, and website in this browser for the next time I comment.' ) |
|
2386 ) |
|
2387 ); |
2291 |
2388 |
2292 // Ensure that the passed fields include cookies consent. |
2389 // Ensure that the passed fields include cookies consent. |
2293 if ( isset( $args['fields'] ) && ! isset( $args['fields']['cookies'] ) ) { |
2390 if ( isset( $args['fields'] ) && ! isset( $args['fields']['cookies'] ) ) { |
2294 $args['fields']['cookies'] = $fields['cookies']; |
2391 $args['fields']['cookies'] = $fields['cookies']; |
2295 } |
2392 } |
2296 } |
2393 } |
2297 |
2394 |
2298 $required_text = sprintf( ' ' . __( 'Required fields are marked %s' ), '<span class="required">*</span>' ); |
2395 $required_text = sprintf( |
|
2396 /* translators: %s: Asterisk symbol (*). */ |
|
2397 ' ' . __( 'Required fields are marked %s' ), |
|
2398 '<span class="required">*</span>' |
|
2399 ); |
2299 |
2400 |
2300 /** |
2401 /** |
2301 * Filters the default comment form fields. |
2402 * Filters the default comment form fields. |
2302 * |
2403 * |
2303 * @since 3.0.0 |
2404 * @since 3.0.0 |
2304 * |
2405 * |
2305 * @param string[] $fields Array of the default comment fields. |
2406 * @param string[] $fields Array of the default comment fields. |
2306 */ |
2407 */ |
2307 $fields = apply_filters( 'comment_form_default_fields', $fields ); |
2408 $fields = apply_filters( 'comment_form_default_fields', $fields ); |
|
2409 |
2308 $defaults = array( |
2410 $defaults = array( |
2309 'fields' => $fields, |
2411 'fields' => $fields, |
2310 '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>', |
2412 'comment_field' => sprintf( |
2311 /** This filter is documented in wp-includes/link-template.php */ |
2413 '<p class="comment-form-comment">%s %s</p>', |
2312 'must_log_in' => '<p class="must-log-in">' . sprintf( |
2414 sprintf( |
2313 /* translators: %s: login URL */ |
2415 '<label for="comment">%s</label>', |
2314 __( 'You must be <a href="%s">logged in</a> to post a comment.' ), |
2416 _x( 'Comment', 'noun' ) |
2315 wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) |
2417 ), |
2316 ) . '</p>', |
2418 '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea>' |
2317 /** This filter is documented in wp-includes/link-template.php */ |
2419 ), |
2318 'logged_in_as' => '<p class="logged-in-as">' . sprintf( |
2420 'must_log_in' => sprintf( |
2319 /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ |
2421 '<p class="must-log-in">%s</p>', |
2320 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), |
2422 sprintf( |
2321 get_edit_user_link(), |
2423 /* translators: %s: Login URL. */ |
2322 /* translators: %s: user name */ |
2424 __( 'You must be <a href="%s">logged in</a> to post a comment.' ), |
2323 esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), |
2425 /** This filter is documented in wp-includes/link-template.php */ |
2324 $user_identity, |
2426 wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) |
2325 wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) |
2427 ) |
2326 ) . '</p>', |
2428 ), |
2327 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>' . ( $req ? $required_text : '' ) . '</p>', |
2429 'logged_in_as' => sprintf( |
|
2430 '<p class="logged-in-as">%s</p>', |
|
2431 sprintf( |
|
2432 /* translators: 1: Edit user link, 2: Accessibility text, 3: User name, 4: Logout URL. */ |
|
2433 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), |
|
2434 get_edit_user_link(), |
|
2435 /* translators: %s: User name. */ |
|
2436 esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), |
|
2437 $user_identity, |
|
2438 /** This filter is documented in wp-includes/link-template.php */ |
|
2439 wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) |
|
2440 ) |
|
2441 ), |
|
2442 'comment_notes_before' => sprintf( |
|
2443 '<p class="comment-notes">%s%s</p>', |
|
2444 sprintf( |
|
2445 '<span id="email-notes">%s</span>', |
|
2446 __( 'Your email address will not be published.' ) |
|
2447 ), |
|
2448 ( $req ? $required_text : '' ) |
|
2449 ), |
2328 'comment_notes_after' => '', |
2450 'comment_notes_after' => '', |
2329 'action' => site_url( '/wp-comments-post.php' ), |
2451 'action' => site_url( '/wp-comments-post.php' ), |
2330 'id_form' => 'commentform', |
2452 'id_form' => 'commentform', |
2331 'id_submit' => 'submit', |
2453 'id_submit' => 'submit', |
|
2454 'class_container' => 'comment-respond', |
2332 'class_form' => 'comment-form', |
2455 'class_form' => 'comment-form', |
2333 'class_submit' => 'submit', |
2456 'class_submit' => 'submit', |
2334 'name_submit' => 'submit', |
2457 'name_submit' => 'submit', |
2335 'title_reply' => __( 'Leave a Reply' ), |
2458 'title_reply' => __( 'Leave a Reply' ), |
|
2459 /* translators: %s: Author of the comment being replied to. */ |
2336 'title_reply_to' => __( 'Leave a Reply to %s' ), |
2460 'title_reply_to' => __( 'Leave a Reply to %s' ), |
2337 'title_reply_before' => '<h3 id="reply-title" class="comment-reply-title">', |
2461 'title_reply_before' => '<h3 id="reply-title" class="comment-reply-title">', |
2338 'title_reply_after' => '</h3>', |
2462 'title_reply_after' => '</h3>', |
2339 'cancel_reply_before' => ' <small>', |
2463 'cancel_reply_before' => ' <small>', |
2340 'cancel_reply_after' => '</small>', |
2464 'cancel_reply_after' => '</small>', |
2379 echo $args['cancel_reply_after']; |
2512 echo $args['cancel_reply_after']; |
2380 |
2513 |
2381 echo $args['title_reply_after']; |
2514 echo $args['title_reply_after']; |
2382 |
2515 |
2383 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) : |
2516 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) : |
|
2517 |
2384 echo $args['must_log_in']; |
2518 echo $args['must_log_in']; |
2385 /** |
2519 /** |
2386 * Fires after the HTML-formatted 'must log in after' message in the comment form. |
2520 * Fires after the HTML-formatted 'must log in after' message in the comment form. |
2387 * |
2521 * |
2388 * @since 3.0.0 |
2522 * @since 3.0.0 |
2389 */ |
2523 */ |
2390 do_action( 'comment_form_must_log_in_after' ); |
2524 do_action( 'comment_form_must_log_in_after' ); |
|
2525 |
2391 else : |
2526 else : |
2392 ?> |
2527 |
2393 <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' : ''; ?>> |
2528 printf( |
2394 <?php |
2529 '<form action="%s" method="post" id="%s" class="%s"%s>', |
|
2530 esc_url( $args['action'] ), |
|
2531 esc_attr( $args['id_form'] ), |
|
2532 esc_attr( $args['class_form'] ), |
|
2533 ( $html5 ? ' novalidate' : '' ) |
|
2534 ); |
|
2535 |
|
2536 /** |
|
2537 * Fires at the top of the comment form, inside the form tag. |
|
2538 * |
|
2539 * @since 3.0.0 |
|
2540 */ |
|
2541 do_action( 'comment_form_top' ); |
|
2542 |
|
2543 if ( is_user_logged_in() ) : |
|
2544 |
2395 /** |
2545 /** |
2396 * Fires at the top of the comment form, inside the form tag. |
2546 * Filters the 'logged in' message for the comment form for display. |
2397 * |
2547 * |
2398 * @since 3.0.0 |
2548 * @since 3.0.0 |
|
2549 * |
|
2550 * @param string $args_logged_in The logged-in-as HTML-formatted message. |
|
2551 * @param array $commenter An array containing the comment author's |
|
2552 * username, email, and URL. |
|
2553 * @param string $user_identity If the commenter is a registered user, |
|
2554 * the display name, blank otherwise. |
2399 */ |
2555 */ |
2400 do_action( 'comment_form_top' ); |
2556 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); |
2401 |
2557 |
2402 if ( is_user_logged_in() ) : |
2558 /** |
|
2559 * Fires after the is_user_logged_in() check in the comment form. |
|
2560 * |
|
2561 * @since 3.0.0 |
|
2562 * |
|
2563 * @param array $commenter An array containing the comment author's |
|
2564 * username, email, and URL. |
|
2565 * @param string $user_identity If the commenter is a registered user, |
|
2566 * the display name, blank otherwise. |
|
2567 */ |
|
2568 do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); |
|
2569 |
|
2570 else : |
|
2571 |
|
2572 echo $args['comment_notes_before']; |
|
2573 |
|
2574 endif; |
|
2575 |
|
2576 // Prepare an array of all fields, including the textarea. |
|
2577 $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields']; |
|
2578 |
|
2579 /** |
|
2580 * Filters the comment form fields, including the textarea. |
|
2581 * |
|
2582 * @since 4.4.0 |
|
2583 * |
|
2584 * @param array $comment_fields The comment fields. |
|
2585 */ |
|
2586 $comment_fields = apply_filters( 'comment_form_fields', $comment_fields ); |
|
2587 |
|
2588 // Get an array of field names, excluding the textarea. |
|
2589 $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) ); |
|
2590 |
|
2591 // Get the first and the last field name, excluding the textarea. |
|
2592 $first_field = reset( $comment_field_keys ); |
|
2593 $last_field = end( $comment_field_keys ); |
|
2594 |
|
2595 foreach ( $comment_fields as $name => $field ) { |
|
2596 |
|
2597 if ( 'comment' === $name ) { |
|
2598 |
2403 /** |
2599 /** |
2404 * Filters the 'logged in' message for the comment form for display. |
2600 * Filters the content of the comment textarea field for display. |
2405 * |
2601 * |
2406 * @since 3.0.0 |
2602 * @since 3.0.0 |
2407 * |
2603 * |
2408 * @param string $args_logged_in The logged-in-as HTML-formatted message. |
2604 * @param string $args_comment_field The content of the comment textarea field. |
2409 * @param array $commenter An array containing the comment author's |
|
2410 * username, email, and URL. |
|
2411 * @param string $user_identity If the commenter is a registered user, |
|
2412 * the display name, blank otherwise. |
|
2413 */ |
2605 */ |
2414 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); |
2606 echo apply_filters( 'comment_form_field_comment', $field ); |
|
2607 |
|
2608 echo $args['comment_notes_after']; |
|
2609 |
|
2610 } elseif ( ! is_user_logged_in() ) { |
|
2611 |
|
2612 if ( $first_field === $name ) { |
|
2613 /** |
|
2614 * Fires before the comment fields in the comment form, excluding the textarea. |
|
2615 * |
|
2616 * @since 3.0.0 |
|
2617 */ |
|
2618 do_action( 'comment_form_before_fields' ); |
|
2619 } |
2415 |
2620 |
2416 /** |
2621 /** |
2417 * Fires after the is_user_logged_in() check in the comment form. |
2622 * Filters a comment form field for display. |
|
2623 * |
|
2624 * The dynamic portion of the filter hook, `$name`, refers to the name |
|
2625 * of the comment form field. Such as 'author', 'email', or 'url'. |
2418 * |
2626 * |
2419 * @since 3.0.0 |
2627 * @since 3.0.0 |
2420 * |
2628 * |
2421 * @param array $commenter An array containing the comment author's |
2629 * @param string $field The HTML-formatted output of the comment form field. |
2422 * username, email, and URL. |
|
2423 * @param string $user_identity If the commenter is a registered user, |
|
2424 * the display name, blank otherwise. |
|
2425 */ |
2630 */ |
2426 do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); |
2631 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; |
2427 |
2632 |
2428 else : |
2633 if ( $last_field === $name ) { |
2429 |
|
2430 echo $args['comment_notes_before']; |
|
2431 |
|
2432 endif; |
|
2433 |
|
2434 // Prepare an array of all fields, including the textarea |
|
2435 $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields']; |
|
2436 |
|
2437 /** |
|
2438 * Filters the comment form fields, including the textarea. |
|
2439 * |
|
2440 * @since 4.4.0 |
|
2441 * |
|
2442 * @param array $comment_fields The comment fields. |
|
2443 */ |
|
2444 $comment_fields = apply_filters( 'comment_form_fields', $comment_fields ); |
|
2445 |
|
2446 // Get an array of field names, excluding the textarea |
|
2447 $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) ); |
|
2448 |
|
2449 // Get the first and the last field name, excluding the textarea |
|
2450 $first_field = reset( $comment_field_keys ); |
|
2451 $last_field = end( $comment_field_keys ); |
|
2452 |
|
2453 foreach ( $comment_fields as $name => $field ) { |
|
2454 |
|
2455 if ( 'comment' === $name ) { |
|
2456 |
|
2457 /** |
2634 /** |
2458 * Filters the content of the comment textarea field for display. |
2635 * Fires after the comment fields in the comment form, excluding the textarea. |
2459 * |
2636 * |
2460 * @since 3.0.0 |
2637 * @since 3.0.0 |
2461 * |
|
2462 * @param string $args_comment_field The content of the comment textarea field. |
|
2463 */ |
2638 */ |
2464 echo apply_filters( 'comment_form_field_comment', $field ); |
2639 do_action( 'comment_form_after_fields' ); |
2465 |
|
2466 echo $args['comment_notes_after']; |
|
2467 |
|
2468 } elseif ( ! is_user_logged_in() ) { |
|
2469 |
|
2470 if ( $first_field === $name ) { |
|
2471 /** |
|
2472 * Fires before the comment fields in the comment form, excluding the textarea. |
|
2473 * |
|
2474 * @since 3.0.0 |
|
2475 */ |
|
2476 do_action( 'comment_form_before_fields' ); |
|
2477 } |
|
2478 |
|
2479 /** |
|
2480 * Filters a comment form field for display. |
|
2481 * |
|
2482 * The dynamic portion of the filter hook, `$name`, refers to the name |
|
2483 * of the comment form field. Such as 'author', 'email', or 'url'. |
|
2484 * |
|
2485 * @since 3.0.0 |
|
2486 * |
|
2487 * @param string $field The HTML-formatted output of the comment form field. |
|
2488 */ |
|
2489 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; |
|
2490 |
|
2491 if ( $last_field === $name ) { |
|
2492 /** |
|
2493 * Fires after the comment fields in the comment form, excluding the textarea. |
|
2494 * |
|
2495 * @since 3.0.0 |
|
2496 */ |
|
2497 do_action( 'comment_form_after_fields' ); |
|
2498 } |
|
2499 } |
2640 } |
2500 } |
2641 } |
2501 |
2642 } |
2502 $submit_button = sprintf( |
2643 |
2503 $args['submit_button'], |
2644 $submit_button = sprintf( |
2504 esc_attr( $args['name_submit'] ), |
2645 $args['submit_button'], |
2505 esc_attr( $args['id_submit'] ), |
2646 esc_attr( $args['name_submit'] ), |
2506 esc_attr( $args['class_submit'] ), |
2647 esc_attr( $args['id_submit'] ), |
2507 esc_attr( $args['label_submit'] ) |
2648 esc_attr( $args['class_submit'] ), |
2508 ); |
2649 esc_attr( $args['label_submit'] ) |
2509 |
2650 ); |
2510 /** |
2651 |
2511 * Filters the submit button for the comment form to display. |
2652 /** |
2512 * |
2653 * Filters the submit button for the comment form to display. |
2513 * @since 4.2.0 |
2654 * |
2514 * |
2655 * @since 4.2.0 |
2515 * @param string $submit_button HTML markup for the submit button. |
2656 * |
2516 * @param array $args Arguments passed to comment_form(). |
2657 * @param string $submit_button HTML markup for the submit button. |
2517 */ |
2658 * @param array $args Arguments passed to comment_form(). |
2518 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args ); |
2659 */ |
2519 |
2660 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args ); |
2520 $submit_field = sprintf( |
2661 |
2521 $args['submit_field'], |
2662 $submit_field = sprintf( |
2522 $submit_button, |
2663 $args['submit_field'], |
2523 get_comment_id_fields( $post_id ) |
2664 $submit_button, |
2524 ); |
2665 get_comment_id_fields( $post_id ) |
2525 |
2666 ); |
2526 /** |
2667 |
2527 * Filters the submit field for the comment form to display. |
2668 /** |
2528 * |
2669 * Filters the submit field for the comment form to display. |
2529 * The submit field includes the submit button, hidden fields for the |
2670 * |
2530 * comment form, and any wrapper markup. |
2671 * The submit field includes the submit button, hidden fields for the |
2531 * |
2672 * comment form, and any wrapper markup. |
2532 * @since 4.2.0 |
2673 * |
2533 * |
2674 * @since 4.2.0 |
2534 * @param string $submit_field HTML markup for the submit field. |
2675 * |
2535 * @param array $args Arguments passed to comment_form(). |
2676 * @param string $submit_field HTML markup for the submit field. |
2536 */ |
2677 * @param array $args Arguments passed to comment_form(). |
2537 echo apply_filters( 'comment_form_submit_field', $submit_field, $args ); |
2678 */ |
2538 |
2679 echo apply_filters( 'comment_form_submit_field', $submit_field, $args ); |
2539 /** |
2680 |
2540 * Fires at the bottom of the comment form, inside the closing </form> tag. |
2681 /** |
2541 * |
2682 * Fires at the bottom of the comment form, inside the closing form tag. |
2542 * @since 1.5.0 |
2683 * |
2543 * |
2684 * @since 1.5.0 |
2544 * @param int $post_id The post ID. |
2685 * |
2545 */ |
2686 * @param int $post_id The post ID. |
2546 do_action( 'comment_form', $post_id ); |
2687 */ |
2547 ?> |
2688 do_action( 'comment_form', $post_id ); |
2548 </form> |
2689 |
2549 <?php endif; ?> |
2690 echo '</form>'; |
|
2691 |
|
2692 endif; |
|
2693 ?> |
2550 </div><!-- #respond --> |
2694 </div><!-- #respond --> |
2551 <?php |
2695 <?php |
2552 |
2696 |
2553 /** |
2697 /** |
2554 * Fires after the comment form. |
2698 * Fires after the comment form. |