]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/comment-template.php
WordPress 3.8.1
[autoinstalls/wordpress.git] / wp-includes / comment-template.php
1 <?php
2 /**
3  * Comment template functions
4  *
5  * These functions are meant to live inside of the WordPress loop.
6  *
7  * @package WordPress
8  * @subpackage Template
9  */
10
11 /**
12  * Retrieve the author of the current comment.
13  *
14  * If the comment has an empty comment_author field, then 'Anonymous' person is
15  * assumed.
16  *
17  * @since 1.5.0
18  *
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
21  */
22 function get_comment_author( $comment_ID = 0 ) {
23         $comment = get_comment( $comment_ID );
24
25         if ( empty( $comment->comment_author ) ) {
26                 if ( $comment->user_id && $user = get_userdata( $comment->user_id ) )
27                         $author = $user->display_name;
28                 else
29                         $author = __('Anonymous');
30         } else {
31                 $author = $comment->comment_author;
32         }
33
34         /**
35          * Filter the returned comment author name.
36          *
37          * @since 1.5.0
38          *
39          * @param string $author The comment author's username.
40          */
41         return apply_filters( 'get_comment_author', $author );
42 }
43
44 /**
45  * Displays the author of the current comment.
46  *
47  * @since 0.71
48  *
49  * @param int $comment_ID Optional. The ID of the comment for which to print the author. Default current comment.
50  */
51 function comment_author( $comment_ID = 0 ) {
52         $author = get_comment_author( $comment_ID );
53         /**
54          * Filter the comment author's name for display.
55          *
56          * @since 1.2.0
57          *
58          * @param string $author The comment author's username.
59          */
60         $author = apply_filters( 'comment_author', $author );
61         echo $author;
62 }
63
64 /**
65  * Retrieve the email of the author of the current comment.
66  *
67  * @since 1.5.0
68  *
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
71  */
72 function get_comment_author_email( $comment_ID = 0 ) {
73         $comment = get_comment( $comment_ID );
74         /**
75          * Filter the comment author's returned email address.
76          *
77          * @since 1.5.0
78          *
79          * @param string $comment->comment_author_email The comment author's email address.
80          */
81         return apply_filters( 'get_comment_author_email', $comment->comment_author_email );
82 }
83
84 /**
85  * Display the email of the author of the current global $comment.
86  *
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.
92  *
93  * @since 0.71
94  *
95  * @param int $comment_ID Optional. The ID of the comment for which to print the author's email. Default current comment.
96  */
97 function comment_author_email( $comment_ID = 0 ) {
98         $author_email = get_comment_author_email( $comment_ID );
99         /**
100          * Filter the comment author's email for display.
101          *
102          * @since 1.2.0
103          *
104          * @param string $author_email The comment author's email address.
105          */
106         echo apply_filters( 'author_email', $author_email );
107 }
108
109 /**
110  * Display the html email link to the author of the current comment.
111  *
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.
117  *
118  * @global object $comment The current Comment row object
119
120  * @since 0.71
121  *
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.
125  */
126 function comment_author_email_link( $linktext = '', $before = '', $after = '' ) {
127         if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )
128                 echo $link;
129 }
130
131 /**
132  * Return the html email link to the author of the current comment.
133  *
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.
139  *
140  * @global object $comment The current Comment row object.
141  *
142  * @since 2.7
143  *
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.
147  */
148 function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) {
149         global $comment;
150         /**
151          * Filter the comment author's email for display.
152          *
153          * Care should be taken to protect the email address and assure that email
154          * harvesters do not capture your commentors' email address.
155          *
156          * @since 1.2.0
157          *
158          * @param string $comment->comment_author_email The comment author's email address.
159          */
160         $email = apply_filters( 'comment_email', $comment->comment_author_email );
161         if ((!empty($email)) && ($email != '@')) {
162         $display = ($linktext != '') ? $linktext : $email;
163                 $return  = $before;
164                 $return .= "<a href='mailto:$email'>$display</a>";
165                 $return .= $after;
166                 return $return;
167         } else {
168                 return '';
169         }
170 }
171
172 /**
173  * Retrieve the HTML link to the URL of the author of the current comment.
174  *
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.
177  *
178  * @since 1.5.0
179  *
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.
182  */
183 function get_comment_author_link( $comment_ID = 0 ) {
184         $url    = get_comment_author_url( $comment_ID );
185         $author = get_comment_author( $comment_ID );
186
187         if ( empty( $url ) || 'http://' == $url )
188                 $return = $author;
189         else
190                 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
191
192         /**
193          * Filter the comment author's link for display.
194          *
195          * @since 1.5.0
196          *
197          * @param string $return The HTML-formatted comment author link. Empty for an invalid URL.
198          */
199         return apply_filters( 'get_comment_author_link', $return );
200 }
201
202 /**
203  * Display the html link to the url of the author of the current comment.
204  *
205  * @since 0.71
206  * @see get_comment_author_link() Echoes result
207  *
208  * @param int $comment_ID Optional. The ID of the comment for which to print the author's link. Default current comment.
209  */
210 function comment_author_link( $comment_ID = 0 ) {
211         echo get_comment_author_link( $comment_ID );
212 }
213
214 /**
215  * Retrieve the IP address of the author of the current comment.
216  *
217  * @since 1.5.0
218  *
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.
221  */
222 function get_comment_author_IP( $comment_ID = 0 ) {
223         $comment = get_comment( $comment_ID );
224
225         /**
226          * Filter the comment author's returned IP address.
227          *
228          * @since 1.5.0
229          *
230          * @param string $comment->comment_author_IP The comment author's IP address.
231          */
232         return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP );
233 }
234
235 /**
236  * Display the IP address of the author of the current comment.
237  *
238  * @since 0.71
239  *
240  * @param int $comment_ID Optional. The ID of the comment for which to print the author's IP address. Default current comment.
241  */
242 function comment_author_IP( $comment_ID = 0 ) {
243         echo get_comment_author_IP( $comment_ID );
244 }
245
246 /**
247  * Retrieve the url of the author of the current comment.
248  *
249  * @since 1.5.0
250  *
251  * @param int $comment_ID Optional. The ID of the comment for which to get the author's URL. Default current comment.
252  * @return string
253  */
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         /**
259          * Filter the comment author's URL.
260          *
261          * @since 1.5.0
262          *
263          * @param string $url The comment author's URL.
264          */
265         return apply_filters( 'get_comment_author_url', $url );
266 }
267
268 /**
269  * Display the url of the author of the current comment.
270  *
271  * @since 0.71
272  *
273  * @param int $comment_ID Optional. The ID of the comment for which to print the author's URL. Default current comment.
274  */
275 function comment_author_url( $comment_ID = 0 ) {
276         $author_url = get_comment_author_url( $comment_ID );
277         /**
278          * Filter the comment author's URL for display.
279          *
280          * @since 1.2.0
281          *
282          * @param string $author_url The comment author's URL.
283          */
284         echo apply_filters( 'comment_url', $author_url );
285 }
286
287 /**
288  * Retrieves the HTML link of the url of the author of the current comment.
289  *
290  * $linktext parameter is only used if the URL does not exist for the comment
291  * author. If the URL does exist then the URL will be used and the $linktext
292  * will be ignored.
293  *
294  * Encapsulate the HTML link between the $before and $after. So it will appear
295  * in the order of $before, link, and finally $after.
296  *
297  * @since 1.5.0
298  *
299  * @param string $linktext Optional. The text to display instead of the comment author's email address. Default empty.
300  * @param string $before   Optional. The text or HTML to display before the email link. Default empty.
301  * @param string $after    Optional. The text or HTML to display after the email link. Default empty.
302  * @return string The HTML link between the $before and $after parameters.
303  */
304 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
305         $url = get_comment_author_url();
306         $display = ($linktext != '') ? $linktext : $url;
307         $display = str_replace( 'http://www.', '', $display );
308         $display = str_replace( 'http://', '', $display );
309         if ( '/' == substr($display, -1) )
310                 $display = substr($display, 0, -1);
311         $return = "$before<a href='$url' rel='external'>$display</a>$after";
312
313         /**
314          * Filter the comment author's returned URL link.
315          *
316          * @since 1.5.0
317          *
318          * @param string $return The HTML-formatted comment author URL link.
319          */
320         return apply_filters( 'get_comment_author_url_link', $return );
321 }
322
323 /**
324  * Displays the HTML link of the url of the author of the current comment.
325  *
326  * @since 0.71
327  *
328  * @param string $linktext Optional. The text to display instead of the comment author's email address. Default empty.
329  * @param string $before   Optional. The text or HTML to display before the email link. Default empty.
330  * @param string $after    Optional. The text or HTML to display after the email link. Default empty.
331  */
332 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
333         echo get_comment_author_url_link( $linktext, $before, $after );
334 }
335
336 /**
337  * Generates semantic classes for each comment element
338  *
339  * @since 2.7.0
340  *
341  * @param string|array $class      Optional. One or more classes to add to the class list. Default empty.
342  * @param int          $comment_id Optional. Comment ID. Default current comment.
343  * @param int|WP_Post  $post_id    Optional. Post ID or WP_Post object. Default current post.
344  * @param bool         $echo       Optional. Whether comment_class should echo or return. Default true.
345  */
346 function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
347         // Separates classes with a single space, collates classes for comment DIV
348         $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
349         if ( $echo)
350                 echo $class;
351         else
352                 return $class;
353 }
354
355 /**
356  * Returns the classes for the comment div as an array
357  *
358  * @since 2.7.0
359  *
360  * @param string|array $class      Optional. One or more classes to add to the class list. Default empty.
361  * @param int          $comment_id Optional. Comment ID. Default current comment.
362  * @param int|WP_Post  $post_id    Optional. Post ID or WP_Post object. Default current post.
363  * @return array An array of classes.
364  */
365 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
366         global $comment_alt, $comment_depth, $comment_thread_alt;
367
368         $comment = get_comment($comment_id);
369
370         $classes = array();
371
372         // Get the comment type (comment, trackback),
373         $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
374
375         // If the comment author has an id (registered), then print the log in name
376         if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
377                 // For all registered users, 'byuser'
378                 $classes[] = 'byuser';
379                 $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
380                 // For comment authors who are the author of the post
381                 if ( $post = get_post($post_id) ) {
382                         if ( $comment->user_id === $post->post_author )
383                                 $classes[] = 'bypostauthor';
384                 }
385         }
386
387         if ( empty($comment_alt) )
388                 $comment_alt = 0;
389         if ( empty($comment_depth) )
390                 $comment_depth = 1;
391         if ( empty($comment_thread_alt) )
392                 $comment_thread_alt = 0;
393
394         if ( $comment_alt % 2 ) {
395                 $classes[] = 'odd';
396                 $classes[] = 'alt';
397         } else {
398                 $classes[] = 'even';
399         }
400
401         $comment_alt++;
402
403         // Alt for top-level comments
404         if ( 1 == $comment_depth ) {
405                 if ( $comment_thread_alt % 2 ) {
406                         $classes[] = 'thread-odd';
407                         $classes[] = 'thread-alt';
408                 } else {
409                         $classes[] = 'thread-even';
410                 }
411                 $comment_thread_alt++;
412         }
413
414         $classes[] = "depth-$comment_depth";
415
416         if ( !empty($class) ) {
417                 if ( !is_array( $class ) )
418                         $class = preg_split('#\s+#', $class);
419                 $classes = array_merge($classes, $class);
420         }
421
422         $classes = array_map('esc_attr', $classes);
423
424         /**
425          * Filter the returned CSS classes for the current comment.
426          *
427          * @since 2.7.0
428          *
429          * @param array       $classes    An array of comment classes.
430          * @param string      $class      A comma-separated list of additional classes added to the list.
431          * @param int         $comment_id The comment id.
432          * @param int|WP_Post $post_id    The post ID or WP_Post object.
433          */
434         return apply_filters( 'comment_class', $classes, $class, $comment_id, $post_id );
435 }
436
437 /**
438  * Retrieve the comment date of the current comment.
439  *
440  * @since 1.5.0
441  *
442  * @param string $d          Optional. The format of the date. Default user's setting.
443  * @param int    $comment_ID Optional. The ID of the comment for which to get the date. Default current comment.
444  * @return string The comment's date.
445  */
446 function get_comment_date( $d = '', $comment_ID = 0 ) {
447         $comment = get_comment( $comment_ID );
448         if ( '' == $d )
449                 $date = mysql2date(get_option('date_format'), $comment->comment_date);
450         else
451                 $date = mysql2date($d, $comment->comment_date);
452         /**
453          * Filter the returned comment date.
454          *
455          * @since 1.5.0
456          *
457          * @param string|int $date Formatted date string or Unix timestamp.
458          * @param string     $d    The format of the date.
459          */
460         return apply_filters( 'get_comment_date', $date, $d );
461 }
462
463 /**
464  * Display the comment date of the current comment.
465  *
466  * @since 0.71
467  *
468  * @param string $d          Optional. The format of the date. Default user's settings.
469  * @param int    $comment_ID Optional. The ID of the comment for which to print the date. Default current comment.
470  */
471 function comment_date( $d = '', $comment_ID = 0 ) {
472         echo get_comment_date( $d, $comment_ID );
473 }
474
475 /**
476  * Retrieve the excerpt of the current comment.
477  *
478  * Will cut each word and only output the first 20 words with '&hellip;' at the end.
479  * If the word count is less than 20, then no truncating is done and no '&hellip;'
480  * will appear.
481  *
482  * @since 1.5.0
483  *
484  * @param int $comment_ID Optional. The ID of the comment for which to get the excerpt. Default current comment.
485  * @return string The maybe truncated comment with 20 words or less.
486  */
487 function get_comment_excerpt( $comment_ID = 0 ) {
488         $comment = get_comment( $comment_ID );
489         $comment_text = strip_tags($comment->comment_content);
490         $blah = explode(' ', $comment_text);
491         if (count($blah) > 20) {
492                 $k = 20;
493                 $use_dotdotdot = 1;
494         } else {
495                 $k = count($blah);
496                 $use_dotdotdot = 0;
497         }
498         $excerpt = '';
499         for ($i=0; $i<$k; $i++) {
500                 $excerpt .= $blah[$i] . ' ';
501         }
502         $excerpt .= ($use_dotdotdot) ? '&hellip;' : '';
503         return apply_filters('get_comment_excerpt', $excerpt);
504 }
505
506 /**
507  * Display the excerpt of the current comment.
508  *
509  * @since 1.2.0
510  *
511  * @param int $comment_ID Optional. The ID of the comment for which to print the excerpt. Default current comment.
512  */
513 function comment_excerpt( $comment_ID = 0 ) {
514         $comment_excerpt = get_comment_excerpt($comment_ID);
515         /**
516          * Filter the comment excerpt for display.
517          *
518          * @since 1.2.0
519          *
520          * @param string $comment_excerpt The comment excerpt text.
521          */
522         echo apply_filters( 'comment_excerpt', $comment_excerpt );
523 }
524
525 /**
526  * Retrieve the comment id of the current comment.
527  *
528  * @since 1.5.0
529  *
530  * @return int The comment ID.
531  */
532 function get_comment_ID() {
533         global $comment;
534         /**
535          * Filter the returned comment ID.
536          *
537          * @since 1.5.0
538          *
539          * @param int $comment->comment_ID The current comment ID.
540          */
541         return apply_filters( 'get_comment_ID', $comment->comment_ID );
542 }
543
544 /**
545  * Display the comment id of the current comment.
546  *
547  * @since 0.71
548  */
549 function comment_ID() {
550         echo get_comment_ID();
551 }
552
553 /**
554  * Retrieve the link to a given comment.
555  *
556  * @since 1.5.0
557  *
558  * @param mixed $comment Optional. Comment to retrieve. Default current comment.
559  * @param array $args    Optional. An array of arguments to override the defaults. @see get_page_of_comment()
560  * @return string The permalink to the given comment.
561  */
562 function get_comment_link( $comment = null, $args = array() ) {
563         global $wp_rewrite, $in_comment_loop;
564
565         $comment = get_comment($comment);
566
567         // Backwards compat
568         if ( !is_array($args) ) {
569                 $page = $args;
570                 $args = array();
571                 $args['page'] = $page;
572         }
573
574         $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
575         $args = wp_parse_args( $args, $defaults );
576
577         if ( '' === $args['per_page'] && get_option('page_comments') )
578                 $args['per_page'] = get_option('comments_per_page');
579
580         if ( empty($args['per_page']) ) {
581                 $args['per_page'] = 0;
582                 $args['page'] = 0;
583         }
584
585         if ( $args['per_page'] ) {
586                 if ( '' == $args['page'] )
587                         $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
588
589                 if ( $wp_rewrite->using_permalinks() )
590                         $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
591                 else
592                         $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
593         } else {
594                 $link = get_permalink( $comment->comment_post_ID );
595         }
596
597         $link = $link . '#comment-' . $comment->comment_ID;
598         /**
599          * Filter the returned single comment permalink.
600          *
601          * @since 2.8.0
602          *
603          * @param string $link    The comment permalink with '#comment-$id' appended.
604          * @param object $comment The current comment object.
605          * @param array  $args    An array of arguments to override the defaults. @see get_page_of_comment()
606          */
607         return apply_filters( 'get_comment_link', $link, $comment, $args );
608 }
609
610 /**
611  * Retrieve the link to the current post comments.
612  *
613  * @since 1.5.0
614  *
615  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
616  * @return string The link to the comments.
617  */
618 function get_comments_link( $post_id = 0 ) {
619         $comments_link = get_permalink( $post_id ) . '#comments';
620         /**
621          * Filter the returned post comments permalink.
622          *
623          * @since
624          *
625          * @param string      $comments_link The post comments permalink with '#comments' appended.
626          * @param int|WP_Post $post_id       The post ID or WP_Post object.
627          */
628         return apply_filters( 'get_comments_link', $comments_link, $post_id );
629 }
630
631 /**
632  * Display the link to the current post comments.
633  *
634  * @since 0.71
635  *
636  * @param string $deprecated   Not Used.
637  * @param bool   $deprecated_2 Not Used.
638  */
639 function comments_link( $deprecated = '', $deprecated_2 = '' ) {
640         if ( !empty( $deprecated ) )
641                 _deprecated_argument( __FUNCTION__, '0.72' );
642         if ( !empty( $deprecated_2 ) )
643                 _deprecated_argument( __FUNCTION__, '1.3' );
644         echo esc_url( get_comments_link() );
645 }
646
647 /**
648  * Retrieve the amount of comments a post has.
649  *
650  * @since 1.5.0
651  *
652  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
653  * @return int The number of comments a post has.
654  */
655 function get_comments_number( $post_id = 0 ) {
656         $post_id = absint( $post_id );
657
658         if ( !$post_id )
659                 $post_id = get_the_ID();
660
661         $post = get_post($post_id);
662         if ( ! isset($post->comment_count) )
663                 $count = 0;
664         else
665                 $count = $post->comment_count;
666
667         /**
668          * Filter the returned comment count for a post.
669          *
670          * @since 1.5.0
671          *
672          * @param int         $count   The number of comments a post has.
673          * @param int|WP_Post $post_id The post ID or WP_Post object.
674          */
675         return apply_filters( 'get_comments_number', $count, $post_id );
676 }
677
678 /**
679  * Display the language string for the number of comments the current post has.
680  *
681  * @since 0.71
682  *
683  * @param string $zero       Optional. Text for no comments. Default false.
684  * @param string $one        Optional. Text for one comment. Default false.
685  * @param string $more       Optional. Text for more than one comment. Default false.
686  * @param string $deprecated Not used.
687  */
688 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
689         if ( !empty( $deprecated ) )
690                 _deprecated_argument( __FUNCTION__, '1.3' );
691
692         $number = get_comments_number();
693
694         if ( $number > 1 )
695                 $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
696         elseif ( $number == 0 )
697                 $output = ( false === $zero ) ? __('No Comments') : $zero;
698         else // must be one
699                 $output = ( false === $one ) ? __('1 Comment') : $one;
700
701         /**
702          * Filter the comments count for display.
703          *
704          * @since 1.5.0
705          *
706          * @param string $output A translatable string formatted based on whether the count is equal to 0, 1, or 1+. @see _n()
707          * @param int    $number The number of post comments.
708          */
709         echo apply_filters( 'comments_number', $output, $number );
710 }
711
712 /**
713  * Retrieve the text of the current comment.
714  *
715  * @since 1.5.0
716  *
717  * @param int   $comment_ID Optional. The ID of the comment for which to get the text. Default current comment.
718  * @param array $args       Optional. An array of arguments. @see Walker_Comment::comment()
719  * @return string The comment content.
720  */
721 function get_comment_text( $comment_ID = 0, $args = array() ) {
722         $comment = get_comment( $comment_ID );
723
724         /**
725          * Filter the text of a comment.
726          *
727          * @since 1.5.0
728          *
729          * @param string $comment->comment_content The text of the comment.
730          * @param object $comment                  The comment object.
731          * @param array  $args                     An array of arguments. @see Walker_Comment::comment()
732          */
733         return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args );
734 }
735
736 /**
737  * Display the text of the current comment.
738  *
739  * @since 0.71
740  *
741  * @param int   $comment_ID Optional. The ID of the comment for which to print the text.
742  *                          Default 0.
743  * @param array $args       Optional. An array of arguments. @see Walker_Comment::comment()
744  *                          Default empty array.
745  */
746 function comment_text( $comment_ID = 0, $args = array() ) {
747         $comment = get_comment( $comment_ID );
748
749         $comment_text = get_comment_text( $comment_ID , $args );
750         /**
751          * Filter the text of a comment to be displayed.
752          *
753          * @since 1.2.0
754          *
755          * @param string $comment_text The text of the current comment.
756          * @param object $comment      The comment object.
757          * @param array  $args         An array of arguments. @see Walker_Comment::comment()
758          */
759         echo apply_filters( 'comment_text', $comment_text, $comment, $args );
760 }
761
762 /**
763  * Retrieve the comment time of the current comment.
764  *
765  * @since 1.5.0
766  *
767  * @param string $d         Optional. The format of the time. Default user's settings.
768  * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
769  * @param bool   $translate Optional. Whether to translate the time (for use in feeds). Default true.
770  * @return string The formatted time
771  */
772 function get_comment_time( $d = '', $gmt = false, $translate = true ) {
773         global $comment;
774         $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
775         if ( '' == $d )
776                 $date = mysql2date(get_option('time_format'), $comment_date, $translate);
777         else
778                 $date = mysql2date($d, $comment_date, $translate);
779
780         /**
781          * Filter the returned comment time.
782          *
783          * @since 1.5.0
784          *
785          * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
786          * @param string     $d         The date format.
787          * @param bool       $gmt       Whether the GMT date is in use.
788          * @param bool       $translate Whether the time is translated.
789          */
790         return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate );
791 }
792
793 /**
794  * Display the comment time of the current comment.
795  *
796  * @since 0.71
797  *
798  * @param string $d Optional. The format of the time. Default user's settings.
799  */
800 function comment_time( $d = '' ) {
801         echo get_comment_time($d);
802 }
803
804 /**
805  * Retrieve the comment type of the current comment.
806  *
807  * @since 1.5.0
808  *
809  * @param int $comment_ID Optional. The ID of the comment for which to get the type. Default current comment.
810  * @return string The comment type
811  */
812 function get_comment_type( $comment_ID = 0 ) {
813         $comment = get_comment( $comment_ID );
814         if ( '' == $comment->comment_type )
815                 $comment->comment_type = 'comment';
816
817         /**
818          * Filter the returned comment type.
819          *
820          * @since 1.5.0
821          *
822          * @param string $comment->comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
823          */
824         return apply_filters( 'get_comment_type', $comment->comment_type );
825 }
826
827 /**
828  * Display the comment type of the current comment.
829  *
830  * @since 0.71
831  *
832  * @param string $commenttxt   Optional. The string to display for comment type. Default false.
833  * @param string $trackbacktxt Optional. The string to display for trackback type. Default false.
834  * @param string $pingbacktxt  Optional. The string to display for pingback type. Default false.
835  */
836 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
837         if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
838         if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
839         if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
840         $type = get_comment_type();
841         switch( $type ) {
842                 case 'trackback' :
843                         echo $trackbacktxt;
844                         break;
845                 case 'pingback' :
846                         echo $pingbacktxt;
847                         break;
848                 default :
849                         echo $commenttxt;
850         }
851 }
852
853 /**
854  * Retrieve The current post's trackback URL.
855  *
856  * There is a check to see if permalink's have been enabled and if so, will
857  * retrieve the pretty path. If permalinks weren't enabled, the ID of the
858  * current post is used and appended to the correct page to go to.
859  *
860  * @since 1.5.0
861  *
862  * @return string The trackback URL after being filtered.
863  */
864 function get_trackback_url() {
865         if ( '' != get_option('permalink_structure') )
866                 $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
867         else
868                 $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
869
870         /**
871          * Filter the returned trackback URL.
872          *
873          * @since 2.2.0
874          *
875          * @param string $tb_url The trackback URL.
876          */
877         return apply_filters( 'trackback_url', $tb_url );
878 }
879
880 /**
881  * Display the current post's trackback URL.
882  *
883  * @since 0.71
884  *
885  * @param bool $deprecated_echo Not used.
886  * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() for the result instead.
887  */
888 function trackback_url( $deprecated_echo = true ) {
889         if ( $deprecated_echo !== true )
890                 _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
891         if ( $deprecated_echo )
892                 echo get_trackback_url();
893         else
894                 return get_trackback_url();
895 }
896
897 /**
898  * Generate and display the RDF for the trackback information of current post.
899  *
900  * Deprecated in 3.0.0, and restored in 3.0.1.
901  *
902  * @since 0.71
903  *
904  * @param int $deprecated Not used (Was $timezone = 0).
905  */
906 function trackback_rdf( $deprecated = '' ) {
907         if ( !empty( $deprecated ) )
908                 _deprecated_argument( __FUNCTION__, '2.5' );
909
910         if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') )
911                 return;
912
913         echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
914                         xmlns:dc="http://purl.org/dc/elements/1.1/"
915                         xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
916                 <rdf:Description rdf:about="';
917         the_permalink();
918         echo '"'."\n";
919         echo '    dc:identifier="';
920         the_permalink();
921         echo '"'."\n";
922         echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
923         echo '    trackback:ping="'.get_trackback_url().'"'." />\n";
924         echo '</rdf:RDF>';
925 }
926
927 /**
928  * Whether the current post is open for comments.
929  *
930  * @since 1.5.0
931  *
932  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
933  * @return bool True if the comments are open.
934  */
935 function comments_open( $post_id = null ) {
936
937         $_post = get_post($post_id);
938
939         $open = ( 'open' == $_post->comment_status );
940
941         /**
942          * Filter whether the current post is open for comments.
943          *
944          * @since
945          *
946          * @param bool        $open    Whether the current post is open for comments.
947          * @param int|WP_Post $post_id The post ID or WP_Post object.
948          */
949         return apply_filters( 'comments_open', $open, $post_id );
950 }
951
952 /**
953  * Whether the current post is open for pings.
954  *
955  * @since 1.5.0
956  *
957  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
958  * @return bool True if pings are accepted
959  */
960 function pings_open( $post_id = null ) {
961
962         $_post = get_post($post_id);
963
964         $open = ( 'open' == $_post->ping_status );
965         return apply_filters( 'pings_open', $open, $post_id );
966 }
967
968 /**
969  * Display form token for unfiltered comments.
970  *
971  * Will only display nonce token if the current user has permissions for
972  * unfiltered html. Won't display the token for other users.
973  *
974  * The function was backported to 2.0.10 and was added to versions 2.1.3 and
975  * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in
976  * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.
977  *
978  * Backported to 2.0.10.
979  *
980  * @since 2.1.3
981  */
982 function wp_comment_form_unfiltered_html_nonce() {
983         $post = get_post();
984         $post_id = $post ? $post->ID : 0;
985
986         if ( current_user_can( 'unfiltered_html' ) ) {
987                 wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
988                 echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
989         }
990 }
991
992 /**
993  * Load the comment template specified in $file.
994  *
995  * Will not display the comments template if not on single post or page, or if
996  * the post does not have comments.
997  *
998  * Uses the WordPress database object to query for the comments. The comments
999  * are passed through the 'comments_array' filter hook with the list of comments
1000  * and the post ID respectively.
1001  *
1002  * The $file path is passed through a filter hook called, 'comments_template'
1003  * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
1004  * first and if it fails it will require the default comment template from the
1005  * default theme. If either does not exist, then the WordPress process will be
1006  * halted. It is advised for that reason, that the default theme is not deleted.
1007  *
1008  * @todo Document globals
1009  * @uses $withcomments Will not try to get the comments if the post has none.
1010  *
1011  * @since 1.5.0
1012  *
1013  * @param string $file              Optional. The file to load. Default '/comments.php'.
1014  * @param bool   $separate_comments Optional. Whether to separate the comments by comment type. Default false.
1015  * @return null Returns null if no comments appear.
1016  */
1017 function comments_template( $file = '/comments.php', $separate_comments = false ) {
1018         global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
1019
1020         if ( !(is_single() || is_page() || $withcomments) || empty($post) )
1021                 return;
1022
1023         if ( empty($file) )
1024                 $file = '/comments.php';
1025
1026         $req = get_option('require_name_email');
1027
1028         /**
1029          * Comment author information fetched from the comment cookies.
1030          *
1031          * @uses wp_get_current_commenter()
1032          */
1033         $commenter = wp_get_current_commenter();
1034
1035         /**
1036          * The name of the current comment author escaped for use in attributes.
1037          */
1038         $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies()
1039
1040         /**
1041          * The email address of the current comment author escaped for use in attributes.
1042          */
1043         $comment_author_email = $commenter['comment_author_email'];  // Escaped by sanitize_comment_cookies()
1044
1045         /**
1046          * The url of the current comment author escaped for use in attributes.
1047          */
1048         $comment_author_url = esc_url($commenter['comment_author_url']);
1049
1050         /** @todo Use API instead of SELECTs. */
1051         if ( $user_ID) {
1052                 $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));
1053         } else if ( empty($comment_author) ) {
1054                 $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
1055         } else {
1056                 $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));
1057         }
1058
1059         // keep $comments for legacy's sake
1060         /**
1061          * Filter the comments array.
1062          *
1063          * @since 2.1.0
1064          *
1065          * @param array $comments The array of comments supplied to the comments template.
1066          * @param int   $post->ID The post ID.
1067          */
1068         $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
1069         $comments = &$wp_query->comments;
1070         $wp_query->comment_count = count($wp_query->comments);
1071         update_comment_cache($wp_query->comments);
1072
1073         if ( $separate_comments ) {
1074                 $wp_query->comments_by_type = separate_comments($comments);
1075                 $comments_by_type = &$wp_query->comments_by_type;
1076         }
1077
1078         $overridden_cpage = false;
1079         if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
1080                 set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
1081                 $overridden_cpage = true;
1082         }
1083
1084         if ( !defined('COMMENTS_TEMPLATE') )
1085                 define('COMMENTS_TEMPLATE', true);
1086
1087         $theme_template = STYLESHEETPATH . $file;
1088         /**
1089          * Filter the path to the theme template file used for the comments template.
1090          *
1091          * @since 1.5.1
1092          *
1093          * @param string $theme_template The path to the theme template file.
1094          */
1095         $include = apply_filters( 'comments_template', $theme_template );
1096         if ( file_exists( $include ) )
1097                 require( $include );
1098         elseif ( file_exists( TEMPLATEPATH . $file ) )
1099                 require( TEMPLATEPATH . $file );
1100         else // Backward compat code will be removed in a future release
1101                 require( ABSPATH . WPINC . '/theme-compat/comments.php');
1102 }
1103
1104 /**
1105  * Display the JS popup script to show a comment.
1106  *
1107  * If the $file parameter is empty, then the home page is assumed. The defaults
1108  * for the window are 400px by 400px.
1109  *
1110  * For the comment link popup to work, this function has to be called or the
1111  * normal comment link will be assumed.
1112  *
1113  * @global string $wpcommentspopupfile  The URL to use for the popup window.
1114  * @global int    $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
1115  *
1116  * @since 0.71
1117  *
1118  * @param int $width  Optional. The width of the popup window. Default 400.
1119  * @param int $height Optional. The height of the popup window. Default 400.
1120  * @param string $file Optional. Sets the location of the popup window.
1121  */
1122 function comments_popup_script( $width = 400, $height = 400, $file = '' ) {
1123         global $wpcommentspopupfile, $wpcommentsjavascript;
1124
1125         if (empty ($file)) {
1126                 $wpcommentspopupfile = '';  // Use the index.
1127         } else {
1128                 $wpcommentspopupfile = $file;
1129         }
1130
1131         $wpcommentsjavascript = 1;
1132         $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";
1133         echo $javascript;
1134 }
1135
1136 /**
1137  * Displays the link to the comments popup window for the current post ID.
1138  *
1139  * Is not meant to be displayed on single posts and pages. Should be used on the
1140  * lists of posts
1141  *
1142  * @global string $wpcommentspopupfile  The URL to use for the popup window.
1143  * @global int    $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
1144  *
1145  * @since 0.71
1146  *
1147  * @param string $zero      Optional. The string to display when no comments. Default false.
1148  * @param string $one       Optional. The string to display when only one comment is available. Default false.
1149  * @param string $more      Optional. The string to display when there are more than one comment. Default false.
1150  * @param string $css_class Optional. The CSS class to use for comments. Default empty.
1151  * @param string $none      Optional. The string to display when comments have been turned off. Default false.
1152  * @return null Returns null on single posts and pages.
1153  */
1154 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
1155         global $wpcommentspopupfile, $wpcommentsjavascript;
1156
1157         $id = get_the_ID();
1158
1159         if ( false === $zero ) $zero = __( 'No Comments' );
1160         if ( false === $one ) $one = __( '1 Comment' );
1161         if ( false === $more ) $more = __( '% Comments' );
1162         if ( false === $none ) $none = __( 'Comments Off' );
1163
1164         $number = get_comments_number( $id );
1165
1166         if ( 0 == $number && !comments_open() && !pings_open() ) {
1167                 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
1168                 return;
1169         }
1170
1171         if ( post_password_required() ) {
1172                 echo __('Enter your password to view comments.');
1173                 return;
1174         }
1175
1176         echo '<a href="';
1177         if ( $wpcommentsjavascript ) {
1178                 if ( empty( $wpcommentspopupfile ) )
1179                         $home = home_url();
1180                 else
1181                         $home = get_option('siteurl');
1182                 echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
1183                 echo '" onclick="wpopen(this.href); return false"';
1184         } else { // if comments_popup_script() is not in the template, display simple comment link
1185                 if ( 0 == $number )
1186                         echo get_permalink() . '#respond';
1187                 else
1188                         comments_link();
1189                 echo '"';
1190         }
1191
1192         if ( !empty( $css_class ) ) {
1193                 echo ' class="'.$css_class.'" ';
1194         }
1195         $title = the_title_attribute( array('echo' => 0 ) );
1196
1197         $attributes = '';
1198         /**
1199          * Filter the comments popup link attributes for display.
1200          *
1201          * @since 2.5.0
1202          *
1203          * @param string $attributes The comments popup link attributes. Default empty.
1204          */
1205         echo apply_filters( 'comments_popup_link_attributes', $attributes );
1206
1207         echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
1208         comments_number( $zero, $one, $more );
1209         echo '</a>';
1210 }
1211
1212 /**
1213  * Retrieve HTML content for reply to comment link.
1214  *
1215  * @since 2.7.0
1216  *
1217  * @param array $args {
1218  *     Optional. Override default arguments.
1219  *
1220  *     @type string 'add_below'  The first part of the selector used to identify the comment to respond below. The resulting
1221  *                               value is passed as the first parameter to addComment.moveForm(), concatenated
1222  *                               as $add_below-$comment->comment_ID. Default 'comment'.
1223  *     @type string 'respond_id' The selector identifying the responding comment. Passed as the third parameter to addComment.moveForm(),
1224  *                               and appended to the link URL as a hash value. Default 'respond'.
1225  *     @type string 'reply_text' The text of the Reply link. Default 'Reply'.
1226  *     @type string 'login_text' The text of the link to reply if logged out. Default 'Log in to Reply'.
1227  *     @type int    'depth'      The depth of the new comment. Must be greater than 0 and less than the value of the 'thread_comments_depth'
1228  *                               option set in Settings > Discussion.
1229  *                               Default 0.
1230  *     @type string 'before'     The text or HTML to add before the reply link. Default empty.
1231  *     @type string 'after'      The text or HTML to add after the reply link. Default empty.
1232  * }
1233  * @param int         $comment Optional. Comment being replied to. Default current comment.
1234  * @param int|WP_Post $post    Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
1235  * @return mixed Link to show comment form, if successful. False, if comments are closed.
1236  */
1237 function get_comment_reply_link($args = array(), $comment = null, $post = null) {
1238
1239         $defaults = array(
1240                 'add_below'  => 'comment',
1241                 'respond_id' => 'respond',
1242                 'reply_text' => __('Reply'),
1243                 'login_text' => __('Log in to Reply'),
1244                 'depth'      => 0,
1245                 'before'     => '',
1246                 'after'      => ''
1247         );
1248
1249         $args = wp_parse_args($args, $defaults);
1250
1251         if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
1252                 return;
1253
1254         extract($args, EXTR_SKIP);
1255
1256         $comment = get_comment($comment);
1257         if ( empty($post) )
1258                 $post = $comment->comment_post_ID;
1259         $post = get_post($post);
1260
1261         if ( !comments_open($post->ID) )
1262                 return false;
1263
1264         $link = '';
1265
1266         if ( get_option('comment_registration') && ! is_user_logged_in() )
1267                 $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
1268         else
1269                 $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>";
1270
1271         /**
1272          * Filter the comment reply link.
1273          *
1274          * @since 2.7.0
1275          *
1276          * @param string  $before  Text or HTML displayed before the reply link.
1277          * @param string  $link    The HTML markup for the comment reply link.
1278          * @param string  $after   Text or HTML displayed after the reply link.
1279          * @param array   $args    An array of arguments overriding the defaults.
1280          * @param object  $comment The object of the comment being replied.
1281          * @param WP_Post $post    The WP_Post object.
1282          */
1283         return apply_filters( 'comment_reply_link', $before . $link . $after, $args, $comment, $post );
1284 }
1285
1286 /**
1287  * Displays the HTML content for reply to comment link.
1288  *
1289  * @since 2.7.0
1290  *
1291  * @param array       $args    Optional. Override default options, @see get_comment_reply_link()
1292  * @param int         $comment Optional. Comment being replied to. Default current comment.
1293  * @param int|WP_Post $post    Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
1294  * @return mixed Link to show comment form, if successful. False, if comments are closed.
1295  */
1296 function comment_reply_link($args = array(), $comment = null, $post = null) {
1297         echo get_comment_reply_link($args, $comment, $post);
1298 }
1299
1300 /**
1301  * Retrieve HTML content for reply to post link.
1302  *
1303  * @since 2.7.0
1304  *
1305  * @param array $args {
1306  *     Optional. Override default arguments.
1307  *
1308  *     @type string 'add_below'  The first part of the selector used to identify the comment to respond below.
1309  *                               The resulting value is passed as the first parameter to addComment.moveForm(),
1310  *                               concatenated as $add_below-$comment->comment_ID. Default is 'post'.
1311  *     @type string 'respond_id' The selector identifying the responding comment. Passed as the third parameter
1312  *                               to addComment.moveForm(), and appended to the link URL as a hash value. Default is 'respond'.
1313  *     @type string 'reply_text' The text of the Reply link. Default is 'Leave a Comment'.
1314  *     @type string 'login_text' The text of the link to reply if logged out. Default is 'Log in to leave a Comment'.
1315  *     @type string 'before'     The text or HTML to add before the reply link. Default empty.
1316  *     @type string 'after'      The text or HTML to add after the reply link. Default empty.
1317  * }
1318  * @param int|WP_Post $post    Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
1319  * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1320  */
1321 function get_post_reply_link($args = array(), $post = null) {
1322         $defaults = array(
1323                 'add_below'  => 'post',
1324                 'respond_id' => 'respond',
1325                 'reply_text' => __('Leave a Comment'),
1326                 'login_text' => __('Log in to leave a Comment'),
1327                 'before'     => '',
1328                 'after'      => '',
1329         );
1330
1331         $args = wp_parse_args($args, $defaults);
1332         extract($args, EXTR_SKIP);
1333         $post = get_post($post);
1334
1335         if ( !comments_open($post->ID) )
1336                 return false;
1337
1338         if ( get_option('comment_registration') && ! is_user_logged_in() )
1339                 $link = '<a rel="nofollow" href="' . wp_login_url( get_permalink() ) . '">' . $login_text . '</a>';
1340         else
1341                 $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>";
1342
1343         $formatted_link = $before . $link . $after;
1344         /**
1345          * Filter the formatted post comments link HTML.
1346          *
1347          * @since 2.7.0
1348          *
1349          * @param string      $formatted The HTML-formatted post comments link.
1350          * @param int|WP_Post $post      The post ID or WP_Post object.
1351          */
1352         return apply_filters( 'post_comments_link', $formatted_link, $post );
1353 }
1354
1355 /**
1356  * Displays the HTML content for reply to post link.
1357  *
1358  * @since 2.7.0
1359  *
1360  * @param array       $args Optional. Override default options, @see get_post_reply_link()
1361  * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
1362  * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1363  */
1364 function post_reply_link($args = array(), $post = null) {
1365         echo get_post_reply_link($args, $post);
1366 }
1367
1368 /**
1369  * Retrieve HTML content for cancel comment reply link.
1370  *
1371  * @since 2.7.0
1372  *
1373  * @param string $text Optional. Text to display for cancel reply link. Default empty.
1374  */
1375 function get_cancel_comment_reply_link( $text = '' ) {
1376         if ( empty($text) )
1377                 $text = __('Click here to cancel reply.');
1378
1379         $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
1380         $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
1381
1382         $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
1383         /**
1384          * Filter the cancel comment reply link HTML.
1385          *
1386          * @since 2.7.0
1387          *
1388          * @param string $formatted_link The HTML-formatted cancel comment reply link.
1389          * @param string $link           The cancel comment reply link URL.
1390          * @param string $text           The cancel comment reply link text.
1391          */
1392         return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
1393 }
1394
1395 /**
1396  * Display HTML content for cancel comment reply link.
1397  *
1398  * @since 2.7.0
1399  *
1400  * @param string $text Optional. Text to display for cancel reply link. Default empty.
1401  */
1402 function cancel_comment_reply_link( $text = '' ) {
1403         echo get_cancel_comment_reply_link($text);
1404 }
1405
1406 /**
1407  * Retrieve hidden input HTML for replying to comments.
1408  *
1409  * @since 3.0.0
1410  *
1411  * @param int $id Optional. Post ID. Default current post ID.
1412  * @return string Hidden input HTML for replying to comments
1413  */
1414 function get_comment_id_fields( $id = 0 ) {
1415         if ( empty( $id ) )
1416                 $id = get_the_ID();
1417
1418         $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1419         $result  = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
1420         $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
1421
1422         /**
1423          * Filter the returned comment id fields.
1424          *
1425          * @since 3.0.0
1426          *
1427          * @param string $result    The HTML-formatted hidden id field comment elements.
1428          * @param int    $id        The post ID.
1429          * @param int    $replytoid The id of the comment being replied to.
1430          */
1431         return apply_filters( 'comment_id_fields', $result, $id, $replytoid );
1432 }
1433
1434 /**
1435  * Output hidden input HTML for replying to comments.
1436  *
1437  * @since 2.7.0
1438  *
1439  * @param int $id Optional. Post ID. Default current post ID.
1440  */
1441 function comment_id_fields( $id = 0 ) {
1442         echo get_comment_id_fields( $id );
1443 }
1444
1445 /**
1446  * Display text based on comment reply status.
1447  *
1448  * Only affects users with Javascript disabled.
1449  *
1450  * @since 2.7.0
1451  *
1452  * @param string $noreplytext  Optional. Text to display when not replying to a comment. Default false.
1453  * @param string $replytext    Optional. Text to display when replying to a comment.
1454  *                             Default false. Accepts "%s" for the author of the comment being replied to.
1455  * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment. Default true.
1456  */
1457 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {
1458         global $comment;
1459
1460         if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
1461         if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
1462
1463         $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1464
1465         if ( 0 == $replytoid )
1466                 echo $noreplytext;
1467         else {
1468                 $comment = get_comment($replytoid);
1469                 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
1470                 printf( $replytext, $author );
1471         }
1472 }
1473
1474 /**
1475  * HTML comment list class.
1476  *
1477  * @package WordPress
1478  * @uses Walker
1479  * @since 2.7.0
1480  */
1481 class Walker_Comment extends Walker {
1482         /**
1483          * What the class handles.
1484          *
1485          * @see Walker::$tree_type
1486          *
1487          * @since 2.7.0
1488          * @var string
1489          */
1490         var $tree_type = 'comment';
1491
1492         /**
1493          * DB fields to use.
1494          *
1495          * @see Walker::$db_fields
1496          *
1497          * @since 2.7.0
1498          * @var array
1499          */
1500         var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
1501
1502         /**
1503          * Start the list before the elements are added.
1504          *
1505          * @see Walker::start_lvl()
1506          *
1507          * @since 2.7.0
1508          *
1509          * @param string $output Passed by reference. Used to append additional content.
1510          * @param int $depth Depth of comment.
1511          * @param array $args Uses 'style' argument for type of HTML list.
1512          */
1513         function start_lvl( &$output, $depth = 0, $args = array() ) {
1514                 $GLOBALS['comment_depth'] = $depth + 1;
1515
1516                 switch ( $args['style'] ) {
1517                         case 'div':
1518                                 break;
1519                         case 'ol':
1520                                 $output .= '<ol class="children">' . "\n";
1521                                 break;
1522                         default:
1523                         case 'ul':
1524                                 $output .= '<ul class="children">' . "\n";
1525                                 break;
1526                 }
1527         }
1528
1529         /**
1530          * End the list of items after the elements are added.
1531          *
1532          * @see Walker::end_lvl()
1533          *
1534          * @since 2.7.0
1535          *
1536          * @param string $output Passed by reference. Used to append additional content.
1537          * @param int    $depth  Depth of comment.
1538          * @param array  $args   Will only append content if style argument value is 'ol' or 'ul'.
1539          */
1540         function end_lvl( &$output, $depth = 0, $args = array() ) {
1541                 $GLOBALS['comment_depth'] = $depth + 1;
1542
1543                 switch ( $args['style'] ) {
1544                         case 'div':
1545                                 break;
1546                         case 'ol':
1547                                 $output .= "</ol><!-- .children -->\n";
1548                                 break;
1549                         default:
1550                         case 'ul':
1551                                 $output .= "</ul><!-- .children -->\n";
1552                                 break;
1553                 }
1554         }
1555
1556         /**
1557          * Traverse elements to create list from elements.
1558          *
1559          * This function is designed to enhance Walker::display_element() to
1560          * display children of higher nesting levels than selected inline on
1561          * the highest depth level displayed. This prevents them being orphaned
1562          * at the end of the comment list.
1563          *
1564          * Example: max_depth = 2, with 5 levels of nested content.
1565          * 1
1566          *  1.1
1567          *    1.1.1
1568          *    1.1.1.1
1569          *    1.1.1.1.1
1570          *    1.1.2
1571          *    1.1.2.1
1572          * 2
1573          *  2.2
1574          *
1575          * @see Walker::display_element()
1576          *
1577          * @since 2.7.0
1578          *
1579          * @param object $element           Data object.
1580          * @param array  $children_elements List of elements to continue traversing.
1581          * @param int    $max_depth         Max depth to traverse.
1582          * @param int    $depth             Depth of current element.
1583          * @param array  $args              An array of arguments. @see wp_list_comments()
1584          * @param string $output            Passed by reference. Used to append additional content.
1585          * @return null Null on failure with no changes to parameters.
1586          */
1587         function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
1588
1589                 if ( !$element )
1590                         return;
1591
1592                 $id_field = $this->db_fields['id'];
1593                 $id = $element->$id_field;
1594
1595                 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
1596
1597                 // If we're at the max depth, and the current element still has children, loop over those and display them at this level
1598                 // This is to prevent them being orphaned to the end of the list.
1599                 if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
1600                         foreach ( $children_elements[ $id ] as $child )
1601                                 $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
1602
1603                         unset( $children_elements[ $id ] );
1604                 }
1605
1606         }
1607
1608         /**
1609          * Start the element output.
1610          *
1611          * @see Walker::start_el()
1612          *
1613          * @since 2.7.0
1614          *
1615          * @param string $output  Passed by reference. Used to append additional content.
1616          * @param object $comment Comment data object.
1617          * @param int    $depth   Depth of comment in reference to parents.
1618          * @param array  $args    An array of arguments. @see wp_list_comments()
1619          */
1620         function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
1621                 $depth++;
1622                 $GLOBALS['comment_depth'] = $depth;
1623                 $GLOBALS['comment'] = $comment;
1624
1625                 if ( !empty( $args['callback'] ) ) {
1626                         ob_start();
1627                         call_user_func( $args['callback'], $comment, $args, $depth );
1628                         $output .= ob_get_clean();
1629                         return;
1630                 }
1631
1632                 if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
1633                         ob_start();
1634                         $this->ping( $comment, $depth, $args );
1635                         $output .= ob_get_clean();
1636                 } elseif ( 'html5' === $args['format'] ) {
1637                         ob_start();
1638                         $this->html5_comment( $comment, $depth, $args );
1639                         $output .= ob_get_clean();
1640                 } else {
1641                         ob_start();
1642                         $this->comment( $comment, $depth, $args );
1643                         $output .= ob_get_clean();
1644                 }
1645         }
1646
1647         /**
1648          * Ends the element output, if needed.
1649          *
1650          * @see Walker::end_el()
1651          *
1652          * @since 2.7.0
1653          *
1654          * @param string $output  Passed by reference. Used to append additional content.
1655          * @param object $comment The comment object. Default current comment.
1656          * @param int    $depth   Depth of comment.
1657          * @param array  $args    An array of arguments. @see wp_list_comments()
1658          */
1659         function end_el( &$output, $comment, $depth = 0, $args = array() ) {
1660                 if ( !empty( $args['end-callback'] ) ) {
1661                         ob_start();
1662                         call_user_func( $args['end-callback'], $comment, $args, $depth );
1663                         $output .= ob_get_clean();
1664                         return;
1665                 }
1666                 if ( 'div' == $args['style'] )
1667                         $output .= "</div><!-- #comment-## -->\n";
1668                 else
1669                         $output .= "</li><!-- #comment-## -->\n";
1670         }
1671
1672         /**
1673          * Output a pingback comment.
1674          *
1675          * @access protected
1676          * @since 3.6.0
1677          *
1678          * @param object $comment The comment object.
1679          * @param int    $depth   Depth of comment.
1680          * @param array  $args    An array of arguments. @see wp_list_comments()
1681          */
1682         protected function ping( $comment, $depth, $args ) {
1683                 $tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
1684 ?>
1685                 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
1686                         <div class="comment-body">
1687                                 <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
1688                         </div>
1689 <?php
1690         }
1691
1692         /**
1693          * Output a single comment.
1694          *
1695          * @access protected
1696          * @since 3.6.0
1697          *
1698          * @param object $comment Comment to display.
1699          * @param int    $depth   Depth of comment.
1700          * @param array  $args    An array of arguments. @see wp_list_comments()
1701          */
1702         protected function comment( $comment, $depth, $args ) {
1703                 if ( 'div' == $args['style'] ) {
1704                         $tag = 'div';
1705                         $add_below = 'comment';
1706                 } else {
1707                         $tag = 'li';
1708                         $add_below = 'div-comment';
1709                 }
1710 ?>
1711                 <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">
1712                 <?php if ( 'div' != $args['style'] ) : ?>
1713                 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
1714                 <?php endif; ?>
1715                 <div class="comment-author vcard">
1716                         <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
1717                         <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
1718                 </div>
1719                 <?php if ( '0' == $comment->comment_approved ) : ?>
1720                 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>
1721                 <br />
1722                 <?php endif; ?>
1723
1724                 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
1725                         <?php
1726                                 /* translators: 1: date, 2: time */
1727                                 printf( __( '%1$s at %2$s' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), '&nbsp;&nbsp;', '' );
1728                         ?>
1729                 </div>
1730
1731                 <?php comment_text( get_comment_id(), array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1732
1733                 <div class="reply">
1734                         <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1735                 </div>
1736                 <?php if ( 'div' != $args['style'] ) : ?>
1737                 </div>
1738                 <?php endif; ?>
1739 <?php
1740         }
1741
1742         /**
1743          * Output a comment in the HTML5 format.
1744          *
1745          * @access protected
1746          * @since 3.6.0
1747          *
1748          * @param object $comment Comment to display.
1749          * @param int    $depth   Depth of comment.
1750          * @param array  $args    An array of arguments. @see wp_list_comments()
1751          */
1752         protected function html5_comment( $comment, $depth, $args ) {
1753                 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
1754 ?>
1755                 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
1756                         <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
1757                                 <footer class="comment-meta">
1758                                         <div class="comment-author vcard">
1759                                                 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
1760                                                 <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?>
1761                                         </div><!-- .comment-author -->
1762
1763                                         <div class="comment-metadata">
1764                                                 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
1765                                                         <time datetime="<?php comment_time( 'c' ); ?>">
1766                                                                 <?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), get_comment_time() ); ?>
1767                                                         </time>
1768                                                 </a>
1769                                                 <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
1770                                         </div><!-- .comment-metadata -->
1771
1772                                         <?php if ( '0' == $comment->comment_approved ) : ?>
1773                                         <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
1774                                         <?php endif; ?>
1775                                 </footer><!-- .comment-meta -->
1776
1777                                 <div class="comment-content">
1778                                         <?php comment_text(); ?>
1779                                 </div><!-- .comment-content -->
1780
1781                                 <div class="reply">
1782                                         <?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
1783                                 </div><!-- .reply -->
1784                         </article><!-- .comment-body -->
1785 <?php
1786         }
1787 }
1788
1789 /**
1790  * List comments.
1791  *
1792  * Used in the comments.php template to list comments for a particular post.
1793  *
1794  * @since 2.7.0
1795  *
1796  * @param string|array $args {
1797  *     Optional. Formatting options.
1798  *
1799  *     @type string 'walker'            The Walker class used to list comments. Default null.
1800  *     @type int    'max_depth'         The maximum comments depth. Default empty.
1801  *     @type string 'style'             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
1802  *     @type string 'callback'          Callback function to use. Default null.
1803  *     @type string 'end-callback'      Callback function to use at the end. Default null.
1804  *     @type string 'type'              Type of comments to list.
1805  *                                      Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
1806  *     @type int    'page'              Page ID to list comments for. Default empty.
1807  *     @type int    'per_page'          Number of comments to list per page. Default empty.
1808  *     @type int    'avatar_size'       Height and width dimensions of the avatar size. Default 32.
1809  *     @type string 'reverse_top_level' Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
1810  *     @type bool   'reverse_children'  Whether to reverse child comments in the list. Default null.
1811  *     @type string 'format'            How to format the comments list.
1812  *                                      Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
1813  *     @type bool   'short_ping'        Whether to output short pings. Default false.
1814  *     @type bool   'echo'              Whether to echo the output or return it. Default true.
1815  * }
1816  * @param array $comments Optional. Array of comment objects. @see WP_Query->comments
1817  */
1818 function wp_list_comments( $args = array(), $comments = null ) {
1819         global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
1820
1821         $in_comment_loop = true;
1822
1823         $comment_alt = $comment_thread_alt = 0;
1824         $comment_depth = 1;
1825
1826         $defaults = array(
1827                 'walker'            => null,
1828                 'max_depth'         => '',
1829                 'style'             => 'ul',
1830                 'callback'          => null,
1831                 'end-callback'      => null,
1832                 'type'              => 'all',
1833                 'page'              => '',
1834                 'per_page'          => '',
1835                 'avatar_size'       => 32,
1836                 'reverse_top_level' => null,
1837                 'reverse_children'  => '',
1838                 'format'            => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
1839                 'short_ping'        => false,
1840                 'echo'              => true,
1841         );
1842
1843         $r = wp_parse_args( $args, $defaults );
1844
1845         // Figure out what comments we'll be looping through ($_comments)
1846         if ( null !== $comments ) {
1847                 $comments = (array) $comments;
1848                 if ( empty($comments) )
1849                         return;
1850                 if ( 'all' != $r['type'] ) {
1851                         $comments_by_type = separate_comments($comments);
1852                         if ( empty($comments_by_type[$r['type']]) )
1853                                 return;
1854                         $_comments = $comments_by_type[$r['type']];
1855                 } else {
1856                         $_comments = $comments;
1857                 }
1858         } else {
1859                 if ( empty($wp_query->comments) )
1860                         return;
1861                 if ( 'all' != $r['type'] ) {
1862                         if ( empty($wp_query->comments_by_type) )
1863                                 $wp_query->comments_by_type = separate_comments($wp_query->comments);
1864                         if ( empty($wp_query->comments_by_type[$r['type']]) )
1865                                 return;
1866                         $_comments = $wp_query->comments_by_type[$r['type']];
1867                 } else {
1868                         $_comments = $wp_query->comments;
1869                 }
1870         }
1871
1872         if ( '' === $r['per_page'] && get_option('page_comments') )
1873                 $r['per_page'] = get_query_var('comments_per_page');
1874
1875         if ( empty($r['per_page']) ) {
1876                 $r['per_page'] = 0;
1877                 $r['page'] = 0;
1878         }
1879
1880         if ( '' === $r['max_depth'] ) {
1881                 if ( get_option('thread_comments') )
1882                         $r['max_depth'] = get_option('thread_comments_depth');
1883                 else
1884                         $r['max_depth'] = -1;
1885         }
1886
1887         if ( '' === $r['page'] ) {
1888                 if ( empty($overridden_cpage) ) {
1889                         $r['page'] = get_query_var('cpage');
1890                 } else {
1891                         $threaded = ( -1 != $r['max_depth'] );
1892                         $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
1893                         set_query_var( 'cpage', $r['page'] );
1894                 }
1895         }
1896         // Validation check
1897         $r['page'] = intval($r['page']);
1898         if ( 0 == $r['page'] && 0 != $r['per_page'] )
1899                 $r['page'] = 1;
1900
1901         if ( null === $r['reverse_top_level'] )
1902                 $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
1903
1904         extract( $r, EXTR_SKIP );
1905
1906         if ( empty($walker) )
1907                 $walker = new Walker_Comment;
1908
1909         $output = $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
1910         $wp_query->max_num_comment_pages = $walker->max_pages;
1911
1912         $in_comment_loop = false;
1913
1914         if ( $r['echo'] )
1915                 echo $output;
1916         else
1917                 return $output;
1918 }
1919
1920 /**
1921  * Output a complete commenting form for use within a template.
1922  *
1923  * Most strings and form fields may be controlled through the $args array passed
1924  * into the function, while you may also choose to use the comment_form_default_fields
1925  * filter to modify the array of default fields if you'd just like to add a new
1926  * one or remove a single field. All fields are also individually passed through
1927  * a filter of the form comment_form_field_$name where $name is the key used
1928  * in the array of fields.
1929  *
1930  * @since 3.0.0
1931  *
1932  * @param array       $args {
1933  *     Optional. Default arguments and form fields to override.
1934  *
1935  *     @type array 'fields' {
1936  *         Default comment fields, filterable by default via the 'comment_form_default_fields' hook.
1937  *
1938  *         @type string 'author' The comment author field HTML.
1939  *         @type string 'email'  The comment author email field HTML.
1940  *         @type string 'url'    The comment author URL field HTML.
1941  *     }
1942  *     @type string 'comment_field'        The comment textarea field HTML.
1943  *     @type string 'must_log_in'          HTML element for a 'must be logged in to comment' message.
1944  *     @type string 'logged_in_as'         HTML element for a 'logged in as <user>' message.
1945  *     @type string 'comment_notes_before' HTML element for a message displayed before the comment form.
1946  *                                         Default 'Your email address will not be published.'.
1947  *     @type string 'comment_notes_after'  HTML element for a message displayed after the comment form.
1948  *                                         Default 'You may use these HTML tags and attributes ...'.
1949  *     @type string 'id_form'              The comment form element id attribute. Default 'commentform'.
1950  *     @type string 'id_submit'            The comment submit element id attribute. Default 'submit'.
1951  *     @type string 'title_reply'          The translatable 'reply' button label. Default 'Leave a Reply'.
1952  *     @type string 'title_reply_to'       The translatable 'reply-to' button label. Default 'Leave a Reply to %s',
1953  *                                         where %s is the author of the comment being replied to.
1954  *     @type string 'cancel_reply_link'    The translatable 'cancel reply' button label. Default 'Cancel reply'.
1955  *     @type string 'label_submit'         The translatable 'submit' button label. Default 'Post a comment'.
1956  *     @type string 'format'               The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
1957  * }
1958  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object to generate the form for. Default current post.
1959  */
1960 function comment_form( $args = array(), $post_id = null ) {
1961         if ( null === $post_id )
1962                 $post_id = get_the_ID();
1963         else
1964                 $id = $post_id;
1965
1966         $commenter = wp_get_current_commenter();
1967         $user = wp_get_current_user();
1968         $user_identity = $user->exists() ? $user->display_name : '';
1969
1970         $args = wp_parse_args( $args );
1971         if ( ! isset( $args['format'] ) )
1972                 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
1973
1974         $req      = get_option( 'require_name_email' );
1975         $aria_req = ( $req ? " aria-required='true'" : '' );
1976         $html5    = 'html5' === $args['format'];
1977         $fields   =  array(
1978                 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
1979                             '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
1980                 'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
1981                             '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
1982                 'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
1983                             '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
1984         );
1985
1986         $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
1987
1988         /**
1989          * Filter the default comment form fields.
1990          *
1991          * @since 3.0.0
1992          *
1993          * @param array $fields The default comment fields.
1994          */
1995         $fields = apply_filters( 'comment_form_default_fields', $fields );
1996         $defaults = array(
1997                 'fields'               => $fields,
1998                 '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>',
1999                 '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>',
2000                 '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>',
2001                 'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
2002                 '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>',
2003                 'id_form'              => 'commentform',
2004                 'id_submit'            => 'submit',
2005                 'title_reply'          => __( 'Leave a Reply' ),
2006                 'title_reply_to'       => __( 'Leave a Reply to %s' ),
2007                 'cancel_reply_link'    => __( 'Cancel reply' ),
2008                 'label_submit'         => __( 'Post Comment' ),
2009                 'format'               => 'xhtml',
2010         );
2011
2012         /**
2013          * Filter the comment form default arguments.
2014          *
2015          * Use 'comment_form_default_fields' to filter the comment fields.
2016          *
2017          * @since 3.0.0
2018          *
2019          * @param array $defaults The default comment form arguments.
2020          */
2021         $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
2022
2023         ?>
2024                 <?php if ( comments_open( $post_id ) ) : ?>
2025                         <?php
2026                         /**
2027                          * Fires before the comment form.
2028                          *
2029                          * @since 3.0.0
2030                          */
2031                         do_action( 'comment_form_before' );
2032                         ?>
2033                         <div id="respond" class="comment-respond">
2034                                 <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>
2035                                 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
2036                                         <?php echo $args['must_log_in']; ?>
2037                                         <?php
2038                                         /**
2039                                          * Fires after the HTML-formatted 'must log in after' message in the comment form.
2040                                          *
2041                                          * @since 3.0.0
2042                                          */
2043                                         do_action( 'comment_form_must_log_in_after' );
2044                                         ?>
2045                                 <?php else : ?>
2046                                         <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' : ''; ?>>
2047                                                 <?php
2048                                                 /**
2049                                                  * Fires at the top of the comment form, inside the <form> tag.
2050                                                  *
2051                                                  * @since 3.0.0
2052                                                  */
2053                                                 do_action( 'comment_form_top' );
2054                                                 ?>
2055                                                 <?php if ( is_user_logged_in() ) : ?>
2056                                                         <?php
2057                                                         /**
2058                                                          * Filter the 'logged in' message for the comment form for display.
2059                                                          *
2060                                                          * @since 3.0.0
2061                                                          *
2062                                                          * @param string $args['logged_in_as'] The logged-in-as HTML-formatted message.
2063                                                          * @param array  $commenter            An array containing the comment author's username, email, and URL.
2064                                                          * @param string $user_identity        If the commenter is a registered user, the display name, blank otherwise.
2065                                                          */
2066                                                         echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
2067                                                         ?>
2068                                                         <?php
2069                                                         /**
2070                                                          * Fires after the is_user_logged_in() check in the comment form.
2071                                                          *
2072                                                          * @since 3.0.0
2073                                                          *
2074                                                          * @param array  $commenter     An array containing the comment author's username, email, and URL.
2075                                                          * @param string $user_identity If the commenter is a registered user, the display name, blank otherwise.
2076                                                          */
2077                                                         do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
2078                                                         ?>
2079                                                 <?php else : ?>
2080                                                         <?php echo $args['comment_notes_before']; ?>
2081                                                         <?php
2082                                                         /**
2083                                                          * Fires before the comment fields in the comment form.
2084                                                          *
2085                                                          * @since 3.0.0
2086                                                          */
2087                                                         do_action( 'comment_form_before_fields' );
2088                                                         foreach ( (array) $args['fields'] as $name => $field ) {
2089                                                                 /**
2090                                                                  * Filter a comment form field for display.
2091                                                                  *
2092                                                                  * The dynamic portion of the filter hook, $name, refers to the name
2093                                                                  * of the comment form field. Such as 'author', 'email', or 'url'.
2094                                                                  *
2095                                                                  * @since 3.0.0
2096                                                                  *
2097                                                                  * @param string $field The HTML-formatted output of the comment form field.
2098                                                                  */
2099                                                                 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
2100                                                         }
2101                                                         /**
2102                                                          * Fires after the comment fields in the comment form.
2103                                                          *
2104                                                          * @since 3.0.0
2105                                                          */
2106                                                         do_action( 'comment_form_after_fields' );
2107                                                         ?>
2108                                                 <?php endif; ?>
2109                                                 <?php
2110                                                 /**
2111                                                  * Filter the content of the comment textarea field for display.
2112                                                  *
2113                                                  * @since 3.0.0
2114                                                  *
2115                                                  * @param string $args['comment_field'] The content of the comment textarea field.
2116                                                  */
2117                                                 echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );
2118                                                 ?>
2119                                                 <?php echo $args['comment_notes_after']; ?>
2120                                                 <p class="form-submit">
2121                                                         <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
2122                                                         <?php comment_id_fields( $post_id ); ?>
2123                                                 </p>
2124                                                 <?php
2125                                                 /**
2126                                                  * Fires at the bottom of the comment form, inside the closing </form> tag.
2127                                                  *
2128                                                  * @since 1.5.0
2129                                                  *
2130                                                  * @param int $post_id The post ID.
2131                                                  */
2132                                                 do_action( 'comment_form', $post_id );
2133                                                 ?>
2134                                         </form>
2135                                 <?php endif; ?>
2136                         </div><!-- #respond -->
2137                         <?php
2138                         /**
2139                          * Fires after the comment form.
2140                          *
2141                          * @since 3.0.0
2142                          */
2143                         do_action( 'comment_form_after' );
2144                 else :
2145                         /**
2146                          * Fires after the comment form if comments are closed.
2147                          *
2148                          * @since 3.0.0
2149                          */
2150                         do_action( 'comment_form_comments_closed' );
2151                 endif;
2152 }