137 * enable anyone, including those that people don't want to get the email |
149 * 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. |
150 * address and use it for their own means good and bad. |
139 * |
151 * |
140 * @global object $comment The current Comment row object. |
152 * @global object $comment The current Comment row object. |
141 * |
153 * |
142 * @since 2.7 |
154 * @since 2.7.0 |
143 * |
155 * |
144 * @param string $linktext Optional. The text to display instead of the comment author's email address. Default empty. |
156 * @param string $linktext Optional. Text to display instead of the comment author's email address. |
145 * @param string $before Optional. The text or HTML to display before the email link. Default empty. |
157 * Default empty. |
146 * @param string $after Optional. The text or HTML to display after the email link. Default empty. |
158 * @param string $before Optional. Text or HTML to display before the email link. Default empty. |
|
159 * @param string $after Optional. Text or HTML to display after the email link. Default empty. |
147 */ |
160 */ |
148 function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) { |
161 function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) { |
149 global $comment; |
162 global $comment; |
|
163 |
150 /** |
164 /** |
151 * Filter the comment author's email for display. |
165 * Filter the comment author's email for display. |
152 * |
166 * |
153 * Care should be taken to protect the email address and assure that email |
167 * Care should be taken to protect the email address and assure that email |
154 * harvesters do not capture your commentors' email address. |
168 * harvesters do not capture your commenter's email address. |
155 * |
169 * |
156 * @since 1.2.1 |
170 * @since 1.2.0 |
157 * |
171 * @since 4.1.0 The `$comment` parameter was added. |
158 * @param string $comment->comment_author_email The comment author's email address. |
172 * |
159 */ |
173 * @param string $comment_author_email The comment author's email address. |
160 $email = apply_filters( 'comment_email', $comment->comment_author_email ); |
174 * @param object $comment The comment object. |
|
175 */ |
|
176 $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment ); |
161 if ((!empty($email)) && ($email != '@')) { |
177 if ((!empty($email)) && ($email != '@')) { |
162 $display = ($linktext != '') ? $linktext : $email; |
178 $display = ($linktext != '') ? $linktext : $email; |
163 $return = $before; |
179 $return = $before; |
164 $return .= "<a href='mailto:$email'>$display</a>"; |
180 $return .= "<a href='mailto:$email'>$display</a>"; |
165 $return .= $after; |
181 $return .= $after; |
190 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; |
207 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; |
191 |
208 |
192 /** |
209 /** |
193 * Filter the comment author's link for display. |
210 * Filter the comment author's link for display. |
194 * |
211 * |
195 * @since 1.5.2 |
212 * @since 1.5.0 |
196 * |
213 * @since 4.1.0 The `$author` and `$comment_ID` parameters were added. |
197 * @param string $return The HTML-formatted comment author link. Empty for an invalid URL. |
214 * |
198 */ |
215 * @param string $return The HTML-formatted comment author link. |
199 return apply_filters( 'get_comment_author_link', $return ); |
216 * Empty for an invalid URL. |
|
217 * @param string $author The comment author's username. |
|
218 * @param int $comment_ID The comment ID. |
|
219 */ |
|
220 return apply_filters( 'get_comment_author_link', $return, $author, $comment_ID ); |
200 } |
221 } |
201 |
222 |
202 /** |
223 /** |
203 * Display the html link to the url of the author of the current comment. |
224 * Display the html link to the url of the author of the current comment. |
204 * |
225 * |
205 * @since 0.71 |
226 * @since 0.71 |
|
227 * |
206 * @see get_comment_author_link() Echoes result |
228 * @see get_comment_author_link() Echoes result |
207 * |
229 * |
208 * @param int $comment_ID Optional. The ID of the comment for which to print the author's link. Default current comment. |
230 * @param int $comment_ID ID of the comment for which to print the author's |
|
231 * link. Default current comment. |
209 */ |
232 */ |
210 function comment_author_link( $comment_ID = 0 ) { |
233 function comment_author_link( $comment_ID = 0 ) { |
211 echo get_comment_author_link( $comment_ID ); |
234 echo get_comment_author_link( $comment_ID ); |
212 } |
235 } |
213 |
236 |
214 /** |
237 /** |
215 * Retrieve the IP address of the author of the current comment. |
238 * Retrieve the IP address of the author of the current comment. |
216 * |
239 * |
217 * @since 1.5.0 |
240 * @since 1.5.0 |
218 * |
241 * |
219 * @param int $comment_ID Optional. The ID of the comment for which to get the author's IP address. Default current comment. |
242 * @param int $comment_ID ID of the comment for which to get the author's IP |
220 * @return string The comment author's IP address. |
243 * address. Default current comment. |
|
244 * @return string Comment author's IP address. |
221 */ |
245 */ |
222 function get_comment_author_IP( $comment_ID = 0 ) { |
246 function get_comment_author_IP( $comment_ID = 0 ) { |
223 $comment = get_comment( $comment_ID ); |
247 $comment = get_comment( $comment_ID ); |
224 |
248 |
225 /** |
249 /** |
226 * Filter the comment author's returned IP address. |
250 * Filter the comment author's returned IP address. |
227 * |
251 * |
228 * @since 1.5.2 |
252 * @since 1.5.0 |
229 * |
253 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
230 * @param string $comment->comment_author_IP The comment author's IP address. |
254 * |
231 */ |
255 * @param string $comment_author_IP The comment author's IP address. |
232 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP ); |
256 * @param int $comment_ID The comment ID. |
|
257 * @param object $comment The comment object. |
|
258 */ |
|
259 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment_ID, $comment ); |
233 } |
260 } |
234 |
261 |
235 /** |
262 /** |
236 * Display the IP address of the author of the current comment. |
263 * Display the IP address of the author of the current comment. |
237 * |
264 * |
238 * @since 0.71 |
265 * @since 0.71 |
239 * |
266 * |
240 * @param int $comment_ID Optional. The ID of the comment for which to print the author's IP address. Default current comment. |
267 * @param int $comment_ID ID of the comment for which to print the author's IP |
|
268 * address. Default current comment. |
241 */ |
269 */ |
242 function comment_author_IP( $comment_ID = 0 ) { |
270 function comment_author_IP( $comment_ID = 0 ) { |
243 echo get_comment_author_IP( $comment_ID ); |
271 echo get_comment_author_IP( $comment_ID ); |
244 } |
272 } |
245 |
273 |
246 /** |
274 /** |
247 * Retrieve the url of the author of the current comment. |
275 * Retrieve the url of the author of the current comment. |
248 * |
276 * |
249 * @since 1.5.0 |
277 * @since 1.5.0 |
250 * |
278 * |
251 * @param int $comment_ID Optional. The ID of the comment for which to get the author's URL. Default current comment. |
279 * @param int $comment_ID ID of the comment for which to get the author's URL. |
|
280 * Default current comment. |
252 * @return string |
281 * @return string |
253 */ |
282 */ |
254 function get_comment_author_url( $comment_ID = 0 ) { |
283 function get_comment_author_url( $comment_ID = 0 ) { |
255 $comment = get_comment( $comment_ID ); |
284 $comment = get_comment( $comment_ID ); |
256 $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url; |
285 $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url; |
257 $url = esc_url( $url, array('http', 'https') ); |
286 $url = esc_url( $url, array('http', 'https') ); |
258 return apply_filters('get_comment_author_url', $url); |
287 |
|
288 /** |
|
289 * Filter the comment author's URL. |
|
290 * |
|
291 * @since 1.5.0 |
|
292 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
|
293 * |
|
294 * @param string $url The comment author's URL. |
|
295 * @param int $comment_ID The comment ID. |
|
296 * @param object $comment The comment object. |
|
297 */ |
|
298 return apply_filters( 'get_comment_author_url', $url, $comment_ID, $comment ); |
259 } |
299 } |
260 |
300 |
261 /** |
301 /** |
262 * Display the url of the author of the current comment. |
302 * Display the url of the author of the current comment. |
263 * |
303 * |
264 * @since 0.71 |
304 * @since 0.71 |
265 * |
305 * |
266 * @param int $comment_ID Optional. The ID of the comment for which to print the author's URL. Default current comment. |
306 * @param int $comment_ID ID of the comment for which to print the author's URL. |
|
307 * Default current comment. |
267 */ |
308 */ |
268 function comment_author_url( $comment_ID = 0 ) { |
309 function comment_author_url( $comment_ID = 0 ) { |
269 $author_url = get_comment_author_url( $comment_ID ); |
310 $author_url = get_comment_author_url( $comment_ID ); |
|
311 |
270 /** |
312 /** |
271 * Filter the comment author's URL for display. |
313 * Filter the comment author's URL for display. |
272 * |
314 * |
273 * @since 1.2.1 |
315 * @since 1.2.0 |
|
316 * @since 4.1.0 The `$comment_ID` parameter was added. |
274 * |
317 * |
275 * @param string $author_url The comment author's URL. |
318 * @param string $author_url The comment author's URL. |
276 */ |
319 * @param int $comment_ID The comment ID. |
277 echo apply_filters( 'comment_url', $author_url ); |
320 */ |
|
321 echo apply_filters( 'comment_url', $author_url, $comment_ID ); |
278 } |
322 } |
279 |
323 |
280 /** |
324 /** |
281 * Retrieves the HTML link of the url of the author of the current comment. |
325 * Retrieves the HTML link of the url of the author of the current comment. |
282 * |
326 * |
287 * Encapsulate the HTML link between the $before and $after. So it will appear |
331 * Encapsulate the HTML link between the $before and $after. So it will appear |
288 * in the order of $before, link, and finally $after. |
332 * in the order of $before, link, and finally $after. |
289 * |
333 * |
290 * @since 1.5.0 |
334 * @since 1.5.0 |
291 * |
335 * |
292 * @param string $linktext Optional. The text to display instead of the comment author's email address. Default empty. |
336 * @param string $linktext Optional. The text to display instead of the comment |
293 * @param string $before Optional. The text or HTML to display before the email link. Default empty. |
337 * author's email address. Default empty. |
294 * @param string $after Optional. The text or HTML to display after the email link. Default empty. |
338 * @param string $before Optional. The text or HTML to display before the email link. |
|
339 * Default empty. |
|
340 * @param string $after Optional. The text or HTML to display after the email link. |
|
341 * Default empty. |
295 * @return string The HTML link between the $before and $after parameters. |
342 * @return string The HTML link between the $before and $after parameters. |
296 */ |
343 */ |
297 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
344 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
298 $url = get_comment_author_url(); |
345 $url = get_comment_author_url(); |
299 $display = ($linktext != '') ? $linktext : $url; |
346 $display = ($linktext != '') ? $linktext : $url; |
300 $display = str_replace( 'http://www.', '', $display ); |
347 $display = str_replace( 'http://www.', '', $display ); |
301 $display = str_replace( 'http://', '', $display ); |
348 $display = str_replace( 'http://', '', $display ); |
302 if ( '/' == substr($display, -1) ) |
349 |
|
350 if ( '/' == substr($display, -1) ) { |
303 $display = substr($display, 0, -1); |
351 $display = substr($display, 0, -1); |
|
352 } |
|
353 |
304 $return = "$before<a href='$url' rel='external'>$display</a>$after"; |
354 $return = "$before<a href='$url' rel='external'>$display</a>$after"; |
305 |
355 |
306 /** |
356 /** |
307 * Filter the comment author's returned URL link. |
357 * Filter the comment author's returned URL link. |
308 * |
358 * |
309 * @since 1.5.2 |
359 * @since 1.5.0 |
310 * |
360 * |
311 * @param string $return The HTML-formatted comment author URL link. |
361 * @param string $return The HTML-formatted comment author URL link. |
312 */ |
362 */ |
313 return apply_filters( 'get_comment_author_url_link', $return ); |
363 return apply_filters( 'get_comment_author_url_link', $return ); |
314 } |
364 } |
316 /** |
366 /** |
317 * Displays the HTML link of the url of the author of the current comment. |
367 * Displays the HTML link of the url of the author of the current comment. |
318 * |
368 * |
319 * @since 0.71 |
369 * @since 0.71 |
320 * |
370 * |
321 * @param string $linktext Optional. The text to display instead of the comment author's email address. Default empty. |
371 * @param string $linktext Optional. Text to display instead of the comment author's |
322 * @param string $before Optional. The text or HTML to display before the email link. Default empty. |
372 * email address. Default empty. |
323 * @param string $after Optional. The text or HTML to display after the email link. Default empty. |
373 * @param string $before Optional. Text or HTML to display before the email link. |
|
374 * Default empty. |
|
375 * @param string $after Optional. Text or HTML to display after the email link. |
|
376 * Default empty. |
324 */ |
377 */ |
325 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
378 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
326 echo get_comment_author_url_link( $linktext, $before, $after ); |
379 echo get_comment_author_url_link( $linktext, $before, $after ); |
327 } |
380 } |
328 |
381 |
329 /** |
382 /** |
330 * Generates semantic classes for each comment element |
383 * Generates semantic classes for each comment element. |
331 * |
384 * |
332 * @since 2.7.0 |
385 * @since 2.7.0 |
333 * |
386 * |
334 * @param string|array $class Optional. One or more classes to add to the class list. Default empty. |
387 * @param string|array $class Optional. One or more classes to add to the class list. |
335 * @param int $comment_id Optional. Comment ID. Default current comment. |
388 * Default empty. |
336 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post. |
389 * @param int $comment_id Comment ID. Default current comment. |
337 * @param bool $echo Optional. Whether comment_class should echo or return. Default true. |
390 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. |
|
391 * @param bool $echo Optional. Whether to cho or return the output. |
|
392 * Default true. |
338 */ |
393 */ |
339 function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) { |
394 function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) { |
340 // Separates classes with a single space, collates classes for comment DIV |
395 // Separates classes with a single space, collates classes for comment DIV |
341 $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"'; |
396 $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"'; |
342 if ( $echo) |
397 if ( $echo) |
420 * @since 2.7.0 |
475 * @since 2.7.0 |
421 * |
476 * |
422 * @param array $classes An array of comment classes. |
477 * @param array $classes An array of comment classes. |
423 * @param string $class A comma-separated list of additional classes added to the list. |
478 * @param string $class A comma-separated list of additional classes added to the list. |
424 * @param int $comment_id The comment id. |
479 * @param int $comment_id The comment id. |
|
480 * @param object $comment The comment |
425 * @param int|WP_Post $post_id The post ID or WP_Post object. |
481 * @param int|WP_Post $post_id The post ID or WP_Post object. |
426 */ |
482 */ |
427 return apply_filters( 'comment_class', $classes, $class, $comment_id, $post_id ); |
483 return apply_filters( 'comment_class', $classes, $class, $comment_id, $comment, $post_id ); |
428 } |
484 } |
429 |
485 |
430 /** |
486 /** |
431 * Retrieve the comment date of the current comment. |
487 * Retrieve the comment date of the current comment. |
432 * |
488 * |
433 * @since 1.5.0 |
489 * @since 1.5.0 |
434 * |
490 * |
435 * @param string $d Optional. The format of the date. Default user's setting. |
491 * @param string $d Optional. The format of the date. Default user's setting. |
436 * @param int $comment_ID Optional. The ID of the comment for which to get the date. Default current comment. |
492 * @param int $comment_ID ID of the comment for which to get the date. Default current comment. |
437 * @return string The comment's date. |
493 * @return string The comment's date. |
438 */ |
494 */ |
439 function get_comment_date( $d = '', $comment_ID = 0 ) { |
495 function get_comment_date( $d = '', $comment_ID = 0 ) { |
440 $comment = get_comment( $comment_ID ); |
496 $comment = get_comment( $comment_ID ); |
441 if ( '' == $d ) |
497 if ( '' == $d ) |
472 * If the word count is less than 20, then no truncating is done and no '…' |
529 * If the word count is less than 20, then no truncating is done and no '…' |
473 * will appear. |
530 * will appear. |
474 * |
531 * |
475 * @since 1.5.0 |
532 * @since 1.5.0 |
476 * |
533 * |
477 * @param int $comment_ID Optional. The ID of the comment for which to get the excerpt. Default current comment. |
534 * @param int $comment_ID ID of the comment for which to get the excerpt. |
|
535 * Default current comment. |
478 * @return string The maybe truncated comment with 20 words or less. |
536 * @return string The maybe truncated comment with 20 words or less. |
479 */ |
537 */ |
480 function get_comment_excerpt( $comment_ID = 0 ) { |
538 function get_comment_excerpt( $comment_ID = 0 ) { |
481 $comment = get_comment( $comment_ID ); |
539 $comment = get_comment( $comment_ID ); |
482 $comment_text = strip_tags($comment->comment_content); |
540 $comment_text = strip_tags($comment->comment_content); |
483 $blah = explode(' ', $comment_text); |
541 $blah = explode(' ', $comment_text); |
|
542 |
484 if (count($blah) > 20) { |
543 if (count($blah) > 20) { |
485 $k = 20; |
544 $k = 20; |
486 $use_dotdotdot = 1; |
545 $use_dotdotdot = 1; |
487 } else { |
546 } else { |
488 $k = count($blah); |
547 $k = count($blah); |
489 $use_dotdotdot = 0; |
548 $use_dotdotdot = 0; |
490 } |
549 } |
|
550 |
491 $excerpt = ''; |
551 $excerpt = ''; |
492 for ($i=0; $i<$k; $i++) { |
552 for ($i=0; $i<$k; $i++) { |
493 $excerpt .= $blah[$i] . ' '; |
553 $excerpt .= $blah[$i] . ' '; |
494 } |
554 } |
495 $excerpt .= ($use_dotdotdot) ? '…' : ''; |
555 $excerpt .= ($use_dotdotdot) ? '…' : ''; |
496 return apply_filters('get_comment_excerpt', $excerpt); |
556 |
|
557 /** |
|
558 * Filter the retrieved comment excerpt. |
|
559 * |
|
560 * @since 1.5.0 |
|
561 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
|
562 * |
|
563 * @param string $excerpt The comment excerpt text. |
|
564 * @param int $comment_ID The comment ID. |
|
565 * @param object $comment The comment object. |
|
566 */ |
|
567 return apply_filters( 'get_comment_excerpt', $excerpt, $comment_ID, $comment ); |
497 } |
568 } |
498 |
569 |
499 /** |
570 /** |
500 * Display the excerpt of the current comment. |
571 * Display the excerpt of the current comment. |
501 * |
572 * |
502 * @since 1.2.0 |
573 * @since 1.2.0 |
503 * |
574 * |
504 * @param int $comment_ID Optional. The ID of the comment for which to print the excerpt. Default current comment. |
575 * @param int $comment_ID ID of the comment for which to print the excerpt. |
|
576 * Default current comment. |
505 */ |
577 */ |
506 function comment_excerpt( $comment_ID = 0 ) { |
578 function comment_excerpt( $comment_ID = 0 ) { |
507 $comment_excerpt = get_comment_excerpt($comment_ID); |
579 $comment_excerpt = get_comment_excerpt($comment_ID); |
|
580 |
508 /** |
581 /** |
509 * Filter the comment excerpt for display. |
582 * Filter the comment excerpt for display. |
510 * |
583 * |
511 * @since 1.2.1 |
584 * @since 1.2.0 |
|
585 * @since 4.1.0 The `$comment_ID` parameter was added. |
512 * |
586 * |
513 * @param string $comment_excerpt The comment excerpt text. |
587 * @param string $comment_excerpt The comment excerpt text. |
514 */ |
588 * @param int $comment_ID The comment ID. |
515 echo apply_filters( 'comment_excerpt', $comment_excerpt ); |
589 */ |
|
590 echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment_ID ); |
516 } |
591 } |
517 |
592 |
518 /** |
593 /** |
519 * Retrieve the comment id of the current comment. |
594 * Retrieve the comment id of the current comment. |
520 * |
595 * |
591 /** |
669 /** |
592 * Filter the returned single comment permalink. |
670 * Filter the returned single comment permalink. |
593 * |
671 * |
594 * @since 2.8.0 |
672 * @since 2.8.0 |
595 * |
673 * |
|
674 * @see get_page_of_comment() |
|
675 * |
596 * @param string $link The comment permalink with '#comment-$id' appended. |
676 * @param string $link The comment permalink with '#comment-$id' appended. |
597 * @param object $comment The current comment object. |
677 * @param object $comment The current comment object. |
598 * @param array $args An array of arguments to override the defaults. @see get_page_of_comment() |
678 * @param array $args An array of arguments to override the defaults. |
599 */ |
679 */ |
600 return apply_filters( 'get_comment_link', $link, $comment, $args ); |
680 return apply_filters( 'get_comment_link', $link, $comment, $args ); |
601 } |
681 } |
602 |
682 |
603 /** |
683 /** |
604 * Retrieve the link to the current post comments. |
684 * Retrieve the link to the current post comments. |
605 * |
685 * |
606 * @since 1.5.0 |
686 * @since 1.5.0 |
607 * |
687 * |
608 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post. |
688 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
609 * @return string The link to the comments. |
689 * @return string The link to the comments. |
610 */ |
690 */ |
611 function get_comments_link( $post_id = 0 ) { |
691 function get_comments_link( $post_id = 0 ) { |
612 $comments_link = get_permalink( $post_id ) . '#comments'; |
692 $comments_link = get_permalink( $post_id ) . '#comments'; |
613 /** |
693 /** |
614 * Filter the returned post comments permalink. |
694 * Filter the returned post comments permalink. |
615 * |
695 * |
616 * @since |
696 * @since 3.6.0 |
617 * |
697 * |
618 * @param string $comments_link The post comments permalink with '#comments' appended. |
698 * @param string $comments_link Post comments permalink with '#comments' appended. |
619 * @param int|WP_Post $post_id The post ID or WP_Post object. |
699 * @param int|WP_Post $post_id Post ID or WP_Post object. |
620 */ |
700 */ |
621 return apply_filters( 'get_comments_link', $comments_link, $post_id ); |
701 return apply_filters( 'get_comments_link', $comments_link, $post_id ); |
622 } |
702 } |
623 |
703 |
624 /** |
704 /** |
625 * Display the link to the current post comments. |
705 * Display the link to the current post comments. |
626 * |
706 * |
627 * @since 0.71 |
707 * @since 0.71 |
628 * |
708 * |
629 * @param string $deprecated Not Used. |
709 * @param string $deprecated Not Used. |
630 * @param bool $deprecated_2 Not Used. |
710 * @param string $deprecated_2 Not Used. |
631 */ |
711 */ |
632 function comments_link( $deprecated = '', $deprecated_2 = '' ) { |
712 function comments_link( $deprecated = '', $deprecated_2 = '' ) { |
633 if ( !empty( $deprecated ) ) |
713 if ( !empty( $deprecated ) ) |
634 _deprecated_argument( __FUNCTION__, '0.72' ); |
714 _deprecated_argument( __FUNCTION__, '0.72' ); |
635 if ( !empty( $deprecated_2 ) ) |
715 if ( !empty( $deprecated_2 ) ) |
677 * @param string $one Optional. Text for one comment. Default false. |
755 * @param string $one Optional. Text for one comment. Default false. |
678 * @param string $more Optional. Text for more than one comment. Default false. |
756 * @param string $more Optional. Text for more than one comment. Default false. |
679 * @param string $deprecated Not used. |
757 * @param string $deprecated Not used. |
680 */ |
758 */ |
681 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { |
759 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { |
682 if ( !empty( $deprecated ) ) |
760 if ( ! empty( $deprecated ) ) { |
683 _deprecated_argument( __FUNCTION__, '1.3' ); |
761 _deprecated_argument( __FUNCTION__, '1.3' ); |
684 |
762 } |
|
763 echo get_comments_number_text( $zero, $one, $more ); |
|
764 } |
|
765 |
|
766 /** |
|
767 * Display the language string for the number of comments the current post has. |
|
768 * |
|
769 * @since 4.0.0 |
|
770 * |
|
771 * @param string $zero Optional. Text for no comments. Default false. |
|
772 * @param string $one Optional. Text for one comment. Default false. |
|
773 * @param string $more Optional. Text for more than one comment. Default false. |
|
774 */ |
|
775 function get_comments_number_text( $zero = false, $one = false, $more = false ) { |
685 $number = get_comments_number(); |
776 $number = get_comments_number(); |
686 |
777 |
687 if ( $number > 1 ) |
778 if ( $number > 1 ) { |
688 $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more); |
779 $output = str_replace( '%', number_format_i18n( $number ), ( false === $more ) ? __( '% Comments' ) : $more ); |
689 elseif ( $number == 0 ) |
780 } elseif ( $number == 0 ) { |
690 $output = ( false === $zero ) ? __('No Comments') : $zero; |
781 $output = ( false === $zero ) ? __( 'No Comments' ) : $zero; |
691 else // must be one |
782 } else { // must be one |
692 $output = ( false === $one ) ? __('1 Comment') : $one; |
783 $output = ( false === $one ) ? __( '1 Comment' ) : $one; |
693 |
784 } |
694 /** |
785 /** |
695 * Filter the comments count for display. |
786 * Filter the comments count for display. |
696 * |
787 * |
697 * @since 1.5.2 |
788 * @since 1.5.0 |
698 * |
789 * |
699 * @param string $output A translatable string formatted based on whether the count is equal to 0, 1, or 1+. @see _n() |
790 * @see _n() |
|
791 * |
|
792 * @param string $output A translatable string formatted based on whether the count |
|
793 * is equal to 0, 1, or 1+. |
700 * @param int $number The number of post comments. |
794 * @param int $number The number of post comments. |
701 */ |
795 */ |
702 echo apply_filters( 'comments_number', $output, $number ); |
796 return apply_filters( 'comments_number', $output, $number ); |
703 } |
797 } |
704 |
798 |
705 /** |
799 /** |
706 * Retrieve the text of the current comment. |
800 * Retrieve the text of the current comment. |
707 * |
801 * |
708 * @since 1.5.0 |
802 * @since 1.5.0 |
709 * |
803 * |
710 * @param int $comment_ID Optional. The ID of the comment for which to get the text. Default current comment. |
804 * @see Walker_Comment::comment() |
711 * @param array $args Optional. An array of arguments. @see Walker_Comment::comment() |
805 * |
|
806 * @param int $comment_ID ID of the comment for which to get the text. Default current comment. |
|
807 * @param array $args Optional. An array of arguments. Default empty. |
712 * @return string The comment content. |
808 * @return string The comment content. |
713 */ |
809 */ |
714 function get_comment_text( $comment_ID = 0, $args = array() ) { |
810 function get_comment_text( $comment_ID = 0, $args = array() ) { |
715 $comment = get_comment( $comment_ID ); |
811 $comment = get_comment( $comment_ID ); |
716 |
812 |
717 /** |
813 /** |
718 * Filter the text of a comment. |
814 * Filter the text of a comment. |
719 * |
815 * |
720 * @since 1.5.2 |
816 * @since 1.5.0 |
721 * |
817 * |
722 * @param string $comment->comment_content The text of the comment. |
818 * @see Walker_Comment::comment() |
723 * @param object $comment The comment object. |
819 * |
724 * @param array $args An array of arguments. @see Walker_Comment::comment() |
820 * @param string $comment_content Text of the comment. |
|
821 * @param object $comment The comment object. |
|
822 * @param array $args An array of arguments. |
725 */ |
823 */ |
726 return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args ); |
824 return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args ); |
727 } |
825 } |
728 |
826 |
729 /** |
827 /** |
730 * Display the text of the current comment. |
828 * Display the text of the current comment. |
731 * |
829 * |
732 * @since 0.71 |
830 * @since 0.71 |
733 * |
831 * |
734 * @param int $comment_ID Optional. The ID of the comment for which to print the text. |
832 * @see Walker_Comment::comment() |
735 * Default 0. |
833 * |
736 * @param array $args Optional. An array of arguments. @see Walker_Comment::comment() |
834 * @param int $comment_ID ID of the comment for which to print the text. Default 0. |
737 * Default empty array. |
835 * @param array $args Optional. An array of arguments. Default empty array. Default empty. |
738 */ |
836 */ |
739 function comment_text( $comment_ID = 0, $args = array() ) { |
837 function comment_text( $comment_ID = 0, $args = array() ) { |
740 $comment = get_comment( $comment_ID ); |
838 $comment = get_comment( $comment_ID ); |
741 |
839 |
742 $comment_text = get_comment_text( $comment_ID , $args ); |
840 $comment_text = get_comment_text( $comment_ID , $args ); |
743 /** |
841 /** |
744 * Filter the text of a comment to be displayed. |
842 * Filter the text of a comment to be displayed. |
745 * |
843 * |
746 * @since 1.2.1 |
844 * @since 1.2.0 |
747 * |
845 * |
748 * @param string $comment_text The text of the current comment. |
846 * @see Walker_Comment::comment() |
|
847 * |
|
848 * @param string $comment_text Text of the current comment. |
749 * @param object $comment The comment object. |
849 * @param object $comment The comment object. |
750 * @param array $args An array of arguments. @see Walker_Comment::comment() |
850 * @param array $args An array of arguments. |
751 */ |
851 */ |
752 echo apply_filters( 'comment_text', $comment_text, $comment, $args ); |
852 echo apply_filters( 'comment_text', $comment_text, $comment, $args ); |
753 } |
853 } |
754 |
854 |
755 /** |
855 /** |
797 /** |
899 /** |
798 * Retrieve the comment type of the current comment. |
900 * Retrieve the comment type of the current comment. |
799 * |
901 * |
800 * @since 1.5.0 |
902 * @since 1.5.0 |
801 * |
903 * |
802 * @param int $comment_ID Optional. The ID of the comment for which to get the type. Default current comment. |
904 * @param int $comment_ID ID of the comment for which to get the type. Default current comment. |
803 * @return string The comment type |
905 * @return string The comment type. |
804 */ |
906 */ |
805 function get_comment_type( $comment_ID = 0 ) { |
907 function get_comment_type( $comment_ID = 0 ) { |
806 $comment = get_comment( $comment_ID ); |
908 $comment = get_comment( $comment_ID ); |
807 if ( '' == $comment->comment_type ) |
909 if ( '' == $comment->comment_type ) |
808 $comment->comment_type = 'comment'; |
910 $comment->comment_type = 'comment'; |
809 |
911 |
810 /** |
912 /** |
811 * Filter the returned comment type. |
913 * Filter the returned comment type. |
812 * |
914 * |
813 * @since 1.5.2 |
915 * @since 1.5.0 |
814 * |
916 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
815 * @param string $comment->comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'. |
917 * |
816 */ |
918 * @param string $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'. |
817 return apply_filters( 'get_comment_type', $comment->comment_type ); |
919 * @param int $comment_ID The comment ID. |
|
920 * @param object $comment The comment object. |
|
921 */ |
|
922 return apply_filters( 'get_comment_type', $comment->comment_type, $comment_ID, $comment ); |
818 } |
923 } |
819 |
924 |
820 /** |
925 /** |
821 * Display the comment type of the current comment. |
926 * Display the comment type of the current comment. |
822 * |
927 * |
823 * @since 0.71 |
928 * @since 0.71 |
824 * |
929 * |
825 * @param string $commenttxt Optional. The string to display for comment type. Default false. |
930 * @param string $commenttxt Optional. String to display for comment type. Default false. |
826 * @param string $trackbacktxt Optional. The string to display for trackback type. Default false. |
931 * @param string $trackbacktxt Optional. String to display for trackback type. Default false. |
827 * @param string $pingbacktxt Optional. The string to display for pingback type. Default false. |
932 * @param string $pingbacktxt Optional. String to display for pingback type. Default false. |
828 */ |
933 */ |
829 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) { |
934 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) { |
830 if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' ); |
935 if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' ); |
831 if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' ); |
936 if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' ); |
832 if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' ); |
937 if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' ); |
1016 if ( empty($file) ) |
1134 if ( empty($file) ) |
1017 $file = '/comments.php'; |
1135 $file = '/comments.php'; |
1018 |
1136 |
1019 $req = get_option('require_name_email'); |
1137 $req = get_option('require_name_email'); |
1020 |
1138 |
1021 /** |
1139 /* |
1022 * Comment author information fetched from the comment cookies. |
1140 * Comment author information fetched from the comment cookies. |
1023 * |
|
1024 * @uses wp_get_current_commenter() |
|
1025 */ |
1141 */ |
1026 $commenter = wp_get_current_commenter(); |
1142 $commenter = wp_get_current_commenter(); |
1027 |
1143 |
1028 /** |
1144 /* |
1029 * The name of the current comment author escaped for use in attributes. |
1145 * The name of the current comment author escaped for use in attributes. |
1030 */ |
1146 * Escaped by sanitize_comment_cookies(). |
1031 $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() |
1147 */ |
1032 |
1148 $comment_author = $commenter['comment_author']; |
1033 /** |
1149 |
|
1150 /* |
1034 * The email address of the current comment author escaped for use in attributes. |
1151 * The email address of the current comment author escaped for use in attributes. |
1035 */ |
1152 * Escaped by sanitize_comment_cookies(). |
1036 $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() |
1153 */ |
1037 |
1154 $comment_author_email = $commenter['comment_author_email']; |
1038 /** |
1155 |
|
1156 /* |
1039 * The url of the current comment author escaped for use in attributes. |
1157 * The url of the current comment author escaped for use in attributes. |
1040 */ |
1158 */ |
1041 $comment_author_url = esc_url($commenter['comment_author_url']); |
1159 $comment_author_url = esc_url($commenter['comment_author_url']); |
1042 |
1160 |
1043 /** @todo Use API instead of SELECTs. */ |
1161 $comment_args = array( |
1044 if ( $user_ID) { |
1162 'order' => 'ASC', |
1045 $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, $user_ID)); |
1163 'orderby' => 'comment_date_gmt', |
1046 } else if ( empty($comment_author) ) { |
1164 'status' => 'approve', |
1047 $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') ); |
1165 'post_id' => $post->ID, |
1048 } else { |
1166 ); |
1049 $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email)); |
1167 |
1050 } |
1168 if ( $user_ID ) { |
1051 |
1169 $comment_args['include_unapproved'] = array( $user_ID ); |
1052 // keep $comments for legacy's sake |
1170 } elseif ( ! empty( $comment_author_email ) ) { |
|
1171 $comment_args['include_unapproved'] = array( $comment_author_email ); |
|
1172 } |
|
1173 |
|
1174 $comments = get_comments( $comment_args ); |
|
1175 |
1053 /** |
1176 /** |
1054 * Filter the comments array. |
1177 * Filter the comments array. |
1055 * |
1178 * |
1056 * @since 2.1.0 |
1179 * @since 2.1.0 |
1057 * |
1180 * |
1058 * @param array $comments The array of comments supplied to the comments template. |
1181 * @param array $comments Array of comments supplied to the comments template. |
1059 * @param int $post->ID The post ID. |
1182 * @param int $post_ID Post ID. |
1060 */ |
1183 */ |
1061 $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); |
1184 $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); |
1062 $comments = &$wp_query->comments; |
1185 $comments = &$wp_query->comments; |
1063 $wp_query->comment_count = count($wp_query->comments); |
1186 $wp_query->comment_count = count($wp_query->comments); |
1064 update_comment_cache($wp_query->comments); |
1187 update_comment_cache($wp_query->comments); |
1127 } |
1250 } |
1128 |
1251 |
1129 /** |
1252 /** |
1130 * Displays the link to the comments popup window for the current post ID. |
1253 * Displays the link to the comments popup window for the current post ID. |
1131 * |
1254 * |
1132 * Is not meant to be displayed on single posts and pages. Should be used on the |
1255 * Is not meant to be displayed on single posts and pages. Should be used |
1133 * lists of posts |
1256 * on the lists of posts |
1134 * |
1257 * |
1135 * @global string $wpcommentspopupfile The URL to use for the popup window. |
1258 * @global string $wpcommentspopupfile The URL to use for the popup window. |
1136 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called. |
1259 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called. |
1137 * |
1260 * |
1138 * @since 0.71 |
1261 * @since 0.71 |
1139 * |
1262 * |
1140 * @param string $zero Optional. The string to display when no comments. Default false. |
1263 * @param string $zero Optional. String to display when no comments. Default false. |
1141 * @param string $one Optional. The string to display when only one comment is available. Default false. |
1264 * @param string $one Optional. String to display when only one comment is available. |
1142 * @param string $more Optional. The string to display when there are more than one comment. Default false. |
1265 * Default false. |
1143 * @param string $css_class Optional. The CSS class to use for comments. Default empty. |
1266 * @param string $more Optional. String to display when there are more than one comment. |
1144 * @param string $none Optional. The string to display when comments have been turned off. Default false. |
1267 * Default false. |
|
1268 * @param string $css_class Optional. CSS class to use for comments. Default empty. |
|
1269 * @param string $none Optional. String to display when comments have been turned off. |
|
1270 * Default false. |
1145 * @return null Returns null on single posts and pages. |
1271 * @return null Returns null on single posts and pages. |
1146 */ |
1272 */ |
1147 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { |
1273 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { |
1148 global $wpcommentspopupfile, $wpcommentsjavascript; |
1274 global $wpcommentspopupfile, $wpcommentsjavascript; |
1149 |
1275 |
1150 $id = get_the_ID(); |
1276 $id = get_the_ID(); |
1151 |
1277 $title = get_the_title(); |
1152 if ( false === $zero ) $zero = __( 'No Comments' ); |
|
1153 if ( false === $one ) $one = __( '1 Comment' ); |
|
1154 if ( false === $more ) $more = __( '% Comments' ); |
|
1155 if ( false === $none ) $none = __( 'Comments Off' ); |
|
1156 |
|
1157 $number = get_comments_number( $id ); |
1278 $number = get_comments_number( $id ); |
|
1279 |
|
1280 if ( false === $zero ) { |
|
1281 /* translators: %s: post title */ |
|
1282 $zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $title ); |
|
1283 } |
|
1284 |
|
1285 if ( false === $one ) { |
|
1286 /* translators: %s: post title */ |
|
1287 $one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $title ); |
|
1288 } |
|
1289 |
|
1290 if ( false === $more ) { |
|
1291 /* translators: 1: Number of comments 2: post title */ |
|
1292 $more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number ); |
|
1293 $more = sprintf( $more, number_format_i18n( $number ), $title ); |
|
1294 } |
|
1295 |
|
1296 if ( false === $none ) { |
|
1297 /* translators: %s: post title */ |
|
1298 $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title ); |
|
1299 } |
1158 |
1300 |
1159 if ( 0 == $number && !comments_open() && !pings_open() ) { |
1301 if ( 0 == $number && !comments_open() && !pings_open() ) { |
1160 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>'; |
1302 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>'; |
1161 return; |
1303 return; |
1162 } |
1304 } |
1208 * @since 2.7.0 |
1349 * @since 2.7.0 |
1209 * |
1350 * |
1210 * @param array $args { |
1351 * @param array $args { |
1211 * Optional. Override default arguments. |
1352 * Optional. Override default arguments. |
1212 * |
1353 * |
1213 * @type string 'add_below' The first part of the selector used to identify the comment to respond below. The resulting |
1354 * @type string $add_below The first part of the selector used to identify the comment to respond below. |
1214 * value is passed as the first parameter to addComment.moveForm(), concatenated |
1355 * The resulting value is passed as the first parameter to addComment.moveForm(), |
1215 * as $add_below-$comment->comment_ID. Default 'comment'. |
1356 * concatenated as $add_below-$comment->comment_ID. Default 'comment'. |
1216 * @type string 'respond_id' The selector identifying the responding comment. Passed as the third parameter to addComment.moveForm(), |
1357 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter |
1217 * and appended to the link URL as a hash value. Default 'respond'. |
1358 * to addComment.moveForm(), and appended to the link URL as a hash value. |
1218 * @type string 'reply_text' The text of the Reply link. Default 'Reply'. |
1359 * Default 'respond'. |
1219 * @type string 'login_text' The text of the link to reply if logged out. Default 'Log in to Reply'. |
1360 * @type string $reply_text The text of the Reply link. Default 'Reply'. |
1220 * @type int 'depth' The depth of the new comment. Must be greater than 0 and less than the value of the 'thread_comments_depth' |
1361 * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'. |
1221 * option set in Settings > Discussion. |
1362 * @type int $depth' The depth of the new comment. Must be greater than 0 and less than the value |
1222 * Default 0. |
1363 * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0. |
1223 * @type string 'before' The text or HTML to add before the reply link. Default empty. |
1364 * @type string $before The text or HTML to add before the reply link. Default empty. |
1224 * @type string 'after' The text or HTML to add after the reply link. Default empty. |
1365 * @type string $after The text or HTML to add after the reply link. Default empty. |
1225 * } |
1366 * } |
1226 * @param int $comment Optional. Comment being replied to. Default current comment. |
1367 * @param int $comment Comment being replied to. Default current comment. |
1227 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post. |
1368 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on. |
1228 * @return mixed Link to show comment form, if successful. False, if comments are closed. |
1369 * Default current post. |
1229 */ |
1370 * @return null|false|string Link to show comment form, if successful. False, if comments are closed. |
1230 function get_comment_reply_link($args = array(), $comment = null, $post = null) { |
1371 */ |
|
1372 function get_comment_reply_link( $args = array(), $comment = null, $post = null ) { |
1231 |
1373 |
1232 $defaults = array( |
1374 $defaults = array( |
1233 'add_below' => 'comment', |
1375 'add_below' => 'comment', |
1234 'respond_id' => 'respond', |
1376 'respond_id' => 'respond', |
1235 'reply_text' => __('Reply'), |
1377 'reply_text' => __( 'Reply' ), |
1236 'login_text' => __('Log in to Reply'), |
1378 'reply_to_text' => __( 'Reply to %s' ), |
1237 'depth' => 0, |
1379 'login_text' => __( 'Log in to Reply' ), |
1238 'before' => '', |
1380 'depth' => 0, |
1239 'after' => '' |
1381 'before' => '', |
|
1382 'after' => '' |
1240 ); |
1383 ); |
1241 |
1384 |
1242 $args = wp_parse_args($args, $defaults); |
1385 $args = wp_parse_args( $args, $defaults ); |
1243 |
1386 |
1244 if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) |
1387 if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) { |
1245 return; |
1388 return; |
1246 |
1389 } |
1247 extract($args, EXTR_SKIP); |
1390 |
1248 |
1391 $comment = get_comment( $comment ); |
1249 $comment = get_comment($comment); |
1392 |
1250 if ( empty($post) ) |
1393 if ( empty( $post ) ) { |
1251 $post = $comment->comment_post_ID; |
1394 $post = $comment->comment_post_ID; |
1252 $post = get_post($post); |
1395 } |
1253 |
1396 |
1254 if ( !comments_open($post->ID) ) |
1397 $post = get_post( $post ); |
|
1398 |
|
1399 if ( ! comments_open( $post->ID ) ) { |
1255 return false; |
1400 return false; |
1256 |
1401 } |
1257 $link = ''; |
1402 |
1258 |
1403 /** |
1259 if ( get_option('comment_registration') && ! is_user_logged_in() ) |
1404 * Filter the comment reply link arguments. |
1260 $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>'; |
1405 * |
1261 else |
1406 * @since 4.1.0 |
1262 $link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>"; |
1407 * |
1263 |
1408 * @param array $args Comment reply link arguments. See {@see get_comment_reply_link()} |
|
1409 * for more information on accepted arguments. |
|
1410 * @param object $comment The object of the comment being replied to. |
|
1411 * @param WP_Post $post The {@see WP_Post} object. |
|
1412 */ |
|
1413 $args = apply_filters( 'comment_reply_link_args', $args, $comment, $post ); |
|
1414 |
|
1415 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) { |
|
1416 $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', |
|
1417 esc_url( wp_login_url( get_permalink() ) ), |
|
1418 $args['login_text'] |
|
1419 ); |
|
1420 } else { |
|
1421 $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )', |
|
1422 $args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID |
|
1423 ); |
|
1424 |
|
1425 $link = sprintf( "<a class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>", |
|
1426 esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $args['respond_id'], |
|
1427 $onclick, |
|
1428 esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ), |
|
1429 $args['reply_text'] |
|
1430 ); |
|
1431 } |
1264 /** |
1432 /** |
1265 * Filter the comment reply link. |
1433 * Filter the comment reply link. |
1266 * |
1434 * |
1267 * @since 2.7.0 |
1435 * @since 2.7.0 |
1268 * |
1436 * |
1269 * @param string $before Text or HTML displayed before the reply link. |
|
1270 * @param string $link The HTML markup for the comment reply link. |
1437 * @param string $link The HTML markup for the comment reply link. |
1271 * @param string $after Text or HTML displayed after the reply link. |
|
1272 * @param array $args An array of arguments overriding the defaults. |
1438 * @param array $args An array of arguments overriding the defaults. |
1273 * @param object $comment The object of the comment being replied. |
1439 * @param object $comment The object of the comment being replied. |
1274 * @param WP_Post $post The WP_Post object. |
1440 * @param WP_Post $post The WP_Post object. |
1275 */ |
1441 */ |
1276 return apply_filters( 'comment_reply_link', $before . $link . $after, $args, $comment, $post ); |
1442 return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post ); |
1277 } |
1443 } |
1278 |
1444 |
1279 /** |
1445 /** |
1280 * Displays the HTML content for reply to comment link. |
1446 * Displays the HTML content for reply to comment link. |
1281 * |
1447 * |
1282 * @since 2.7.0 |
1448 * @since 2.7.0 |
1283 * |
1449 * |
1284 * @param array $args Optional. Override default options, @see get_comment_reply_link() |
1450 * @see get_comment_reply_link() |
1285 * @param int $comment Optional. Comment being replied to. Default current comment. |
1451 * |
1286 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post. |
1452 * @param array $args Optional. Override default options. |
|
1453 * @param int $comment Comment being replied to. Default current comment. |
|
1454 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on. |
|
1455 * Default current post. |
1287 * @return mixed Link to show comment form, if successful. False, if comments are closed. |
1456 * @return mixed Link to show comment form, if successful. False, if comments are closed. |
1288 */ |
1457 */ |
1289 function comment_reply_link($args = array(), $comment = null, $post = null) { |
1458 function comment_reply_link($args = array(), $comment = null, $post = null) { |
1290 echo get_comment_reply_link($args, $comment, $post); |
1459 echo get_comment_reply_link($args, $comment, $post); |
1291 } |
1460 } |
1296 * @since 2.7.0 |
1465 * @since 2.7.0 |
1297 * |
1466 * |
1298 * @param array $args { |
1467 * @param array $args { |
1299 * Optional. Override default arguments. |
1468 * Optional. Override default arguments. |
1300 * |
1469 * |
1301 * @type string 'add_below' The first part of the selector used to identify the comment to respond below. |
1470 * @type string $add_below The first part of the selector used to identify the comment to respond below. |
1302 * The resulting value is passed as the first parameter to addComment.moveForm(), |
1471 * The resulting value is passed as the first parameter to addComment.moveForm(), |
1303 * concatenated as $add_below-$comment->comment_ID. Default is 'post'. |
1472 * concatenated as $add_below-$comment->comment_ID. Default is 'post'. |
1304 * @type string 'respond_id' The selector identifying the responding comment. Passed as the third parameter |
1473 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter |
1305 * to addComment.moveForm(), and appended to the link URL as a hash value. Default is 'respond'. |
1474 * to addComment.moveForm(), and appended to the link URL as a hash value. |
1306 * @type string 'reply_text' The text of the Reply link. Default is 'Leave a Comment'. |
1475 * Default 'respond'. |
1307 * @type string 'login_text' The text of the link to reply if logged out. Default is 'Log in to leave a Comment'. |
1476 * @type string $reply_text Text of the Reply link. Default is 'Leave a Comment'. |
1308 * @type string 'before' The text or HTML to add before the reply link. Default empty. |
1477 * @type string $login_text Text of the link to reply if logged out. Default is 'Log in to leave a Comment'. |
1309 * @type string 'after' The text or HTML to add after the reply link. Default empty. |
1478 * @type string $before Text or HTML to add before the reply link. Default empty. |
|
1479 * @type string $after Text or HTML to add after the reply link. Default empty. |
1310 * } |
1480 * } |
1311 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post. |
1481 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. |
1312 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed. |
1482 * Default current post. |
|
1483 * @return false|null|string Link to show comment form, if successful. False, if comments are closed. |
1313 */ |
1484 */ |
1314 function get_post_reply_link($args = array(), $post = null) { |
1485 function get_post_reply_link($args = array(), $post = null) { |
1315 $defaults = array( |
1486 $defaults = array( |
1316 'add_below' => 'post', |
1487 'add_below' => 'post', |
1317 'respond_id' => 'respond', |
1488 'respond_id' => 'respond', |
1599 } |
1788 } |
1600 |
1789 |
1601 /** |
1790 /** |
1602 * Start the element output. |
1791 * Start the element output. |
1603 * |
1792 * |
|
1793 * @since 2.7.0 |
|
1794 * |
1604 * @see Walker::start_el() |
1795 * @see Walker::start_el() |
1605 * |
1796 * @see wp_list_comments() |
1606 * @since 2.7.0 |
|
1607 * |
1797 * |
1608 * @param string $output Passed by reference. Used to append additional content. |
1798 * @param string $output Passed by reference. Used to append additional content. |
1609 * @param object $comment Comment data object. |
1799 * @param object $comment Comment data object. |
1610 * @param int $depth Depth of comment in reference to parents. |
1800 * @param int $depth Depth of comment in reference to parents. |
1611 * @param array $args An array of arguments. @see wp_list_comments() |
1801 * @param array $args An array of arguments. |
1612 */ |
1802 */ |
1613 function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) { |
1803 public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) { |
1614 $depth++; |
1804 $depth++; |
1615 $GLOBALS['comment_depth'] = $depth; |
1805 $GLOBALS['comment_depth'] = $depth; |
1616 $GLOBALS['comment'] = $comment; |
1806 $GLOBALS['comment'] = $comment; |
1617 |
1807 |
1618 if ( !empty( $args['callback'] ) ) { |
1808 if ( !empty( $args['callback'] ) ) { |
|
1809 ob_start(); |
1619 call_user_func( $args['callback'], $comment, $args, $depth ); |
1810 call_user_func( $args['callback'], $comment, $args, $depth ); |
|
1811 $output .= ob_get_clean(); |
1620 return; |
1812 return; |
1621 } |
1813 } |
1622 |
1814 |
1623 if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) { |
1815 if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) { |
|
1816 ob_start(); |
1624 $this->ping( $comment, $depth, $args ); |
1817 $this->ping( $comment, $depth, $args ); |
|
1818 $output .= ob_get_clean(); |
1625 } elseif ( 'html5' === $args['format'] ) { |
1819 } elseif ( 'html5' === $args['format'] ) { |
|
1820 ob_start(); |
1626 $this->html5_comment( $comment, $depth, $args ); |
1821 $this->html5_comment( $comment, $depth, $args ); |
|
1822 $output .= ob_get_clean(); |
1627 } else { |
1823 } else { |
|
1824 ob_start(); |
1628 $this->comment( $comment, $depth, $args ); |
1825 $this->comment( $comment, $depth, $args ); |
|
1826 $output .= ob_get_clean(); |
1629 } |
1827 } |
1630 } |
1828 } |
1631 |
1829 |
1632 /** |
1830 /** |
1633 * Ends the element output, if needed. |
1831 * Ends the element output, if needed. |
1634 * |
1832 * |
|
1833 * @since 2.7.0 |
|
1834 * |
1635 * @see Walker::end_el() |
1835 * @see Walker::end_el() |
1636 * |
1836 * @see wp_list_comments() |
1637 * @since 2.7.0 |
|
1638 * |
1837 * |
1639 * @param string $output Passed by reference. Used to append additional content. |
1838 * @param string $output Passed by reference. Used to append additional content. |
1640 * @param object $comment The comment object. Default current comment. |
1839 * @param object $comment The comment object. Default current comment. |
1641 * @param int $depth Depth of comment. |
1840 * @param int $depth Depth of comment. |
1642 * @param array $args An array of arguments. @see wp_list_comments() |
1841 * @param array $args An array of arguments. |
1643 */ |
1842 */ |
1644 function end_el( &$output, $comment, $depth = 0, $args = array() ) { |
1843 public function end_el( &$output, $comment, $depth = 0, $args = array() ) { |
1645 if ( !empty( $args['end-callback'] ) ) { |
1844 if ( !empty( $args['end-callback'] ) ) { |
|
1845 ob_start(); |
1646 call_user_func( $args['end-callback'], $comment, $args, $depth ); |
1846 call_user_func( $args['end-callback'], $comment, $args, $depth ); |
|
1847 $output .= ob_get_clean(); |
1647 return; |
1848 return; |
1648 } |
1849 } |
1649 if ( 'div' == $args['style'] ) |
1850 if ( 'div' == $args['style'] ) |
1650 echo "</div><!-- #comment-## -->\n"; |
1851 $output .= "</div><!-- #comment-## -->\n"; |
1651 else |
1852 else |
1652 echo "</li><!-- #comment-## -->\n"; |
1853 $output .= "</li><!-- #comment-## -->\n"; |
1653 } |
1854 } |
1654 |
1855 |
1655 /** |
1856 /** |
1656 * Output a pingback comment. |
1857 * Output a pingback comment. |
1657 * |
1858 * |
1658 * @access protected |
1859 * @access protected |
1659 * @since 3.6.0 |
1860 * @since 3.6.0 |
1660 * |
1861 * |
|
1862 * @see wp_list_comments() |
|
1863 * |
1661 * @param object $comment The comment object. |
1864 * @param object $comment The comment object. |
1662 * @param int $depth Depth of comment. |
1865 * @param int $depth Depth of comment. |
1663 * @param array $args An array of arguments. @see wp_list_comments() |
1866 * @param array $args An array of arguments. |
1664 */ |
1867 */ |
1665 protected function ping( $comment, $depth, $args ) { |
1868 protected function ping( $comment, $depth, $args ) { |
1666 $tag = ( 'div' == $args['style'] ) ? 'div' : 'li'; |
1869 $tag = ( 'div' == $args['style'] ) ? 'div' : 'li'; |
1667 ?> |
1870 ?> |
1668 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>> |
1871 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>> |
1676 * Output a single comment. |
1879 * Output a single comment. |
1677 * |
1880 * |
1678 * @access protected |
1881 * @access protected |
1679 * @since 3.6.0 |
1882 * @since 3.6.0 |
1680 * |
1883 * |
|
1884 * @see wp_list_comments() |
|
1885 * |
1681 * @param object $comment Comment to display. |
1886 * @param object $comment Comment to display. |
1682 * @param int $depth Depth of comment. |
1887 * @param int $depth Depth of comment. |
1683 * @param array $args An array of arguments. @see wp_list_comments() |
1888 * @param array $args An array of arguments. |
1684 */ |
1889 */ |
1685 protected function comment( $comment, $depth, $args ) { |
1890 protected function comment( $comment, $depth, $args ) { |
1686 if ( 'div' == $args['style'] ) { |
1891 if ( 'div' == $args['style'] ) { |
1687 $tag = 'div'; |
1892 $tag = 'div'; |
1688 $add_below = 'comment'; |
1893 $add_below = 'comment'; |
1689 } else { |
1894 } else { |
1690 $tag = 'li'; |
1895 $tag = 'li'; |
1691 $add_below = 'div-comment'; |
1896 $add_below = 'div-comment'; |
1692 } |
1897 } |
1693 ?> |
1898 ?> |
1694 <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>"> |
1899 <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '' ); ?> id="comment-<?php comment_ID(); ?>"> |
1695 <?php if ( 'div' != $args['style'] ) : ?> |
1900 <?php if ( 'div' != $args['style'] ) : ?> |
1696 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body"> |
1901 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body"> |
1697 <?php endif; ?> |
1902 <?php endif; ?> |
1698 <div class="comment-author vcard"> |
1903 <div class="comment-author vcard"> |
1699 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?> |
1904 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?> |
1702 <?php if ( '0' == $comment->comment_approved ) : ?> |
1907 <?php if ( '0' == $comment->comment_approved ) : ?> |
1703 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em> |
1908 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em> |
1704 <br /> |
1909 <br /> |
1705 <?php endif; ?> |
1910 <?php endif; ?> |
1706 |
1911 |
1707 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> |
1912 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>"> |
1708 <?php |
1913 <?php |
1709 /* translators: 1: date, 2: time */ |
1914 /* translators: 1: date, 2: time */ |
1710 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' ); |
1915 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' ); |
1711 ?> |
1916 ?> |
1712 </div> |
1917 </div> |
1713 |
1918 |
1714 <?php comment_text( get_comment_id(), array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> |
1919 <?php comment_text( get_comment_id(), array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> |
1715 |
1920 |
1716 <div class="reply"> |
1921 <?php |
1717 <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> |
1922 comment_reply_link( array_merge( $args, array( |
1718 </div> |
1923 'add_below' => $add_below, |
|
1924 'depth' => $depth, |
|
1925 'max_depth' => $args['max_depth'], |
|
1926 'before' => '<div class="reply">', |
|
1927 'after' => '</div>' |
|
1928 ) ) ); |
|
1929 ?> |
|
1930 |
1719 <?php if ( 'div' != $args['style'] ) : ?> |
1931 <?php if ( 'div' != $args['style'] ) : ?> |
1720 </div> |
1932 </div> |
1721 <?php endif; ?> |
1933 <?php endif; ?> |
1722 <?php |
1934 <?php |
1723 } |
1935 } |
1726 * Output a comment in the HTML5 format. |
1938 * Output a comment in the HTML5 format. |
1727 * |
1939 * |
1728 * @access protected |
1940 * @access protected |
1729 * @since 3.6.0 |
1941 * @since 3.6.0 |
1730 * |
1942 * |
|
1943 * @see wp_list_comments() |
|
1944 * |
1731 * @param object $comment Comment to display. |
1945 * @param object $comment Comment to display. |
1732 * @param int $depth Depth of comment. |
1946 * @param int $depth Depth of comment. |
1733 * @param array $args An array of arguments. @see wp_list_comments() |
1947 * @param array $args An array of arguments. |
1734 */ |
1948 */ |
1735 protected function html5_comment( $comment, $depth, $args ) { |
1949 protected function html5_comment( $comment, $depth, $args ) { |
1736 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; |
1950 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; |
1737 ?> |
1951 ?> |
1738 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>> |
1952 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '' ); ?>> |
1739 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> |
1953 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> |
1740 <footer class="comment-meta"> |
1954 <footer class="comment-meta"> |
1741 <div class="comment-author vcard"> |
1955 <div class="comment-author vcard"> |
1742 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?> |
1956 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?> |
1743 <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?> |
1957 <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?> |
1744 </div><!-- .comment-author --> |
1958 </div><!-- .comment-author --> |
1745 |
1959 |
1746 <div class="comment-metadata"> |
1960 <div class="comment-metadata"> |
1747 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> |
1961 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>"> |
1748 <time datetime="<?php comment_time( 'c' ); ?>"> |
1962 <time datetime="<?php comment_time( 'c' ); ?>"> |
1749 <?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), get_comment_time() ); ?> |
1963 <?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), get_comment_time() ); ?> |
1750 </time> |
1964 </time> |
1751 </a> |
1965 </a> |
1752 <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?> |
1966 <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?> |
1774 * |
1994 * |
1775 * Used in the comments.php template to list comments for a particular post. |
1995 * Used in the comments.php template to list comments for a particular post. |
1776 * |
1996 * |
1777 * @since 2.7.0 |
1997 * @since 2.7.0 |
1778 * |
1998 * |
|
1999 * @see WP_Query->comments |
|
2000 * |
1779 * @param string|array $args { |
2001 * @param string|array $args { |
1780 * Optional. Formatting options. |
2002 * Optional. Formatting options. |
1781 * |
2003 * |
1782 * @type string 'walker' The Walker class used to list comments. Default null. |
2004 * @type object $walker Instance of a Walker class to list comments. Default null. |
1783 * @type int 'max_depth' The maximum comments depth. Default empty. |
2005 * @type int $max_depth The maximum comments depth. Default empty. |
1784 * @type string 'style' The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'. |
2006 * @type string $style The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'. |
1785 * @type string 'callback' Callback function to use. Default null. |
2007 * @type string $callback Callback function to use. Default null. |
1786 * @type string 'end-callback' Callback function to use at the end. Default null. |
2008 * @type string $end-callback Callback function to use at the end. Default null. |
1787 * @type string 'type' Type of comments to list. |
2009 * @type string $type Type of comments to list. |
1788 * Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'. |
2010 * Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'. |
1789 * @type int 'page' Page ID to list comments for. Default empty. |
2011 * @type int $page Page ID to list comments for. Default empty. |
1790 * @type int 'per_page' Number of comments to list per page. Default empty. |
2012 * @type int $per_page Number of comments to list per page. Default empty. |
1791 * @type int 'avatar_size' Height and width dimensions of the avatar size. Default 32. |
2013 * @type int $avatar_size Height and width dimensions of the avatar size. Default 32. |
1792 * @type string 'reverse_top_level' Ordering of the listed comments. Default null. Accepts 'desc', 'asc'. |
2014 * @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'. |
1793 * @type bool 'reverse_children' Whether to reverse child comments in the list. Default null. |
2015 * @type bool $reverse_children Whether to reverse child comments in the list. Default null. |
1794 * @type string 'format' How to format the comments list. |
2016 * @type string $format How to format the comments list. |
1795 * Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'. |
2017 * Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'. |
1796 * @type bool 'short_ping' Whether to output short pings. Default false. |
2018 * @type bool $short_ping Whether to output short pings. Default false. |
|
2019 * @type bool $echo Whether to echo the output or return it. Default true. |
1797 * } |
2020 * } |
1798 * @param array $comments Optional. Array of comment objects. @see WP_Query->comments |
2021 * @param array $comments Optional. Array of comment objects. |
1799 */ |
2022 */ |
1800 function wp_list_comments( $args = array(), $comments = null ) { |
2023 function wp_list_comments( $args = array(), $comments = null ) { |
1801 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; |
2024 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; |
1802 |
2025 |
1803 $in_comment_loop = true; |
2026 $in_comment_loop = true; |
1902 * one or remove a single field. All fields are also individually passed through |
2144 * one or remove a single field. All fields are also individually passed through |
1903 * a filter of the form comment_form_field_$name where $name is the key used |
2145 * a filter of the form comment_form_field_$name where $name is the key used |
1904 * in the array of fields. |
2146 * in the array of fields. |
1905 * |
2147 * |
1906 * @since 3.0.0 |
2148 * @since 3.0.0 |
|
2149 * @since 4.1.0 Introduced the 'class_submit' argument. |
|
2150 * @since 4.2.0 Introduced 'submit_button' and 'submit_fields' arguments. |
1907 * |
2151 * |
1908 * @param array $args { |
2152 * @param array $args { |
1909 * Optional. Default arguments and form fields to override. |
2153 * Optional. Default arguments and form fields to override. |
1910 * |
2154 * |
1911 * @type array 'fields' { |
2155 * @type array $fields { |
1912 * Default comment fields, filterable by default via the 'comment_form_default_fields' hook. |
2156 * Default comment fields, filterable by default via the 'comment_form_default_fields' hook. |
1913 * |
2157 * |
1914 * @type string 'author' The comment author field HTML. |
2158 * @type string $author Comment author field HTML. |
1915 * @type string 'email' The comment author email field HTML. |
2159 * @type string $email Comment author email field HTML. |
1916 * @type string 'url' The comment author URL field HTML. |
2160 * @type string $url Comment author URL field HTML. |
1917 * } |
2161 * } |
1918 * @type string 'comment_field' The comment textarea field HTML. |
2162 * @type string $comment_field The comment textarea field HTML. |
1919 * @type string 'must_log_in' HTML element for a 'must be logged in to comment' message. |
2163 * @type string $must_log_in HTML element for a 'must be logged in to comment' message. |
1920 * @type string 'logged_in_as' HTML element for a 'logged in as <user>' message. |
2164 * @type string $logged_in_as HTML element for a 'logged in as [user]' message. |
1921 * @type string 'comment_notes_before' HTML element for a message displayed before the comment form. |
2165 * @type string $comment_notes_before HTML element for a message displayed before the comment form. |
1922 * Default 'Your email address will not be published.'. |
2166 * Default 'Your email address will not be published.'. |
1923 * @type string 'comment_notes_after' HTML element for a message displayed after the comment form. |
2167 * @type string $comment_notes_after HTML element for a message displayed after the comment form. |
1924 * Default 'You may use these HTML tags and attributes ...'. |
2168 * Default 'You may use these HTML tags and attributes ...'. |
1925 * @type string 'id_form' The comment form element id attribute. Default 'commentform'. |
2169 * @type string $id_form The comment form element id attribute. Default 'commentform'. |
1926 * @type string 'id_submit' The comment submit element id attribute. Default 'submit'. |
2170 * @type string $id_submit The comment submit element id attribute. Default 'submit'. |
1927 * @type string 'title_reply' The translatable 'reply' button label. Default 'Leave a Reply'. |
2171 * @type string $class_submit The comment submit element class attribute. Default 'submit'. |
1928 * @type string 'title_reply_to' The translatable 'reply-to' button label. Default 'Leave a Reply to %s', |
2172 * @type string $name_submit The comment submit element name attribute. Default 'submit'. |
1929 * where %s is the author of the comment being replied to. |
2173 * @type string $title_reply The translatable 'reply' button label. Default 'Leave a Reply'. |
1930 * @type string 'cancel_reply_link' The translatable 'cancel reply' button label. Default 'Cancel reply'. |
2174 * @type string $title_reply_to The translatable 'reply-to' button label. Default 'Leave a Reply to %s', |
1931 * @type string 'label_submit' The translatable 'submit' button label. Default 'Post a comment'. |
2175 * where %s is the author of the comment being replied to. |
1932 * @type string 'format' The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'. |
2176 * @type string $cancel_reply_link The translatable 'cancel reply' button label. Default 'Cancel reply'. |
|
2177 * @type string $label_submit The translatable 'submit' button label. Default 'Post a comment'. |
|
2178 * @type string $submit_button HTML format for the Submit button. |
|
2179 * Default: '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'. |
|
2180 * @type string $submit_field HTML format for the markup surrounding the Submit button and comment hidden |
|
2181 * fields. Default: '<p class="form-submit">%1$s %2$s</a>', where %1$s is the |
|
2182 * submit button markup and %2$s is the comment hidden fields. |
|
2183 * @type string $format The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'. |
1933 * } |
2184 * } |
1934 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object to generate the form for. Default current post. |
2185 * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post. |
1935 */ |
2186 */ |
1936 function comment_form( $args = array(), $post_id = null ) { |
2187 function comment_form( $args = array(), $post_id = null ) { |
1937 if ( null === $post_id ) |
2188 if ( null === $post_id ) |
1938 $post_id = get_the_ID(); |
2189 $post_id = get_the_ID(); |
1939 else |
|
1940 $id = $post_id; |
|
1941 |
2190 |
1942 $commenter = wp_get_current_commenter(); |
2191 $commenter = wp_get_current_commenter(); |
1943 $user = wp_get_current_user(); |
2192 $user = wp_get_current_user(); |
1944 $user_identity = $user->exists() ? $user->display_name : ''; |
2193 $user_identity = $user->exists() ? $user->display_name : ''; |
1945 |
2194 |
1947 if ( ! isset( $args['format'] ) ) |
2196 if ( ! isset( $args['format'] ) ) |
1948 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml'; |
2197 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml'; |
1949 |
2198 |
1950 $req = get_option( 'require_name_email' ); |
2199 $req = get_option( 'require_name_email' ); |
1951 $aria_req = ( $req ? " aria-required='true'" : '' ); |
2200 $aria_req = ( $req ? " aria-required='true'" : '' ); |
|
2201 $html_req = ( $req ? " required='required'" : '' ); |
1952 $html5 = 'html5' === $args['format']; |
2202 $html5 = 'html5' === $args['format']; |
1953 $fields = array( |
2203 $fields = array( |
1954 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2204 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
1955 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>', |
2205 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req . ' /></p>', |
1956 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2206 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
1957 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>', |
2207 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>', |
1958 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . |
2208 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . |
1959 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>', |
2209 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>', |
1960 ); |
2210 ); |
1961 |
2211 |
1962 $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' ); |
2212 $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' ); |
1969 * @param array $fields The default comment fields. |
2219 * @param array $fields The default comment fields. |
1970 */ |
2220 */ |
1971 $fields = apply_filters( 'comment_form_default_fields', $fields ); |
2221 $fields = apply_filters( 'comment_form_default_fields', $fields ); |
1972 $defaults = array( |
2222 $defaults = array( |
1973 'fields' => $fields, |
2223 'fields' => $fields, |
1974 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>', |
2224 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-describedby="form-allowed-tags" aria-required="true" required="required"></textarea></p>', |
|
2225 /** This filter is documented in wp-includes/link-template.php */ |
1975 'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>', |
2226 '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>', |
|
2227 /** This filter is documented in wp-includes/link-template.php */ |
1976 'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>', |
2228 'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>', |
1977 'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>', |
2229 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . '</p>', |
1978 'comment_notes_after' => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>', |
2230 'comment_notes_after' => '<p class="form-allowed-tags" id="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>', |
1979 'id_form' => 'commentform', |
2231 'id_form' => 'commentform', |
1980 'id_submit' => 'submit', |
2232 'id_submit' => 'submit', |
|
2233 'class_submit' => 'submit', |
|
2234 'name_submit' => 'submit', |
1981 'title_reply' => __( 'Leave a Reply' ), |
2235 'title_reply' => __( 'Leave a Reply' ), |
1982 'title_reply_to' => __( 'Leave a Reply to %s' ), |
2236 'title_reply_to' => __( 'Leave a Reply to %s' ), |
1983 'cancel_reply_link' => __( 'Cancel reply' ), |
2237 'cancel_reply_link' => __( 'Cancel reply' ), |
1984 'label_submit' => __( 'Post Comment' ), |
2238 'label_submit' => __( 'Post Comment' ), |
|
2239 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />', |
|
2240 'submit_field' => '<p class="form-submit">%1$s %2$s</p>', |
1985 'format' => 'xhtml', |
2241 'format' => 'xhtml', |
1986 ); |
2242 ); |
1987 |
2243 |
1988 /** |
2244 /** |
1989 * Filter the comment form default arguments. |
2245 * Filter the comment form default arguments. |
2033 /** |
2288 /** |
2034 * Filter the 'logged in' message for the comment form for display. |
2289 * Filter the 'logged in' message for the comment form for display. |
2035 * |
2290 * |
2036 * @since 3.0.0 |
2291 * @since 3.0.0 |
2037 * |
2292 * |
2038 * @param string $args['logged_in_as'] The logged-in-as HTML-formatted message. |
2293 * @param string $args_logged_in The logged-in-as HTML-formatted message. |
2039 * @param array $commenter An array containing the comment author's username, email, and URL. |
2294 * @param array $commenter An array containing the comment author's |
2040 * @param string $user_identity If the commenter is a registered user, the display name, blank otherwise. |
2295 * username, email, and URL. |
|
2296 * @param string $user_identity If the commenter is a registered user, |
|
2297 * the display name, blank otherwise. |
2041 */ |
2298 */ |
2042 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); |
2299 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); |
2043 ?> |
2300 ?> |
2044 <?php |
2301 <?php |
2045 /** |
2302 /** |
2046 * Fires after the is_user_logged_in() check in the comment form. |
2303 * Fires after the is_user_logged_in() check in the comment form. |
2047 * |
2304 * |
2048 * @since 3.0.0 |
2305 * @since 3.0.0 |
2049 * |
2306 * |
2050 * @param array $commenter An array containing the comment author's username, email, and URL. |
2307 * @param array $commenter An array containing the comment author's |
2051 * @param string $user_identity If the commenter is a registered user, the display name, blank otherwise. |
2308 * username, email, and URL. |
|
2309 * @param string $user_identity If the commenter is a registered user, |
|
2310 * the display name, blank otherwise. |
2052 */ |
2311 */ |
2053 do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); |
2312 do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); |
2054 ?> |
2313 ?> |
2055 <?php else : ?> |
2314 <?php else : ?> |
2056 <?php echo $args['comment_notes_before']; ?> |
2315 <?php echo $args['comment_notes_before']; ?> |
2086 /** |
2345 /** |
2087 * Filter the content of the comment textarea field for display. |
2346 * Filter the content of the comment textarea field for display. |
2088 * |
2347 * |
2089 * @since 3.0.0 |
2348 * @since 3.0.0 |
2090 * |
2349 * |
2091 * @param string $args['comment_field'] The content of the comment textarea field. |
2350 * @param string $args_comment_field The content of the comment textarea field. |
2092 */ |
2351 */ |
2093 echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); |
2352 echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); |
2094 ?> |
2353 ?> |
2095 <?php echo $args['comment_notes_after']; ?> |
2354 <?php echo $args['comment_notes_after']; ?> |
2096 <p class="form-submit"> |
2355 |
2097 <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" /> |
|
2098 <?php comment_id_fields( $post_id ); ?> |
|
2099 </p> |
|
2100 <?php |
2356 <?php |
|
2357 $submit_button = sprintf( |
|
2358 $args['submit_button'], |
|
2359 esc_attr( $args['name_submit'] ), |
|
2360 esc_attr( $args['id_submit'] ), |
|
2361 esc_attr( $args['class_submit'] ), |
|
2362 esc_attr( $args['label_submit'] ) |
|
2363 ); |
|
2364 |
|
2365 /** |
|
2366 * Filter the submit button for the comment form to display. |
|
2367 * |
|
2368 * @since 4.2.0 |
|
2369 * |
|
2370 * @param string $submit_button HTML markup for the submit button. |
|
2371 * @param array $args Arguments passed to `comment_form()`. |
|
2372 */ |
|
2373 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args ); |
|
2374 |
|
2375 $submit_field = sprintf( |
|
2376 $args['submit_field'], |
|
2377 $submit_button, |
|
2378 get_comment_id_fields( $post_id ) |
|
2379 ); |
|
2380 |
|
2381 /** |
|
2382 * Filter the submit field for the comment form to display. |
|
2383 * |
|
2384 * The submit field includes the submit button, hidden fields for the |
|
2385 * comment form, and any wrapper markup. |
|
2386 * |
|
2387 * @since 4.2.0 |
|
2388 * |
|
2389 * @param string $submit_field HTML markup for the submit field. |
|
2390 * @param array $args Arguments passed to comment_form(). |
|
2391 */ |
|
2392 echo apply_filters( 'comment_form_submit_field', $submit_field, $args ); |
|
2393 |
2101 /** |
2394 /** |
2102 * Fires at the bottom of the comment form, inside the closing </form> tag. |
2395 * Fires at the bottom of the comment form, inside the closing </form> tag. |
2103 * |
2396 * |
2104 * @since 1.5.2 |
2397 * @since 1.5.0 |
2105 * |
2398 * |
2106 * @param int $post_id The post ID. |
2399 * @param int $post_id The post ID. |
2107 */ |
2400 */ |
2108 do_action( 'comment_form', $post_id ); |
2401 do_action( 'comment_form', $post_id ); |
2109 ?> |
2402 ?> |