Changeset 33962
- Timestamp:
- 09/09/2015 02:40:53 AM (9 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-walker-comment.php
r33961 r33962 1 1 <?php 2 2 /** 3 * Comment template functions 4 * 5 * These functions are meant to live inside of the WordPress loop. 3 * Comments API: Walker_Comment class 6 4 * 7 5 * @package WordPress 8 * @subpackage Template 6 * @subpackage Comments 7 * @since 4.4.0 9 8 */ 10 11 /**12 * Retrieve the author of the current comment.13 *14 * If the comment has an empty comment_author field, then 'Anonymous' person is15 * assumed.16 *17 * @since 1.5.018 *19 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to retrieve the author.20 * Default current comment.21 * @return string The comment author22 */23 function get_comment_author( $comment_ID = 0 ) {24 $comment = get_comment( $comment_ID );25 26 if ( empty( $comment->comment_author ) ) {27 if ( $comment->user_id && $user = get_userdata( $comment->user_id ) )28 $author = $user->display_name;29 else30 $author = __('Anonymous');31 } else {32 $author = $comment->comment_author;33 }34 35 /**36 * Filter the returned comment author name.37 *38 * @since 1.5.039 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.40 *41 * @param string $author The comment author's username.42 * @param int $comment_ID The comment ID.43 * @param WP_Comment $comment The comment object.44 */45 return apply_filters( 'get_comment_author', $author, $comment_ID, $comment );46 }47 48 /**49 * Displays the author of the current comment.50 *51 * @since 0.7152 *53 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author.54 * Default current comment.55 */56 function comment_author( $comment_ID = 0 ) {57 $author = get_comment_author( $comment_ID );58 59 /**60 * Filter the comment author's name for display.61 *62 * @since 1.2.063 * @since 4.1.0 The `$comment_ID` parameter was added.64 *65 * @param string $author The comment author's username.66 * @param int $comment_ID The comment ID.67 */68 echo apply_filters( 'comment_author', $author, $comment_ID );69 }70 71 /**72 * Retrieve the email of the author of the current comment.73 *74 * @since 1.5.075 *76 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email.77 * Default current comment.78 * @return string The current comment author's email79 */80 function get_comment_author_email( $comment_ID = 0 ) {81 $comment = get_comment( $comment_ID );82 83 /**84 * Filter the comment author's returned email address.85 *86 * @since 1.5.087 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.88 *89 * @param string $comment_author_email The comment author's email address.90 * @param int $comment_ID The comment ID.91 * @param WP_Comment $comment The comment object.92 */93 return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment_ID, $comment );94 }95 96 /**97 * Display the email of the author of the current global $comment.98 *99 * Care should be taken to protect the email address and assure that email100 * harvesters do not capture your commentors' email address. Most assume that101 * their email address will not appear in raw form on the blog. Doing so will102 * enable anyone, including those that people don't want to get the email103 * address and use it for their own means good and bad.104 *105 * @since 0.71106 *107 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's email.108 * Default current comment.109 */110 function comment_author_email( $comment_ID = 0 ) {111 $author_email = get_comment_author_email( $comment_ID );112 113 /**114 * Filter the comment author's email for display.115 *116 * @since 1.2.0117 * @since 4.1.0 The `$comment_ID` parameter was added.118 *119 * @param string $author_email The comment author's email address.120 * @param int $comment_ID The comment ID.121 */122 echo apply_filters( 'author_email', $author_email, $comment_ID );123 }124 125 /**126 * Display the html email link to the author of the current comment.127 *128 * Care should be taken to protect the email address and assure that email129 * harvesters do not capture your commentors' email address. Most assume that130 * their email address will not appear in raw form on the blog. Doing so will131 * enable anyone, including those that people don't want to get the email132 * address and use it for their own means good and bad.133 *134 * @since 0.71135 *136 * @param string $linktext Optional. Text to display instead of the comment author's email address.137 * Default empty.138 * @param string $before Optional. Text or HTML to display before the email link. Default empty.139 * @param string $after Optional. Text or HTML to display after the email link. Default empty.140 */141 function comment_author_email_link( $linktext = '', $before = '', $after = '' ) {142 if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )143 echo $link;144 }145 146 /**147 * Return the html email link to the author of the current comment.148 *149 * Care should be taken to protect the email address and assure that email150 * harvesters do not capture your commentors' email address. Most assume that151 * their email address will not appear in raw form on the blog. Doing so will152 * enable anyone, including those that people don't want to get the email153 * address and use it for their own means good and bad.154 *155 * @global object $comment The current Comment row object.156 *157 * @since 2.7.0158 *159 * @param string $linktext Optional. Text to display instead of the comment author's email address.160 * Default empty.161 * @param string $before Optional. Text or HTML to display before the email link. Default empty.162 * @param string $after Optional. Text or HTML to display after the email link. Default empty.163 * @return string164 */165 function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) {166 global $comment;167 168 /**169 * Filter the comment author's email for display.170 *171 * Care should be taken to protect the email address and assure that email172 * harvesters do not capture your commenter's email address.173 *174 * @since 1.2.0175 * @since 4.1.0 The `$comment` parameter was added.176 *177 * @param string $comment_author_email The comment author's email address.178 * @param WP_Comment $comment The comment object.179 */180 $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );181 if ((!empty($email)) && ($email != '@')) {182 $display = ($linktext != '') ? $linktext : $email;183 $return = $before;184 $return .= "<a href='mailto:$email'>$display</a>";185 $return .= $after;186 return $return;187 } else {188 return '';189 }190 }191 192 /**193 * Retrieve the HTML link to the URL of the author of the current comment.194 *195 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),196 * which falls back to the global comment variable if the $comment_ID argument is empty.197 *198 * @since 1.5.0199 *200 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.201 * Default current comment.202 * @return string The comment author name or HTML link for author's URL.203 */204 function get_comment_author_link( $comment_ID = 0 ) {205 $url = get_comment_author_url( $comment_ID );206 $author = get_comment_author( $comment_ID );207 208 if ( empty( $url ) || 'http://' == $url )209 $return = $author;210 else211 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";212 213 /**214 * Filter the comment author's link for display.215 *216 * @since 1.5.0217 * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.218 *219 * @param string $return The HTML-formatted comment author link.220 * Empty for an invalid URL.221 * @param string $author The comment author's username.222 * @param int $comment_ID The comment ID.223 */224 return apply_filters( 'get_comment_author_link', $return, $author, $comment_ID );225 }226 227 /**228 * Display the html link to the url of the author of the current comment.229 *230 * @since 0.71231 *232 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link.233 * Default current comment.234 */235 function comment_author_link( $comment_ID = 0 ) {236 echo get_comment_author_link( $comment_ID );237 }238 239 /**240 * Retrieve the IP address of the author of the current comment.241 *242 * @since 1.5.0243 *244 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address.245 * Default current comment.246 * @return string Comment author's IP address.247 */248 function get_comment_author_IP( $comment_ID = 0 ) {249 $comment = get_comment( $comment_ID );250 251 /**252 * Filter the comment author's returned IP address.253 *254 * @since 1.5.0255 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.256 *257 * @param string $comment_author_IP The comment author's IP address.258 * @param int $comment_ID The comment ID.259 * @param WP_Comment $comment The comment object.260 */261 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment_ID, $comment );262 }263 264 /**265 * Display the IP address of the author of the current comment.266 *267 * @since 0.71268 *269 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address.270 * Default current comment.271 */272 function comment_author_IP( $comment_ID = 0 ) {273 echo get_comment_author_IP( $comment_ID );274 }275 276 /**277 * Retrieve the url of the author of the current comment.278 *279 * @since 1.5.0280 *281 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL.282 * Default current comment.283 * @return string284 */285 function get_comment_author_url( $comment_ID = 0 ) {286 $comment = get_comment( $comment_ID );287 $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;288 $url = esc_url( $url, array('http', 'https') );289 290 /**291 * Filter the comment author's URL.292 *293 * @since 1.5.0294 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.295 *296 * @param string $url The comment author's URL.297 * @param int $comment_ID The comment ID.298 * @param WP_Comment $comment The comment object.299 */300 return apply_filters( 'get_comment_author_url', $url, $comment_ID, $comment );301 }302 303 /**304 * Display the url of the author of the current comment.305 *306 * @since 0.71307 *308 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL.309 * Default current comment.310 */311 function comment_author_url( $comment_ID = 0 ) {312 $author_url = get_comment_author_url( $comment_ID );313 314 /**315 * Filter the comment author's URL for display.316 *317 * @since 1.2.0318 * @since 4.1.0 The `$comment_ID` parameter was added.319 *320 * @param string $author_url The comment author's URL.321 * @param int $comment_ID The comment ID.322 */323 echo apply_filters( 'comment_url', $author_url, $comment_ID );324 }325 326 /**327 * Retrieves the HTML link of the url of the author of the current comment.328 *329 * $linktext parameter is only used if the URL does not exist for the comment330 * author. If the URL does exist then the URL will be used and the $linktext331 * will be ignored.332 *333 * Encapsulate the HTML link between the $before and $after. So it will appear334 * in the order of $before, link, and finally $after.335 *336 * @since 1.5.0337 *338 * @param string $linktext Optional. The text to display instead of the comment339 * author's email address. Default empty.340 * @param string $before Optional. The text or HTML to display before the email link.341 * Default empty.342 * @param string $after Optional. The text or HTML to display after the email link.343 * Default empty.344 * @return string The HTML link between the $before and $after parameters.345 */346 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {347 $url = get_comment_author_url();348 $display = ($linktext != '') ? $linktext : $url;349 $display = str_replace( 'http://www.', '', $display );350 $display = str_replace( 'http://', '', $display );351 352 if ( '/' == substr($display, -1) ) {353 $display = substr($display, 0, -1);354 }355 356 $return = "$before<a href='$url' rel='external'>$display</a>$after";357 358 /**359 * Filter the comment author's returned URL link.360 *361 * @since 1.5.0362 *363 * @param string $return The HTML-formatted comment author URL link.364 */365 return apply_filters( 'get_comment_author_url_link', $return );366 }367 368 /**369 * Displays the HTML link of the url of the author of the current comment.370 *371 * @since 0.71372 *373 * @param string $linktext Optional. Text to display instead of the comment author's374 * email address. Default empty.375 * @param string $before Optional. Text or HTML to display before the email link.376 * Default empty.377 * @param string $after Optional. Text or HTML to display after the email link.378 * Default empty.379 */380 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {381 echo get_comment_author_url_link( $linktext, $before, $after );382 }383 384 /**385 * Generates semantic classes for each comment element.386 *387 * @since 2.7.0388 *389 * @param string|array $class Optional. One or more classes to add to the class list.390 * Default empty.391 * @param int|WP_Comment $comment Comment ID or WP_Comment object. Default current comment.392 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.393 * @param bool $echo Optional. Whether to cho or return the output.394 * Default true.395 * @return string|void396 */397 function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) {398 // Separates classes with a single space, collates classes for comment DIV399 $class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';400 if ( $echo)401 echo $class;402 else403 return $class;404 }405 406 /**407 * Returns the classes for the comment div as an array.408 *409 * @since 2.7.0410 *411 * @global int $comment_alt412 * @global int $comment_depth413 * @global int $comment_thread_alt414 *415 * @param string|array $class Optional. One or more classes to add to the class list. Default empty.416 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment.417 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.418 * @return array An array of classes.419 */420 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {421 global $comment_alt, $comment_depth, $comment_thread_alt;422 423 $comment = get_comment($comment_id);424 425 $classes = array();426 427 // Get the comment type (comment, trackback),428 $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;429 430 // Add classes for comment authors that are registered users.431 if ( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) ) {432 $classes[] = 'byuser';433 $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );434 // For comment authors who are the author of the post435 if ( $post = get_post($post_id) ) {436 if ( $comment->user_id === $post->post_author ) {437 $classes[] = 'bypostauthor';438 }439 }440 }441 442 if ( empty($comment_alt) )443 $comment_alt = 0;444 if ( empty($comment_depth) )445 $comment_depth = 1;446 if ( empty($comment_thread_alt) )447 $comment_thread_alt = 0;448 449 if ( $comment_alt % 2 ) {450 $classes[] = 'odd';451 $classes[] = 'alt';452 } else {453 $classes[] = 'even';454 }455 456 $comment_alt++;457 458 // Alt for top-level comments459 if ( 1 == $comment_depth ) {460 if ( $comment_thread_alt % 2 ) {461 $classes[] = 'thread-odd';462 $classes[] = 'thread-alt';463 } else {464 $classes[] = 'thread-even';465 }466 $comment_thread_alt++;467 }468 469 $classes[] = "depth-$comment_depth";470 471 if ( !empty($class) ) {472 if ( !is_array( $class ) )473 $class = preg_split('#\s+#', $class);474 $classes = array_merge($classes, $class);475 }476 477 $classes = array_map('esc_attr', $classes);478 479 /**480 * Filter the returned CSS classes for the current comment.481 *482 * @since 2.7.0483 *484 * @param array $classes An array of comment classes.485 * @param string $class A comma-separated list of additional classes added to the list.486 * @param int $comment_id The comment id.487 * @param object $comment The comment488 * @param int|WP_Post $post_id The post ID or WP_Post object.489 */490 return apply_filters( 'comment_class', $classes, $class, $comment_id, $comment, $post_id );491 }492 493 /**494 * Retrieve the comment date of the current comment.495 *496 * @since 1.5.0497 *498 * @param string $d Optional. The format of the date. Default user's setting.499 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the date.500 * Default current comment.501 * @return string The comment's date.502 */503 function get_comment_date( $d = '', $comment_ID = 0 ) {504 $comment = get_comment( $comment_ID );505 if ( '' == $d )506 $date = mysql2date(get_option('date_format'), $comment->comment_date);507 else508 $date = mysql2date($d, $comment->comment_date);509 /**510 * Filter the returned comment date.511 *512 * @since 1.5.0513 *514 * @param string|int $date Formatted date string or Unix timestamp.515 * @param string $d The format of the date.516 * @param WP_Comment $comment The comment object.517 */518 return apply_filters( 'get_comment_date', $date, $d, $comment );519 }520 521 /**522 * Display the comment date of the current comment.523 *524 * @since 0.71525 *526 * @param string $d Optional. The format of the date. Default user's settings.527 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date.528 * Default current comment.529 */530 function comment_date( $d = '', $comment_ID = 0 ) {531 echo get_comment_date( $d, $comment_ID );532 }533 534 /**535 * Retrieve the excerpt of the current comment.536 *537 * Will cut each word and only output the first 20 words with '…' at the end.538 * If the word count is less than 20, then no truncating is done and no '…'539 * will appear.540 *541 * @since 1.5.0542 *543 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt.544 * Default current comment.545 * @return string The maybe truncated comment with 20 words or less.546 */547 function get_comment_excerpt( $comment_ID = 0 ) {548 $comment = get_comment( $comment_ID );549 $comment_text = strip_tags($comment->comment_content);550 $blah = explode(' ', $comment_text);551 552 if (count($blah) > 20) {553 $k = 20;554 $use_dotdotdot = 1;555 } else {556 $k = count($blah);557 $use_dotdotdot = 0;558 }559 560 $excerpt = '';561 for ($i=0; $i<$k; $i++) {562 $excerpt .= $blah[$i] . ' ';563 }564 $excerpt .= ($use_dotdotdot) ? '…' : '';565 566 /**567 * Filter the retrieved comment excerpt.568 *569 * @since 1.5.0570 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.571 *572 * @param string $excerpt The comment excerpt text.573 * @param int $comment_ID The comment ID.574 * @param WP_Comment $comment The comment object.575 */576 return apply_filters( 'get_comment_excerpt', $excerpt, $comment_ID, $comment );577 }578 579 /**580 * Display the excerpt of the current comment.581 *582 * @since 1.2.0583 *584 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the excerpt.585 * Default current comment.586 */587 function comment_excerpt( $comment_ID = 0 ) {588 $comment_excerpt = get_comment_excerpt($comment_ID);589 590 /**591 * Filter the comment excerpt for display.592 *593 * @since 1.2.0594 * @since 4.1.0 The `$comment_ID` parameter was added.595 *596 * @param string $comment_excerpt The comment excerpt text.597 * @param int $comment_ID The comment ID.598 */599 echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment_ID );600 }601 602 /**603 * Retrieve the comment id of the current comment.604 *605 * @since 1.5.0606 *607 * @global object $comment608 *609 * @return int The comment ID.610 */611 function get_comment_ID() {612 global $comment;613 614 /**615 * Filter the returned comment ID.616 *617 * @since 1.5.0618 * @since 4.1.0 The `$comment_ID` parameter was added.619 *620 * @param int $comment_ID The current comment ID.621 * @param WP_Comment $comment The comment object.622 */623 return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment );624 }625 626 /**627 * Display the comment id of the current comment.628 *629 * @since 0.71630 */631 function comment_ID() {632 echo get_comment_ID();633 }634 635 /**636 * Retrieve the link to a given comment.637 *638 * @since 1.5.0639 *640 * @see get_page_of_comment()641 *642 * @global WP_Rewrite $wp_rewrite643 * @global bool $in_comment_loop644 *645 * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.646 * @param array $args Optional. An array of arguments to override the defaults.647 * @return string The permalink to the given comment.648 */649 function get_comment_link( $comment = null, $args = array() ) {650 global $wp_rewrite, $in_comment_loop;651 652 $comment = get_comment($comment);653 654 // Backwards compat655 if ( ! is_array( $args ) ) {656 $args = array( 'page' => $args );657 }658 659 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );660 $args = wp_parse_args( $args, $defaults );661 662 if ( '' === $args['per_page'] && get_option('page_comments') )663 $args['per_page'] = get_option('comments_per_page');664 665 if ( empty($args['per_page']) ) {666 $args['per_page'] = 0;667 $args['page'] = 0;668 }669 670 if ( $args['per_page'] ) {671 if ( '' == $args['page'] )672 $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );673 674 if ( $wp_rewrite->using_permalinks() )675 $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment' );676 else677 $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );678 } else {679 $link = get_permalink( $comment->comment_post_ID );680 }681 682 $link = $link . '#comment-' . $comment->comment_ID;683 /**684 * Filter the returned single comment permalink.685 *686 * @since 2.8.0687 *688 * @see get_page_of_comment()689 *690 * @param string $link The comment permalink with '#comment-$id' appended.691 * @param WP_Comment $comment The current comment object.692 * @param array $args An array of arguments to override the defaults.693 */694 return apply_filters( 'get_comment_link', $link, $comment, $args );695 }696 697 /**698 * Retrieve the link to the current post comments.699 *700 * @since 1.5.0701 *702 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.703 * @return string The link to the comments.704 */705 function get_comments_link( $post_id = 0 ) {706 $comments_link = get_permalink( $post_id ) . '#comments';707 /**708 * Filter the returned post comments permalink.709 *710 * @since 3.6.0711 *712 * @param string $comments_link Post comments permalink with '#comments' appended.713 * @param int|WP_Post $post_id Post ID or WP_Post object.714 */715 return apply_filters( 'get_comments_link', $comments_link, $post_id );716 }717 718 /**719 * Display the link to the current post comments.720 *721 * @since 0.71722 *723 * @param string $deprecated Not Used.724 * @param string $deprecated_2 Not Used.725 */726 function comments_link( $deprecated = '', $deprecated_2 = '' ) {727 if ( !empty( $deprecated ) )728 _deprecated_argument( __FUNCTION__, '0.72' );729 if ( !empty( $deprecated_2 ) )730 _deprecated_argument( __FUNCTION__, '1.3' );731 echo esc_url( get_comments_link() );732 }733 734 /**735 * Retrieve the amount of comments a post has.736 *737 * @since 1.5.0738 *739 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.740 * @return int The number of comments a post has.741 */742 function get_comments_number( $post_id = 0 ) {743 $post = get_post( $post_id );744 745 if ( ! $post ) {746 $count = 0;747 } else {748 $count = $post->comment_count;749 $post_id = $post->ID;750 }751 752 /**753 * Filter the returned comment count for a post.754 *755 * @since 1.5.0756 *757 * @param int $count Number of comments a post has.758 * @param int $post_id Post ID.759 */760 return apply_filters( 'get_comments_number', $count, $post_id );761 }762 763 /**764 * Display the language string for the number of comments the current post has.765 *766 * @since 0.71767 *768 * @param string $zero Optional. Text for no comments. Default false.769 * @param string $one Optional. Text for one comment. Default false.770 * @param string $more Optional. Text for more than one comment. Default false.771 * @param string $deprecated Not used.772 */773 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {774 if ( ! empty( $deprecated ) ) {775 _deprecated_argument( __FUNCTION__, '1.3' );776 }777 echo get_comments_number_text( $zero, $one, $more );778 }779 780 /**781 * Display the language string for the number of comments the current post has.782 *783 * @since 4.0.0784 *785 * @param string $zero Optional. Text for no comments. Default false.786 * @param string $one Optional. Text for one comment. Default false.787 * @param string $more Optional. Text for more than one comment. Default false.788 */789 function get_comments_number_text( $zero = false, $one = false, $more = false ) {790 $number = get_comments_number();791 792 if ( $number > 1 ) {793 $output = str_replace( '%', number_format_i18n( $number ), ( false === $more ) ? __( '% Comments' ) : $more );794 } elseif ( $number == 0 ) {795 $output = ( false === $zero ) ? __( 'No Comments' ) : $zero;796 } else { // must be one797 $output = ( false === $one ) ? __( '1 Comment' ) : $one;798 }799 /**800 * Filter the comments count for display.801 *802 * @since 1.5.0803 *804 * @see _n()805 *806 * @param string $output A translatable string formatted based on whether the count807 * is equal to 0, 1, or 1+.808 * @param int $number The number of post comments.809 */810 return apply_filters( 'comments_number', $output, $number );811 }812 813 /**814 * Retrieve the text of the current comment.815 *816 * @since 1.5.0817 *818 * @see Walker_Comment::comment()819 *820 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the text.821 * Default current comment.822 * @param array $args Optional. An array of arguments. Default empty.823 * @return string The comment content.824 */825 function get_comment_text( $comment_ID = 0, $args = array() ) {826 $comment = get_comment( $comment_ID );827 828 /**829 * Filter the text of a comment.830 *831 * @since 1.5.0832 *833 * @see Walker_Comment::comment()834 *835 * @param string $comment_content Text of the comment.836 * @param WP_Comment $comment The comment object.837 * @param array $args An array of arguments.838 */839 return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args );840 }841 842 /**843 * Display the text of the current comment.844 *845 * @since 0.71846 *847 * @see Walker_Comment::comment()848 *849 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the text.850 * Default current comment.851 * @param array $args Optional. An array of arguments. Default empty array. Default empty.852 */853 function comment_text( $comment_ID = 0, $args = array() ) {854 $comment = get_comment( $comment_ID );855 856 $comment_text = get_comment_text( $comment_ID , $args );857 /**858 * Filter the text of a comment to be displayed.859 *860 * @since 1.2.0861 *862 * @see Walker_Comment::comment()863 *864 * @param string $comment_text Text of the current comment.865 * @param WP_Comment $comment The comment object.866 * @param array $args An array of arguments.867 */868 echo apply_filters( 'comment_text', $comment_text, $comment, $args );869 }870 871 /**872 * Retrieve the comment time of the current comment.873 *874 * @since 1.5.0875 *876 * @global object $comment877 *878 * @param string $d Optional. The format of the time. Default user's settings.879 * @param bool $gmt Optional. Whether to use the GMT date. Default false.880 * @param bool $translate Optional. Whether to translate the time (for use in feeds).881 * Default true.882 * @return string The formatted time.883 */884 function get_comment_time( $d = '', $gmt = false, $translate = true ) {885 global $comment;886 $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;887 if ( '' == $d )888 $date = mysql2date(get_option('time_format'), $comment_date, $translate);889 else890 $date = mysql2date($d, $comment_date, $translate);891 892 /**893 * Filter the returned comment time.894 *895 * @since 1.5.0896 *897 * @param string|int $date The comment time, formatted as a date string or Unix timestamp.898 * @param string $d Date format.899 * @param bool $gmt Whether the GMT date is in use.900 * @param bool $translate Whether the time is translated.901 * @param WP_Comment $comment The comment object.902 */903 return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment );904 }905 906 /**907 * Display the comment time of the current comment.908 *909 * @since 0.71910 *911 * @param string $d Optional. The format of the time. Default user's settings.912 */913 function comment_time( $d = '' ) {914 echo get_comment_time($d);915 }916 917 /**918 * Retrieve the comment type of the current comment.919 *920 * @since 1.5.0921 *922 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the type.923 * Default current comment.924 * @return string The comment type.925 */926 function get_comment_type( $comment_ID = 0 ) {927 $comment = get_comment( $comment_ID );928 if ( '' == $comment->comment_type )929 $comment->comment_type = 'comment';930 931 /**932 * Filter the returned comment type.933 *934 * @since 1.5.0935 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.936 *937 * @param string $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.938 * @param int $comment_ID The comment ID.939 * @param WP_Comment $comment The comment object.940 */941 return apply_filters( 'get_comment_type', $comment->comment_type, $comment_ID, $comment );942 }943 944 /**945 * Display the comment type of the current comment.946 *947 * @since 0.71948 *949 * @param string $commenttxt Optional. String to display for comment type. Default false.950 * @param string $trackbacktxt Optional. String to display for trackback type. Default false.951 * @param string $pingbacktxt Optional. String to display for pingback type. Default false.952 */953 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {954 if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );955 if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );956 if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );957 $type = get_comment_type();958 switch( $type ) {959 case 'trackback' :960 echo $trackbacktxt;961 break;962 case 'pingback' :963 echo $pingbacktxt;964 break;965 default :966 echo $commenttxt;967 }968 }969 970 /**971 * Retrieve The current post's trackback URL.972 *973 * There is a check to see if permalink's have been enabled and if so, will974 * retrieve the pretty path. If permalinks weren't enabled, the ID of the975 * current post is used and appended to the correct page to go to.976 *977 * @since 1.5.0978 *979 * @return string The trackback URL after being filtered.980 */981 function get_trackback_url() {982 if ( '' != get_option('permalink_structure') )983 $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');984 else985 $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();986 987 /**988 * Filter the returned trackback URL.989 *990 * @since 2.2.0991 *992 * @param string $tb_url The trackback URL.993 */994 return apply_filters( 'trackback_url', $tb_url );995 }996 997 /**998 * Display the current post's trackback URL.999 *1000 * @since 0.711001 *1002 * @param bool $deprecated_echo Not used.1003 * @return void|string Should only be used to echo the trackback URL, use get_trackback_url()1004 * for the result instead.1005 */1006 function trackback_url( $deprecated_echo = true ) {1007 if ( $deprecated_echo !== true )1008 _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );1009 if ( $deprecated_echo )1010 echo get_trackback_url();1011 else1012 return get_trackback_url();1013 }1014 1015 /**1016 * Generate and display the RDF for the trackback information of current post.1017 *1018 * Deprecated in 3.0.0, and restored in 3.0.1.1019 *1020 * @since 0.711021 *1022 * @param int $deprecated Not used (Was $timezone = 0).1023 */1024 function trackback_rdf( $deprecated = '' ) {1025 if ( ! empty( $deprecated ) ) {1026 _deprecated_argument( __FUNCTION__, '2.5' );1027 }1028 1029 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'W3C_Validator' ) ) {1030 return;1031 }1032 1033 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"1034 xmlns:dc="http://purl.org/dc/elements/1.1/"1035 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">1036 <rdf:Description rdf:about="';1037 the_permalink();1038 echo '"'."\n";1039 echo ' dc:identifier="';1040 the_permalink();1041 echo '"'."\n";1042 echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n";1043 echo ' trackback:ping="'.get_trackback_url().'"'." />\n";1044 echo '</rdf:RDF>';1045 }1046 1047 /**1048 * Whether the current post is open for comments.1049 *1050 * @since 1.5.01051 *1052 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.1053 * @return bool True if the comments are open.1054 */1055 function comments_open( $post_id = null ) {1056 1057 $_post = get_post($post_id);1058 1059 $open = ( 'open' == $_post->comment_status );1060 1061 /**1062 * Filter whether the current post is open for comments.1063 *1064 * @since 2.5.01065 *1066 * @param bool $open Whether the current post is open for comments.1067 * @param int|WP_Post $post_id The post ID or WP_Post object.1068 */1069 return apply_filters( 'comments_open', $open, $post_id );1070 }1071 1072 /**1073 * Whether the current post is open for pings.1074 *1075 * @since 1.5.01076 *1077 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.1078 * @return bool True if pings are accepted1079 */1080 function pings_open( $post_id = null ) {1081 1082 $_post = get_post($post_id);1083 1084 $open = ( 'open' == $_post->ping_status );1085 1086 /**1087 * Filter whether the current post is open for pings.1088 *1089 * @since 2.5.01090 *1091 * @param bool $open Whether the current post is open for pings.1092 * @param int|WP_Post $post_id The post ID or WP_Post object.1093 */1094 return apply_filters( 'pings_open', $open, $post_id );1095 }1096 1097 /**1098 * Display form token for unfiltered comments.1099 *1100 * Will only display nonce token if the current user has permissions for1101 * unfiltered html. Won't display the token for other users.1102 *1103 * The function was backported to 2.0.10 and was added to versions 2.1.3 and1104 * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in1105 * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.1106 *1107 * Backported to 2.0.10.1108 *1109 * @since 2.1.31110 */1111 function wp_comment_form_unfiltered_html_nonce() {1112 $post = get_post();1113 $post_id = $post ? $post->ID : 0;1114 1115 if ( current_user_can( 'unfiltered_html' ) ) {1116 wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );1117 echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";1118 }1119 }1120 1121 /**1122 * Load the comment template specified in $file.1123 *1124 * Will not display the comments template if not on single post or page, or if1125 * the post does not have comments.1126 *1127 * Uses the WordPress database object to query for the comments. The comments1128 * are passed through the 'comments_array' filter hook with the list of comments1129 * and the post ID respectively.1130 *1131 * The $file path is passed through a filter hook called, 'comments_template'1132 * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path1133 * first and if it fails it will require the default comment template from the1134 * default theme. If either does not exist, then the WordPress process will be1135 * halted. It is advised for that reason, that the default theme is not deleted.1136 *1137 * @uses $withcomments Will not try to get the comments if the post has none.1138 *1139 * @since 1.5.01140 *1141 * @global WP_Query $wp_query1142 * @global WP_Post $post1143 * @global wpdb $wpdb1144 * @global int $id1145 * @global object $comment1146 * @global string $user_login1147 * @global int $user_ID1148 * @global string $user_identity1149 * @global bool $overridden_cpage1150 *1151 * @param string $file Optional. The file to load. Default '/comments.php'.1152 * @param bool $separate_comments Optional. Whether to separate the comments by comment type.1153 * Default false.1154 */1155 function comments_template( $file = '/comments.php', $separate_comments = false ) {1156 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;1157 1158 if ( !(is_single() || is_page() || $withcomments) || empty($post) )1159 return;1160 1161 if ( empty($file) )1162 $file = '/comments.php';1163 1164 $req = get_option('require_name_email');1165 1166 /*1167 * Comment author information fetched from the comment cookies.1168 */1169 $commenter = wp_get_current_commenter();1170 1171 /*1172 * The name of the current comment author escaped for use in attributes.1173 * Escaped by sanitize_comment_cookies().1174 */1175 $comment_author = $commenter['comment_author'];1176 1177 /*1178 * The email address of the current comment author escaped for use in attributes.1179 * Escaped by sanitize_comment_cookies().1180 */1181 $comment_author_email = $commenter['comment_author_email'];1182 1183 /*1184 * The url of the current comment author escaped for use in attributes.1185 */1186 $comment_author_url = esc_url($commenter['comment_author_url']);1187 1188 $comment_args = array(1189 'order' => 'ASC',1190 'orderby' => 'comment_date_gmt',1191 'status' => 'approve',1192 'post_id' => $post->ID,1193 );1194 1195 if ( $user_ID ) {1196 $comment_args['include_unapproved'] = array( $user_ID );1197 } elseif ( ! empty( $comment_author_email ) ) {1198 $comment_args['include_unapproved'] = array( $comment_author_email );1199 }1200 1201 $comments = get_comments( $comment_args );1202 1203 /**1204 * Filter the comments array.1205 *1206 * @since 2.1.01207 *1208 * @param array $comments Array of comments supplied to the comments template.1209 * @param int $post_ID Post ID.1210 */1211 $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );1212 $comments = &$wp_query->comments;1213 $wp_query->comment_count = count($wp_query->comments);1214 1215 if ( $separate_comments ) {1216 $wp_query->comments_by_type = separate_comments($comments);1217 $comments_by_type = &$wp_query->comments_by_type;1218 }1219 1220 $overridden_cpage = false;1221 if ( '' == get_query_var('cpage') && get_option('page_comments') ) {1222 set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );1223 $overridden_cpage = true;1224 }1225 1226 if ( !defined('COMMENTS_TEMPLATE') )1227 define('COMMENTS_TEMPLATE', true);1228 1229 $theme_template = STYLESHEETPATH . $file;1230 /**1231 * Filter the path to the theme template file used for the comments template.1232 *1233 * @since 1.5.11234 *1235 * @param string $theme_template The path to the theme template file.1236 */1237 $include = apply_filters( 'comments_template', $theme_template );1238 if ( file_exists( $include ) )1239 require( $include );1240 elseif ( file_exists( TEMPLATEPATH . $file ) )1241 require( TEMPLATEPATH . $file );1242 else // Backward compat code will be removed in a future release1243 require( ABSPATH . WPINC . '/theme-compat/comments.php');1244 }1245 1246 /**1247 * Display the JS popup script to show a comment.1248 *1249 * If the $file parameter is empty, then the home page is assumed. The defaults1250 * for the window are 400px by 400px.1251 *1252 * For the comment link popup to work, this function has to be called or the1253 * normal comment link will be assumed.1254 *1255 * @global string $wpcommentspopupfile The URL to use for the popup window.1256 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.1257 *1258 * @since 0.711259 *1260 * @param int $width Optional. The width of the popup window. Default 400.1261 * @param int $height Optional. The height of the popup window. Default 400.1262 * @param string $file Optional. Sets the location of the popup window.1263 */1264 function comments_popup_script( $width = 400, $height = 400, $file = '' ) {1265 global $wpcommentspopupfile, $wpcommentsjavascript;1266 1267 if (empty ($file)) {1268 $wpcommentspopupfile = ''; // Use the index.1269 } else {1270 $wpcommentspopupfile = $file;1271 }1272 1273 $wpcommentsjavascript = 1;1274 $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";1275 echo $javascript;1276 }1277 1278 /**1279 * Displays the link to the comments popup window for the current post ID.1280 *1281 * Is not meant to be displayed on single posts and pages. Should be used1282 * on the lists of posts1283 *1284 * @global string $wpcommentspopupfile The URL to use for the popup window.1285 * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.1286 *1287 * @since 0.711288 *1289 * @param string $zero Optional. String to display when no comments. Default false.1290 * @param string $one Optional. String to display when only one comment is available.1291 * Default false.1292 * @param string $more Optional. String to display when there are more than one comment.1293 * Default false.1294 * @param string $css_class Optional. CSS class to use for comments. Default empty.1295 * @param string $none Optional. String to display when comments have been turned off.1296 * Default false.1297 */1298 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {1299 global $wpcommentspopupfile, $wpcommentsjavascript;1300 1301 $id = get_the_ID();1302 $title = get_the_title();1303 $number = get_comments_number( $id );1304 1305 if ( false === $zero ) {1306 /* translators: %s: post title */1307 $zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $title );1308 }1309 1310 if ( false === $one ) {1311 /* translators: %s: post title */1312 $one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $title );1313 }1314 1315 if ( false === $more ) {1316 /* translators: 1: Number of comments 2: post title */1317 $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 );1318 $more = sprintf( $more, number_format_i18n( $number ), $title );1319 }1320 1321 if ( false === $none ) {1322 /* translators: %s: post title */1323 $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title );1324 }1325 1326 if ( 0 == $number && !comments_open() && !pings_open() ) {1327 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';1328 return;1329 }1330 1331 if ( post_password_required() ) {1332 _e( 'Enter your password to view comments.' );1333 return;1334 }1335 1336 echo '<a href="';1337 if ( $wpcommentsjavascript ) {1338 if ( empty( $wpcommentspopupfile ) )1339 $home = home_url();1340 else1341 $home = get_option('siteurl');1342 echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;1343 echo '" onclick="wpopen(this.href); return false"';1344 } else { // if comments_popup_script() is not in the template, display simple comment link1345 if ( 0 == $number )1346 echo get_permalink() . '#respond';1347 else1348 comments_link();1349 echo '"';1350 }1351 1352 if ( !empty( $css_class ) ) {1353 echo ' class="'.$css_class.'" ';1354 }1355 1356 $attributes = '';1357 /**1358 * Filter the comments popup link attributes for display.1359 *1360 * @since 2.5.01361 *1362 * @param string $attributes The comments popup link attributes. Default empty.1363 */1364 echo apply_filters( 'comments_popup_link_attributes', $attributes );1365 1366 echo '>';1367 comments_number( $zero, $one, $more );1368 echo '</a>';1369 }1370 1371 /**1372 * Retrieve HTML content for reply to comment link.1373 *1374 * @since 2.7.01375 *1376 * @param array $args {1377 * Optional. Override default arguments.1378 *1379 * @type string $add_below The first part of the selector used to identify the comment to respond below.1380 * The resulting value is passed as the first parameter to addComment.moveForm(),1381 * concatenated as $add_below-$comment->comment_ID. Default 'comment'.1382 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter1383 * to addComment.moveForm(), and appended to the link URL as a hash value.1384 * Default 'respond'.1385 * @type string $reply_text The text of the Reply link. Default 'Reply'.1386 * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.1387 * @type int $depth' The depth of the new comment. Must be greater than 0 and less than the value1388 * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.1389 * @type string $before The text or HTML to add before the reply link. Default empty.1390 * @type string $after The text or HTML to add after the reply link. Default empty.1391 * }1392 * @param int $comment Comment being replied to. Default current comment.1393 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.1394 * Default current post.1395 * @return void|false|string Link to show comment form, if successful. False, if comments are closed.1396 */1397 function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {1398 $defaults = array(1399 'add_below' => 'comment',1400 'respond_id' => 'respond',1401 'reply_text' => __( 'Reply' ),1402 'reply_to_text' => __( 'Reply to %s' ),1403 'login_text' => __( 'Log in to Reply' ),1404 'depth' => 0,1405 'before' => '',1406 'after' => ''1407 );1408 1409 $args = wp_parse_args( $args, $defaults );1410 1411 if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {1412 return;1413 }1414 1415 $comment = get_comment( $comment );1416 1417 if ( empty( $post ) ) {1418 $post = $comment->comment_post_ID;1419 }1420 1421 $post = get_post( $post );1422 1423 if ( ! comments_open( $post->ID ) ) {1424 return false;1425 }1426 1427 /**1428 * Filter the comment reply link arguments.1429 *1430 * @since 4.1.01431 *1432 * @param array $args Comment reply link arguments. See {@see get_comment_reply_link()}1433 * for more information on accepted arguments.1434 * @param object $comment The object of the comment being replied to.1435 * @param WP_Post $post The {@see WP_Post} object.1436 */1437 $args = apply_filters( 'comment_reply_link_args', $args, $comment, $post );1438 1439 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {1440 $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',1441 esc_url( wp_login_url( get_permalink() ) ),1442 $args['login_text']1443 );1444 } else {1445 $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',1446 $args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID1447 );1448 1449 $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>",1450 esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . "#" . $args['respond_id'],1451 $onclick,1452 esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),1453 $args['reply_text']1454 );1455 }1456 /**1457 * Filter the comment reply link.1458 *1459 * @since 2.7.01460 *1461 * @param string $link The HTML markup for the comment reply link.1462 * @param array $args An array of arguments overriding the defaults.1463 * @param object $comment The object of the comment being replied.1464 * @param WP_Post $post The WP_Post object.1465 */1466 return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );1467 }1468 1469 /**1470 * Displays the HTML content for reply to comment link.1471 *1472 * @since 2.7.01473 *1474 * @see get_comment_reply_link()1475 *1476 * @param array $args Optional. Override default options.1477 * @param int $comment Comment being replied to. Default current comment.1478 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.1479 * Default current post.1480 * @return mixed Link to show comment form, if successful. False, if comments are closed.1481 */1482 function comment_reply_link($args = array(), $comment = null, $post = null) {1483 echo get_comment_reply_link($args, $comment, $post);1484 }1485 1486 /**1487 * Retrieve HTML content for reply to post link.1488 *1489 * @since 2.7.01490 *1491 * @param array $args {1492 * Optional. Override default arguments.1493 *1494 * @type string $add_below The first part of the selector used to identify the comment to respond below.1495 * The resulting value is passed as the first parameter to addComment.moveForm(),1496 * concatenated as $add_below-$comment->comment_ID. Default is 'post'.1497 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter1498 * to addComment.moveForm(), and appended to the link URL as a hash value.1499 * Default 'respond'.1500 * @type string $reply_text Text of the Reply link. Default is 'Leave a Comment'.1501 * @type string $login_text Text of the link to reply if logged out. Default is 'Log in to leave a Comment'.1502 * @type string $before Text or HTML to add before the reply link. Default empty.1503 * @type string $after Text or HTML to add after the reply link. Default empty.1504 * }1505 * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on.1506 * Default current post.1507 * @return false|null|string Link to show comment form, if successful. False, if comments are closed.1508 */1509 function get_post_reply_link($args = array(), $post = null) {1510 $defaults = array(1511 'add_below' => 'post',1512 'respond_id' => 'respond',1513 'reply_text' => __('Leave a Comment'),1514 'login_text' => __('Log in to leave a Comment'),1515 'before' => '',1516 'after' => '',1517 );1518 1519 $args = wp_parse_args($args, $defaults);1520 1521 $post = get_post($post);1522 1523 if ( ! comments_open( $post->ID ) ) {1524 return false;1525 }1526 1527 if ( get_option('comment_registration') && ! is_user_logged_in() ) {1528 $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',1529 wp_login_url( get_permalink() ),1530 $args['login_text']1531 );1532 } else {1533 $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )',1534 $args['add_below'], $post->ID, $args['respond_id']1535 );1536 1537 $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>",1538 get_permalink( $post->ID ) . '#' . $args['respond_id'],1539 $onclick,1540 $args['reply_text']1541 );1542 }1543 $formatted_link = $args['before'] . $link . $args['after'];1544 /**1545 * Filter the formatted post comments link HTML.1546 *1547 * @since 2.7.01548 *1549 * @param string $formatted The HTML-formatted post comments link.1550 * @param int|WP_Post $post The post ID or WP_Post object.1551 */1552 return apply_filters( 'post_comments_link', $formatted_link, $post );1553 }1554 1555 /**1556 * Displays the HTML content for reply to post link.1557 *1558 * @since 2.7.01559 *1560 * @see get_post_reply_link()1561 *1562 * @param array $args Optional. Override default options,1563 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.1564 * Default current post.1565 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.1566 */1567 function post_reply_link($args = array(), $post = null) {1568 echo get_post_reply_link($args, $post);1569 }1570 1571 /**1572 * Retrieve HTML content for cancel comment reply link.1573 *1574 * @since 2.7.01575 *1576 * @param string $text Optional. Text to display for cancel reply link. Default empty.1577 * @return string1578 */1579 function get_cancel_comment_reply_link( $text = '' ) {1580 if ( empty($text) )1581 $text = __('Click here to cancel reply.');1582 1583 $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';1584 $link = esc_html( remove_query_arg('replytocom') ) . '#respond';1585 1586 $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';1587 /**1588 * Filter the cancel comment reply link HTML.1589 *1590 * @since 2.7.01591 *1592 * @param string $formatted_link The HTML-formatted cancel comment reply link.1593 * @param string $link Cancel comment reply link URL.1594 * @param string $text Cancel comment reply link text.1595 */1596 return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );1597 }1598 1599 /**1600 * Display HTML content for cancel comment reply link.1601 *1602 * @since 2.7.01603 *1604 * @param string $text Optional. Text to display for cancel reply link. Default empty.1605 */1606 function cancel_comment_reply_link( $text = '' ) {1607 echo get_cancel_comment_reply_link($text);1608 }1609 1610 /**1611 * Retrieve hidden input HTML for replying to comments.1612 *1613 * @since 3.0.01614 *1615 * @param int $id Optional. Post ID. Default current post ID.1616 * @return string Hidden input HTML for replying to comments1617 */1618 function get_comment_id_fields( $id = 0 ) {1619 if ( empty( $id ) )1620 $id = get_the_ID();1621 1622 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;1623 $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";1624 $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";1625 1626 /**1627 * Filter the returned comment id fields.1628 *1629 * @since 3.0.01630 *1631 * @param string $result The HTML-formatted hidden id field comment elements.1632 * @param int $id The post ID.1633 * @param int $replytoid The id of the comment being replied to.1634 */1635 return apply_filters( 'comment_id_fields', $result, $id, $replytoid );1636 }1637 1638 /**1639 * Output hidden input HTML for replying to comments.1640 *1641 * @since 2.7.01642 *1643 * @param int $id Optional. Post ID. Default current post ID.1644 */1645 function comment_id_fields( $id = 0 ) {1646 echo get_comment_id_fields( $id );1647 }1648 1649 /**1650 * Display text based on comment reply status.1651 *1652 * Only affects users with JavaScript disabled.1653 *1654 * @since 2.7.01655 *1656 * @global object $comment1657 *1658 * @param string $noreplytext Optional. Text to display when not replying to a comment.1659 * Default false.1660 * @param string $replytext Optional. Text to display when replying to a comment.1661 * Default false. Accepts "%s" for the author of the comment1662 * being replied to.1663 * @param string $linktoparent Optional. Boolean to control making the author's name a link1664 * to their comment. Default true.1665 */1666 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {1667 global $comment;1668 1669 if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );1670 if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );1671 1672 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;1673 1674 if ( 0 == $replytoid )1675 echo $noreplytext;1676 else {1677 $comment = get_comment($replytoid);1678 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();1679 printf( $replytext, $author );1680 }1681 }1682 9 1683 10 /** … … 2024 351 } 2025 352 } 2026 2027 /**2028 * List comments.2029 *2030 * Used in the comments.php template to list comments for a particular post.2031 *2032 * @since 2.7.02033 *2034 * @see WP_Query->comments2035 *2036 * @global WP_Query $wp_query2037 * @global int $comment_alt2038 * @global int $comment_depth2039 * @global int $comment_thread_alt2040 * @global bool $overridden_cpage2041 * @global bool $in_comment_loop2042 *2043 * @param string|array $args {2044 * Optional. Formatting options.2045 *2046 * @type object $walker Instance of a Walker class to list comments. Default null.2047 * @type int $max_depth The maximum comments depth. Default empty.2048 * @type string $style The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.2049 * @type string $callback Callback function to use. Default null.2050 * @type string $end-callback Callback function to use at the end. Default null.2051 * @type string $type Type of comments to list.2052 * Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.2053 * @type int $page Page ID to list comments for. Default empty.2054 * @type int $per_page Number of comments to list per page. Default empty.2055 * @type int $avatar_size Height and width dimensions of the avatar size. Default 32.2056 * @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.2057 * @type bool $reverse_children Whether to reverse child comments in the list. Default null.2058 * @type string $format How to format the comments list.2059 * Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.2060 * @type bool $short_ping Whether to output short pings. Default false.2061 * @type bool $echo Whether to echo the output or return it. Default true.2062 * }2063 * @param array $comments Optional. Array of WP_Comment objects.2064 */2065 function wp_list_comments( $args = array(), $comments = null ) {2066 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;2067 2068 $in_comment_loop = true;2069 2070 $comment_alt = $comment_thread_alt = 0;2071 $comment_depth = 1;2072 2073 $defaults = array(2074 'walker' => null,2075 'max_depth' => '',2076 'style' => 'ul',2077 'callback' => null,2078 'end-callback' => null,2079 'type' => 'all',2080 'page' => '',2081 'per_page' => '',2082 'avatar_size' => 32,2083 'reverse_top_level' => null,2084 'reverse_children' => '',2085 'format' => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',2086 'short_ping' => false,2087 'echo' => true,2088 );2089 2090 $r = wp_parse_args( $args, $defaults );2091 2092 /**2093 * Filter the arguments used in retrieving the comment list.2094 *2095 * @since 4.0.02096 *2097 * @see wp_list_comments()2098 *2099 * @param array $r An array of arguments for displaying comments.2100 */2101 $r = apply_filters( 'wp_list_comments_args', $r );2102 2103 // Figure out what comments we'll be looping through ($_comments)2104 if ( null !== $comments ) {2105 $comments = (array) $comments;2106 if ( empty($comments) )2107 return;2108 if ( 'all' != $r['type'] ) {2109 $comments_by_type = separate_comments($comments);2110 if ( empty($comments_by_type[$r['type']]) )2111 return;2112 $_comments = $comments_by_type[$r['type']];2113 } else {2114 $_comments = $comments;2115 }2116 } else {2117 if ( empty($wp_query->comments) )2118 return;2119 if ( 'all' != $r['type'] ) {2120 if ( empty($wp_query->comments_by_type) )2121 $wp_query->comments_by_type = separate_comments($wp_query->comments);2122 if ( empty($wp_query->comments_by_type[$r['type']]) )2123 return;2124 $_comments = $wp_query->comments_by_type[$r['type']];2125 } else {2126 $_comments = $wp_query->comments;2127 }2128 2129 if ( ! $wp_query->comment_meta_cached ) {2130 $comment_ids = wp_list_pluck( $_comments, 'comment_ID' );2131 update_meta_cache( 'comment', $comment_ids );2132 $wp_query->comment_meta_cached = true;2133 }2134 }2135 2136 if ( '' === $r['per_page'] && get_option('page_comments') )2137 $r['per_page'] = get_query_var('comments_per_page');2138 2139 if ( empty($r['per_page']) ) {2140 $r['per_page'] = 0;2141 $r['page'] = 0;2142 }2143 2144 if ( '' === $r['max_depth'] ) {2145 if ( get_option('thread_comments') )2146 $r['max_depth'] = get_option('thread_comments_depth');2147 else2148 $r['max_depth'] = -1;2149 }2150 2151 if ( '' === $r['page'] ) {2152 if ( empty($overridden_cpage) ) {2153 $r['page'] = get_query_var('cpage');2154 } else {2155 $threaded = ( -1 != $r['max_depth'] );2156 $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;2157 set_query_var( 'cpage', $r['page'] );2158 }2159 }2160 // Validation check2161 $r['page'] = intval($r['page']);2162 if ( 0 == $r['page'] && 0 != $r['per_page'] )2163 $r['page'] = 1;2164 2165 if ( null === $r['reverse_top_level'] )2166 $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );2167 2168 if ( empty( $r['walker'] ) ) {2169 $walker = new Walker_Comment;2170 } else {2171 $walker = $r['walker'];2172 }2173 2174 $output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r );2175 $wp_query->max_num_comment_pages = $walker->max_pages;2176 2177 $in_comment_loop = false;2178 2179 if ( $r['echo'] ) {2180 echo $output;2181 } else {2182 return $output;2183 }2184 }2185 2186 /**2187 * Output a complete commenting form for use within a template.2188 *2189 * Most strings and form fields may be controlled through the $args array passed2190 * into the function, while you may also choose to use the comment_form_default_fields2191 * filter to modify the array of default fields if you'd just like to add a new2192 * one or remove a single field. All fields are also individually passed through2193 * a filter of the form comment_form_field_$name where $name is the key used2194 * in the array of fields.2195 *2196 * @since 3.0.02197 * @since 4.1.0 Introduced the 'class_submit' argument.2198 * @since 4.2.0 Introduced 'submit_button' and 'submit_fields' arguments.2199 *2200 * @param array $args {2201 * Optional. Default arguments and form fields to override.2202 *2203 * @type array $fields {2204 * Default comment fields, filterable by default via the 'comment_form_default_fields' hook.2205 *2206 * @type string $author Comment author field HTML.2207 * @type string $email Comment author email field HTML.2208 * @type string $url Comment author URL field HTML.2209 * }2210 * @type string $comment_field The comment textarea field HTML.2211 * @type string $must_log_in HTML element for a 'must be logged in to comment' message.2212 * @type string $logged_in_as HTML element for a 'logged in as [user]' message.2213 * @type string $comment_notes_before HTML element for a message displayed before the comment form.2214 * Default 'Your email address will not be published.'.2215 * @type string $comment_notes_after HTML element for a message displayed after the comment form.2216 * @type string $id_form The comment form element id attribute. Default 'commentform'.2217 * @type string $id_submit The comment submit element id attribute. Default 'submit'.2218 * @type string $class_submit The comment submit element class attribute. Default 'submit'.2219 * @type string $name_submit The comment submit element name attribute. Default 'submit'.2220 * @type string $title_reply The translatable 'reply' button label. Default 'Leave a Reply'.2221 * @type string $title_reply_to The translatable 'reply-to' button label. Default 'Leave a Reply to %s',2222 * where %s is the author of the comment being replied to.2223 * @type string $cancel_reply_link The translatable 'cancel reply' button label. Default 'Cancel reply'.2224 * @type string $label_submit The translatable 'submit' button label. Default 'Post a comment'.2225 * @type string $submit_button HTML format for the Submit button.2226 * Default: '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'.2227 * @type string $submit_field HTML format for the markup surrounding the Submit button and comment hidden2228 * fields. Default: '<p class="form-submit">%1$s %2$s</a>', where %1$s is the2229 * submit button markup and %2$s is the comment hidden fields.2230 * @type string $format The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.2231 * }2232 * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post.2233 */2234 function comment_form( $args = array(), $post_id = null ) {2235 if ( null === $post_id )2236 $post_id = get_the_ID();2237 2238 $commenter = wp_get_current_commenter();2239 $user = wp_get_current_user();2240 $user_identity = $user->exists() ? $user->display_name : '';2241 2242 $args = wp_parse_args( $args );2243 if ( ! isset( $args['format'] ) )2244 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';2245 2246 $req = get_option( 'require_name_email' );2247 $aria_req = ( $req ? " aria-required='true'" : '' );2248 $html_req = ( $req ? " required='required'" : '' );2249 $html5 = 'html5' === $args['format'];2250 $fields = array(2251 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .2252 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req . ' /></p>',2253 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .2254 '<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>',2255 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .2256 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',2257 );2258 2259 $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );2260 2261 /**2262 * Filter the default comment form fields.2263 *2264 * @since 3.0.02265 *2266 * @param array $fields The default comment fields.2267 */2268 $fields = apply_filters( 'comment_form_default_fields', $fields );2269 $defaults = array(2270 'fields' => $fields,2271 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="required"></textarea></p>',2272 /** This filter is documented in wp-includes/link-template.php */2273 '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>',2274 /** This filter is documented in wp-includes/link-template.php */2275 '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>',2276 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . '</p>',2277 'comment_notes_after' => '',2278 'id_form' => 'commentform',2279 'id_submit' => 'submit',2280 'class_submit' => 'submit',2281 'name_submit' => 'submit',2282 'title_reply' => __( 'Leave a Reply' ),2283 'title_reply_to' => __( 'Leave a Reply to %s' ),2284 'cancel_reply_link' => __( 'Cancel reply' ),2285 'label_submit' => __( 'Post Comment' ),2286 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',2287 'submit_field' => '<p class="form-submit">%1$s %2$s</p>',2288 'format' => 'xhtml',2289 );2290 2291 /**2292 * Filter the comment form default arguments.2293 *2294 * Use 'comment_form_default_fields' to filter the comment fields.2295 *2296 * @since 3.0.02297 *2298 * @param array $defaults The default comment form arguments.2299 */2300 $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );2301 2302 // Ensure that the filtered args contain all required default values.2303 $args = array_merge( $defaults, $args );2304 2305 if ( comments_open( $post_id ) ) : ?>2306 <?php2307 /**2308 * Fires before the comment form.2309 *2310 * @since 3.0.02311 */2312 do_action( 'comment_form_before' );2313 ?>2314 <div id="respond" class="comment-respond">2315 <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>2316 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>2317 <?php echo $args['must_log_in']; ?>2318 <?php2319 /**2320 * Fires after the HTML-formatted 'must log in after' message in the comment form.2321 *2322 * @since 3.0.02323 */2324 do_action( 'comment_form_must_log_in_after' );2325 ?>2326 <?php else : ?>2327 <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' : ''; ?>>2328 <?php2329 /**2330 * Fires at the top of the comment form, inside the form tag.2331 *2332 * @since 3.0.02333 */2334 do_action( 'comment_form_top' );2335 ?>2336 <?php if ( is_user_logged_in() ) : ?>2337 <?php2338 /**2339 * Filter the 'logged in' message for the comment form for display.2340 *2341 * @since 3.0.02342 *2343 * @param string $args_logged_in The logged-in-as HTML-formatted message.2344 * @param array $commenter An array containing the comment author's2345 * username, email, and URL.2346 * @param string $user_identity If the commenter is a registered user,2347 * the display name, blank otherwise.2348 */2349 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );2350 ?>2351 <?php2352 /**2353 * Fires after the is_user_logged_in() check in the comment form.2354 *2355 * @since 3.0.02356 *2357 * @param array $commenter An array containing the comment author's2358 * username, email, and URL.2359 * @param string $user_identity If the commenter is a registered user,2360 * the display name, blank otherwise.2361 */2362 do_action( 'comment_form_logged_in_after', $commenter, $user_identity );2363 ?>2364 <?php else : ?>2365 <?php echo $args['comment_notes_before']; ?>2366 <?php2367 /**2368 * Fires before the comment fields in the comment form.2369 *2370 * @since 3.0.02371 */2372 do_action( 'comment_form_before_fields' );2373 foreach ( (array) $args['fields'] as $name => $field ) {2374 /**2375 * Filter a comment form field for display.2376 *2377 * The dynamic portion of the filter hook, `$name`, refers to the name2378 * of the comment form field. Such as 'author', 'email', or 'url'.2379 *2380 * @since 3.0.02381 *2382 * @param string $field The HTML-formatted output of the comment form field.2383 */2384 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";2385 }2386 /**2387 * Fires after the comment fields in the comment form.2388 *2389 * @since 3.0.02390 */2391 do_action( 'comment_form_after_fields' );2392 ?>2393 <?php endif; ?>2394 <?php2395 /**2396 * Filter the content of the comment textarea field for display.2397 *2398 * @since 3.0.02399 *2400 * @param string $args_comment_field The content of the comment textarea field.2401 */2402 echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );2403 ?>2404 <?php echo $args['comment_notes_after']; ?>2405 2406 <?php2407 $submit_button = sprintf(2408 $args['submit_button'],2409 esc_attr( $args['name_submit'] ),2410 esc_attr( $args['id_submit'] ),2411 esc_attr( $args['class_submit'] ),2412 esc_attr( $args['label_submit'] )2413 );2414 2415 /**2416 * Filter the submit button for the comment form to display.2417 *2418 * @since 4.2.02419 *2420 * @param string $submit_button HTML markup for the submit button.2421 * @param array $args Arguments passed to `comment_form()`.2422 */2423 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );2424 2425 $submit_field = sprintf(2426 $args['submit_field'],2427 $submit_button,2428 get_comment_id_fields( $post_id )2429 );2430 2431 /**2432 * Filter the submit field for the comment form to display.2433 *2434 * The submit field includes the submit button, hidden fields for the2435 * comment form, and any wrapper markup.2436 *2437 * @since 4.2.02438 *2439 * @param string $submit_field HTML markup for the submit field.2440 * @param array $args Arguments passed to comment_form().2441 */2442 echo apply_filters( 'comment_form_submit_field', $submit_field, $args );2443 2444 /**2445 * Fires at the bottom of the comment form, inside the closing </form> tag.2446 *2447 * @since 1.5.02448 *2449 * @param int $post_id The post ID.2450 */2451 do_action( 'comment_form', $post_id );2452 ?>2453 </form>2454 <?php endif; ?>2455 </div><!-- #respond -->2456 <?php2457 /**2458 * Fires after the comment form.2459 *2460 * @since 3.0.02461 */2462 do_action( 'comment_form_after' );2463 else :2464 /**2465 * Fires after the comment form if comments are closed.2466 *2467 * @since 3.0.02468 */2469 do_action( 'comment_form_comments_closed' );2470 endif;2471 } -
trunk/src/wp-includes/comment-template.php
r33961 r33962 1678 1678 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author(); 1679 1679 printf( $replytext, $author ); 1680 }1681 }1682 1683 /**1684 * HTML comment list class.1685 *1686 * @uses Walker1687 * @since 2.7.01688 */1689 class Walker_Comment extends Walker {1690 /**1691 * What the class handles.1692 *1693 * @see Walker::$tree_type1694 *1695 * @since 2.7.01696 * @var string1697 */1698 public $tree_type = 'comment';1699 1700 /**1701 * DB fields to use.1702 *1703 * @see Walker::$db_fields1704 *1705 * @since 2.7.01706 * @var array1707 */1708 public $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');1709 1710 /**1711 * Start the list before the elements are added.1712 *1713 * @see Walker::start_lvl()1714 *1715 * @since 2.7.01716 *1717 * @global int $comment_depth1718 *1719 * @param string $output Passed by reference. Used to append additional content.1720 * @param int $depth Depth of comment.1721 * @param array $args Uses 'style' argument for type of HTML list.1722 */1723 public function start_lvl( &$output, $depth = 0, $args = array() ) {1724 $GLOBALS['comment_depth'] = $depth + 1;1725 1726 switch ( $args['style'] ) {1727 case 'div':1728 break;1729 case 'ol':1730 $output .= '<ol class="children">' . "\n";1731 break;1732 case 'ul':1733 default:1734 $output .= '<ul class="children">' . "\n";1735 break;1736 }1737 }1738 1739 /**1740 * End the list of items after the elements are added.1741 *1742 * @see Walker::end_lvl()1743 *1744 * @since 2.7.01745 *1746 * @global int $comment_depth1747 *1748 * @param string $output Passed by reference. Used to append additional content.1749 * @param int $depth Depth of comment.1750 * @param array $args Will only append content if style argument value is 'ol' or 'ul'.1751 */1752 public function end_lvl( &$output, $depth = 0, $args = array() ) {1753 $GLOBALS['comment_depth'] = $depth + 1;1754 1755 switch ( $args['style'] ) {1756 case 'div':1757 break;1758 case 'ol':1759 $output .= "</ol><!-- .children -->\n";1760 break;1761 case 'ul':1762 default:1763 $output .= "</ul><!-- .children -->\n";1764 break;1765 }1766 }1767 1768 /**1769 * Traverse elements to create list from elements.1770 *1771 * This function is designed to enhance Walker::display_element() to1772 * display children of higher nesting levels than selected inline on1773 * the highest depth level displayed. This prevents them being orphaned1774 * at the end of the comment list.1775 *1776 * Example: max_depth = 2, with 5 levels of nested content.1777 * 11778 * 1.11779 * 1.1.11780 * 1.1.1.11781 * 1.1.1.1.11782 * 1.1.21783 * 1.1.2.11784 * 21785 * 2.21786 *1787 * @see Walker::display_element()1788 * @see wp_list_comments()1789 *1790 * @since 2.7.01791 *1792 * @param object $element Data object.1793 * @param array $children_elements List of elements to continue traversing.1794 * @param int $max_depth Max depth to traverse.1795 * @param int $depth Depth of current element.1796 * @param array $args An array of arguments.1797 * @param string $output Passed by reference. Used to append additional content.1798 */1799 public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {1800 if ( !$element )1801 return;1802 1803 $id_field = $this->db_fields['id'];1804 $id = $element->$id_field;1805 1806 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );1807 1808 // If we're at the max depth, and the current element still has children, loop over those and display them at this level1809 // This is to prevent them being orphaned to the end of the list.1810 if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {1811 foreach ( $children_elements[ $id ] as $child )1812 $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );1813 1814 unset( $children_elements[ $id ] );1815 }1816 1817 }1818 1819 /**1820 * Start the element output.1821 *1822 * @since 2.7.01823 *1824 * @see Walker::start_el()1825 * @see wp_list_comments()1826 *1827 * @global int $comment_depth1828 * @global object $comment1829 *1830 * @param string $output Passed by reference. Used to append additional content.1831 * @param object $comment Comment data object.1832 * @param int $depth Depth of comment in reference to parents.1833 * @param array $args An array of arguments.1834 */1835 public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {1836 $depth++;1837 $GLOBALS['comment_depth'] = $depth;1838 $GLOBALS['comment'] = $comment;1839 1840 if ( !empty( $args['callback'] ) ) {1841 ob_start();1842 call_user_func( $args['callback'], $comment, $args, $depth );1843 $output .= ob_get_clean();1844 return;1845 }1846 1847 if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {1848 ob_start();1849 $this->ping( $comment, $depth, $args );1850 $output .= ob_get_clean();1851 } elseif ( 'html5' === $args['format'] ) {1852 ob_start();1853 $this->html5_comment( $comment, $depth, $args );1854 $output .= ob_get_clean();1855 } else {1856 ob_start();1857 $this->comment( $comment, $depth, $args );1858 $output .= ob_get_clean();1859 }1860 }1861 1862 /**1863 * Ends the element output, if needed.1864 *1865 * @since 2.7.01866 *1867 * @see Walker::end_el()1868 * @see wp_list_comments()1869 *1870 * @param string $output Passed by reference. Used to append additional content.1871 * @param WP_Comment $comment The comment object. Default current comment.1872 * @param int $depth Depth of comment.1873 * @param array $args An array of arguments.1874 */1875 public function end_el( &$output, $comment, $depth = 0, $args = array() ) {1876 if ( !empty( $args['end-callback'] ) ) {1877 ob_start();1878 call_user_func( $args['end-callback'], $comment, $args, $depth );1879 $output .= ob_get_clean();1880 return;1881 }1882 if ( 'div' == $args['style'] )1883 $output .= "</div><!-- #comment-## -->\n";1884 else1885 $output .= "</li><!-- #comment-## -->\n";1886 }1887 1888 /**1889 * Output a pingback comment.1890 *1891 * @access protected1892 * @since 3.6.01893 *1894 * @see wp_list_comments()1895 *1896 * @param WP_Comment $comment The comment object.1897 * @param int $depth Depth of comment.1898 * @param array $args An array of arguments.1899 */1900 protected function ping( $comment, $depth, $args ) {1901 $tag = ( 'div' == $args['style'] ) ? 'div' : 'li';1902 ?>1903 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>1904 <div class="comment-body">1905 <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>1906 </div>1907 <?php1908 }1909 1910 /**1911 * Output a single comment.1912 *1913 * @access protected1914 * @since 3.6.01915 *1916 * @see wp_list_comments()1917 *1918 * @param object $comment Comment to display.1919 * @param int $depth Depth of comment.1920 * @param array $args An array of arguments.1921 */1922 protected function comment( $comment, $depth, $args ) {1923 if ( 'div' == $args['style'] ) {1924 $tag = 'div';1925 $add_below = 'comment';1926 } else {1927 $tag = 'li';1928 $add_below = 'div-comment';1929 }1930 ?>1931 <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '' ); ?> id="comment-<?php comment_ID(); ?>">1932 <?php if ( 'div' != $args['style'] ) : ?>1933 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">1934 <?php endif; ?>1935 <div class="comment-author vcard">1936 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>1937 <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>1938 </div>1939 <?php if ( '0' == $comment->comment_approved ) : ?>1940 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>1941 <br />1942 <?php endif; ?>1943 1944 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>">1945 <?php1946 /* translators: 1: comment date, 2: comment time */1947 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );1948 ?>1949 </div>1950 1951 <?php comment_text( get_comment_id(), array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>1952 1953 <?php1954 comment_reply_link( array_merge( $args, array(1955 'add_below' => $add_below,1956 'depth' => $depth,1957 'max_depth' => $args['max_depth'],1958 'before' => '<div class="reply">',1959 'after' => '</div>'1960 ) ) );1961 ?>1962 1963 <?php if ( 'div' != $args['style'] ) : ?>1964 </div>1965 <?php endif; ?>1966 <?php1967 }1968 1969 /**1970 * Output a comment in the HTML5 format.1971 *1972 * @access protected1973 * @since 3.6.01974 *1975 * @see wp_list_comments()1976 *1977 * @param object $comment Comment to display.1978 * @param int $depth Depth of comment.1979 * @param array $args An array of arguments.1980 */1981 protected function html5_comment( $comment, $depth, $args ) {1982 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';1983 ?>1984 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '' ); ?>>1985 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">1986 <footer class="comment-meta">1987 <div class="comment-author vcard">1988 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>1989 <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?>1990 </div><!-- .comment-author -->1991 1992 <div class="comment-metadata">1993 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>">1994 <time datetime="<?php comment_time( 'c' ); ?>">1995 <?php1996 /* translators: 1: comment date, 2: comment time */1997 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() );1998 ?>1999 </time>2000 </a>2001 <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>2002 </div><!-- .comment-metadata -->2003 2004 <?php if ( '0' == $comment->comment_approved ) : ?>2005 <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>2006 <?php endif; ?>2007 </footer><!-- .comment-meta -->2008 2009 <div class="comment-content">2010 <?php comment_text(); ?>2011 </div><!-- .comment-content -->2012 2013 <?php2014 comment_reply_link( array_merge( $args, array(2015 'add_below' => 'div-comment',2016 'depth' => $depth,2017 'max_depth' => $args['max_depth'],2018 'before' => '<div class="reply">',2019 'after' => '</div>'2020 ) ) );2021 ?>2022 </article><!-- .comment-body -->2023 <?php2024 1680 } 2025 1681 } -
trunk/src/wp-includes/comment.php
r33900 r33962 14 14 require_once( ABSPATH . WPINC . '/class-wp-comment-query.php' ); 15 15 16 /** Walker_Comment class */ 17 require_once( ABSPATH . WPINC . '/class-walker-comment.php' ); 18 16 19 /** Core comments functionality */ 17 20 require_once( ABSPATH . WPINC . '/comment-functions.php' );
Note: See TracChangeset
for help on using the changeset viewer.