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->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.
118 * @global object $comment The current Comment row object
122 * @param string $linktext Optional. The text to display instead of the comment author's email address. Default empty.
123 * @param string $before Optional. The text or HTML to display before the email link.Default empty.
124 * @param string $after Optional. The text or HTML to display after the email link. Default empty.
126 function comment_author_email_link( $linktext = '', $before = '', $after = '' ) {
127 if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )
132 * Return the html email link to the author of the current comment.
134 * Care should be taken to protect the email address and assure that email
135 * harvesters do not capture your commentors' email address. Most assume that
136 * their email address will not appear in raw form on the blog. Doing so will
137 * enable anyone, including those that people don't want to get the email
138 * address and use it for their own means good and bad.
140 * @global object $comment The current Comment row object.
144 * @param string $linktext Optional. The text to display instead of the comment author's email address. Default empty.
145 * @param string $before Optional. The text or HTML to display before the email link. Default empty.
146 * @param string $after Optional. The 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 commentors' email address.
158 * @param string $comment->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 Optional. The ID of the comment for which to get the author's link. Default current comment.
181 * @return string The comment author name or HTML link for author's URL.
183 function get_comment_author_link( $comment_ID = 0 ) {
184 $url = get_comment_author_url( $comment_ID );
185 $author = get_comment_author( $comment_ID );
187 if ( empty( $url ) || 'http://' == $url )
190 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
193 * Filter the comment author's link for display.
197 * @param string $return The HTML-formatted comment author link. Empty for an invalid URL.
199 return apply_filters( 'get_comment_author_link', $return );
203 * Display the html link to the url of the author of the current comment.
206 * @see get_comment_author_link() Echoes result
208 * @param int $comment_ID Optional. The ID of the comment for which to print the author's link. Default current comment.
210 function comment_author_link( $comment_ID = 0 ) {
211 echo get_comment_author_link( $comment_ID );
215 * Retrieve the IP address of the author of the current comment.
219 * @param int $comment_ID Optional. The ID of the comment for which to get the author's IP address. Default current comment.
220 * @return string The comment author's IP address.
222 function get_comment_author_IP( $comment_ID = 0 ) {
223 $comment = get_comment( $comment_ID );
226 * Filter the comment author's returned IP address.
230 * @param string $comment->comment_author_IP The comment author's IP address.
232 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP );
236 * Display the IP address of the author of the current comment.
240 * @param int $comment_ID Optional. The ID of the comment for which to print the author's IP address. Default current comment.
242 function comment_author_IP( $comment_ID = 0 ) {
243 echo get_comment_author_IP( $comment_ID );
247 * Retrieve the url of the author of the current comment.
251 * @param int $comment_ID Optional. The ID of the comment for which to get the author's URL. Default current comment.
254 function get_comment_author_url( $comment_ID = 0 ) {
255 $comment = get_comment( $comment_ID );
256 $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
257 $url = esc_url( $url, array('http', 'https') );
258 return apply_filters('get_comment_author_url', $url);
262 * Display the url of the author of the current comment.
266 * @param int $comment_ID Optional. The ID of the comment for which to print the author's URL. Default current comment.
268 function comment_author_url( $comment_ID = 0 ) {
269 $author_url = get_comment_author_url( $comment_ID );
271 * Filter the comment author's URL for display.
275 * @param string $author_url The comment author's URL.
277 echo apply_filters( 'comment_url', $author_url );
281 * Retrieves the HTML link of the url of the author of the current comment.
283 * $linktext parameter is only used if the URL does not exist for the comment
284 * author. If the URL does exist then the URL will be used and the $linktext
287 * Encapsulate the HTML link between the $before and $after. So it will appear
288 * in the order of $before, link, and finally $after.
292 * @param string $linktext Optional. The text to display instead of the comment author's email address. Default empty.
293 * @param string $before Optional. The text or HTML to display before the email link. Default empty.
294 * @param string $after Optional. The text or HTML to display after the email link. Default empty.
295 * @return string The HTML link between the $before and $after parameters.
297 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
298 $url = get_comment_author_url();
299 $display = ($linktext != '') ? $linktext : $url;
300 $display = str_replace( 'http://www.', '', $display );
301 $display = str_replace( 'http://', '', $display );
302 if ( '/' == substr($display, -1) )
303 $display = substr($display, 0, -1);
304 $return = "$before<a href='$url' rel='external'>$display</a>$after";
307 * Filter the comment author's returned URL link.
311 * @param string $return The HTML-formatted comment author URL link.
313 return apply_filters( 'get_comment_author_url_link', $return );
317 * Displays the HTML link of the url of the author of the current comment.
321 * @param string $linktext Optional. The text to display instead of the comment author's email address. Default empty.
322 * @param string $before Optional. The text or HTML to display before the email link. Default empty.
323 * @param string $after Optional. The text or HTML to display after the email link. Default empty.
325 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
326 echo get_comment_author_url_link( $linktext, $before, $after );
330 * Generates semantic classes for each comment element
334 * @param string|array $class Optional. One or more classes to add to the class list. Default empty.
335 * @param int $comment_id Optional. Comment ID. Default current comment.
336 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
337 * @param bool $echo Optional. Whether comment_class should echo or return. Default true.
339 function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
340 // Separates classes with a single space, collates classes for comment DIV
341 $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
349 * Returns the classes for the comment div as an array
353 * @param string|array $class Optional. One or more classes to add to the class list. Default empty.
354 * @param int $comment_id Optional. Comment ID. Default current comment.
355 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
356 * @return array An array of classes.
358 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
359 global $comment_alt, $comment_depth, $comment_thread_alt;
361 $comment = get_comment($comment_id);
365 // Get the comment type (comment, trackback),
366 $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
368 // If the comment author has an id (registered), then print the log in name
369 if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
370 // For all registered users, 'byuser'
371 $classes[] = 'byuser';
372 $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
373 // For comment authors who are the author of the post
374 if ( $post = get_post($post_id) ) {
375 if ( $comment->user_id === $post->post_author )
376 $classes[] = 'bypostauthor';
380 if ( empty($comment_alt) )
382 if ( empty($comment_depth) )
384 if ( empty($comment_thread_alt) )
385 $comment_thread_alt = 0;
387 if ( $comment_alt % 2 ) {
396 // Alt for top-level comments
397 if ( 1 == $comment_depth ) {
398 if ( $comment_thread_alt % 2 ) {
399 $classes[] = 'thread-odd';
400 $classes[] = 'thread-alt';
402 $classes[] = 'thread-even';
404 $comment_thread_alt++;
407 $classes[] = "depth-$comment_depth";
409 if ( !empty($class) ) {
410 if ( !is_array( $class ) )
411 $class = preg_split('#\s+#', $class);
412 $classes = array_merge($classes, $class);
415 $classes = array_map('esc_attr', $classes);
418 * Filter the returned CSS classes for the current comment.
422 * @param array $classes An array of comment classes.
423 * @param string $class A comma-separated list of additional classes added to the list.
424 * @param int $comment_id The comment id.
425 * @param int|WP_Post $post_id The post ID or WP_Post object.
427 return apply_filters( 'comment_class', $classes, $class, $comment_id, $post_id );
431 * Retrieve the comment date of the current comment.
435 * @param string $d Optional. The format of the date. Default user's setting.
436 * @param int $comment_ID Optional. The ID of the comment for which to get the date. Default current comment.
437 * @return string The comment's date.
439 function get_comment_date( $d = '', $comment_ID = 0 ) {
440 $comment = get_comment( $comment_ID );
442 $date = mysql2date(get_option('date_format'), $comment->comment_date);
444 $date = mysql2date($d, $comment->comment_date);
446 * Filter the returned comment date.
450 * @param string|int $date Formatted date string or Unix timestamp.
451 * @param string $d The format of the date.
453 return apply_filters( 'get_comment_date', $date, $d );
457 * Display the comment date of the current comment.
461 * @param string $d Optional. The format of the date. Default user's settings.
462 * @param int $comment_ID Optional. The ID of the comment for which to print the date. Default current comment.
464 function comment_date( $d = '', $comment_ID = 0 ) {
465 echo get_comment_date( $d, $comment_ID );
469 * Retrieve the excerpt of the current comment.
471 * Will cut each word and only output the first 20 words with '…' at the end.
472 * If the word count is less than 20, then no truncating is done and no '…'
477 * @param int $comment_ID Optional. The ID of the comment for which to get the excerpt. Default current comment.
478 * @return string The maybe truncated comment with 20 words or less.
480 function get_comment_excerpt( $comment_ID = 0 ) {
481 $comment = get_comment( $comment_ID );
482 $comment_text = strip_tags($comment->comment_content);
483 $blah = explode(' ', $comment_text);
484 if (count($blah) > 20) {
492 for ($i=0; $i<$k; $i++) {
493 $excerpt .= $blah[$i] . ' ';
495 $excerpt .= ($use_dotdotdot) ? '…' : '';
496 return apply_filters('get_comment_excerpt', $excerpt);
500 * Display the excerpt of the current comment.
504 * @param int $comment_ID Optional. The ID of the comment for which to print the excerpt. Default current comment.
506 function comment_excerpt( $comment_ID = 0 ) {
507 $comment_excerpt = get_comment_excerpt($comment_ID);
509 * Filter the comment excerpt for display.
513 * @param string $comment_excerpt The comment excerpt text.
515 echo apply_filters( 'comment_excerpt', $comment_excerpt );
519 * Retrieve the comment id of the current comment.
523 * @return int The comment ID.
525 function get_comment_ID() {
528 * Filter the returned comment ID.
532 * @param int $comment->comment_ID The current comment ID.
534 return apply_filters( 'get_comment_ID', $comment->comment_ID );
538 * Display the comment id of the current comment.
542 function comment_ID() {
543 echo get_comment_ID();
547 * Retrieve the link to a given comment.
551 * @param mixed $comment Optional. Comment to retrieve. Default current comment.
552 * @param array $args Optional. An array of arguments to override the defaults. @see get_page_of_comment()
553 * @return string The permalink to the given comment.
555 function get_comment_link( $comment = null, $args = array() ) {
556 global $wp_rewrite, $in_comment_loop;
558 $comment = get_comment($comment);
561 if ( !is_array($args) ) {
564 $args['page'] = $page;
567 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
568 $args = wp_parse_args( $args, $defaults );
570 if ( '' === $args['per_page'] && get_option('page_comments') )
571 $args['per_page'] = get_option('comments_per_page');
573 if ( empty($args['per_page']) ) {
574 $args['per_page'] = 0;
578 if ( $args['per_page'] ) {
579 if ( '' == $args['page'] )
580 $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
582 if ( $wp_rewrite->using_permalinks() )
583 $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
585 $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
587 $link = get_permalink( $comment->comment_post_ID );
590 $link = $link . '#comment-' . $comment->comment_ID;
592 * Filter the returned single comment permalink.
596 * @param string $link The comment permalink with '#comment-$id' appended.
597 * @param object $comment The current comment object.
598 * @param array $args An array of arguments to override the defaults. @see get_page_of_comment()
600 return apply_filters( 'get_comment_link', $link, $comment, $args );
604 * Retrieve the link to the current post comments.
608 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
609 * @return string The link to the comments.
611 function get_comments_link( $post_id = 0 ) {
612 $comments_link = get_permalink( $post_id ) . '#comments';
614 * Filter the returned post comments permalink.
618 * @param string $comments_link The post comments permalink with '#comments' appended.
619 * @param int|WP_Post $post_id The post ID or WP_Post object.
621 return apply_filters( 'get_comments_link', $comments_link, $post_id );
625 * Display the link to the current post comments.
629 * @param string $deprecated Not Used.
630 * @param bool $deprecated_2 Not Used.
632 function comments_link( $deprecated = '', $deprecated_2 = '' ) {
633 if ( !empty( $deprecated ) )
634 _deprecated_argument( __FUNCTION__, '0.72' );
635 if ( !empty( $deprecated_2 ) )
636 _deprecated_argument( __FUNCTION__, '1.3' );
637 echo esc_url( get_comments_link() );
641 * Retrieve the amount of comments a post has.
645 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
646 * @return int The number of comments a post has.
648 function get_comments_number( $post_id = 0 ) {
649 $post_id = absint( $post_id );
652 $post_id = get_the_ID();
654 $post = get_post($post_id);
655 if ( ! isset($post->comment_count) )
658 $count = $post->comment_count;
661 * Filter the returned comment count for a post.
665 * @param int $count The number of comments a post has.
666 * @param int|WP_Post $post_id The post ID or WP_Post object.
668 return apply_filters( 'get_comments_number', $count, $post_id );
672 * Display the language string for the number of comments the current post has.
676 * @param string $zero Optional. Text for no comments. Default false.
677 * @param string $one Optional. Text for one comment. Default false.
678 * @param string $more Optional. Text for more than one comment. Default false.
679 * @param string $deprecated Not used.
681 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
682 if ( !empty( $deprecated ) )
683 _deprecated_argument( __FUNCTION__, '1.3' );
685 $number = get_comments_number();
688 $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
689 elseif ( $number == 0 )
690 $output = ( false === $zero ) ? __('No Comments') : $zero;
692 $output = ( false === $one ) ? __('1 Comment') : $one;
695 * Filter the comments count for display.
699 * @param string $output A translatable string formatted based on whether the count is equal to 0, 1, or 1+. @see _n()
700 * @param int $number The number of post comments.
702 echo apply_filters( 'comments_number', $output, $number );
706 * Retrieve the text of the current comment.
710 * @param int $comment_ID Optional. The ID of the comment for which to get the text. Default current comment.
711 * @param array $args Optional. An array of arguments. @see Walker_Comment::comment()
712 * @return string The comment content.
714 function get_comment_text( $comment_ID = 0, $args = array() ) {
715 $comment = get_comment( $comment_ID );
718 * Filter the text of a comment.
722 * @param string $comment->comment_content The text of the comment.
723 * @param object $comment The comment object.
724 * @param array $args An array of arguments. @see Walker_Comment::comment()
726 return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args );
730 * Display the text of the current comment.
734 * @param int $comment_ID Optional. The ID of the comment for which to print the text.
736 * @param array $args Optional. An array of arguments. @see Walker_Comment::comment()
737 * Default empty array.
739 function comment_text( $comment_ID = 0, $args = array() ) {
740 $comment = get_comment( $comment_ID );
742 $comment_text = get_comment_text( $comment_ID , $args );
744 * Filter the text of a comment to be displayed.
748 * @param string $comment_text The text of the current comment.
749 * @param object $comment The comment object.
750 * @param array $args An array of arguments. @see Walker_Comment::comment()
752 echo apply_filters( 'comment_text', $comment_text, $comment, $args );
756 * Retrieve the comment time of the current comment.
760 * @param string $d Optional. The format of the time. Default user's settings.
761 * @param bool $gmt Optional. Whether to use the GMT date. Default false.
762 * @param bool $translate Optional. Whether to translate the time (for use in feeds). Default true.
763 * @return string The formatted time
765 function get_comment_time( $d = '', $gmt = false, $translate = true ) {
767 $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
769 $date = mysql2date(get_option('time_format'), $comment_date, $translate);
771 $date = mysql2date($d, $comment_date, $translate);
774 * Filter the returned comment time.
778 * @param string|int $date The comment time, formatted as a date string or Unix timestamp.
779 * @param string $d The date format.
780 * @param bool $gmt Whether the GMT date is in use.
781 * @param bool $translate Whether the time is translated.
783 return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate );
787 * Display the comment time of the current comment.
791 * @param string $d Optional. The format of the time. Default user's settings.
793 function comment_time( $d = '' ) {
794 echo get_comment_time($d);
798 * Retrieve the comment type of the current comment.
802 * @param int $comment_ID Optional. The ID of the comment for which to get the type. Default current comment.
803 * @return string The comment type
805 function get_comment_type( $comment_ID = 0 ) {
806 $comment = get_comment( $comment_ID );
807 if ( '' == $comment->comment_type )
808 $comment->comment_type = 'comment';
811 * Filter the returned comment type.
815 * @param string $comment->comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
817 return apply_filters( 'get_comment_type', $comment->comment_type );
821 * Display the comment type of the current comment.
825 * @param string $commenttxt Optional. The string to display for comment type. Default false.
826 * @param string $trackbacktxt Optional. The string to display for trackback type. Default false.
827 * @param string $pingbacktxt Optional. The string to display for pingback type. Default false.
829 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
830 if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
831 if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
832 if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
833 $type = get_comment_type();
847 * Retrieve The current post's trackback URL.
849 * There is a check to see if permalink's have been enabled and if so, will
850 * retrieve the pretty path. If permalinks weren't enabled, the ID of the
851 * current post is used and appended to the correct page to go to.
855 * @return string The trackback URL after being filtered.
857 function get_trackback_url() {
858 if ( '' != get_option('permalink_structure') )
859 $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
861 $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
864 * Filter the returned trackback URL.
868 * @param string $tb_url The trackback URL.
870 return apply_filters( 'trackback_url', $tb_url );
874 * Display the current post's trackback URL.
878 * @param bool $deprecated_echo Not used.
879 * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() for the result instead.
881 function trackback_url( $deprecated_echo = true ) {
882 if ( $deprecated_echo !== true )
883 _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
884 if ( $deprecated_echo )
885 echo get_trackback_url();
887 return get_trackback_url();
891 * Generate and display the RDF for the trackback information of current post.
893 * Deprecated in 3.0.0, and restored in 3.0.1.
897 * @param int $deprecated Not used (Was $timezone = 0).
899 function trackback_rdf( $deprecated = '' ) {
900 if ( !empty( $deprecated ) )
901 _deprecated_argument( __FUNCTION__, '2.5' );
903 if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') )
906 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
907 xmlns:dc="http://purl.org/dc/elements/1.1/"
908 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
909 <rdf:Description rdf:about="';
912 echo ' dc:identifier="';
915 echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n";
916 echo ' trackback:ping="'.get_trackback_url().'"'." />\n";
921 * Whether the current post is open for comments.
925 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
926 * @return bool True if the comments are open.
928 function comments_open( $post_id = null ) {
930 $_post = get_post($post_id);
932 $open = ( 'open' == $_post->comment_status );
935 * Filter whether the current post is open for comments.
939 * @param bool $open Whether the current post is open for comments.
940 * @param int|WP_Post $post_id The post ID or WP_Post object.
942 return apply_filters( 'comments_open', $open, $post_id );
946 * Whether the current post is open for pings.
950 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
951 * @return bool True if pings are accepted
953 function pings_open( $post_id = null ) {
955 $_post = get_post($post_id);
957 $open = ( 'open' == $_post->ping_status );
958 return apply_filters( 'pings_open', $open, $post_id );
962 * Display form token for unfiltered comments.
964 * Will only display nonce token if the current user has permissions for
965 * unfiltered html. Won't display the token for other users.
967 * The function was backported to 2.0.10 and was added to versions 2.1.3 and
968 * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in
969 * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.
971 * Backported to 2.0.10.
975 function wp_comment_form_unfiltered_html_nonce() {
977 $post_id = $post ? $post->ID : 0;
979 if ( current_user_can( 'unfiltered_html' ) ) {
980 wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
981 echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
986 * Load the comment template specified in $file.
988 * Will not display the comments template if not on single post or page, or if
989 * the post does not have comments.
991 * Uses the WordPress database object to query for the comments. The comments
992 * are passed through the 'comments_array' filter hook with the list of comments
993 * and the post ID respectively.
995 * The $file path is passed through a filter hook called, 'comments_template'
996 * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
997 * first and if it fails it will require the default comment template from the
998 * default theme. If either does not exist, then the WordPress process will be
999 * halted. It is advised for that reason, that the default theme is not deleted.
1001 * @todo Document globals
1002 * @uses $withcomments Will not try to get the comments if the post has none.
1006 * @param string $file Optional. The file to load. Default '/comments.php'.
1007 * @param bool $separate_comments Optional. Whether to separate the comments by comment type. Default false.
1008 * @return null Returns null if no comments appear.
1010 function comments_template( $file = '/comments.php', $separate_comments = false ) {
1011 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
1013 if ( !(is_single() || is_page() || $withcomments) || empty($post) )
1017 $file = '/comments.php';
1019 $req = get_option('require_name_email');
1022 * Comment author information fetched from the comment cookies.
1024 * @uses wp_get_current_commenter()
1026 $commenter = wp_get_current_commenter();
1029 * The name of the current comment author escaped for use in attributes.
1031 $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies()
1034 * The email address of the current comment author escaped for use in attributes.
1036 $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies()
1039 * The url of the current comment author escaped for use in attributes.
1041 $comment_author_url = esc_url($commenter['comment_author_url']);
1043 /** @todo Use API instead of SELECTs. */
1045 $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));
1046 } else if ( empty($comment_author) ) {
1047 $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
1049 $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));
1052 // keep $comments for legacy's sake
1054 * Filter the comments array.
1058 * @param array $comments The array of comments supplied to the comments template.
1059 * @param int $post->ID The post ID.
1061 $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
1062 $comments = &$wp_query->comments;
1063 $wp_query->comment_count = count($wp_query->comments);
1064 update_comment_cache($wp_query->comments);
1066 if ( $separate_comments ) {
1067 $wp_query->comments_by_type = separate_comments($comments);
1068 $comments_by_type = &$wp_query->comments_by_type;
1071 $overridden_cpage = false;
1072 if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
1073 set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
1074 $overridden_cpage = true;
1077 if ( !defined('COMMENTS_TEMPLATE') )
1078 define('COMMENTS_TEMPLATE', true);
1080 $theme_template = STYLESHEETPATH . $file;
1082 * Filter the path to the theme template file used for the comments template.
1086 * @param string $theme_template The path to the theme template file.
1088 $include = apply_filters( 'comments_template', $theme_template );
1089 if ( file_exists( $include ) )
1090 require( $include );
1091 elseif ( file_exists( TEMPLATEPATH . $file ) )
1092 require( TEMPLATEPATH . $file );
1093 else // Backward compat code will be removed in a future release
1094 require( ABSPATH . WPINC . '/theme-compat/comments.php');
1098 * Display the JS popup script to show a comment.
1100 * If the $file parameter is empty, then the home page is assumed. The defaults
1101 * for the window are 400px by 400px.
1103 * For the comment link popup to work, this function has to be called or the
1104 * normal comment link will be assumed.
1106 * @global string $wpcommentspopupfile The URL to use for the popup window.
1107 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
1111 * @param int $width Optional. The width of the popup window. Default 400.
1112 * @param int $height Optional. The height of the popup window. Default 400.
1113 * @param string $file Optional. Sets the location of the popup window.
1115 function comments_popup_script( $width = 400, $height = 400, $file = '' ) {
1116 global $wpcommentspopupfile, $wpcommentsjavascript;
1118 if (empty ($file)) {
1119 $wpcommentspopupfile = ''; // Use the index.
1121 $wpcommentspopupfile = $file;
1124 $wpcommentsjavascript = 1;
1125 $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";
1130 * Displays the link to the comments popup window for the current post ID.
1132 * Is not meant to be displayed on single posts and pages. Should be used on the
1135 * @global string $wpcommentspopupfile The URL to use for the popup window.
1136 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
1140 * @param string $zero Optional. The string to display when no comments. Default false.
1141 * @param string $one Optional. The string to display when only one comment is available. Default false.
1142 * @param string $more Optional. The string to display when there are more than one comment. Default false.
1143 * @param string $css_class Optional. The CSS class to use for comments. Default empty.
1144 * @param string $none Optional. The string to display when comments have been turned off. Default false.
1145 * @return null Returns null on single posts and pages.
1147 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
1148 global $wpcommentspopupfile, $wpcommentsjavascript;
1152 if ( false === $zero ) $zero = __( 'No Comments' );
1153 if ( false === $one ) $one = __( '1 Comment' );
1154 if ( false === $more ) $more = __( '% Comments' );
1155 if ( false === $none ) $none = __( 'Comments Off' );
1157 $number = get_comments_number( $id );
1159 if ( 0 == $number && !comments_open() && !pings_open() ) {
1160 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
1164 if ( post_password_required() ) {
1165 echo __('Enter your password to view comments.');
1170 if ( $wpcommentsjavascript ) {
1171 if ( empty( $wpcommentspopupfile ) )
1174 $home = get_option('siteurl');
1175 echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
1176 echo '" onclick="wpopen(this.href); return false"';
1177 } else { // if comments_popup_script() is not in the template, display simple comment link
1179 echo get_permalink() . '#respond';
1185 if ( !empty( $css_class ) ) {
1186 echo ' class="'.$css_class.'" ';
1188 $title = the_title_attribute( array('echo' => 0 ) );
1192 * Filter the comments popup link attributes for display.
1196 * @param string $attributes The comments popup link attributes. Default empty.
1198 echo apply_filters( 'comments_popup_link_attributes', $attributes );
1200 echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
1201 comments_number( $zero, $one, $more );
1206 * Retrieve HTML content for reply to comment link.
1210 * @param array $args {
1211 * Optional. Override default arguments.
1213 * @type string 'add_below' The first part of the selector used to identify the comment to respond below. The resulting
1214 * value is passed as the first parameter to addComment.moveForm(), concatenated
1215 * as $add_below-$comment->comment_ID. Default 'comment'.
1216 * @type string 'respond_id' The selector identifying the responding comment. Passed as the third parameter to addComment.moveForm(),
1217 * and appended to the link URL as a hash value. Default 'respond'.
1218 * @type string 'reply_text' The text of the Reply link. Default 'Reply'.
1219 * @type string 'login_text' The text of the link to reply if logged out. Default 'Log in to Reply'.
1220 * @type int 'depth' The depth of the new comment. Must be greater than 0 and less than the value of the 'thread_comments_depth'
1221 * option set in Settings > Discussion.
1223 * @type string 'before' The text or HTML to add before the reply link. Default empty.
1224 * @type string 'after' The text or HTML to add after the reply link. Default empty.
1226 * @param int $comment Optional. Comment being replied to. Default current comment.
1227 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
1228 * @return mixed Link to show comment form, if successful. False, if comments are closed.
1230 function get_comment_reply_link($args = array(), $comment = null, $post = null) {
1233 'add_below' => 'comment',
1234 'respond_id' => 'respond',
1235 'reply_text' => __('Reply'),
1236 'login_text' => __('Log in to Reply'),
1242 $args = wp_parse_args($args, $defaults);
1244 if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
1247 extract($args, EXTR_SKIP);
1249 $comment = get_comment($comment);
1251 $post = $comment->comment_post_ID;
1252 $post = get_post($post);
1254 if ( !comments_open($post->ID) )
1259 if ( get_option('comment_registration') && ! is_user_logged_in() )
1260 $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
1262 $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>";
1265 * Filter the comment reply link.
1269 * @param string $before Text or HTML displayed before the reply link.
1270 * @param string $link The HTML markup for the comment reply link.
1271 * @param string $after Text or HTML displayed after the reply link.
1272 * @param array $args An array of arguments overriding the defaults.
1273 * @param object $comment The object of the comment being replied.
1274 * @param WP_Post $post The WP_Post object.
1276 return apply_filters( 'comment_reply_link', $before . $link . $after, $args, $comment, $post );
1280 * Displays the HTML content for reply to comment link.
1284 * @param array $args Optional. Override default options, @see get_comment_reply_link()
1285 * @param int $comment Optional. Comment being replied to. Default current comment.
1286 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
1287 * @return mixed Link to show comment form, if successful. False, if comments are closed.
1289 function comment_reply_link($args = array(), $comment = null, $post = null) {
1290 echo get_comment_reply_link($args, $comment, $post);
1294 * Retrieve HTML content for reply to post link.
1298 * @param array $args {
1299 * Optional. Override default arguments.
1301 * @type string 'add_below' The first part of the selector used to identify the comment to respond below.
1302 * The resulting value is passed as the first parameter to addComment.moveForm(),
1303 * concatenated as $add_below-$comment->comment_ID. Default is 'post'.
1304 * @type string 'respond_id' The selector identifying the responding comment. Passed as the third parameter
1305 * to addComment.moveForm(), and appended to the link URL as a hash value. Default is 'respond'.
1306 * @type string 'reply_text' The text of the Reply link. Default is 'Leave a Comment'.
1307 * @type string 'login_text' The text of the link to reply if logged out. Default is 'Log in to leave a Comment'.
1308 * @type string 'before' The text or HTML to add before the reply link. Default empty.
1309 * @type string 'after' The text or HTML to add after the reply link. Default empty.
1311 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
1312 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1314 function get_post_reply_link($args = array(), $post = null) {
1316 'add_below' => 'post',
1317 'respond_id' => 'respond',
1318 'reply_text' => __('Leave a Comment'),
1319 'login_text' => __('Log in to leave a Comment'),
1324 $args = wp_parse_args($args, $defaults);
1325 extract($args, EXTR_SKIP);
1326 $post = get_post($post);
1328 if ( !comments_open($post->ID) )
1331 if ( get_option('comment_registration') && ! is_user_logged_in() )
1332 $link = '<a rel="nofollow" href="' . wp_login_url( get_permalink() ) . '">' . $login_text . '</a>';
1334 $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>";
1336 $formatted_link = $before . $link . $after;
1338 * Filter the formatted post comments link HTML.
1342 * @param string $formatted The HTML-formatted post comments link.
1343 * @param int|WP_Post $post The post ID or WP_Post object.
1345 return apply_filters( 'post_comments_link', $formatted_link, $post );
1349 * Displays the HTML content for reply to post link.
1353 * @param array $args Optional. Override default options, @see get_post_reply_link()
1354 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
1355 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1357 function post_reply_link($args = array(), $post = null) {
1358 echo get_post_reply_link($args, $post);
1362 * Retrieve HTML content for cancel comment reply link.
1366 * @param string $text Optional. Text to display for cancel reply link. Default empty.
1368 function get_cancel_comment_reply_link( $text = '' ) {
1370 $text = __('Click here to cancel reply.');
1372 $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
1373 $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
1375 $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
1377 * Filter the cancel comment reply link HTML.
1381 * @param string $formatted_link The HTML-formatted cancel comment reply link.
1382 * @param string $link The cancel comment reply link URL.
1383 * @param string $text The cancel comment reply link text.
1385 return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
1389 * Display HTML content for cancel comment reply link.
1393 * @param string $text Optional. Text to display for cancel reply link. Default empty.
1395 function cancel_comment_reply_link( $text = '' ) {
1396 echo get_cancel_comment_reply_link($text);
1400 * Retrieve hidden input HTML for replying to comments.
1404 * @param int $id Optional. Post ID. Default current post ID.
1405 * @return string Hidden input HTML for replying to comments
1407 function get_comment_id_fields( $id = 0 ) {
1411 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1412 $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
1413 $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
1416 * Filter the returned comment id fields.
1420 * @param string $result The HTML-formatted hidden id field comment elements.
1421 * @param int $id The post ID.
1422 * @param int $replytoid The id of the comment being replied to.
1424 return apply_filters( 'comment_id_fields', $result, $id, $replytoid );
1428 * Output hidden input HTML for replying to comments.
1432 * @param int $id Optional. Post ID. Default current post ID.
1434 function comment_id_fields( $id = 0 ) {
1435 echo get_comment_id_fields( $id );
1439 * Display text based on comment reply status.
1441 * Only affects users with Javascript disabled.
1445 * @param string $noreplytext Optional. Text to display when not replying to a comment. Default false.
1446 * @param string $replytext Optional. Text to display when replying to a comment.
1447 * Default false. Accepts "%s" for the author of the comment being replied to.
1448 * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment. Default true.
1450 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {
1453 if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
1454 if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
1456 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1458 if ( 0 == $replytoid )
1461 $comment = get_comment($replytoid);
1462 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
1463 printf( $replytext, $author );
1468 * HTML comment list class.
1470 * @package WordPress
1474 class Walker_Comment extends Walker {
1476 * What the class handles.
1478 * @see Walker::$tree_type
1483 var $tree_type = 'comment';
1488 * @see Walker::$db_fields
1493 var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
1496 * Start the list before the elements are added.
1498 * @see Walker::start_lvl()
1502 * @param string $output Passed by reference. Used to append additional content.
1503 * @param int $depth Depth of comment.
1504 * @param array $args Uses 'style' argument for type of HTML list.
1506 function start_lvl( &$output, $depth = 0, $args = array() ) {
1507 $GLOBALS['comment_depth'] = $depth + 1;
1509 switch ( $args['style'] ) {
1513 echo '<ol class="children">' . "\n";
1517 echo '<ul class="children">' . "\n";
1523 * End the list of items after the elements are added.
1525 * @see Walker::end_lvl()
1529 * @param string $output Passed by reference. Used to append additional content.
1530 * @param int $depth Depth of comment.
1531 * @param array $args Will only append content if style argument value is 'ol' or 'ul'.
1533 function end_lvl( &$output, $depth = 0, $args = array() ) {
1534 $GLOBALS['comment_depth'] = $depth + 1;
1536 switch ( $args['style'] ) {
1540 echo "</ol><!-- .children -->\n";
1544 echo "</ul><!-- .children -->\n";
1550 * Traverse elements to create list from elements.
1552 * This function is designed to enhance Walker::display_element() to
1553 * display children of higher nesting levels than selected inline on
1554 * the highest depth level displayed. This prevents them being orphaned
1555 * at the end of the comment list.
1557 * Example: max_depth = 2, with 5 levels of nested content.
1568 * @see Walker::display_element()
1572 * @param object $element Data object.
1573 * @param array $children_elements List of elements to continue traversing.
1574 * @param int $max_depth Max depth to traverse.
1575 * @param int $depth Depth of current element.
1576 * @param array $args An array of arguments. @see wp_list_comments()
1577 * @param string $output Passed by reference. Used to append additional content.
1578 * @return null Null on failure with no changes to parameters.
1580 function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
1585 $id_field = $this->db_fields['id'];
1586 $id = $element->$id_field;
1588 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
1590 // If we're at the max depth, and the current element still has children, loop over those and display them at this level
1591 // This is to prevent them being orphaned to the end of the list.
1592 if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
1593 foreach ( $children_elements[ $id ] as $child )
1594 $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
1596 unset( $children_elements[ $id ] );
1602 * Start the element output.
1604 * @see Walker::start_el()
1608 * @param string $output Passed by reference. Used to append additional content.
1609 * @param object $comment Comment data object.
1610 * @param int $depth Depth of comment in reference to parents.
1611 * @param array $args An array of arguments. @see wp_list_comments()
1613 function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
1615 $GLOBALS['comment_depth'] = $depth;
1616 $GLOBALS['comment'] = $comment;
1618 if ( !empty( $args['callback'] ) ) {
1619 call_user_func( $args['callback'], $comment, $args, $depth );
1623 if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
1624 $this->ping( $comment, $depth, $args );
1625 } elseif ( 'html5' === $args['format'] ) {
1626 $this->html5_comment( $comment, $depth, $args );
1628 $this->comment( $comment, $depth, $args );
1633 * Ends the element output, if needed.
1635 * @see Walker::end_el()
1639 * @param string $output Passed by reference. Used to append additional content.
1640 * @param object $comment The comment object. Default current comment.
1641 * @param int $depth Depth of comment.
1642 * @param array $args An array of arguments. @see wp_list_comments()
1644 function end_el( &$output, $comment, $depth = 0, $args = array() ) {
1645 if ( !empty( $args['end-callback'] ) ) {
1646 call_user_func( $args['end-callback'], $comment, $args, $depth );
1649 if ( 'div' == $args['style'] )
1650 echo "</div><!-- #comment-## -->\n";
1652 echo "</li><!-- #comment-## -->\n";
1656 * Output a pingback comment.
1661 * @param object $comment The comment object.
1662 * @param int $depth Depth of comment.
1663 * @param array $args An array of arguments. @see wp_list_comments()
1665 protected function ping( $comment, $depth, $args ) {
1666 $tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
1668 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
1669 <div class="comment-body">
1670 <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
1676 * Output a single comment.
1681 * @param object $comment Comment to display.
1682 * @param int $depth Depth of comment.
1683 * @param array $args An array of arguments. @see wp_list_comments()
1685 protected function comment( $comment, $depth, $args ) {
1686 if ( 'div' == $args['style'] ) {
1688 $add_below = 'comment';
1691 $add_below = 'div-comment';
1694 <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">
1695 <?php if ( 'div' != $args['style'] ) : ?>
1696 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
1698 <div class="comment-author vcard">
1699 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
1700 <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
1702 <?php if ( '0' == $comment->comment_approved ) : ?>
1703 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>
1707 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
1709 /* translators: 1: date, 2: time */
1710 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
1714 <?php comment_text( get_comment_id(), array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1717 <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1719 <?php if ( 'div' != $args['style'] ) : ?>
1726 * Output a comment in the HTML5 format.
1731 * @param object $comment Comment to display.
1732 * @param int $depth Depth of comment.
1733 * @param array $args An array of arguments. @see wp_list_comments()
1735 protected function html5_comment( $comment, $depth, $args ) {
1736 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
1738 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
1739 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
1740 <footer class="comment-meta">
1741 <div class="comment-author vcard">
1742 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
1743 <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?>
1744 </div><!-- .comment-author -->
1746 <div class="comment-metadata">
1747 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
1748 <time datetime="<?php comment_time( 'c' ); ?>">
1749 <?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), get_comment_time() ); ?>
1752 <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
1753 </div><!-- .comment-metadata -->
1755 <?php if ( '0' == $comment->comment_approved ) : ?>
1756 <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
1758 </footer><!-- .comment-meta -->
1760 <div class="comment-content">
1761 <?php comment_text(); ?>
1762 </div><!-- .comment-content -->
1765 <?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1766 </div><!-- .reply -->
1767 </article><!-- .comment-body -->
1775 * Used in the comments.php template to list comments for a particular post.
1779 * @param string|array $args {
1780 * Optional. Formatting options.
1782 * @type string 'walker' The Walker class used to list comments. Default null.
1783 * @type int 'max_depth' The maximum comments depth. Default empty.
1784 * @type string 'style' The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
1785 * @type string 'callback' Callback function to use. Default null.
1786 * @type string 'end-callback' Callback function to use at the end. Default null.
1787 * @type string 'type' Type of comments to list.
1788 * Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
1789 * @type int 'page' Page ID to list comments for. Default empty.
1790 * @type int 'per_page' Number of comments to list per page. Default empty.
1791 * @type int 'avatar_size' Height and width dimensions of the avatar size. Default 32.
1792 * @type string 'reverse_top_level' Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
1793 * @type bool 'reverse_children' Whether to reverse child comments in the list. Default null.
1794 * @type string 'format' How to format the comments list.
1795 * Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
1796 * @type bool 'short_ping' Whether to output short pings. Default false.
1798 * @param array $comments Optional. Array of comment objects. @see WP_Query->comments
1800 function wp_list_comments( $args = array(), $comments = null ) {
1801 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
1803 $in_comment_loop = true;
1805 $comment_alt = $comment_thread_alt = 0;
1813 'end-callback' => null,
1817 'avatar_size' => 32,
1818 'reverse_top_level' => null,
1819 'reverse_children' => '',
1820 'format' => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
1821 'short_ping' => false,
1824 $r = wp_parse_args( $args, $defaults );
1826 // Figure out what comments we'll be looping through ($_comments)
1827 if ( null !== $comments ) {
1828 $comments = (array) $comments;
1829 if ( empty($comments) )
1831 if ( 'all' != $r['type'] ) {
1832 $comments_by_type = separate_comments($comments);
1833 if ( empty($comments_by_type[$r['type']]) )
1835 $_comments = $comments_by_type[$r['type']];
1837 $_comments = $comments;
1840 if ( empty($wp_query->comments) )
1842 if ( 'all' != $r['type'] ) {
1843 if ( empty($wp_query->comments_by_type) )
1844 $wp_query->comments_by_type = separate_comments($wp_query->comments);
1845 if ( empty($wp_query->comments_by_type[$r['type']]) )
1847 $_comments = $wp_query->comments_by_type[$r['type']];
1849 $_comments = $wp_query->comments;
1853 if ( '' === $r['per_page'] && get_option('page_comments') )
1854 $r['per_page'] = get_query_var('comments_per_page');
1856 if ( empty($r['per_page']) ) {
1861 if ( '' === $r['max_depth'] ) {
1862 if ( get_option('thread_comments') )
1863 $r['max_depth'] = get_option('thread_comments_depth');
1865 $r['max_depth'] = -1;
1868 if ( '' === $r['page'] ) {
1869 if ( empty($overridden_cpage) ) {
1870 $r['page'] = get_query_var('cpage');
1872 $threaded = ( -1 != $r['max_depth'] );
1873 $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
1874 set_query_var( 'cpage', $r['page'] );
1878 $r['page'] = intval($r['page']);
1879 if ( 0 == $r['page'] && 0 != $r['per_page'] )
1882 if ( null === $r['reverse_top_level'] )
1883 $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
1885 extract( $r, EXTR_SKIP );
1887 if ( empty($walker) )
1888 $walker = new Walker_Comment;
1890 $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
1891 $wp_query->max_num_comment_pages = $walker->max_pages;
1893 $in_comment_loop = false;
1897 * Output a complete commenting form for use within a template.
1899 * Most strings and form fields may be controlled through the $args array passed
1900 * into the function, while you may also choose to use the comment_form_default_fields
1901 * filter to modify the array of default fields if you'd just like to add a new
1902 * one or remove a single field. All fields are also individually passed through
1903 * a filter of the form comment_form_field_$name where $name is the key used
1904 * in the array of fields.
1908 * @param array $args {
1909 * Optional. Default arguments and form fields to override.
1911 * @type array 'fields' {
1912 * Default comment fields, filterable by default via the 'comment_form_default_fields' hook.
1914 * @type string 'author' The comment author field HTML.
1915 * @type string 'email' The comment author email field HTML.
1916 * @type string 'url' The comment author URL field HTML.
1918 * @type string 'comment_field' The comment textarea field HTML.
1919 * @type string 'must_log_in' HTML element for a 'must be logged in to comment' message.
1920 * @type string 'logged_in_as' HTML element for a 'logged in as <user>' message.
1921 * @type string 'comment_notes_before' HTML element for a message displayed before the comment form.
1922 * Default 'Your email address will not be published.'.
1923 * @type string 'comment_notes_after' HTML element for a message displayed after the comment form.
1924 * Default 'You may use these HTML tags and attributes ...'.
1925 * @type string 'id_form' The comment form element id attribute. Default 'commentform'.
1926 * @type string 'id_submit' The comment submit element id attribute. Default 'submit'.
1927 * @type string 'title_reply' The translatable 'reply' button label. Default 'Leave a Reply'.
1928 * @type string 'title_reply_to' The translatable 'reply-to' button label. Default 'Leave a Reply to %s',
1929 * where %s is the author of the comment being replied to.
1930 * @type string 'cancel_reply_link' The translatable 'cancel reply' button label. Default 'Cancel reply'.
1931 * @type string 'label_submit' The translatable 'submit' button label. Default 'Post a comment'.
1932 * @type string 'format' The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
1934 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object to generate the form for. Default current post.
1936 function comment_form( $args = array(), $post_id = null ) {
1937 if ( null === $post_id )
1938 $post_id = get_the_ID();
1942 $commenter = wp_get_current_commenter();
1943 $user = wp_get_current_user();
1944 $user_identity = $user->exists() ? $user->display_name : '';
1946 $args = wp_parse_args( $args );
1947 if ( ! isset( $args['format'] ) )
1948 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
1950 $req = get_option( 'require_name_email' );
1951 $aria_req = ( $req ? " aria-required='true'" : '' );
1952 $html5 = 'html5' === $args['format'];
1954 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
1955 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
1956 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
1957 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
1958 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
1959 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
1962 $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
1965 * Filter the default comment form fields.
1969 * @param array $fields The default comment fields.
1971 $fields = apply_filters( 'comment_form_default_fields', $fields );
1973 'fields' => $fields,
1974 '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>',
1975 '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>',
1976 '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>',
1977 'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
1978 '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>',
1979 'id_form' => 'commentform',
1980 'id_submit' => 'submit',
1981 'title_reply' => __( 'Leave a Reply' ),
1982 'title_reply_to' => __( 'Leave a Reply to %s' ),
1983 'cancel_reply_link' => __( 'Cancel reply' ),
1984 'label_submit' => __( 'Post Comment' ),
1985 'format' => 'xhtml',
1989 * Filter the comment form default arguments.
1991 * Use 'comment_form_default_fields' to filter the comment fields.
1995 * @param array $defaults The default comment form arguments.
1997 $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
2000 <?php if ( comments_open( $post_id ) ) : ?>
2003 * Fires before the comment form.
2007 do_action( 'comment_form_before' );
2009 <div id="respond" class="comment-respond">
2010 <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>
2011 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
2012 <?php echo $args['must_log_in']; ?>
2015 * Fires after the HTML-formatted 'must log in after' message in the comment form.
2019 do_action( 'comment_form_must_log_in_after' );
2022 <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' : ''; ?>>
2025 * Fires at the top of the comment form, inside the <form> tag.
2029 do_action( 'comment_form_top' );
2031 <?php if ( is_user_logged_in() ) : ?>
2034 * Filter the 'logged in' message for the comment form for display.
2038 * @param string $args['logged_in_as'] The logged-in-as HTML-formatted message.
2039 * @param array $commenter An array containing the comment author's username, email, and URL.
2040 * @param string $user_identity If the commenter is a registered user, the display name, blank otherwise.
2042 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
2046 * Fires after the is_user_logged_in() check in the comment form.
2050 * @param array $commenter An array containing the comment author's username, email, and URL.
2051 * @param string $user_identity If the commenter is a registered user, the display name, blank otherwise.
2053 do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
2056 <?php echo $args['comment_notes_before']; ?>
2059 * Fires before the comment fields in the comment form.
2063 do_action( 'comment_form_before_fields' );
2064 foreach ( (array) $args['fields'] as $name => $field ) {
2066 * Filter a comment form field for display.
2068 * The dynamic portion of the filter hook, $name, refers to the name
2069 * of the comment form field. Such as 'author', 'email', or 'url'.
2073 * @param string $field The HTML-formatted output of the comment form field.
2075 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
2078 * Fires after the comment fields in the comment form.
2082 do_action( 'comment_form_after_fields' );
2087 * Filter the content of the comment textarea field for display.
2091 * @param string $args['comment_field'] The content of the comment textarea field.
2093 echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );
2095 <?php echo $args['comment_notes_after']; ?>
2096 <p class="form-submit">
2097 <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
2098 <?php comment_id_fields( $post_id ); ?>
2102 * Fires at the bottom of the comment form, inside the closing </form> tag.
2106 * @param int $post_id The post ID.
2108 do_action( 'comment_form', $post_id );
2112 </div><!-- #respond -->
2115 * Fires after the comment form.
2119 do_action( 'comment_form_after' );
2122 * Fires after the comment form if comments are closed.
2126 do_action( 'comment_form_comments_closed' );