420 * Generates semantic classes for each comment element. |
420 * Generates semantic classes for each comment element. |
421 * |
421 * |
422 * @since 2.7.0 |
422 * @since 2.7.0 |
423 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. |
423 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. |
424 * |
424 * |
425 * @param string|array $class Optional. One or more classes to add to the class list. |
425 * @param string|string[] $class Optional. One or more classes to add to the class list. |
426 * Default empty. |
426 * Default empty. |
427 * @param int|WP_Comment $comment Comment ID or WP_Comment object. Default current comment. |
427 * @param int|WP_Comment $comment Comment ID or WP_Comment object. Default current comment. |
428 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. |
428 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. |
429 * @param bool $echo Optional. Whether to echo or return the output. |
429 * @param bool $echo Optional. Whether to echo or return the output. |
430 * Default true. |
430 * Default true. |
431 * @return void|string Void if `$echo` argument is true, comment classes if `$echo` is false. |
431 * @return void|string Void if `$echo` argument is true, comment classes if `$echo` is false. |
432 */ |
432 */ |
433 function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) { |
433 function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) { |
434 // Separates classes with a single space, collates classes for comment DIV. |
434 // Separates classes with a single space, collates classes for comment DIV. |
435 $class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"'; |
435 $class = 'class="' . implode( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"'; |
436 |
436 |
437 if ( $echo ) { |
437 if ( $echo ) { |
438 echo $class; |
438 echo $class; |
439 } else { |
439 } else { |
440 return $class; |
440 return $class; |
449 * |
449 * |
450 * @global int $comment_alt |
450 * @global int $comment_alt |
451 * @global int $comment_depth |
451 * @global int $comment_depth |
452 * @global int $comment_thread_alt |
452 * @global int $comment_thread_alt |
453 * |
453 * |
454 * @param string|array $class Optional. One or more classes to add to the class list. Default empty. |
454 * @param string|string[] $class Optional. One or more classes to add to the class list. Default empty. |
455 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment. |
455 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment. |
456 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. |
456 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. |
457 * @return string[] An array of classes. |
457 * @return string[] An array of classes. |
458 */ |
458 */ |
459 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { |
459 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { |
460 global $comment_alt, $comment_depth, $comment_thread_alt; |
460 global $comment_alt, $comment_depth, $comment_thread_alt; |
461 |
461 |
528 * Filters the returned CSS classes for the current comment. |
528 * Filters the returned CSS classes for the current comment. |
529 * |
529 * |
530 * @since 2.7.0 |
530 * @since 2.7.0 |
531 * |
531 * |
532 * @param string[] $classes An array of comment classes. |
532 * @param string[] $classes An array of comment classes. |
533 * @param string $class A comma-separated list of additional classes added to the list. |
533 * @param string[] $class An array of additional classes added to the list. |
534 * @param int $comment_id The comment ID. |
534 * @param int $comment_id The comment ID. |
535 * @param WP_Comment $comment The comment object. |
535 * @param WP_Comment $comment The comment object. |
536 * @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. |
537 */ |
537 */ |
538 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 ); |
542 * Retrieves the comment date of the current comment. |
542 * Retrieves the comment date of the current comment. |
543 * |
543 * |
544 * @since 1.5.0 |
544 * @since 1.5.0 |
545 * @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. |
546 * |
546 * |
547 * @param string $format Optional. The format of the date. Default user's setting. |
547 * @param string $format Optional. PHP date format. Defaults to the 'date_format' option. |
548 * @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. |
549 * Default current comment. |
549 * Default current comment. |
550 * @return string The comment's date. |
550 * @return string The comment's date. |
551 */ |
551 */ |
552 function get_comment_date( $format = '', $comment_ID = 0 ) { |
552 function get_comment_date( $format = '', $comment_ID = 0 ) { |
560 * Filters the returned comment date. |
560 * Filters the returned comment date. |
561 * |
561 * |
562 * @since 1.5.0 |
562 * @since 1.5.0 |
563 * |
563 * |
564 * @param string|int $date Formatted date string or Unix timestamp. |
564 * @param string|int $date Formatted date string or Unix timestamp. |
565 * @param string $format The format of the date. |
565 * @param string $format PHP date format. |
566 * @param WP_Comment $comment The comment object. |
566 * @param WP_Comment $comment The comment object. |
567 */ |
567 */ |
568 return apply_filters( 'get_comment_date', $date, $format, $comment ); |
568 return apply_filters( 'get_comment_date', $date, $format, $comment ); |
569 } |
569 } |
570 |
570 |
572 * Displays the comment date of the current comment. |
572 * Displays the comment date of the current comment. |
573 * |
573 * |
574 * @since 0.71 |
574 * @since 0.71 |
575 * @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. |
576 * |
576 * |
577 * @param string $format Optional. The format of the date. Default user's settings. |
577 * @param string $format Optional. PHP date format. Defaults to the 'date_format' option. |
578 * @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. |
579 * Default current comment. |
579 * Default current comment. |
580 */ |
580 */ |
581 function comment_date( $format = '', $comment_ID = 0 ) { |
581 function comment_date( $format = '', $comment_ID = 0 ) { |
582 echo get_comment_date( $format, $comment_ID ); |
582 echo get_comment_date( $format, $comment_ID ); |
602 } else { |
602 } else { |
603 $comment_text = __( 'Password protected' ); |
603 $comment_text = __( 'Password protected' ); |
604 } |
604 } |
605 |
605 |
606 /* translators: Maximum number of words used in a comment excerpt. */ |
606 /* translators: Maximum number of words used in a comment excerpt. */ |
607 $comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) ); |
607 $comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' ); |
608 |
608 |
609 /** |
609 /** |
610 * Filters the maximum number of words used in the comment excerpt. |
610 * Filters the maximum number of words used in the comment excerpt. |
611 * |
611 * |
612 * @since 4.4.0 |
612 * @since 4.4.0 |
876 * Displays 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. |
877 * |
877 * |
878 * @since 0.71 |
878 * @since 0.71 |
879 * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`. |
879 * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`. |
880 * |
880 * |
881 * @param string $zero Optional. Text for no comments. Default false. |
881 * @param string|false $zero Optional. Text for no comments. Default false. |
882 * @param string $one Optional. Text for one comment. Default false. |
882 * @param string|false $one Optional. Text for one comment. Default false. |
883 * @param string $more Optional. Text for more than one comment. Default false. |
883 * @param string|false $more Optional. Text for more than one comment. Default false. |
884 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. |
884 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. |
885 */ |
885 */ |
886 function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) { |
886 function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) { |
887 echo get_comments_number_text( $zero, $one, $more, $post_id ); |
887 echo get_comments_number_text( $zero, $one, $more, $post_id ); |
888 } |
888 } |
889 |
889 |
1031 /** |
1031 /** |
1032 * Retrieves the comment time of the current comment. |
1032 * Retrieves the comment time of the current comment. |
1033 * |
1033 * |
1034 * @since 1.5.0 |
1034 * @since 1.5.0 |
1035 * |
1035 * |
1036 * @param string $format Optional. The format of the time. Default user's settings. |
1036 * @param string $format Optional. PHP time format. Defaults to the 'time_format' option. |
1037 * @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. |
1038 * @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). |
1039 * Default true. |
1039 * Default true. |
1040 * @return string The formatted time. |
1040 * @return string The formatted time. |
1041 */ |
1041 */ |
1052 * Filters the returned comment time. |
1052 * Filters the returned comment time. |
1053 * |
1053 * |
1054 * @since 1.5.0 |
1054 * @since 1.5.0 |
1055 * |
1055 * |
1056 * @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. |
1057 * @param string $format Date format. |
1057 * @param string $format PHP date format. |
1058 * @param bool $gmt Whether the GMT date is in use. |
1058 * @param bool $gmt Whether the GMT date is in use. |
1059 * @param bool $translate Whether the time is translated. |
1059 * @param bool $translate Whether the time is translated. |
1060 * @param WP_Comment $comment The comment object. |
1060 * @param WP_Comment $comment The comment object. |
1061 */ |
1061 */ |
1062 return apply_filters( 'get_comment_time', $date, $format, $gmt, $translate, $comment ); |
1062 return apply_filters( 'get_comment_time', $date, $format, $gmt, $translate, $comment ); |
1106 /** |
1106 /** |
1107 * Displays the comment type of the current comment. |
1107 * Displays the comment type of the current comment. |
1108 * |
1108 * |
1109 * @since 0.71 |
1109 * @since 0.71 |
1110 * |
1110 * |
1111 * @param string $commenttxt Optional. String to display for comment type. Default false. |
1111 * @param string|false $commenttxt Optional. String to display for comment type. Default false. |
1112 * @param string $trackbacktxt Optional. String to display for trackback type. Default false. |
1112 * @param string|false $trackbacktxt Optional. String to display for trackback type. Default false. |
1113 * @param string $pingbacktxt Optional. String to display for pingback type. Default false. |
1113 * @param string|false $pingbacktxt Optional. String to display for pingback type. Default false. |
1114 */ |
1114 */ |
1115 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) { |
1115 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) { |
1116 if ( false === $commenttxt ) { |
1116 if ( false === $commenttxt ) { |
1117 $commenttxt = _x( 'Comment', 'noun' ); |
1117 $commenttxt = _x( 'Comment', 'noun' ); |
1118 } |
1118 } |
1197 * |
1197 * |
1198 * Deprecated in 3.0.0, and restored in 3.0.1. |
1198 * Deprecated in 3.0.0, and restored in 3.0.1. |
1199 * |
1199 * |
1200 * @since 0.71 |
1200 * @since 0.71 |
1201 * |
1201 * |
1202 * @param int $deprecated Not used (Was $timezone = 0). |
1202 * @param int|string $deprecated Not used (Was $timezone = 0). |
1203 */ |
1203 */ |
1204 function trackback_rdf( $deprecated = '' ) { |
1204 function trackback_rdf( $deprecated = '' ) { |
1205 if ( ! empty( $deprecated ) ) { |
1205 if ( ! empty( $deprecated ) ) { |
1206 _deprecated_argument( __FUNCTION__, '2.5.0' ); |
1206 _deprecated_argument( __FUNCTION__, '2.5.0' ); |
1207 } |
1207 } |
1432 |
1432 |
1433 if ( isset( $comment_args['include_unapproved'] ) ) { |
1433 if ( isset( $comment_args['include_unapproved'] ) ) { |
1434 $top_level_args['include_unapproved'] = $comment_args['include_unapproved']; |
1434 $top_level_args['include_unapproved'] = $comment_args['include_unapproved']; |
1435 } |
1435 } |
1436 |
1436 |
|
1437 /** |
|
1438 * Filters the arguments used in the top level comments query. |
|
1439 * |
|
1440 * @since 5.6.0 |
|
1441 * |
|
1442 * @see WP_Comment_Query::__construct() |
|
1443 * |
|
1444 * @param array $top_level_args { |
|
1445 * The top level query arguments for the comments template. |
|
1446 * |
|
1447 * @type bool $count Whether to return a comment count. |
|
1448 * @type string|array $orderby The field(s) to order by. |
|
1449 * @type int $post_id The post ID. |
|
1450 * @type string|array $status The comment status to limit results by. |
|
1451 * } |
|
1452 */ |
|
1453 $top_level_args = apply_filters( 'comments_template_top_level_query_args', $top_level_args ); |
|
1454 |
1437 $top_level_count = $top_level_query->query( $top_level_args ); |
1455 $top_level_count = $top_level_query->query( $top_level_args ); |
1438 |
1456 |
1439 $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; |
1457 $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; |
1440 } |
1458 } |
1441 } |
1459 } |
1461 * @type bool|string $hierarchical Whether to query for comments hierarchically. |
1479 * @type bool|string $hierarchical Whether to query for comments hierarchically. |
1462 * @type int $offset Comment offset. |
1480 * @type int $offset Comment offset. |
1463 * @type int $number Number of comments to fetch. |
1481 * @type int $number Number of comments to fetch. |
1464 * } |
1482 * } |
1465 */ |
1483 */ |
1466 $comment_args = apply_filters( 'comments_template_query_args', $comment_args ); |
1484 $comment_args = apply_filters( 'comments_template_query_args', $comment_args ); |
|
1485 |
1467 $comment_query = new WP_Comment_Query( $comment_args ); |
1486 $comment_query = new WP_Comment_Query( $comment_args ); |
1468 $_comments = $comment_query->comments; |
1487 $_comments = $comment_query->comments; |
1469 |
1488 |
1470 // Trees must be flattened before they're passed to the walker. |
1489 // Trees must be flattened before they're passed to the walker. |
1471 if ( $comment_args['hierarchical'] ) { |
1490 if ( $comment_args['hierarchical'] ) { |
1729 array( |
1754 array( |
1730 'replytocom' => $comment->comment_ID, |
1755 'replytocom' => $comment->comment_ID, |
1731 'unapproved' => false, |
1756 'unapproved' => false, |
1732 'moderation-hash' => false, |
1757 'moderation-hash' => false, |
1733 ), |
1758 ), |
1734 get_permalink( $post->ID ) |
1759 $permalink |
1735 ) |
1760 ) |
1736 ) . '#' . $args['respond_id'], |
1761 ) . '#' . $args['respond_id'], |
1737 $data_attribute_string, |
1762 $data_attribute_string, |
1738 esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ), |
1763 esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ), |
1739 $args['reply_text'] |
1764 $args['reply_text'] |
1959 * |
1984 * |
1960 * @since 2.7.0 |
1985 * @since 2.7.0 |
1961 * |
1986 * |
1962 * @global WP_Comment $comment Global comment object. |
1987 * @global WP_Comment $comment Global comment object. |
1963 * |
1988 * |
1964 * @param string $no_reply_text Optional. Text to display when not replying to a comment. |
1989 * @param string|false $no_reply_text Optional. Text to display when not replying to a comment. |
1965 * Default false. |
1990 * Default false. |
1966 * @param string $reply_text Optional. Text to display when replying to a comment. |
1991 * @param string|false $reply_text Optional. Text to display when replying to a comment. |
1967 * Default false. Accepts "%s" for the author of the comment |
1992 * Default false. Accepts "%s" for the author of the comment |
1968 * being replied to. |
1993 * being replied to. |
1969 * @param string $link_to_parent Optional. Boolean to control making the author's name a link |
1994 * @param bool $link_to_parent Optional. Boolean to control making the author's name a link |
1970 * to their comment. Default true. |
1995 * to their comment. Default true. |
1971 */ |
1996 */ |
1972 function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true ) { |
1997 function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true ) { |
1973 global $comment; |
1998 global $comment; |
1974 |
1999 |
1975 if ( false === $no_reply_text ) { |
2000 if ( false === $no_reply_text ) { |
2203 $parsed_args['page'] = ( 'newest' === get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $parsed_args['per_page'], $threaded ) : 1; |
2228 $parsed_args['page'] = ( 'newest' === get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $parsed_args['per_page'], $threaded ) : 1; |
2204 set_query_var( 'cpage', $parsed_args['page'] ); |
2229 set_query_var( 'cpage', $parsed_args['page'] ); |
2205 } |
2230 } |
2206 } |
2231 } |
2207 // Validation check. |
2232 // Validation check. |
2208 $parsed_args['page'] = intval( $parsed_args['page'] ); |
2233 $parsed_args['page'] = (int) $parsed_args['page']; |
2209 if ( 0 == $parsed_args['page'] && 0 != $parsed_args['per_page'] ) { |
2234 if ( 0 == $parsed_args['page'] && 0 != $parsed_args['per_page'] ) { |
2210 $parsed_args['page'] = 1; |
2235 $parsed_args['page'] = 1; |
2211 } |
2236 } |
2212 |
2237 |
2213 if ( null === $parsed_args['reverse_top_level'] ) { |
2238 if ( null === $parsed_args['reverse_top_level'] ) { |
2234 } |
2259 } |
2235 |
2260 |
2236 /** |
2261 /** |
2237 * Outputs a complete commenting form for use within a template. |
2262 * Outputs a complete commenting form for use within a template. |
2238 * |
2263 * |
2239 * Most strings and form fields may be controlled through the $args array passed |
2264 * Most strings and form fields may be controlled through the `$args` array passed |
2240 * into the function, while you may also choose to use the {@see 'comment_form_default_fields'} |
2265 * into the function, while you may also choose to use the {@see 'comment_form_default_fields'} |
2241 * filter to modify the array of default fields if you'd just like to add a new |
2266 * filter to modify the array of default fields if you'd just like to add a new |
2242 * one or remove a single field. All fields are also individually passed through |
2267 * one or remove a single field. All fields are also individually passed through |
2243 * a filter of the {@see 'comment_form_field_$name'} where $name is the key used |
2268 * a filter of the {@see 'comment_form_field_$name'} where `$name` is the key used |
2244 * in the array of fields. |
2269 * in the array of fields. |
2245 * |
2270 * |
2246 * @since 3.0.0 |
2271 * @since 3.0.0 |
2247 * @since 4.1.0 Introduced the 'class_submit' argument. |
2272 * @since 4.1.0 Introduced the 'class_submit' argument. |
2248 * @since 4.2.0 Introduced the 'submit_button' and 'submit_fields' arguments. |
2273 * @since 4.2.0 Introduced the 'submit_button' and 'submit_fields' arguments. |
2478 * |
2503 * |
2479 * @param array $defaults The default comment form arguments. |
2504 * @param array $defaults The default comment form arguments. |
2480 */ |
2505 */ |
2481 $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) ); |
2506 $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) ); |
2482 |
2507 |
2483 // Ensure that the filtered args contain all required default values. |
2508 // Ensure that the filtered arguments contain all required default values. |
2484 $args = array_merge( $defaults, $args ); |
2509 $args = array_merge( $defaults, $args ); |
2485 |
2510 |
2486 // Remove `aria-describedby` from the email field if there's no associated description. |
2511 // Remove `aria-describedby` from the email field if there's no associated description. |
2487 if ( isset( $args['fields']['email'] ) && false === strpos( $args['comment_notes_before'], 'id="email-notes"' ) ) { |
2512 if ( isset( $args['fields']['email'] ) && false === strpos( $args['comment_notes_before'], 'id="email-notes"' ) ) { |
2488 $args['fields']['email'] = str_replace( |
2513 $args['fields']['email'] = str_replace( |