3 * Comment template functions
5 * These functions are meant to live inside of the WordPress loop.
12 * Retrieve the author of the current comment.
14 * If the comment has an empty comment_author field, then 'Anonymous' person is
19 * @param int $comment_ID Optional. The ID of the comment for which to retrieve the author. Default current comment.
20 * @return string The comment author
22 function get_comment_author( $comment_ID = 0 ) {
23 $comment = get_comment( $comment_ID );
25 if ( empty( $comment->comment_author ) ) {
26 if ( $comment->user_id && $user = get_userdata( $comment->user_id ) )
27 $author = $user->display_name;
29 $author = __('Anonymous');
31 $author = $comment->comment_author;
35 * Filter the returned comment author name.
38 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
40 * @param string $author The comment author's username.
41 * @param int $comment_ID The comment ID.
42 * @param object $comment The comment object.
44 return apply_filters( 'get_comment_author', $author, $comment_ID, $comment );
48 * Displays the author of the current comment.
52 * @param int $comment_ID Optional. The ID of the comment for which to print the author. Default current comment.
54 function comment_author( $comment_ID = 0 ) {
55 $author = get_comment_author( $comment_ID );
58 * Filter the comment author's name for display.
61 * @since 4.1.0 The `$comment_ID` parameter was added.
63 * @param string $author The comment author's username.
64 * @param int $comment_ID The comment ID.
66 echo apply_filters( 'comment_author', $author, $comment_ID );
70 * Retrieve the email of the author of the current comment.
74 * @param int $comment_ID Optional. The ID of the comment for which to get the author's email. Default current comment.
75 * @return string The current comment author's email
77 function get_comment_author_email( $comment_ID = 0 ) {
78 $comment = get_comment( $comment_ID );
81 * Filter the comment author's returned email address.
84 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
86 * @param string $comment_author_email The comment author's email address.
87 * @param int $comment_ID The comment ID.
88 * @param object $comment The comment object.
90 return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment_ID, $comment );
94 * Display the email of the author of the current global $comment.
96 * Care should be taken to protect the email address and assure that email
97 * harvesters do not capture your commentors' email address. Most assume that
98 * their email address will not appear in raw form on the blog. Doing so will
99 * enable anyone, including those that people don't want to get the email
100 * address and use it for their own means good and bad.
104 * @param int $comment_ID Optional. The ID of the comment for which to print the author's email. Default current comment.
106 function comment_author_email( $comment_ID = 0 ) {
107 $author_email = get_comment_author_email( $comment_ID );
110 * Filter the comment author's email for display.
113 * @since 4.1.0 The `$comment_ID` parameter was added.
115 * @param string $author_email The comment author's email address.
116 * @param int $comment_ID The comment ID.
118 echo apply_filters( 'author_email', $author_email, $comment_ID );
122 * Display the html email link to the author of the current comment.
124 * Care should be taken to protect the email address and assure that email
125 * harvesters do not capture your commentors' email address. Most assume that
126 * their email address will not appear in raw form on the blog. Doing so will
127 * enable anyone, including those that people don't want to get the email
128 * address and use it for their own means good and bad.
132 * @param string $linktext Optional. Text to display instead of the comment author's email address.
134 * @param string $before Optional. Text or HTML to display before the email link. Default empty.
135 * @param string $after Optional. Text or HTML to display after the email link. Default empty.
137 function comment_author_email_link( $linktext = '', $before = '', $after = '' ) {
138 if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )
143 * Return the html email link to the author of the current comment.
145 * Care should be taken to protect the email address and assure that email
146 * harvesters do not capture your commentors' email address. Most assume that
147 * their email address will not appear in raw form on the blog. Doing so will
148 * enable anyone, including those that people don't want to get the email
149 * address and use it for their own means good and bad.
151 * @global object $comment The current Comment row object.
155 * @param string $linktext Optional. Text to display instead of the comment author's email address.
157 * @param string $before Optional. Text or HTML to display before the email link. Default empty.
158 * @param string $after Optional. Text or HTML to display after the email link. Default empty.
161 function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) {
165 * Filter the comment author's email for display.
167 * Care should be taken to protect the email address and assure that email
168 * harvesters do not capture your commenter's email address.
171 * @since 4.1.0 The `$comment` parameter was added.
173 * @param string $comment_author_email The comment author's email address.
174 * @param object $comment The comment object.
176 $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
177 if ((!empty($email)) && ($email != '@')) {
178 $display = ($linktext != '') ? $linktext : $email;
180 $return .= "<a href='mailto:$email'>$display</a>";
189 * Retrieve the HTML link to the URL of the author of the current comment.
191 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
192 * which falls back to the global comment variable if the $comment_ID argument is empty.
196 * @param int $comment_ID ID of the comment for which to get the author's link.
197 * Default current comment.
198 * @return string The comment author name or HTML link for author's URL.
200 function get_comment_author_link( $comment_ID = 0 ) {
201 $url = get_comment_author_url( $comment_ID );
202 $author = get_comment_author( $comment_ID );
204 if ( empty( $url ) || 'http://' == $url )
207 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
210 * Filter the comment author's link for display.
213 * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
215 * @param string $return The HTML-formatted comment author link.
216 * Empty for an invalid URL.
217 * @param string $author The comment author's username.
218 * @param int $comment_ID The comment ID.
220 return apply_filters( 'get_comment_author_link', $return, $author, $comment_ID );
224 * Display the html link to the url of the author of the current comment.
228 * @param int $comment_ID ID of the comment for which to print the author's
229 * link. Default current comment.
231 function comment_author_link( $comment_ID = 0 ) {
232 echo get_comment_author_link( $comment_ID );
236 * Retrieve the IP address of the author of the current comment.
240 * @param int $comment_ID ID of the comment for which to get the author's IP
241 * address. Default current comment.
242 * @return string Comment author's IP address.
244 function get_comment_author_IP( $comment_ID = 0 ) {
245 $comment = get_comment( $comment_ID );
248 * Filter the comment author's returned IP address.
251 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
253 * @param string $comment_author_IP The comment author's IP address.
254 * @param int $comment_ID The comment ID.
255 * @param object $comment The comment object.
257 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment_ID, $comment );
261 * Display the IP address of the author of the current comment.
265 * @param int $comment_ID ID of the comment for which to print the author's IP
266 * address. Default current comment.
268 function comment_author_IP( $comment_ID = 0 ) {
269 echo get_comment_author_IP( $comment_ID );
273 * Retrieve the url of the author of the current comment.
277 * @param int $comment_ID ID of the comment for which to get the author's URL.
278 * Default current comment.
281 function get_comment_author_url( $comment_ID = 0 ) {
282 $comment = get_comment( $comment_ID );
283 $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
284 $url = esc_url( $url, array('http', 'https') );
287 * Filter the comment author's URL.
290 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
292 * @param string $url The comment author's URL.
293 * @param int $comment_ID The comment ID.
294 * @param object $comment The comment object.
296 return apply_filters( 'get_comment_author_url', $url, $comment_ID, $comment );
300 * Display the url of the author of the current comment.
304 * @param int $comment_ID ID of the comment for which to print the author's URL.
305 * Default current comment.
307 function comment_author_url( $comment_ID = 0 ) {
308 $author_url = get_comment_author_url( $comment_ID );
311 * Filter the comment author's URL for display.
314 * @since 4.1.0 The `$comment_ID` parameter was added.
316 * @param string $author_url The comment author's URL.
317 * @param int $comment_ID The comment ID.
319 echo apply_filters( 'comment_url', $author_url, $comment_ID );
323 * Retrieves the HTML link of the url of the author of the current comment.
325 * $linktext parameter is only used if the URL does not exist for the comment
326 * author. If the URL does exist then the URL will be used and the $linktext
329 * Encapsulate the HTML link between the $before and $after. So it will appear
330 * in the order of $before, link, and finally $after.
334 * @param string $linktext Optional. The text to display instead of the comment
335 * author's email address. Default empty.
336 * @param string $before Optional. The text or HTML to display before the email link.
338 * @param string $after Optional. The text or HTML to display after the email link.
340 * @return string The HTML link between the $before and $after parameters.
342 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
343 $url = get_comment_author_url();
344 $display = ($linktext != '') ? $linktext : $url;
345 $display = str_replace( 'http://www.', '', $display );
346 $display = str_replace( 'http://', '', $display );
348 if ( '/' == substr($display, -1) ) {
349 $display = substr($display, 0, -1);
352 $return = "$before<a href='$url' rel='external'>$display</a>$after";
355 * Filter the comment author's returned URL link.
359 * @param string $return The HTML-formatted comment author URL link.
361 return apply_filters( 'get_comment_author_url_link', $return );
365 * Displays the HTML link of the url of the author of the current comment.
369 * @param string $linktext Optional. Text to display instead of the comment author's
370 * email address. Default empty.
371 * @param string $before Optional. Text or HTML to display before the email link.
373 * @param string $after Optional. Text or HTML to display after the email link.
376 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
377 echo get_comment_author_url_link( $linktext, $before, $after );
381 * Generates semantic classes for each comment element.
385 * @param string|array $class Optional. One or more classes to add to the class list.
387 * @param int $comment_id Comment ID. Default current comment.
388 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
389 * @param bool $echo Optional. Whether to cho or return the output.
391 * @return string|void
393 function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
394 // Separates classes with a single space, collates classes for comment DIV
395 $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
403 * Returns the classes for the comment div as an array.
407 * @global int $comment_alt
408 * @global int $comment_depth
409 * @global int $comment_thread_alt
411 * @param string|array $class Optional. One or more classes to add to the class list. Default empty.
412 * @param int $comment_id Comment ID. Default current comment.
413 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
414 * @return array An array of classes.
416 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
417 global $comment_alt, $comment_depth, $comment_thread_alt;
419 $comment = get_comment($comment_id);
423 // Get the comment type (comment, trackback),
424 $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
426 // Add classes for comment authors that are registered users.
427 if ( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) ) {
428 $classes[] = 'byuser';
429 $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
430 // For comment authors who are the author of the post
431 if ( $post = get_post($post_id) ) {
432 if ( $comment->user_id === $post->post_author ) {
433 $classes[] = 'bypostauthor';
438 if ( empty($comment_alt) )
440 if ( empty($comment_depth) )
442 if ( empty($comment_thread_alt) )
443 $comment_thread_alt = 0;
445 if ( $comment_alt % 2 ) {
454 // Alt for top-level comments
455 if ( 1 == $comment_depth ) {
456 if ( $comment_thread_alt % 2 ) {
457 $classes[] = 'thread-odd';
458 $classes[] = 'thread-alt';
460 $classes[] = 'thread-even';
462 $comment_thread_alt++;
465 $classes[] = "depth-$comment_depth";
467 if ( !empty($class) ) {
468 if ( !is_array( $class ) )
469 $class = preg_split('#\s+#', $class);
470 $classes = array_merge($classes, $class);
473 $classes = array_map('esc_attr', $classes);
476 * Filter the returned CSS classes for the current comment.
480 * @param array $classes An array of comment classes.
481 * @param string $class A comma-separated list of additional classes added to the list.
482 * @param int $comment_id The comment id.
483 * @param object $comment The comment
484 * @param int|WP_Post $post_id The post ID or WP_Post object.
486 return apply_filters( 'comment_class', $classes, $class, $comment_id, $comment, $post_id );
490 * Retrieve the comment date of the current comment.
494 * @param string $d Optional. The format of the date. Default user's setting.
495 * @param int $comment_ID ID of the comment for which to get the date. Default current comment.
496 * @return string The comment's date.
498 function get_comment_date( $d = '', $comment_ID = 0 ) {
499 $comment = get_comment( $comment_ID );
501 $date = mysql2date(get_option('date_format'), $comment->comment_date);
503 $date = mysql2date($d, $comment->comment_date);
505 * Filter the returned comment date.
509 * @param string|int $date Formatted date string or Unix timestamp.
510 * @param string $d The format of the date.
511 * @param object $comment The comment object.
513 return apply_filters( 'get_comment_date', $date, $d, $comment );
517 * Display the comment date of the current comment.
521 * @param string $d Optional. The format of the date. Default user's settings.
522 * @param int $comment_ID ID of the comment for which to print the date. Default current comment.
524 function comment_date( $d = '', $comment_ID = 0 ) {
525 echo get_comment_date( $d, $comment_ID );
529 * Retrieve the excerpt of the current comment.
531 * Will cut each word and only output the first 20 words with '…' at the end.
532 * If the word count is less than 20, then no truncating is done and no '…'
537 * @param int $comment_ID ID of the comment for which to get the excerpt.
538 * Default current comment.
539 * @return string The maybe truncated comment with 20 words or less.
541 function get_comment_excerpt( $comment_ID = 0 ) {
542 $comment = get_comment( $comment_ID );
543 $comment_text = strip_tags($comment->comment_content);
544 $blah = explode(' ', $comment_text);
546 if (count($blah) > 20) {
555 for ($i=0; $i<$k; $i++) {
556 $excerpt .= $blah[$i] . ' ';
558 $excerpt .= ($use_dotdotdot) ? '…' : '';
561 * Filter the retrieved comment excerpt.
564 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
566 * @param string $excerpt The comment excerpt text.
567 * @param int $comment_ID The comment ID.
568 * @param object $comment The comment object.
570 return apply_filters( 'get_comment_excerpt', $excerpt, $comment_ID, $comment );
574 * Display the excerpt of the current comment.
578 * @param int $comment_ID ID of the comment for which to print the excerpt.
579 * Default current comment.
581 function comment_excerpt( $comment_ID = 0 ) {
582 $comment_excerpt = get_comment_excerpt($comment_ID);
585 * Filter the comment excerpt for display.
588 * @since 4.1.0 The `$comment_ID` parameter was added.
590 * @param string $comment_excerpt The comment excerpt text.
591 * @param int $comment_ID The comment ID.
593 echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment_ID );
597 * Retrieve the comment id of the current comment.
601 * @global object $comment
603 * @return int The comment ID.
605 function get_comment_ID() {
609 * Filter the returned comment ID.
612 * @since 4.1.0 The `$comment_ID` parameter was added.
614 * @param int $comment_ID The current comment ID.
615 * @param object $comment The comment object.
617 return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment );
621 * Display the comment id of the current comment.
625 function comment_ID() {
626 echo get_comment_ID();
630 * Retrieve the link to a given comment.
634 * @see get_page_of_comment()
636 * @global WP_Rewrite $wp_rewrite
637 * @global bool $in_comment_loop
639 * @param mixed $comment Comment to retrieve. Default current comment.
640 * @param array $args Optional. An array of arguments to override the defaults.
641 * @return string The permalink to the given comment.
643 function get_comment_link( $comment = null, $args = array() ) {
644 global $wp_rewrite, $in_comment_loop;
646 $comment = get_comment($comment);
649 if ( ! is_array( $args ) ) {
650 $args = array( 'page' => $args );
653 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
654 $args = wp_parse_args( $args, $defaults );
656 if ( '' === $args['per_page'] && get_option('page_comments') )
657 $args['per_page'] = get_option('comments_per_page');
659 if ( empty($args['per_page']) ) {
660 $args['per_page'] = 0;
664 if ( $args['per_page'] ) {
665 if ( '' == $args['page'] )
666 $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
668 if ( $wp_rewrite->using_permalinks() )
669 $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment' );
671 $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
673 $link = get_permalink( $comment->comment_post_ID );
676 $link = $link . '#comment-' . $comment->comment_ID;
678 * Filter the returned single comment permalink.
682 * @see get_page_of_comment()
684 * @param string $link The comment permalink with '#comment-$id' appended.
685 * @param object $comment The current comment object.
686 * @param array $args An array of arguments to override the defaults.
688 return apply_filters( 'get_comment_link', $link, $comment, $args );
692 * Retrieve the link to the current post comments.
696 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
697 * @return string The link to the comments.
699 function get_comments_link( $post_id = 0 ) {
700 $comments_link = get_permalink( $post_id ) . '#comments';
702 * Filter the returned post comments permalink.
706 * @param string $comments_link Post comments permalink with '#comments' appended.
707 * @param int|WP_Post $post_id Post ID or WP_Post object.
709 return apply_filters( 'get_comments_link', $comments_link, $post_id );
713 * Display the link to the current post comments.
717 * @param string $deprecated Not Used.
718 * @param string $deprecated_2 Not Used.
720 function comments_link( $deprecated = '', $deprecated_2 = '' ) {
721 if ( !empty( $deprecated ) )
722 _deprecated_argument( __FUNCTION__, '0.72' );
723 if ( !empty( $deprecated_2 ) )
724 _deprecated_argument( __FUNCTION__, '1.3' );
725 echo esc_url( get_comments_link() );
729 * Retrieve the amount of comments a post has.
733 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
734 * @return int The number of comments a post has.
736 function get_comments_number( $post_id = 0 ) {
737 $post = get_post( $post_id );
742 $count = $post->comment_count;
743 $post_id = $post->ID;
747 * Filter the returned comment count for a post.
751 * @param int $count Number of comments a post has.
752 * @param int $post_id Post ID.
754 return apply_filters( 'get_comments_number', $count, $post_id );
758 * Display the language string for the number of comments the current post has.
762 * @param string $zero Optional. Text for no comments. Default false.
763 * @param string $one Optional. Text for one comment. Default false.
764 * @param string $more Optional. Text for more than one comment. Default false.
765 * @param string $deprecated Not used.
767 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
768 if ( ! empty( $deprecated ) ) {
769 _deprecated_argument( __FUNCTION__, '1.3' );
771 echo get_comments_number_text( $zero, $one, $more );
775 * Display the language string for the number of comments the current post has.
779 * @param string $zero Optional. Text for no comments. Default false.
780 * @param string $one Optional. Text for one comment. Default false.
781 * @param string $more Optional. Text for more than one comment. Default false.
783 function get_comments_number_text( $zero = false, $one = false, $more = false ) {
784 $number = get_comments_number();
787 $output = str_replace( '%', number_format_i18n( $number ), ( false === $more ) ? __( '% Comments' ) : $more );
788 } elseif ( $number == 0 ) {
789 $output = ( false === $zero ) ? __( 'No Comments' ) : $zero;
790 } else { // must be one
791 $output = ( false === $one ) ? __( '1 Comment' ) : $one;
794 * Filter the comments count for display.
800 * @param string $output A translatable string formatted based on whether the count
801 * is equal to 0, 1, or 1+.
802 * @param int $number The number of post comments.
804 return apply_filters( 'comments_number', $output, $number );
808 * Retrieve the text of the current comment.
812 * @see Walker_Comment::comment()
814 * @param int $comment_ID ID of the comment for which to get the text. Default current comment.
815 * @param array $args Optional. An array of arguments. Default empty.
816 * @return string The comment content.
818 function get_comment_text( $comment_ID = 0, $args = array() ) {
819 $comment = get_comment( $comment_ID );
822 * Filter the text of a comment.
826 * @see Walker_Comment::comment()
828 * @param string $comment_content Text of the comment.
829 * @param object $comment The comment object.
830 * @param array $args An array of arguments.
832 return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args );
836 * Display the text of the current comment.
840 * @see Walker_Comment::comment()
842 * @param int $comment_ID ID of the comment for which to print the text. Default 0.
843 * @param array $args Optional. An array of arguments. Default empty array. Default empty.
845 function comment_text( $comment_ID = 0, $args = array() ) {
846 $comment = get_comment( $comment_ID );
848 $comment_text = get_comment_text( $comment_ID , $args );
850 * Filter the text of a comment to be displayed.
854 * @see Walker_Comment::comment()
856 * @param string $comment_text Text of the current comment.
857 * @param object $comment The comment object.
858 * @param array $args An array of arguments.
860 echo apply_filters( 'comment_text', $comment_text, $comment, $args );
864 * Retrieve the comment time of the current comment.
868 * @global object $comment
870 * @param string $d Optional. The format of the time. Default user's settings.
871 * @param bool $gmt Optional. Whether to use the GMT date. Default false.
872 * @param bool $translate Optional. Whether to translate the time (for use in feeds).
874 * @return string The formatted time.
876 function get_comment_time( $d = '', $gmt = false, $translate = true ) {
878 $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
880 $date = mysql2date(get_option('time_format'), $comment_date, $translate);
882 $date = mysql2date($d, $comment_date, $translate);
885 * Filter the returned comment time.
889 * @param string|int $date The comment time, formatted as a date string or Unix timestamp.
890 * @param string $d Date format.
891 * @param bool $gmt Whether the GMT date is in use.
892 * @param bool $translate Whether the time is translated.
893 * @param object $comment The comment object.
895 return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment );
899 * Display the comment time of the current comment.
903 * @param string $d Optional. The format of the time. Default user's settings.
905 function comment_time( $d = '' ) {
906 echo get_comment_time($d);
910 * Retrieve the comment type of the current comment.
914 * @param int $comment_ID ID of the comment for which to get the type. Default current comment.
915 * @return string The comment type.
917 function get_comment_type( $comment_ID = 0 ) {
918 $comment = get_comment( $comment_ID );
919 if ( '' == $comment->comment_type )
920 $comment->comment_type = 'comment';
923 * Filter the returned comment type.
926 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
928 * @param string $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
929 * @param int $comment_ID The comment ID.
930 * @param object $comment The comment object.
932 return apply_filters( 'get_comment_type', $comment->comment_type, $comment_ID, $comment );
936 * Display the comment type of the current comment.
940 * @param string $commenttxt Optional. String to display for comment type. Default false.
941 * @param string $trackbacktxt Optional. String to display for trackback type. Default false.
942 * @param string $pingbacktxt Optional. String to display for pingback type. Default false.
944 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
945 if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
946 if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
947 if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
948 $type = get_comment_type();
962 * Retrieve The current post's trackback URL.
964 * There is a check to see if permalink's have been enabled and if so, will
965 * retrieve the pretty path. If permalinks weren't enabled, the ID of the
966 * current post is used and appended to the correct page to go to.
970 * @return string The trackback URL after being filtered.
972 function get_trackback_url() {
973 if ( '' != get_option('permalink_structure') )
974 $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
976 $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
979 * Filter the returned trackback URL.
983 * @param string $tb_url The trackback URL.
985 return apply_filters( 'trackback_url', $tb_url );
989 * Display the current post's trackback URL.
993 * @param bool $deprecated_echo Not used.
994 * @return void|string Should only be used to echo the trackback URL, use get_trackback_url()
995 * for the result instead.
997 function trackback_url( $deprecated_echo = true ) {
998 if ( $deprecated_echo !== true )
999 _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
1000 if ( $deprecated_echo )
1001 echo get_trackback_url();
1003 return get_trackback_url();
1007 * Generate and display the RDF for the trackback information of current post.
1009 * Deprecated in 3.0.0, and restored in 3.0.1.
1013 * @param int $deprecated Not used (Was $timezone = 0).
1015 function trackback_rdf( $deprecated = '' ) {
1016 if ( ! empty( $deprecated ) ) {
1017 _deprecated_argument( __FUNCTION__, '2.5' );
1020 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'W3C_Validator' ) ) {
1024 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
1025 xmlns:dc="http://purl.org/dc/elements/1.1/"
1026 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
1027 <rdf:Description rdf:about="';
1030 echo ' dc:identifier="';
1033 echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n";
1034 echo ' trackback:ping="'.get_trackback_url().'"'." />\n";
1039 * Whether the current post is open for comments.
1043 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
1044 * @return bool True if the comments are open.
1046 function comments_open( $post_id = null ) {
1048 $_post = get_post($post_id);
1050 $open = ( 'open' == $_post->comment_status );
1053 * Filter whether the current post is open for comments.
1057 * @param bool $open Whether the current post is open for comments.
1058 * @param int|WP_Post $post_id The post ID or WP_Post object.
1060 return apply_filters( 'comments_open', $open, $post_id );
1064 * Whether the current post is open for pings.
1068 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
1069 * @return bool True if pings are accepted
1071 function pings_open( $post_id = null ) {
1073 $_post = get_post($post_id);
1075 $open = ( 'open' == $_post->ping_status );
1078 * Filter whether the current post is open for pings.
1082 * @param bool $open Whether the current post is open for pings.
1083 * @param int|WP_Post $post_id The post ID or WP_Post object.
1085 return apply_filters( 'pings_open', $open, $post_id );
1089 * Display form token for unfiltered comments.
1091 * Will only display nonce token if the current user has permissions for
1092 * unfiltered html. Won't display the token for other users.
1094 * The function was backported to 2.0.10 and was added to versions 2.1.3 and
1095 * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in
1096 * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.
1098 * Backported to 2.0.10.
1102 function wp_comment_form_unfiltered_html_nonce() {
1104 $post_id = $post ? $post->ID : 0;
1106 if ( current_user_can( 'unfiltered_html' ) ) {
1107 wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
1108 echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
1113 * Load the comment template specified in $file.
1115 * Will not display the comments template if not on single post or page, or if
1116 * the post does not have comments.
1118 * Uses the WordPress database object to query for the comments. The comments
1119 * are passed through the 'comments_array' filter hook with the list of comments
1120 * and the post ID respectively.
1122 * The $file path is passed through a filter hook called, 'comments_template'
1123 * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
1124 * first and if it fails it will require the default comment template from the
1125 * default theme. If either does not exist, then the WordPress process will be
1126 * halted. It is advised for that reason, that the default theme is not deleted.
1128 * @uses $withcomments Will not try to get the comments if the post has none.
1132 * @global WP_Query $wp_query
1133 * @global WP_Post $post
1134 * @global wpdb $wpdb
1136 * @global object $comment
1137 * @global string $user_login
1138 * @global int $user_ID
1139 * @global string $user_identity
1140 * @global bool $overridden_cpage
1142 * @param string $file Optional. The file to load. Default '/comments.php'.
1143 * @param bool $separate_comments Optional. Whether to separate the comments by comment type.
1146 function comments_template( $file = '/comments.php', $separate_comments = false ) {
1147 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
1149 if ( !(is_single() || is_page() || $withcomments) || empty($post) )
1153 $file = '/comments.php';
1155 $req = get_option('require_name_email');
1158 * Comment author information fetched from the comment cookies.
1160 $commenter = wp_get_current_commenter();
1163 * The name of the current comment author escaped for use in attributes.
1164 * Escaped by sanitize_comment_cookies().
1166 $comment_author = $commenter['comment_author'];
1169 * The email address of the current comment author escaped for use in attributes.
1170 * Escaped by sanitize_comment_cookies().
1172 $comment_author_email = $commenter['comment_author_email'];
1175 * The url of the current comment author escaped for use in attributes.
1177 $comment_author_url = esc_url($commenter['comment_author_url']);
1179 $comment_args = array(
1181 'orderby' => 'comment_date_gmt',
1182 'status' => 'approve',
1183 'post_id' => $post->ID,
1187 $comment_args['include_unapproved'] = array( $user_ID );
1188 } elseif ( ! empty( $comment_author_email ) ) {
1189 $comment_args['include_unapproved'] = array( $comment_author_email );
1192 $comments = get_comments( $comment_args );
1195 * Filter the comments array.
1199 * @param array $comments Array of comments supplied to the comments template.
1200 * @param int $post_ID Post ID.
1202 $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
1203 $comments = &$wp_query->comments;
1204 $wp_query->comment_count = count($wp_query->comments);
1206 if ( $separate_comments ) {
1207 $wp_query->comments_by_type = separate_comments($comments);
1208 $comments_by_type = &$wp_query->comments_by_type;
1211 $overridden_cpage = false;
1212 if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
1213 set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
1214 $overridden_cpage = true;
1217 if ( !defined('COMMENTS_TEMPLATE') )
1218 define('COMMENTS_TEMPLATE', true);
1220 $theme_template = STYLESHEETPATH . $file;
1222 * Filter the path to the theme template file used for the comments template.
1226 * @param string $theme_template The path to the theme template file.
1228 $include = apply_filters( 'comments_template', $theme_template );
1229 if ( file_exists( $include ) )
1230 require( $include );
1231 elseif ( file_exists( TEMPLATEPATH . $file ) )
1232 require( TEMPLATEPATH . $file );
1233 else // Backward compat code will be removed in a future release
1234 require( ABSPATH . WPINC . '/theme-compat/comments.php');
1238 * Display the JS popup script to show a comment.
1240 * If the $file parameter is empty, then the home page is assumed. The defaults
1241 * for the window are 400px by 400px.
1243 * For the comment link popup to work, this function has to be called or the
1244 * normal comment link will be assumed.
1246 * @global string $wpcommentspopupfile The URL to use for the popup window.
1247 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
1251 * @param int $width Optional. The width of the popup window. Default 400.
1252 * @param int $height Optional. The height of the popup window. Default 400.
1253 * @param string $file Optional. Sets the location of the popup window.
1255 function comments_popup_script( $width = 400, $height = 400, $file = '' ) {
1256 global $wpcommentspopupfile, $wpcommentsjavascript;
1258 if (empty ($file)) {
1259 $wpcommentspopupfile = ''; // Use the index.
1261 $wpcommentspopupfile = $file;
1264 $wpcommentsjavascript = 1;
1265 $javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n";
1270 * Displays the link to the comments popup window for the current post ID.
1272 * Is not meant to be displayed on single posts and pages. Should be used
1273 * on the lists of posts
1275 * @global string $wpcommentspopupfile The URL to use for the popup window.
1276 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
1280 * @param string $zero Optional. String to display when no comments. Default false.
1281 * @param string $one Optional. String to display when only one comment is available.
1283 * @param string $more Optional. String to display when there are more than one comment.
1285 * @param string $css_class Optional. CSS class to use for comments. Default empty.
1286 * @param string $none Optional. String to display when comments have been turned off.
1289 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
1290 global $wpcommentspopupfile, $wpcommentsjavascript;
1293 $title = get_the_title();
1294 $number = get_comments_number( $id );
1296 if ( false === $zero ) {
1297 /* translators: %s: post title */
1298 $zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $title );
1301 if ( false === $one ) {
1302 /* translators: %s: post title */
1303 $one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $title );
1306 if ( false === $more ) {
1307 /* translators: 1: Number of comments 2: post title */
1308 $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 );
1309 $more = sprintf( $more, number_format_i18n( $number ), $title );
1312 if ( false === $none ) {
1313 /* translators: %s: post title */
1314 $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title );
1317 if ( 0 == $number && !comments_open() && !pings_open() ) {
1318 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
1322 if ( post_password_required() ) {
1323 _e( 'Enter your password to view comments.' );
1328 if ( $wpcommentsjavascript ) {
1329 if ( empty( $wpcommentspopupfile ) )
1332 $home = get_option('siteurl');
1333 echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
1334 echo '" onclick="wpopen(this.href); return false"';
1335 } else { // if comments_popup_script() is not in the template, display simple comment link
1337 echo get_permalink() . '#respond';
1343 if ( !empty( $css_class ) ) {
1344 echo ' class="'.$css_class.'" ';
1349 * Filter the comments popup link attributes for display.
1353 * @param string $attributes The comments popup link attributes. Default empty.
1355 echo apply_filters( 'comments_popup_link_attributes', $attributes );
1358 comments_number( $zero, $one, $more );
1363 * Retrieve HTML content for reply to comment link.
1367 * @param array $args {
1368 * Optional. Override default arguments.
1370 * @type string $add_below The first part of the selector used to identify the comment to respond below.
1371 * The resulting value is passed as the first parameter to addComment.moveForm(),
1372 * concatenated as $add_below-$comment->comment_ID. Default 'comment'.
1373 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
1374 * to addComment.moveForm(), and appended to the link URL as a hash value.
1375 * Default 'respond'.
1376 * @type string $reply_text The text of the Reply link. Default 'Reply'.
1377 * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.
1378 * @type int $depth' The depth of the new comment. Must be greater than 0 and less than the value
1379 * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
1380 * @type string $before The text or HTML to add before the reply link. Default empty.
1381 * @type string $after The text or HTML to add after the reply link. Default empty.
1383 * @param int $comment Comment being replied to. Default current comment.
1384 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
1385 * Default current post.
1386 * @return void|false|string Link to show comment form, if successful. False, if comments are closed.
1388 function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
1390 'add_below' => 'comment',
1391 'respond_id' => 'respond',
1392 'reply_text' => __( 'Reply' ),
1393 'reply_to_text' => __( 'Reply to %s' ),
1394 'login_text' => __( 'Log in to Reply' ),
1400 $args = wp_parse_args( $args, $defaults );
1402 if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
1406 $comment = get_comment( $comment );
1408 if ( empty( $post ) ) {
1409 $post = $comment->comment_post_ID;
1412 $post = get_post( $post );
1414 if ( ! comments_open( $post->ID ) ) {
1419 * Filter the comment reply link arguments.
1423 * @param array $args Comment reply link arguments. See {@see get_comment_reply_link()}
1424 * for more information on accepted arguments.
1425 * @param object $comment The object of the comment being replied to.
1426 * @param WP_Post $post The {@see WP_Post} object.
1428 $args = apply_filters( 'comment_reply_link_args', $args, $comment, $post );
1430 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
1431 $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
1432 esc_url( wp_login_url( get_permalink() ) ),
1436 $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
1437 $args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID
1440 $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>",
1441 esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . "#" . $args['respond_id'],
1443 esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
1448 * Filter the comment reply link.
1452 * @param string $link The HTML markup for the comment reply link.
1453 * @param array $args An array of arguments overriding the defaults.
1454 * @param object $comment The object of the comment being replied.
1455 * @param WP_Post $post The WP_Post object.
1457 return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
1461 * Displays the HTML content for reply to comment link.
1465 * @see get_comment_reply_link()
1467 * @param array $args Optional. Override default options.
1468 * @param int $comment Comment being replied to. Default current comment.
1469 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
1470 * Default current post.
1471 * @return mixed Link to show comment form, if successful. False, if comments are closed.
1473 function comment_reply_link($args = array(), $comment = null, $post = null) {
1474 echo get_comment_reply_link($args, $comment, $post);
1478 * Retrieve HTML content for reply to post link.
1482 * @param array $args {
1483 * Optional. Override default arguments.
1485 * @type string $add_below The first part of the selector used to identify the comment to respond below.
1486 * The resulting value is passed as the first parameter to addComment.moveForm(),
1487 * concatenated as $add_below-$comment->comment_ID. Default is 'post'.
1488 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
1489 * to addComment.moveForm(), and appended to the link URL as a hash value.
1490 * Default 'respond'.
1491 * @type string $reply_text Text of the Reply link. Default is 'Leave a Comment'.
1492 * @type string $login_text Text of the link to reply if logged out. Default is 'Log in to leave a Comment'.
1493 * @type string $before Text or HTML to add before the reply link. Default empty.
1494 * @type string $after Text or HTML to add after the reply link. Default empty.
1496 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on.
1497 * Default current post.
1498 * @return false|null|string Link to show comment form, if successful. False, if comments are closed.
1500 function get_post_reply_link($args = array(), $post = null) {
1502 'add_below' => 'post',
1503 'respond_id' => 'respond',
1504 'reply_text' => __('Leave a Comment'),
1505 'login_text' => __('Log in to leave a Comment'),
1510 $args = wp_parse_args($args, $defaults);
1512 $post = get_post($post);
1514 if ( ! comments_open( $post->ID ) ) {
1518 if ( get_option('comment_registration') && ! is_user_logged_in() ) {
1519 $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
1520 wp_login_url( get_permalink() ),
1524 $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )',
1525 $args['add_below'], $post->ID, $args['respond_id']
1528 $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>",
1529 get_permalink( $post->ID ) . '#' . $args['respond_id'],
1534 $formatted_link = $args['before'] . $link . $args['after'];
1536 * Filter the formatted post comments link HTML.
1540 * @param string $formatted The HTML-formatted post comments link.
1541 * @param int|WP_Post $post The post ID or WP_Post object.
1543 return apply_filters( 'post_comments_link', $formatted_link, $post );
1547 * Displays the HTML content for reply to post link.
1551 * @see get_post_reply_link()
1553 * @param array $args Optional. Override default options,
1554 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
1555 * Default current post.
1556 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1558 function post_reply_link($args = array(), $post = null) {
1559 echo get_post_reply_link($args, $post);
1563 * Retrieve HTML content for cancel comment reply link.
1567 * @param string $text Optional. Text to display for cancel reply link. Default empty.
1570 function get_cancel_comment_reply_link( $text = '' ) {
1572 $text = __('Click here to cancel reply.');
1574 $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
1575 $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
1577 $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
1579 * Filter the cancel comment reply link HTML.
1583 * @param string $formatted_link The HTML-formatted cancel comment reply link.
1584 * @param string $link Cancel comment reply link URL.
1585 * @param string $text Cancel comment reply link text.
1587 return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
1591 * Display HTML content for cancel comment reply link.
1595 * @param string $text Optional. Text to display for cancel reply link. Default empty.
1597 function cancel_comment_reply_link( $text = '' ) {
1598 echo get_cancel_comment_reply_link($text);
1602 * Retrieve hidden input HTML for replying to comments.
1606 * @param int $id Optional. Post ID. Default current post ID.
1607 * @return string Hidden input HTML for replying to comments
1609 function get_comment_id_fields( $id = 0 ) {
1613 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1614 $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
1615 $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
1618 * Filter the returned comment id fields.
1622 * @param string $result The HTML-formatted hidden id field comment elements.
1623 * @param int $id The post ID.
1624 * @param int $replytoid The id of the comment being replied to.
1626 return apply_filters( 'comment_id_fields', $result, $id, $replytoid );
1630 * Output hidden input HTML for replying to comments.
1634 * @param int $id Optional. Post ID. Default current post ID.
1636 function comment_id_fields( $id = 0 ) {
1637 echo get_comment_id_fields( $id );
1641 * Display text based on comment reply status.
1643 * Only affects users with JavaScript disabled.
1647 * @global object $comment
1649 * @param string $noreplytext Optional. Text to display when not replying to a comment.
1651 * @param string $replytext Optional. Text to display when replying to a comment.
1652 * Default false. Accepts "%s" for the author of the comment
1654 * @param string $linktoparent Optional. Boolean to control making the author's name a link
1655 * to their comment. Default true.
1657 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {
1660 if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
1661 if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
1663 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1665 if ( 0 == $replytoid )
1668 $comment = get_comment($replytoid);
1669 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
1670 printf( $replytext, $author );
1675 * HTML comment list class.
1680 class Walker_Comment extends Walker {
1682 * What the class handles.
1684 * @see Walker::$tree_type
1689 public $tree_type = 'comment';
1694 * @see Walker::$db_fields
1699 public $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
1702 * Start the list before the elements are added.
1704 * @see Walker::start_lvl()
1708 * @global int $comment_depth
1710 * @param string $output Passed by reference. Used to append additional content.
1711 * @param int $depth Depth of comment.
1712 * @param array $args Uses 'style' argument for type of HTML list.
1714 public function start_lvl( &$output, $depth = 0, $args = array() ) {
1715 $GLOBALS['comment_depth'] = $depth + 1;
1717 switch ( $args['style'] ) {
1721 $output .= '<ol class="children">' . "\n";
1725 $output .= '<ul class="children">' . "\n";
1731 * End the list of items after the elements are added.
1733 * @see Walker::end_lvl()
1737 * @global int $comment_depth
1739 * @param string $output Passed by reference. Used to append additional content.
1740 * @param int $depth Depth of comment.
1741 * @param array $args Will only append content if style argument value is 'ol' or 'ul'.
1743 public function end_lvl( &$output, $depth = 0, $args = array() ) {
1744 $GLOBALS['comment_depth'] = $depth + 1;
1746 switch ( $args['style'] ) {
1750 $output .= "</ol><!-- .children -->\n";
1754 $output .= "</ul><!-- .children -->\n";
1760 * Traverse elements to create list from elements.
1762 * This function is designed to enhance Walker::display_element() to
1763 * display children of higher nesting levels than selected inline on
1764 * the highest depth level displayed. This prevents them being orphaned
1765 * at the end of the comment list.
1767 * Example: max_depth = 2, with 5 levels of nested content.
1778 * @see Walker::display_element()
1779 * @see wp_list_comments()
1783 * @param object $element Data object.
1784 * @param array $children_elements List of elements to continue traversing.
1785 * @param int $max_depth Max depth to traverse.
1786 * @param int $depth Depth of current element.
1787 * @param array $args An array of arguments.
1788 * @param string $output Passed by reference. Used to append additional content.
1790 public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
1794 $id_field = $this->db_fields['id'];
1795 $id = $element->$id_field;
1797 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
1799 // If we're at the max depth, and the current element still has children, loop over those and display them at this level
1800 // This is to prevent them being orphaned to the end of the list.
1801 if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
1802 foreach ( $children_elements[ $id ] as $child )
1803 $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
1805 unset( $children_elements[ $id ] );
1811 * Start the element output.
1815 * @see Walker::start_el()
1816 * @see wp_list_comments()
1818 * @global int $comment_depth
1819 * @global object $comment
1821 * @param string $output Passed by reference. Used to append additional content.
1822 * @param object $comment Comment data object.
1823 * @param int $depth Depth of comment in reference to parents.
1824 * @param array $args An array of arguments.
1826 public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
1828 $GLOBALS['comment_depth'] = $depth;
1829 $GLOBALS['comment'] = $comment;
1831 if ( !empty( $args['callback'] ) ) {
1833 call_user_func( $args['callback'], $comment, $args, $depth );
1834 $output .= ob_get_clean();
1838 if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
1840 $this->ping( $comment, $depth, $args );
1841 $output .= ob_get_clean();
1842 } elseif ( 'html5' === $args['format'] ) {
1844 $this->html5_comment( $comment, $depth, $args );
1845 $output .= ob_get_clean();
1848 $this->comment( $comment, $depth, $args );
1849 $output .= ob_get_clean();
1854 * Ends the element output, if needed.
1858 * @see Walker::end_el()
1859 * @see wp_list_comments()
1861 * @param string $output Passed by reference. Used to append additional content.
1862 * @param object $comment The comment object. Default current comment.
1863 * @param int $depth Depth of comment.
1864 * @param array $args An array of arguments.
1866 public function end_el( &$output, $comment, $depth = 0, $args = array() ) {
1867 if ( !empty( $args['end-callback'] ) ) {
1869 call_user_func( $args['end-callback'], $comment, $args, $depth );
1870 $output .= ob_get_clean();
1873 if ( 'div' == $args['style'] )
1874 $output .= "</div><!-- #comment-## -->\n";
1876 $output .= "</li><!-- #comment-## -->\n";
1880 * Output a pingback comment.
1885 * @see wp_list_comments()
1887 * @param object $comment The comment object.
1888 * @param int $depth Depth of comment.
1889 * @param array $args An array of arguments.
1891 protected function ping( $comment, $depth, $args ) {
1892 $tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
1894 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
1895 <div class="comment-body">
1896 <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
1902 * Output a single comment.
1907 * @see wp_list_comments()
1909 * @param object $comment Comment to display.
1910 * @param int $depth Depth of comment.
1911 * @param array $args An array of arguments.
1913 protected function comment( $comment, $depth, $args ) {
1914 if ( 'div' == $args['style'] ) {
1916 $add_below = 'comment';
1919 $add_below = 'div-comment';
1922 <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '' ); ?> id="comment-<?php comment_ID(); ?>">
1923 <?php if ( 'div' != $args['style'] ) : ?>
1924 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
1926 <div class="comment-author vcard">
1927 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
1928 <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
1930 <?php if ( '0' == $comment->comment_approved ) : ?>
1931 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>
1935 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>">
1937 /* translators: 1: date, 2: time */
1938 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
1942 <?php comment_text( get_comment_id(), array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1945 comment_reply_link( array_merge( $args, array(
1946 'add_below' => $add_below,
1948 'max_depth' => $args['max_depth'],
1949 'before' => '<div class="reply">',
1954 <?php if ( 'div' != $args['style'] ) : ?>
1961 * Output a comment in the HTML5 format.
1966 * @see wp_list_comments()
1968 * @param object $comment Comment to display.
1969 * @param int $depth Depth of comment.
1970 * @param array $args An array of arguments.
1972 protected function html5_comment( $comment, $depth, $args ) {
1973 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
1975 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '' ); ?>>
1976 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
1977 <footer class="comment-meta">
1978 <div class="comment-author vcard">
1979 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
1980 <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?>
1981 </div><!-- .comment-author -->
1983 <div class="comment-metadata">
1984 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>">
1985 <time datetime="<?php comment_time( 'c' ); ?>">
1986 <?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), get_comment_time() ); ?>
1989 <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
1990 </div><!-- .comment-metadata -->
1992 <?php if ( '0' == $comment->comment_approved ) : ?>
1993 <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
1995 </footer><!-- .comment-meta -->
1997 <div class="comment-content">
1998 <?php comment_text(); ?>
1999 </div><!-- .comment-content -->
2002 comment_reply_link( array_merge( $args, array(
2003 'add_below' => 'div-comment',
2005 'max_depth' => $args['max_depth'],
2006 'before' => '<div class="reply">',
2010 </article><!-- .comment-body -->
2018 * Used in the comments.php template to list comments for a particular post.
2022 * @see WP_Query->comments
2024 * @global WP_Query $wp_query
2025 * @global int $comment_alt
2026 * @global int $comment_depth
2027 * @global int $comment_thread_alt
2028 * @global bool $overridden_cpage
2029 * @global bool $in_comment_loop
2031 * @param string|array $args {
2032 * Optional. Formatting options.
2034 * @type object $walker Instance of a Walker class to list comments. Default null.
2035 * @type int $max_depth The maximum comments depth. Default empty.
2036 * @type string $style The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
2037 * @type string $callback Callback function to use. Default null.
2038 * @type string $end-callback Callback function to use at the end. Default null.
2039 * @type string $type Type of comments to list.
2040 * Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
2041 * @type int $page Page ID to list comments for. Default empty.
2042 * @type int $per_page Number of comments to list per page. Default empty.
2043 * @type int $avatar_size Height and width dimensions of the avatar size. Default 32.
2044 * @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
2045 * @type bool $reverse_children Whether to reverse child comments in the list. Default null.
2046 * @type string $format How to format the comments list.
2047 * Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
2048 * @type bool $short_ping Whether to output short pings. Default false.
2049 * @type bool $echo Whether to echo the output or return it. Default true.
2051 * @param array $comments Optional. Array of comment objects.
2053 function wp_list_comments( $args = array(), $comments = null ) {
2054 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
2056 $in_comment_loop = true;
2058 $comment_alt = $comment_thread_alt = 0;
2066 'end-callback' => null,
2070 'avatar_size' => 32,
2071 'reverse_top_level' => null,
2072 'reverse_children' => '',
2073 'format' => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
2074 'short_ping' => false,
2078 $r = wp_parse_args( $args, $defaults );
2081 * Filter the arguments used in retrieving the comment list.
2085 * @see wp_list_comments()
2087 * @param array $r An array of arguments for displaying comments.
2089 $r = apply_filters( 'wp_list_comments_args', $r );
2091 // Figure out what comments we'll be looping through ($_comments)
2092 if ( null !== $comments ) {
2093 $comments = (array) $comments;
2094 if ( empty($comments) )
2096 if ( 'all' != $r['type'] ) {
2097 $comments_by_type = separate_comments($comments);
2098 if ( empty($comments_by_type[$r['type']]) )
2100 $_comments = $comments_by_type[$r['type']];
2102 $_comments = $comments;
2105 if ( empty($wp_query->comments) )
2107 if ( 'all' != $r['type'] ) {
2108 if ( empty($wp_query->comments_by_type) )
2109 $wp_query->comments_by_type = separate_comments($wp_query->comments);
2110 if ( empty($wp_query->comments_by_type[$r['type']]) )
2112 $_comments = $wp_query->comments_by_type[$r['type']];
2114 $_comments = $wp_query->comments;
2118 if ( '' === $r['per_page'] && get_option('page_comments') )
2119 $r['per_page'] = get_query_var('comments_per_page');
2121 if ( empty($r['per_page']) ) {
2126 if ( '' === $r['max_depth'] ) {
2127 if ( get_option('thread_comments') )
2128 $r['max_depth'] = get_option('thread_comments_depth');
2130 $r['max_depth'] = -1;
2133 if ( '' === $r['page'] ) {
2134 if ( empty($overridden_cpage) ) {
2135 $r['page'] = get_query_var('cpage');
2137 $threaded = ( -1 != $r['max_depth'] );
2138 $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
2139 set_query_var( 'cpage', $r['page'] );
2143 $r['page'] = intval($r['page']);
2144 if ( 0 == $r['page'] && 0 != $r['per_page'] )
2147 if ( null === $r['reverse_top_level'] )
2148 $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
2150 if ( empty( $r['walker'] ) ) {
2151 $walker = new Walker_Comment;
2153 $walker = $r['walker'];
2156 $output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r );
2157 $wp_query->max_num_comment_pages = $walker->max_pages;
2159 $in_comment_loop = false;
2169 * Output a complete commenting form for use within a template.
2171 * Most strings and form fields may be controlled through the $args array passed
2172 * into the function, while you may also choose to use the comment_form_default_fields
2173 * filter to modify the array of default fields if you'd just like to add a new
2174 * one or remove a single field. All fields are also individually passed through
2175 * a filter of the form comment_form_field_$name where $name is the key used
2176 * in the array of fields.
2179 * @since 4.1.0 Introduced the 'class_submit' argument.
2180 * @since 4.2.0 Introduced 'submit_button' and 'submit_fields' arguments.
2182 * @param array $args {
2183 * Optional. Default arguments and form fields to override.
2185 * @type array $fields {
2186 * Default comment fields, filterable by default via the 'comment_form_default_fields' hook.
2188 * @type string $author Comment author field HTML.
2189 * @type string $email Comment author email field HTML.
2190 * @type string $url Comment author URL field HTML.
2192 * @type string $comment_field The comment textarea field HTML.
2193 * @type string $must_log_in HTML element for a 'must be logged in to comment' message.
2194 * @type string $logged_in_as HTML element for a 'logged in as [user]' message.
2195 * @type string $comment_notes_before HTML element for a message displayed before the comment form.
2196 * Default 'Your email address will not be published.'.
2197 * @type string $comment_notes_after HTML element for a message displayed after the comment form.
2198 * @type string $id_form The comment form element id attribute. Default 'commentform'.
2199 * @type string $id_submit The comment submit element id attribute. Default 'submit'.
2200 * @type string $class_submit The comment submit element class attribute. Default 'submit'.
2201 * @type string $name_submit The comment submit element name attribute. Default 'submit'.
2202 * @type string $title_reply The translatable 'reply' button label. Default 'Leave a Reply'.
2203 * @type string $title_reply_to The translatable 'reply-to' button label. Default 'Leave a Reply to %s',
2204 * where %s is the author of the comment being replied to.
2205 * @type string $cancel_reply_link The translatable 'cancel reply' button label. Default 'Cancel reply'.
2206 * @type string $label_submit The translatable 'submit' button label. Default 'Post a comment'.
2207 * @type string $submit_button HTML format for the Submit button.
2208 * Default: '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'.
2209 * @type string $submit_field HTML format for the markup surrounding the Submit button and comment hidden
2210 * fields. Default: '<p class="form-submit">%1$s %2$s</a>', where %1$s is the
2211 * submit button markup and %2$s is the comment hidden fields.
2212 * @type string $format The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
2214 * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post.
2216 function comment_form( $args = array(), $post_id = null ) {
2217 if ( null === $post_id )
2218 $post_id = get_the_ID();
2220 $commenter = wp_get_current_commenter();
2221 $user = wp_get_current_user();
2222 $user_identity = $user->exists() ? $user->display_name : '';
2224 $args = wp_parse_args( $args );
2225 if ( ! isset( $args['format'] ) )
2226 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
2228 $req = get_option( 'require_name_email' );
2229 $aria_req = ( $req ? " aria-required='true'" : '' );
2230 $html_req = ( $req ? " required='required'" : '' );
2231 $html5 = 'html5' === $args['format'];
2233 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
2234 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req . ' /></p>',
2235 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
2236 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>',
2237 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
2238 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
2241 $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
2244 * Filter the default comment form fields.
2248 * @param array $fields The default comment fields.
2250 $fields = apply_filters( 'comment_form_default_fields', $fields );
2252 'fields' => $fields,
2253 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="required"></textarea></p>',
2254 /** This filter is documented in wp-includes/link-template.php */
2255 'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
2256 /** This filter is documented in wp-includes/link-template.php */
2257 'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
2258 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . '</p>',
2259 'comment_notes_after' => '',
2260 'id_form' => 'commentform',
2261 'id_submit' => 'submit',
2262 'class_submit' => 'submit',
2263 'name_submit' => 'submit',
2264 'title_reply' => __( 'Leave a Reply' ),
2265 'title_reply_to' => __( 'Leave a Reply to %s' ),
2266 'cancel_reply_link' => __( 'Cancel reply' ),
2267 'label_submit' => __( 'Post Comment' ),
2268 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
2269 'submit_field' => '<p class="form-submit">%1$s %2$s</p>',
2270 'format' => 'xhtml',
2274 * Filter the comment form default arguments.
2276 * Use 'comment_form_default_fields' to filter the comment fields.
2280 * @param array $defaults The default comment form arguments.
2282 $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
2284 // Ensure that the filtered args contain all required default values.
2285 $args = array_merge( $defaults, $args );
2287 if ( comments_open( $post_id ) ) : ?>
2290 * Fires before the comment form.
2294 do_action( 'comment_form_before' );
2296 <div id="respond" class="comment-respond">
2297 <h3 id="reply-title" class="comment-reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
2298 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
2299 <?php echo $args['must_log_in']; ?>
2302 * Fires after the HTML-formatted 'must log in after' message in the comment form.
2306 do_action( 'comment_form_must_log_in_after' );
2309 <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>
2312 * Fires at the top of the comment form, inside the form tag.
2316 do_action( 'comment_form_top' );
2318 <?php if ( is_user_logged_in() ) : ?>
2321 * Filter the 'logged in' message for the comment form for display.
2325 * @param string $args_logged_in The logged-in-as HTML-formatted message.
2326 * @param array $commenter An array containing the comment author's
2327 * username, email, and URL.
2328 * @param string $user_identity If the commenter is a registered user,
2329 * the display name, blank otherwise.
2331 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
2335 * Fires after the is_user_logged_in() check in the comment form.
2339 * @param array $commenter An array containing the comment author's
2340 * username, email, and URL.
2341 * @param string $user_identity If the commenter is a registered user,
2342 * the display name, blank otherwise.
2344 do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
2347 <?php echo $args['comment_notes_before']; ?>
2350 * Fires before the comment fields in the comment form.
2354 do_action( 'comment_form_before_fields' );
2355 foreach ( (array) $args['fields'] as $name => $field ) {
2357 * Filter a comment form field for display.
2359 * The dynamic portion of the filter hook, `$name`, refers to the name
2360 * of the comment form field. Such as 'author', 'email', or 'url'.
2364 * @param string $field The HTML-formatted output of the comment form field.
2366 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
2369 * Fires after the comment fields in the comment form.
2373 do_action( 'comment_form_after_fields' );
2378 * Filter the content of the comment textarea field for display.
2382 * @param string $args_comment_field The content of the comment textarea field.
2384 echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );
2386 <?php echo $args['comment_notes_after']; ?>
2389 $submit_button = sprintf(
2390 $args['submit_button'],
2391 esc_attr( $args['name_submit'] ),
2392 esc_attr( $args['id_submit'] ),
2393 esc_attr( $args['class_submit'] ),
2394 esc_attr( $args['label_submit'] )
2398 * Filter the submit button for the comment form to display.
2402 * @param string $submit_button HTML markup for the submit button.
2403 * @param array $args Arguments passed to `comment_form()`.
2405 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
2407 $submit_field = sprintf(
2408 $args['submit_field'],
2410 get_comment_id_fields( $post_id )
2414 * Filter the submit field for the comment form to display.
2416 * The submit field includes the submit button, hidden fields for the
2417 * comment form, and any wrapper markup.
2421 * @param string $submit_field HTML markup for the submit field.
2422 * @param array $args Arguments passed to comment_form().
2424 echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
2427 * Fires at the bottom of the comment form, inside the closing </form> tag.
2431 * @param int $post_id The post ID.
2433 do_action( 'comment_form', $post_id );
2437 </div><!-- #respond -->
2440 * Fires after the comment form.
2444 do_action( 'comment_form_after' );
2447 * Fires after the comment form if comments are closed.
2451 do_action( 'comment_form_comments_closed' );