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.
39 * @param string $author The comment author's username.
41 return apply_filters( 'get_comment_author', $author );
45 * Displays the author of the current comment.
49 * @param int $comment_ID Optional. The ID of the comment for which to print the author. Default current comment.
51 function comment_author( $comment_ID = 0 ) {
52 $author = get_comment_author( $comment_ID );
54 * Filter the comment author's name for display.
58 * @param string $author The comment author's username.
60 $author = apply_filters( 'comment_author', $author );
65 * Retrieve the email of the author of the current comment.
69 * @param int $comment_ID Optional. The ID of the comment for which to get the author's email. Default current comment.
70 * @return string The current comment author's email
72 function get_comment_author_email( $comment_ID = 0 ) {
73 $comment = get_comment( $comment_ID );
75 * Filter the comment author's returned email address.
79 * @param string $comment_author_email The comment author's email address.
81 return apply_filters( 'get_comment_author_email', $comment->comment_author_email );
85 * Display the email of the author of the current global $comment.
87 * Care should be taken to protect the email address and assure that email
88 * harvesters do not capture your commentors' email address. Most assume that
89 * their email address will not appear in raw form on the blog. Doing so will
90 * enable anyone, including those that people don't want to get the email
91 * address and use it for their own means good and bad.
95 * @param int $comment_ID Optional. The ID of the comment for which to print the author's email. Default current comment.
97 function comment_author_email( $comment_ID = 0 ) {
98 $author_email = get_comment_author_email( $comment_ID );
100 * Filter the comment author's email for display.
104 * @param string $author_email The comment author's email address.
106 echo apply_filters( 'author_email', $author_email );
110 * Display the html email link to the author of the current comment.
112 * Care should be taken to protect the email address and assure that email
113 * harvesters do not capture your commentors' email address. Most assume that
114 * their email address will not appear in raw form on the blog. Doing so will
115 * enable anyone, including those that people don't want to get the email
116 * address and use it for their own means good and bad.
120 * @param string $linktext Optional. Text to display instead of the comment author's email address.
122 * @param string $before Optional. Text or HTML to display before the email link. Default empty.
123 * @param string $after Optional. Text or HTML to display after the email link. Default empty.
125 function comment_author_email_link( $linktext = '', $before = '', $after = '' ) {
126 if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )
131 * Return the html email link to the author of the current comment.
133 * Care should be taken to protect the email address and assure that email
134 * harvesters do not capture your commentors' email address. Most assume that
135 * their email address will not appear in raw form on the blog. Doing so will
136 * enable anyone, including those that people don't want to get the email
137 * address and use it for their own means good and bad.
139 * @global object $comment The current Comment row object.
143 * @param string $linktext Optional. Text to display instead of the comment author's email address.
145 * @param string $before Optional. Text or HTML to display before the email link. Default empty.
146 * @param string $after Optional. Text or HTML to display after the email link. Default empty.
148 function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) {
151 * Filter the comment author's email for display.
153 * Care should be taken to protect the email address and assure that email
154 * harvesters do not capture your commenters' email address.
158 * @param string $comment_author_email The comment author's email address.
160 $email = apply_filters( 'comment_email', $comment->comment_author_email );
161 if ((!empty($email)) && ($email != '@')) {
162 $display = ($linktext != '') ? $linktext : $email;
164 $return .= "<a href='mailto:$email'>$display</a>";
173 * Retrieve the HTML link to the URL of the author of the current comment.
175 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
176 * which falls back to the global comment variable if the $comment_ID argument is empty.
180 * @param int $comment_ID ID of the comment for which to get the author's link.
181 * Default current comment.
182 * @return string The comment author name or HTML link for author's URL.
184 function get_comment_author_link( $comment_ID = 0 ) {
185 $url = get_comment_author_url( $comment_ID );
186 $author = get_comment_author( $comment_ID );
188 if ( empty( $url ) || 'http://' == $url )
191 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
194 * Filter the comment author's link for display.
198 * @param string $return The HTML-formatted comment author link.
199 * Empty for an invalid URL.
201 return apply_filters( 'get_comment_author_link', $return );
205 * Display the html link to the url of the author of the current comment.
209 * @see get_comment_author_link() Echoes result
211 * @param int $comment_ID ID of the comment for which to print the author's
212 * link. Default current comment.
214 function comment_author_link( $comment_ID = 0 ) {
215 echo get_comment_author_link( $comment_ID );
219 * Retrieve the IP address of the author of the current comment.
223 * @param int $comment_ID ID of the comment for which to get the author's IP
224 * address. Default current comment.
225 * @return string Comment author's IP address.
227 function get_comment_author_IP( $comment_ID = 0 ) {
228 $comment = get_comment( $comment_ID );
231 * Filter the comment author's returned IP address.
235 * @param string $comment_author_IP The comment author's IP address.
237 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP );
241 * Display the IP address of the author of the current comment.
245 * @param int $comment_ID ID of the comment for which to print the author's IP
246 * address. Default current comment.
248 function comment_author_IP( $comment_ID = 0 ) {
249 echo get_comment_author_IP( $comment_ID );
253 * Retrieve the url of the author of the current comment.
257 * @param int $comment_ID ID of the comment for which to get the author's URL.
258 * Default current comment.
261 function get_comment_author_url( $comment_ID = 0 ) {
262 $comment = get_comment( $comment_ID );
263 $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
264 $url = esc_url( $url, array('http', 'https') );
266 * Filter the comment author's URL.
270 * @param string $url The comment author's URL.
272 return apply_filters( 'get_comment_author_url', $url );
276 * Display the url of the author of the current comment.
280 * @param int $comment_ID ID of the comment for which to print the author's URL.
281 * Default current comment.
283 function comment_author_url( $comment_ID = 0 ) {
284 $author_url = get_comment_author_url( $comment_ID );
286 * Filter the comment author's URL for display.
290 * @param string $author_url The comment author's URL.
292 echo apply_filters( 'comment_url', $author_url );
296 * Retrieves the HTML link of the url of the author of the current comment.
298 * $linktext parameter is only used if the URL does not exist for the comment
299 * author. If the URL does exist then the URL will be used and the $linktext
302 * Encapsulate the HTML link between the $before and $after. So it will appear
303 * in the order of $before, link, and finally $after.
307 * @param string $linktext Optional. The text to display instead of the comment
308 * author's email address. Default empty.
309 * @param string $before Optional. The text or HTML to display before the email link.
311 * @param string $after Optional. The text or HTML to display after the email link.
313 * @return string The HTML link between the $before and $after parameters.
315 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
316 $url = get_comment_author_url();
317 $display = ($linktext != '') ? $linktext : $url;
318 $display = str_replace( 'http://www.', '', $display );
319 $display = str_replace( 'http://', '', $display );
320 if ( '/' == substr($display, -1) )
321 $display = substr($display, 0, -1);
322 $return = "$before<a href='$url' rel='external'>$display</a>$after";
325 * Filter the comment author's returned URL link.
329 * @param string $return The HTML-formatted comment author URL link.
331 return apply_filters( 'get_comment_author_url_link', $return );
335 * Displays the HTML link of the url of the author of the current comment.
339 * @param string $linktext Optional. Text to display instead of the comment author's
340 * email address. Default empty.
341 * @param string $before Optional. Text or HTML to display before the email link.
343 * @param string $after Optional. Text or HTML to display after the email link.
346 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
347 echo get_comment_author_url_link( $linktext, $before, $after );
351 * Generates semantic classes for each comment element.
355 * @param string|array $class Optional. One or more classes to add to the class list.
357 * @param int $comment_id Comment ID. Default current comment.
358 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
359 * @param bool $echo Optional. Whether to cho or return the output.
362 function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
363 // Separates classes with a single space, collates classes for comment DIV
364 $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
372 * Returns the classes for the comment div as an array.
376 * @param string|array $class Optional. One or more classes to add to the class list. Default empty.
377 * @param int $comment_id Comment ID. Default current comment.
378 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
379 * @return array An array of classes.
381 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
382 global $comment_alt, $comment_depth, $comment_thread_alt;
384 $comment = get_comment($comment_id);
388 // Get the comment type (comment, trackback),
389 $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
391 // If the comment author has an id (registered), then print the log in name
392 if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
393 // For all registered users, 'byuser'
394 $classes[] = 'byuser';
395 $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
396 // For comment authors who are the author of the post
397 if ( $post = get_post($post_id) ) {
398 if ( $comment->user_id === $post->post_author )
399 $classes[] = 'bypostauthor';
403 if ( empty($comment_alt) )
405 if ( empty($comment_depth) )
407 if ( empty($comment_thread_alt) )
408 $comment_thread_alt = 0;
410 if ( $comment_alt % 2 ) {
419 // Alt for top-level comments
420 if ( 1 == $comment_depth ) {
421 if ( $comment_thread_alt % 2 ) {
422 $classes[] = 'thread-odd';
423 $classes[] = 'thread-alt';
425 $classes[] = 'thread-even';
427 $comment_thread_alt++;
430 $classes[] = "depth-$comment_depth";
432 if ( !empty($class) ) {
433 if ( !is_array( $class ) )
434 $class = preg_split('#\s+#', $class);
435 $classes = array_merge($classes, $class);
438 $classes = array_map('esc_attr', $classes);
441 * Filter the returned CSS classes for the current comment.
445 * @param array $classes An array of comment classes.
446 * @param string $class A comma-separated list of additional classes added to the list.
447 * @param int $comment_id The comment id.
448 * @param int|WP_Post $post_id The post ID or WP_Post object.
450 return apply_filters( 'comment_class', $classes, $class, $comment_id, $post_id );
454 * Retrieve the comment date of the current comment.
458 * @param string $d Optional. The format of the date. Default user's setting.
459 * @param int $comment_ID ID of the comment for which to get the date. Default current comment.
460 * @return string The comment's date.
462 function get_comment_date( $d = '', $comment_ID = 0 ) {
463 $comment = get_comment( $comment_ID );
465 $date = mysql2date(get_option('date_format'), $comment->comment_date);
467 $date = mysql2date($d, $comment->comment_date);
469 * Filter the returned comment date.
473 * @param string|int $date Formatted date string or Unix timestamp.
474 * @param string $d The format of the date.
475 * @param object $comment The comment object.
477 return apply_filters( 'get_comment_date', $date, $d, $comment );
481 * Display the comment date of the current comment.
485 * @param string $d Optional. The format of the date. Default user's settings.
486 * @param int $comment_ID ID of the comment for which to print the date. Default current comment.
488 function comment_date( $d = '', $comment_ID = 0 ) {
489 echo get_comment_date( $d, $comment_ID );
493 * Retrieve the excerpt of the current comment.
495 * Will cut each word and only output the first 20 words with '…' at the end.
496 * If the word count is less than 20, then no truncating is done and no '…'
501 * @param int $comment_ID ID of the comment for which to get the excerpt.
502 * Default current comment.
503 * @return string The maybe truncated comment with 20 words or less.
505 function get_comment_excerpt( $comment_ID = 0 ) {
506 $comment = get_comment( $comment_ID );
507 $comment_text = strip_tags($comment->comment_content);
508 $blah = explode(' ', $comment_text);
509 if (count($blah) > 20) {
517 for ($i=0; $i<$k; $i++) {
518 $excerpt .= $blah[$i] . ' ';
520 $excerpt .= ($use_dotdotdot) ? '…' : '';
523 * Filter the retrieved comment excerpt.
527 * @param string $excerpt The comment excerpt text.
529 return apply_filters( 'get_comment_excerpt', $excerpt );
533 * Display the excerpt of the current comment.
537 * @param int $comment_ID ID of the comment for which to print the excerpt.
538 * Default current comment.
540 function comment_excerpt( $comment_ID = 0 ) {
541 $comment_excerpt = get_comment_excerpt($comment_ID);
543 * Filter the comment excerpt for display.
547 * @param string $comment_excerpt The comment excerpt text.
549 echo apply_filters( 'comment_excerpt', $comment_excerpt );
553 * Retrieve the comment id of the current comment.
557 * @return int The comment ID.
559 function get_comment_ID() {
562 * Filter the returned comment ID.
566 * @param int $comment_ID The current comment ID.
568 return apply_filters( 'get_comment_ID', $comment->comment_ID );
572 * Display the comment id of the current comment.
576 function comment_ID() {
577 echo get_comment_ID();
581 * Retrieve the link to a given comment.
585 * @see get_page_of_comment()
587 * @param mixed $comment Comment to retrieve. Default current comment.
588 * @param array $args Optional. An array of arguments to override the defaults.
589 * @return string The permalink to the given comment.
591 function get_comment_link( $comment = null, $args = array() ) {
592 global $wp_rewrite, $in_comment_loop;
594 $comment = get_comment($comment);
597 if ( ! is_array( $args ) ) {
598 $args = array( 'page' => $args );
601 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
602 $args = wp_parse_args( $args, $defaults );
604 if ( '' === $args['per_page'] && get_option('page_comments') )
605 $args['per_page'] = get_option('comments_per_page');
607 if ( empty($args['per_page']) ) {
608 $args['per_page'] = 0;
612 if ( $args['per_page'] ) {
613 if ( '' == $args['page'] )
614 $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
616 if ( $wp_rewrite->using_permalinks() )
617 $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
619 $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
621 $link = get_permalink( $comment->comment_post_ID );
624 $link = $link . '#comment-' . $comment->comment_ID;
626 * Filter the returned single comment permalink.
630 * @see get_page_of_comment()
632 * @param string $link The comment permalink with '#comment-$id' appended.
633 * @param object $comment The current comment object.
634 * @param array $args An array of arguments to override the defaults.
636 return apply_filters( 'get_comment_link', $link, $comment, $args );
640 * Retrieve the link to the current post comments.
644 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
645 * @return string The link to the comments.
647 function get_comments_link( $post_id = 0 ) {
648 $comments_link = get_permalink( $post_id ) . '#comments';
650 * Filter the returned post comments permalink.
654 * @param string $comments_link Post comments permalink with '#comments' appended.
655 * @param int|WP_Post $post_id Post ID or WP_Post object.
657 return apply_filters( 'get_comments_link', $comments_link, $post_id );
661 * Display the link to the current post comments.
665 * @param string $deprecated Not Used.
666 * @param bool $deprecated_2 Not Used.
668 function comments_link( $deprecated = '', $deprecated_2 = '' ) {
669 if ( !empty( $deprecated ) )
670 _deprecated_argument( __FUNCTION__, '0.72' );
671 if ( !empty( $deprecated_2 ) )
672 _deprecated_argument( __FUNCTION__, '1.3' );
673 echo esc_url( get_comments_link() );
677 * Retrieve the amount of comments a post has.
681 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
682 * @return int The number of comments a post has.
684 function get_comments_number( $post_id = 0 ) {
685 $post = get_post( $post_id );
690 $count = $post->comment_count;
691 $post_id = $post->ID;
695 * Filter the returned comment count for a post.
699 * @param int $count Number of comments a post has.
700 * @param int $post_id Post ID.
702 return apply_filters( 'get_comments_number', $count, $post_id );
706 * Display the language string for the number of comments the current post has.
710 * @param string $zero Optional. Text for no comments. Default false.
711 * @param string $one Optional. Text for one comment. Default false.
712 * @param string $more Optional. Text for more than one comment. Default false.
713 * @param string $deprecated Not used.
715 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
716 if ( ! empty( $deprecated ) ) {
717 _deprecated_argument( __FUNCTION__, '1.3' );
719 echo get_comments_number_text( $zero, $one, $more );
723 * Display the language string for the number of comments the current post has.
727 * @param string $zero Optional. Text for no comments. Default false.
728 * @param string $one Optional. Text for one comment. Default false.
729 * @param string $more Optional. Text for more than one comment. Default false.
731 function get_comments_number_text( $zero = false, $one = false, $more = false ) {
732 $number = get_comments_number();
735 $output = str_replace( '%', number_format_i18n( $number ), ( false === $more ) ? __( '% Comments' ) : $more );
736 } elseif ( $number == 0 ) {
737 $output = ( false === $zero ) ? __( 'No Comments' ) : $zero;
738 } else { // must be one
739 $output = ( false === $one ) ? __( '1 Comment' ) : $one;
742 * Filter the comments count for display.
748 * @param string $output A translatable string formatted based on whether the count
749 * is equal to 0, 1, or 1+.
750 * @param int $number The number of post comments.
752 return apply_filters( 'comments_number', $output, $number );
756 * Retrieve the text of the current comment.
760 * @see Walker_Comment::comment()
762 * @param int $comment_ID ID of the comment for which to get the text. Default current comment.
763 * @param array $args Optional. An array of arguments. Default empty.
764 * @return string The comment content.
766 function get_comment_text( $comment_ID = 0, $args = array() ) {
767 $comment = get_comment( $comment_ID );
770 * Filter the text of a comment.
774 * @see Walker_Comment::comment()
776 * @param string $comment_content Text of the comment.
777 * @param object $comment The comment object.
778 * @param array $args An array of arguments.
780 return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args );
784 * Display the text of the current comment.
788 * @see Walker_Comment::comment()
790 * @param int $comment_ID ID of the comment for which to print the text. Default 0.
791 * @param array $args Optional. An array of arguments. Default empty array. Default empty.
793 function comment_text( $comment_ID = 0, $args = array() ) {
794 $comment = get_comment( $comment_ID );
796 $comment_text = get_comment_text( $comment_ID , $args );
798 * Filter the text of a comment to be displayed.
802 * @see Walker_Comment::comment()
804 * @param string $comment_text Text of the current comment.
805 * @param object $comment The comment object.
806 * @param array $args An array of arguments.
808 echo apply_filters( 'comment_text', $comment_text, $comment, $args );
812 * Retrieve the comment time of the current comment.
816 * @param string $d Optional. The format of the time. Default user's settings.
817 * @param bool $gmt Optional. Whether to use the GMT date. Default false.
818 * @param bool $translate Optional. Whether to translate the time (for use in feeds).
820 * @return string The formatted time.
822 function get_comment_time( $d = '', $gmt = false, $translate = true ) {
824 $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
826 $date = mysql2date(get_option('time_format'), $comment_date, $translate);
828 $date = mysql2date($d, $comment_date, $translate);
831 * Filter the returned comment time.
835 * @param string|int $date The comment time, formatted as a date string or Unix timestamp.
836 * @param string $d Date format.
837 * @param bool $gmt Whether the GMT date is in use.
838 * @param bool $translate Whether the time is translated.
839 * @param object $comment The comment object.
841 return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment );
845 * Display the comment time of the current comment.
849 * @param string $d Optional. The format of the time. Default user's settings.
851 function comment_time( $d = '' ) {
852 echo get_comment_time($d);
856 * Retrieve the comment type of the current comment.
860 * @param int $comment_ID ID of the comment for which to get the type. Default current comment.
861 * @return string The comment type.
863 function get_comment_type( $comment_ID = 0 ) {
864 $comment = get_comment( $comment_ID );
865 if ( '' == $comment->comment_type )
866 $comment->comment_type = 'comment';
869 * Filter the returned comment type.
873 * @param string $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
875 return apply_filters( 'get_comment_type', $comment->comment_type );
879 * Display the comment type of the current comment.
883 * @param string $commenttxt Optional. String to display for comment type. Default false.
884 * @param string $trackbacktxt Optional. String to display for trackback type. Default false.
885 * @param string $pingbacktxt Optional. String to display for pingback type. Default false.
887 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
888 if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
889 if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
890 if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
891 $type = get_comment_type();
905 * Retrieve The current post's trackback URL.
907 * There is a check to see if permalink's have been enabled and if so, will
908 * retrieve the pretty path. If permalinks weren't enabled, the ID of the
909 * current post is used and appended to the correct page to go to.
913 * @return string The trackback URL after being filtered.
915 function get_trackback_url() {
916 if ( '' != get_option('permalink_structure') )
917 $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
919 $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
922 * Filter the returned trackback URL.
926 * @param string $tb_url The trackback URL.
928 return apply_filters( 'trackback_url', $tb_url );
932 * Display the current post's trackback URL.
936 * @param bool $deprecated_echo Not used.
937 * @return void|string Should only be used to echo the trackback URL, use get_trackback_url()
938 * for the result instead.
940 function trackback_url( $deprecated_echo = true ) {
941 if ( $deprecated_echo !== true )
942 _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
943 if ( $deprecated_echo )
944 echo get_trackback_url();
946 return get_trackback_url();
950 * Generate and display the RDF for the trackback information of current post.
952 * Deprecated in 3.0.0, and restored in 3.0.1.
956 * @param int $deprecated Not used (Was $timezone = 0).
958 function trackback_rdf( $deprecated = '' ) {
959 if ( ! empty( $deprecated ) ) {
960 _deprecated_argument( __FUNCTION__, '2.5' );
963 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'W3C_Validator' ) ) {
967 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
968 xmlns:dc="http://purl.org/dc/elements/1.1/"
969 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
970 <rdf:Description rdf:about="';
973 echo ' dc:identifier="';
976 echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n";
977 echo ' trackback:ping="'.get_trackback_url().'"'." />\n";
982 * Whether the current post is open for comments.
986 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
987 * @return bool True if the comments are open.
989 function comments_open( $post_id = null ) {
991 $_post = get_post($post_id);
993 $open = ( 'open' == $_post->comment_status );
996 * Filter whether the current post is open for comments.
1000 * @param bool $open Whether the current post is open for comments.
1001 * @param int|WP_Post $post_id The post ID or WP_Post object.
1003 return apply_filters( 'comments_open', $open, $post_id );
1007 * Whether the current post is open for pings.
1011 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
1012 * @return bool True if pings are accepted
1014 function pings_open( $post_id = null ) {
1016 $_post = get_post($post_id);
1018 $open = ( 'open' == $_post->ping_status );
1021 * Filter whether the current post is open for pings.
1025 * @param bool $open Whether the current post is open for pings.
1026 * @param int|WP_Post $post_id The post ID or WP_Post object.
1028 return apply_filters( 'pings_open', $open, $post_id );
1032 * Display form token for unfiltered comments.
1034 * Will only display nonce token if the current user has permissions for
1035 * unfiltered html. Won't display the token for other users.
1037 * The function was backported to 2.0.10 and was added to versions 2.1.3 and
1038 * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in
1039 * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.
1041 * Backported to 2.0.10.
1045 function wp_comment_form_unfiltered_html_nonce() {
1047 $post_id = $post ? $post->ID : 0;
1049 if ( current_user_can( 'unfiltered_html' ) ) {
1050 wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
1051 echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
1056 * Load the comment template specified in $file.
1058 * Will not display the comments template if not on single post or page, or if
1059 * the post does not have comments.
1061 * Uses the WordPress database object to query for the comments. The comments
1062 * are passed through the 'comments_array' filter hook with the list of comments
1063 * and the post ID respectively.
1065 * The $file path is passed through a filter hook called, 'comments_template'
1066 * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
1067 * first and if it fails it will require the default comment template from the
1068 * default theme. If either does not exist, then the WordPress process will be
1069 * halted. It is advised for that reason, that the default theme is not deleted.
1071 * @todo Document globals
1072 * @uses $withcomments Will not try to get the comments if the post has none.
1076 * @param string $file Optional. The file to load. Default '/comments.php'.
1077 * @param bool $separate_comments Optional. Whether to separate the comments by comment type.
1079 * @return null Returns null if no comments appear.
1081 function comments_template( $file = '/comments.php', $separate_comments = false ) {
1082 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
1084 if ( !(is_single() || is_page() || $withcomments) || empty($post) )
1088 $file = '/comments.php';
1090 $req = get_option('require_name_email');
1093 * Comment author information fetched from the comment cookies.
1094 * Uuses wp_get_current_commenter().
1096 $commenter = wp_get_current_commenter();
1099 * The name of the current comment author escaped for use in attributes.
1100 * Escaped by sanitize_comment_cookies().
1102 $comment_author = $commenter['comment_author'];
1105 * The email address of the current comment author escaped for use in attributes.
1106 * Escaped by sanitize_comment_cookies().
1108 $comment_author_email = $commenter['comment_author_email'];
1111 * The url of the current comment author escaped for use in attributes.
1113 $comment_author_url = esc_url($commenter['comment_author_url']);
1115 /** @todo Use API instead of SELECTs. */
1117 $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, $user_ID));
1118 } else if ( empty($comment_author) ) {
1119 $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
1121 $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email));
1125 * Filter the comments array.
1129 * @param array $comments Array of comments supplied to the comments template.
1130 * @param int $post_ID Post ID.
1132 $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
1133 $comments = &$wp_query->comments;
1134 $wp_query->comment_count = count($wp_query->comments);
1135 update_comment_cache($wp_query->comments);
1137 if ( $separate_comments ) {
1138 $wp_query->comments_by_type = separate_comments($comments);
1139 $comments_by_type = &$wp_query->comments_by_type;
1142 $overridden_cpage = false;
1143 if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
1144 set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
1145 $overridden_cpage = true;
1148 if ( !defined('COMMENTS_TEMPLATE') )
1149 define('COMMENTS_TEMPLATE', true);
1151 $theme_template = STYLESHEETPATH . $file;
1153 * Filter the path to the theme template file used for the comments template.
1157 * @param string $theme_template The path to the theme template file.
1159 $include = apply_filters( 'comments_template', $theme_template );
1160 if ( file_exists( $include ) )
1161 require( $include );
1162 elseif ( file_exists( TEMPLATEPATH . $file ) )
1163 require( TEMPLATEPATH . $file );
1164 else // Backward compat code will be removed in a future release
1165 require( ABSPATH . WPINC . '/theme-compat/comments.php');
1169 * Display the JS popup script to show a comment.
1171 * If the $file parameter is empty, then the home page is assumed. The defaults
1172 * for the window are 400px by 400px.
1174 * For the comment link popup to work, this function has to be called or the
1175 * normal comment link will be assumed.
1177 * @global string $wpcommentspopupfile The URL to use for the popup window.
1178 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
1182 * @param int $width Optional. The width of the popup window. Default 400.
1183 * @param int $height Optional. The height of the popup window. Default 400.
1184 * @param string $file Optional. Sets the location of the popup window.
1186 function comments_popup_script( $width = 400, $height = 400, $file = '' ) {
1187 global $wpcommentspopupfile, $wpcommentsjavascript;
1189 if (empty ($file)) {
1190 $wpcommentspopupfile = ''; // Use the index.
1192 $wpcommentspopupfile = $file;
1195 $wpcommentsjavascript = 1;
1196 $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";
1201 * Displays the link to the comments popup window for the current post ID.
1203 * Is not meant to be displayed on single posts and pages. Should be used
1204 * on the lists of posts
1206 * @global string $wpcommentspopupfile The URL to use for the popup window.
1207 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
1211 * @param string $zero Optional. String to display when no comments. Default false.
1212 * @param string $one Optional. String to display when only one comment is available.
1214 * @param string $more Optional. String to display when there are more than one comment.
1216 * @param string $css_class Optional. CSS class to use for comments. Default empty.
1217 * @param string $none Optional. String to display when comments have been turned off.
1219 * @return null Returns null on single posts and pages.
1221 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
1222 global $wpcommentspopupfile, $wpcommentsjavascript;
1226 if ( false === $zero ) $zero = __( 'No Comments' );
1227 if ( false === $one ) $one = __( '1 Comment' );
1228 if ( false === $more ) $more = __( '% Comments' );
1229 if ( false === $none ) $none = __( 'Comments Off' );
1231 $number = get_comments_number( $id );
1233 if ( 0 == $number && !comments_open() && !pings_open() ) {
1234 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
1238 if ( post_password_required() ) {
1239 echo __('Enter your password to view comments.');
1244 if ( $wpcommentsjavascript ) {
1245 if ( empty( $wpcommentspopupfile ) )
1248 $home = get_option('siteurl');
1249 echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
1250 echo '" onclick="wpopen(this.href); return false"';
1251 } else { // if comments_popup_script() is not in the template, display simple comment link
1253 echo get_permalink() . '#respond';
1259 if ( !empty( $css_class ) ) {
1260 echo ' class="'.$css_class.'" ';
1262 $title = the_title_attribute( array('echo' => 0 ) );
1266 * Filter the comments popup link attributes for display.
1270 * @param string $attributes The comments popup link attributes. Default empty.
1272 echo apply_filters( 'comments_popup_link_attributes', $attributes );
1274 echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
1275 comments_number( $zero, $one, $more );
1280 * Retrieve HTML content for reply to comment link.
1284 * @param array $args {
1285 * Optional. Override default arguments.
1287 * @type string $add_below The first part of the selector used to identify the comment to respond below.
1288 * The resulting value is passed as the first parameter to addComment.moveForm(),
1289 * concatenated as $add_below-$comment->comment_ID. Default 'comment'.
1290 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
1291 * to addComment.moveForm(), and appended to the link URL as a hash value.
1292 * Default 'respond'.
1293 * @type string $reply_text The text of the Reply link. Default 'Reply'.
1294 * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.
1295 * @type int $depth' The depth of the new comment. Must be greater than 0 and less than the value
1296 * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
1297 * @type string $before The text or HTML to add before the reply link. Default empty.
1298 * @type string $after The text or HTML to add after the reply link. Default empty.
1300 * @param int $comment Comment being replied to. Default current comment.
1301 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
1302 * Default current post.
1303 * @return mixed Link to show comment form, if successful. False, if comments are closed.
1305 function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
1308 'add_below' => 'comment',
1309 'respond_id' => 'respond',
1310 'reply_text' => __('Reply'),
1311 'login_text' => __('Log in to Reply'),
1317 $args = wp_parse_args( $args, $defaults );
1319 if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
1323 $add_below = $args['add_below'];
1324 $respond_id = $args['respond_id'];
1325 $reply_text = $args['reply_text'];
1327 $comment = get_comment( $comment );
1328 if ( empty( $post ) ) {
1329 $post = $comment->comment_post_ID;
1331 $post = get_post( $post );
1333 if ( ! comments_open( $post->ID ) ) {
1337 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
1338 $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $args['login_text'] . '</a>';
1340 $link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
1343 * Filter the comment reply link.
1347 * @param string $link The HTML markup for the comment reply link.
1348 * @param array $args An array of arguments overriding the defaults.
1349 * @param object $comment The object of the comment being replied.
1350 * @param WP_Post $post The WP_Post object.
1352 return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
1356 * Displays the HTML content for reply to comment link.
1360 * @see get_comment_reply_link()
1362 * @param array $args Optional. Override default options.
1363 * @param int $comment Comment being replied to. Default current comment.
1364 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
1365 * Default current post.
1366 * @return mixed Link to show comment form, if successful. False, if comments are closed.
1368 function comment_reply_link($args = array(), $comment = null, $post = null) {
1369 echo get_comment_reply_link($args, $comment, $post);
1373 * Retrieve HTML content for reply to post link.
1377 * @param array $args {
1378 * Optional. Override default arguments.
1380 * @type string $add_below The first part of the selector used to identify the comment to respond below.
1381 * The resulting value is passed as the first parameter to addComment.moveForm(),
1382 * concatenated as $add_below-$comment->comment_ID. Default is 'post'.
1383 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
1384 * to addComment.moveForm(), and appended to the link URL as a hash value.
1385 * Default 'respond'.
1386 * @type string $reply_text Text of the Reply link. Default is 'Leave a Comment'.
1387 * @type string $login_text Text of the link to reply if logged out. Default is 'Log in to leave a Comment'.
1388 * @type string $before Text or HTML to add before the reply link. Default empty.
1389 * @type string $after Text or HTML to add after the reply link. Default empty.
1391 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on.
1392 * Default current post.
1393 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1395 function get_post_reply_link($args = array(), $post = null) {
1397 'add_below' => 'post',
1398 'respond_id' => 'respond',
1399 'reply_text' => __('Leave a Comment'),
1400 'login_text' => __('Log in to leave a Comment'),
1405 $args = wp_parse_args($args, $defaults);
1406 $add_below = $args['add_below'];
1407 $respond_id = $args['respond_id'];
1408 $reply_text = $args['reply_text'];
1409 $post = get_post($post);
1411 if ( ! comments_open( $post->ID ) ) {
1415 if ( get_option('comment_registration') && ! is_user_logged_in() ) {
1416 $link = '<a rel="nofollow" href="' . wp_login_url( get_permalink() ) . '">' . $args['login_text'] . '</a>';
1418 $link = "<a rel='nofollow' class='comment-reply-link' href='" . get_permalink($post->ID) . "#$respond_id' onclick='return addComment.moveForm(\"$add_below-$post->ID\", \"0\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
1420 $formatted_link = $args['before'] . $link . $args['after'];
1422 * Filter the formatted post comments link HTML.
1426 * @param string $formatted The HTML-formatted post comments link.
1427 * @param int|WP_Post $post The post ID or WP_Post object.
1429 return apply_filters( 'post_comments_link', $formatted_link, $post );
1433 * Displays the HTML content for reply to post link.
1437 * @see get_post_reply_link()
1439 * @param array $args Optional. Override default options,
1440 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
1441 * Default current post.
1442 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1444 function post_reply_link($args = array(), $post = null) {
1445 echo get_post_reply_link($args, $post);
1449 * Retrieve HTML content for cancel comment reply link.
1453 * @param string $text Optional. Text to display for cancel reply link. Default empty.
1455 function get_cancel_comment_reply_link( $text = '' ) {
1457 $text = __('Click here to cancel reply.');
1459 $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
1460 $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
1462 $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
1464 * Filter the cancel comment reply link HTML.
1468 * @param string $formatted_link The HTML-formatted cancel comment reply link.
1469 * @param string $link Cancel comment reply link URL.
1470 * @param string $text Cancel comment reply link text.
1472 return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
1476 * Display HTML content for cancel comment reply link.
1480 * @param string $text Optional. Text to display for cancel reply link. Default empty.
1482 function cancel_comment_reply_link( $text = '' ) {
1483 echo get_cancel_comment_reply_link($text);
1487 * Retrieve hidden input HTML for replying to comments.
1491 * @param int $id Optional. Post ID. Default current post ID.
1492 * @return string Hidden input HTML for replying to comments
1494 function get_comment_id_fields( $id = 0 ) {
1498 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1499 $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
1500 $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
1503 * Filter the returned comment id fields.
1507 * @param string $result The HTML-formatted hidden id field comment elements.
1508 * @param int $id The post ID.
1509 * @param int $replytoid The id of the comment being replied to.
1511 return apply_filters( 'comment_id_fields', $result, $id, $replytoid );
1515 * Output hidden input HTML for replying to comments.
1519 * @param int $id Optional. Post ID. Default current post ID.
1521 function comment_id_fields( $id = 0 ) {
1522 echo get_comment_id_fields( $id );
1526 * Display text based on comment reply status.
1528 * Only affects users with Javascript disabled.
1532 * @param string $noreplytext Optional. Text to display when not replying to a comment.
1534 * @param string $replytext Optional. Text to display when replying to a comment.
1535 * Default false. Accepts "%s" for the author of the comment
1537 * @param string $linktoparent Optional. Boolean to control making the author's name a link
1538 * to their comment. Default true.
1540 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {
1543 if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
1544 if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
1546 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1548 if ( 0 == $replytoid )
1551 $comment = get_comment($replytoid);
1552 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
1553 printf( $replytext, $author );
1558 * HTML comment list class.
1563 class Walker_Comment extends Walker {
1565 * What the class handles.
1567 * @see Walker::$tree_type
1572 public $tree_type = 'comment';
1577 * @see Walker::$db_fields
1582 public $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
1585 * Start the list before the elements are added.
1587 * @see Walker::start_lvl()
1591 * @param string $output Passed by reference. Used to append additional content.
1592 * @param int $depth Depth of comment.
1593 * @param array $args Uses 'style' argument for type of HTML list.
1595 public function start_lvl( &$output, $depth = 0, $args = array() ) {
1596 $GLOBALS['comment_depth'] = $depth + 1;
1598 switch ( $args['style'] ) {
1602 $output .= '<ol class="children">' . "\n";
1606 $output .= '<ul class="children">' . "\n";
1612 * End the list of items after the elements are added.
1614 * @see Walker::end_lvl()
1618 * @param string $output Passed by reference. Used to append additional content.
1619 * @param int $depth Depth of comment.
1620 * @param array $args Will only append content if style argument value is 'ol' or 'ul'.
1622 public function end_lvl( &$output, $depth = 0, $args = array() ) {
1623 $GLOBALS['comment_depth'] = $depth + 1;
1625 switch ( $args['style'] ) {
1629 $output .= "</ol><!-- .children -->\n";
1633 $output .= "</ul><!-- .children -->\n";
1639 * Traverse elements to create list from elements.
1641 * This function is designed to enhance Walker::display_element() to
1642 * display children of higher nesting levels than selected inline on
1643 * the highest depth level displayed. This prevents them being orphaned
1644 * at the end of the comment list.
1646 * Example: max_depth = 2, with 5 levels of nested content.
1657 * @see Walker::display_element()
1658 * @see wp_list_comments()
1662 * @param object $element Data object.
1663 * @param array $children_elements List of elements to continue traversing.
1664 * @param int $max_depth Max depth to traverse.
1665 * @param int $depth Depth of current element.
1666 * @param array $args An array of arguments.
1667 * @param string $output Passed by reference. Used to append additional content.
1668 * @return null Null on failure with no changes to parameters.
1670 public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
1675 $id_field = $this->db_fields['id'];
1676 $id = $element->$id_field;
1678 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
1680 // If we're at the max depth, and the current element still has children, loop over those and display them at this level
1681 // This is to prevent them being orphaned to the end of the list.
1682 if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
1683 foreach ( $children_elements[ $id ] as $child )
1684 $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
1686 unset( $children_elements[ $id ] );
1692 * Start the element output.
1696 * @see Walker::start_el()
1697 * @see wp_list_comments()
1699 * @param string $output Passed by reference. Used to append additional content.
1700 * @param object $comment Comment data object.
1701 * @param int $depth Depth of comment in reference to parents.
1702 * @param array $args An array of arguments.
1704 public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
1706 $GLOBALS['comment_depth'] = $depth;
1707 $GLOBALS['comment'] = $comment;
1709 if ( !empty( $args['callback'] ) ) {
1711 call_user_func( $args['callback'], $comment, $args, $depth );
1712 $output .= ob_get_clean();
1716 if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
1718 $this->ping( $comment, $depth, $args );
1719 $output .= ob_get_clean();
1720 } elseif ( 'html5' === $args['format'] ) {
1722 $this->html5_comment( $comment, $depth, $args );
1723 $output .= ob_get_clean();
1726 $this->comment( $comment, $depth, $args );
1727 $output .= ob_get_clean();
1732 * Ends the element output, if needed.
1736 * @see Walker::end_el()
1737 * @see wp_list_comments()
1739 * @param string $output Passed by reference. Used to append additional content.
1740 * @param object $comment The comment object. Default current comment.
1741 * @param int $depth Depth of comment.
1742 * @param array $args An array of arguments.
1744 public function end_el( &$output, $comment, $depth = 0, $args = array() ) {
1745 if ( !empty( $args['end-callback'] ) ) {
1747 call_user_func( $args['end-callback'], $comment, $args, $depth );
1748 $output .= ob_get_clean();
1751 if ( 'div' == $args['style'] )
1752 $output .= "</div><!-- #comment-## -->\n";
1754 $output .= "</li><!-- #comment-## -->\n";
1758 * Output a pingback comment.
1763 * @see wp_list_comments()
1765 * @param object $comment The comment object.
1766 * @param int $depth Depth of comment.
1767 * @param array $args An array of arguments.
1769 protected function ping( $comment, $depth, $args ) {
1770 $tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
1772 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
1773 <div class="comment-body">
1774 <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
1780 * Output a single comment.
1785 * @see wp_list_comments()
1787 * @param object $comment Comment to display.
1788 * @param int $depth Depth of comment.
1789 * @param array $args An array of arguments.
1791 protected function comment( $comment, $depth, $args ) {
1792 if ( 'div' == $args['style'] ) {
1794 $add_below = 'comment';
1797 $add_below = 'div-comment';
1800 <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '' ); ?> id="comment-<?php comment_ID(); ?>">
1801 <?php if ( 'div' != $args['style'] ) : ?>
1802 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
1804 <div class="comment-author vcard">
1805 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
1806 <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
1808 <?php if ( '0' == $comment->comment_approved ) : ?>
1809 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>
1813 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>">
1815 /* translators: 1: date, 2: time */
1816 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
1820 <?php comment_text( get_comment_id(), array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1823 <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1825 <?php if ( 'div' != $args['style'] ) : ?>
1832 * Output a comment in the HTML5 format.
1837 * @see wp_list_comments()
1839 * @param object $comment Comment to display.
1840 * @param int $depth Depth of comment.
1841 * @param array $args An array of arguments.
1843 protected function html5_comment( $comment, $depth, $args ) {
1844 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
1846 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '' ); ?>>
1847 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
1848 <footer class="comment-meta">
1849 <div class="comment-author vcard">
1850 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
1851 <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?>
1852 </div><!-- .comment-author -->
1854 <div class="comment-metadata">
1855 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>">
1856 <time datetime="<?php comment_time( 'c' ); ?>">
1857 <?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), get_comment_time() ); ?>
1860 <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
1861 </div><!-- .comment-metadata -->
1863 <?php if ( '0' == $comment->comment_approved ) : ?>
1864 <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
1866 </footer><!-- .comment-meta -->
1868 <div class="comment-content">
1869 <?php comment_text(); ?>
1870 </div><!-- .comment-content -->
1873 <?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1874 </div><!-- .reply -->
1875 </article><!-- .comment-body -->
1883 * Used in the comments.php template to list comments for a particular post.
1887 * @see WP_Query->comments
1889 * @param string|array $args {
1890 * Optional. Formatting options.
1892 * @type object $walker Instance of a Walker class to list comments. Default null.
1893 * @type int $max_depth The maximum comments depth. Default empty.
1894 * @type string $style The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
1895 * @type string $callback Callback function to use. Default null.
1896 * @type string $end-callback Callback function to use at the end. Default null.
1897 * @type string $type Type of comments to list.
1898 * Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
1899 * @type int $page Page ID to list comments for. Default empty.
1900 * @type int $per_page Number of comments to list per page. Default empty.
1901 * @type int $avatar_size Height and width dimensions of the avatar size. Default 32.
1902 * @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
1903 * @type bool $reverse_children Whether to reverse child comments in the list. Default null.
1904 * @type string $format How to format the comments list.
1905 * Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
1906 * @type bool $short_ping Whether to output short pings. Default false.
1907 * @type bool $echo Whether to echo the output or return it. Default true.
1909 * @param array $comments Optional. Array of comment objects.
1911 function wp_list_comments( $args = array(), $comments = null ) {
1912 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
1914 $in_comment_loop = true;
1916 $comment_alt = $comment_thread_alt = 0;
1924 'end-callback' => null,
1928 'avatar_size' => 32,
1929 'reverse_top_level' => null,
1930 'reverse_children' => '',
1931 'format' => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
1932 'short_ping' => false,
1936 $r = wp_parse_args( $args, $defaults );
1939 * Filter the arguments used in retrieving the comment list.
1943 * @see wp_list_comments()
1945 * @param array $r An array of arguments for displaying comments.
1947 $r = apply_filters( 'wp_list_comments_args', $r );
1949 // Figure out what comments we'll be looping through ($_comments)
1950 if ( null !== $comments ) {
1951 $comments = (array) $comments;
1952 if ( empty($comments) )
1954 if ( 'all' != $r['type'] ) {
1955 $comments_by_type = separate_comments($comments);
1956 if ( empty($comments_by_type[$r['type']]) )
1958 $_comments = $comments_by_type[$r['type']];
1960 $_comments = $comments;
1963 if ( empty($wp_query->comments) )
1965 if ( 'all' != $r['type'] ) {
1966 if ( empty($wp_query->comments_by_type) )
1967 $wp_query->comments_by_type = separate_comments($wp_query->comments);
1968 if ( empty($wp_query->comments_by_type[$r['type']]) )
1970 $_comments = $wp_query->comments_by_type[$r['type']];
1972 $_comments = $wp_query->comments;
1976 if ( '' === $r['per_page'] && get_option('page_comments') )
1977 $r['per_page'] = get_query_var('comments_per_page');
1979 if ( empty($r['per_page']) ) {
1984 if ( '' === $r['max_depth'] ) {
1985 if ( get_option('thread_comments') )
1986 $r['max_depth'] = get_option('thread_comments_depth');
1988 $r['max_depth'] = -1;
1991 if ( '' === $r['page'] ) {
1992 if ( empty($overridden_cpage) ) {
1993 $r['page'] = get_query_var('cpage');
1995 $threaded = ( -1 != $r['max_depth'] );
1996 $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
1997 set_query_var( 'cpage', $r['page'] );
2001 $r['page'] = intval($r['page']);
2002 if ( 0 == $r['page'] && 0 != $r['per_page'] )
2005 if ( null === $r['reverse_top_level'] )
2006 $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
2008 if ( empty( $r['walker'] ) ) {
2009 $walker = new Walker_Comment;
2011 $walker = $r['walker'];
2014 $output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r );
2015 $wp_query->max_num_comment_pages = $walker->max_pages;
2017 $in_comment_loop = false;
2027 * Output a complete commenting form for use within a template.
2029 * Most strings and form fields may be controlled through the $args array passed
2030 * into the function, while you may also choose to use the comment_form_default_fields
2031 * filter to modify the array of default fields if you'd just like to add a new
2032 * one or remove a single field. All fields are also individually passed through
2033 * a filter of the form comment_form_field_$name where $name is the key used
2034 * in the array of fields.
2038 * @param array $args {
2039 * Optional. Default arguments and form fields to override.
2041 * @type array $fields {
2042 * Default comment fields, filterable by default via the 'comment_form_default_fields' hook.
2044 * @type string $author Comment author field HTML.
2045 * @type string $email Comment author email field HTML.
2046 * @type string $url Comment author URL field HTML.
2048 * @type string $comment_field The comment textarea field HTML.
2049 * @type string $must_log_in HTML element for a 'must be logged in to comment' message.
2050 * @type string $logged_in_as HTML element for a 'logged in as <user>' message.
2051 * @type string $comment_notes_before HTML element for a message displayed before the comment form.
2052 * Default 'Your email address will not be published.'.
2053 * @type string $comment_notes_after HTML element for a message displayed after the comment form.
2054 * Default 'You may use these HTML tags and attributes ...'.
2055 * @type string $id_form The comment form element id attribute. Default 'commentform'.
2056 * @type string $id_submit The comment submit element id attribute. Default 'submit'.
2057 * @type string $name_submit The comment submit element name attribute. Default 'submit'.
2058 * @type string $title_reply The translatable 'reply' button label. Default 'Leave a Reply'.
2059 * @type string $title_reply_to The translatable 'reply-to' button label. Default 'Leave a Reply to %s',
2060 * where %s is the author of the comment being replied to.
2061 * @type string $cancel_reply_link The translatable 'cancel reply' button label. Default 'Cancel reply'.
2062 * @type string $label_submit The translatable 'submit' button label. Default 'Post a comment'.
2063 * @type string $format The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
2065 * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post.
2067 function comment_form( $args = array(), $post_id = null ) {
2068 if ( null === $post_id )
2069 $post_id = get_the_ID();
2071 $commenter = wp_get_current_commenter();
2072 $user = wp_get_current_user();
2073 $user_identity = $user->exists() ? $user->display_name : '';
2075 $args = wp_parse_args( $args );
2076 if ( ! isset( $args['format'] ) )
2077 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
2079 $req = get_option( 'require_name_email' );
2080 $aria_req = ( $req ? " aria-required='true'" : '' );
2081 $html5 = 'html5' === $args['format'];
2083 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
2084 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
2085 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
2086 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
2087 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
2088 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
2091 $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
2094 * Filter the default comment form fields.
2098 * @param array $fields The default comment fields.
2100 $fields = apply_filters( 'comment_form_default_fields', $fields );
2102 'fields' => $fields,
2103 '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"></textarea></p>',
2104 /** This filter is documented in wp-includes/link-template.php */
2105 '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>',
2106 /** This filter is documented in wp-includes/link-template.php */
2107 '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>',
2108 'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
2109 'comment_notes_after' => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
2110 'id_form' => 'commentform',
2111 'id_submit' => 'submit',
2112 'name_submit' => 'submit',
2113 'title_reply' => __( 'Leave a Reply' ),
2114 'title_reply_to' => __( 'Leave a Reply to %s' ),
2115 'cancel_reply_link' => __( 'Cancel reply' ),
2116 'label_submit' => __( 'Post Comment' ),
2117 'format' => 'xhtml',
2121 * Filter the comment form default arguments.
2123 * Use 'comment_form_default_fields' to filter the comment fields.
2127 * @param array $defaults The default comment form arguments.
2129 $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
2132 <?php if ( comments_open( $post_id ) ) : ?>
2135 * Fires before the comment form.
2139 do_action( 'comment_form_before' );
2141 <div id="respond" class="comment-respond">
2142 <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>
2143 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
2144 <?php echo $args['must_log_in']; ?>
2147 * Fires after the HTML-formatted 'must log in after' message in the comment form.
2151 do_action( 'comment_form_must_log_in_after' );
2154 <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' : ''; ?>>
2157 * Fires at the top of the comment form, inside the <form> tag.
2161 do_action( 'comment_form_top' );
2163 <?php if ( is_user_logged_in() ) : ?>
2166 * Filter the 'logged in' message for the comment form for display.
2170 * @param string $args_logged_in The logged-in-as HTML-formatted message.
2171 * @param array $commenter An array containing the comment author's
2172 * username, email, and URL.
2173 * @param string $user_identity If the commenter is a registered user,
2174 * the display name, blank otherwise.
2176 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
2180 * Fires after the is_user_logged_in() check in the comment form.
2184 * @param array $commenter An array containing the comment author's
2185 * username, email, and URL.
2186 * @param string $user_identity If the commenter is a registered user,
2187 * the display name, blank otherwise.
2189 do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
2192 <?php echo $args['comment_notes_before']; ?>
2195 * Fires before the comment fields in the comment form.
2199 do_action( 'comment_form_before_fields' );
2200 foreach ( (array) $args['fields'] as $name => $field ) {
2202 * Filter a comment form field for display.
2204 * The dynamic portion of the filter hook, $name, refers to the name
2205 * of the comment form field. Such as 'author', 'email', or 'url'.
2209 * @param string $field The HTML-formatted output of the comment form field.
2211 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
2214 * Fires after the comment fields in the comment form.
2218 do_action( 'comment_form_after_fields' );
2223 * Filter the content of the comment textarea field for display.
2227 * @param string $args_comment_field The content of the comment textarea field.
2229 echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );
2231 <?php echo $args['comment_notes_after']; ?>
2232 <p class="form-submit">
2233 <input name="<?php echo esc_attr( $args['name_submit'] ); ?>" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
2234 <?php comment_id_fields( $post_id ); ?>
2238 * Fires at the bottom of the comment form, inside the closing </form> tag.
2242 * @param int $post_id The post ID.
2244 do_action( 'comment_form', $post_id );
2248 </div><!-- #respond -->
2251 * Fires after the comment form.
2255 do_action( 'comment_form_after' );
2258 * Fires after the comment form if comments are closed.
2262 do_action( 'comment_form_comments_closed' );