PageRenderTime 52ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/comment-template.php

https://github.com/davodey/WordPress
PHP | 2247 lines | 859 code | 189 blank | 1199 comment | 198 complexity | 8a279ca21ac1776d205ef1a60c9c760d MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Comment template functions
  4. *
  5. * These functions are meant to live inside of the WordPress loop.
  6. *
  7. * @package WordPress
  8. * @subpackage Template
  9. */
  10. /**
  11. * Retrieve the author of the current comment.
  12. *
  13. * If the comment has an empty comment_author field, then 'Anonymous' person is
  14. * assumed.
  15. *
  16. * @since 1.5.0
  17. *
  18. * @param int $comment_ID Optional. The ID of the comment for which to retrieve the author. Default current comment.
  19. * @return string The comment author
  20. */
  21. function get_comment_author( $comment_ID = 0 ) {
  22. $comment = get_comment( $comment_ID );
  23. if ( empty( $comment->comment_author ) ) {
  24. if ( $comment->user_id && $user = get_userdata( $comment->user_id ) )
  25. $author = $user->display_name;
  26. else
  27. $author = __('Anonymous');
  28. } else {
  29. $author = $comment->comment_author;
  30. }
  31. /**
  32. * Filter the returned comment author name.
  33. *
  34. * @since 1.5.0
  35. *
  36. * @param string $author The comment author's username.
  37. */
  38. return apply_filters( 'get_comment_author', $author );
  39. }
  40. /**
  41. * Displays the author of the current comment.
  42. *
  43. * @since 0.71
  44. *
  45. * @param int $comment_ID Optional. The ID of the comment for which to print the author. Default current comment.
  46. */
  47. function comment_author( $comment_ID = 0 ) {
  48. $author = get_comment_author( $comment_ID );
  49. /**
  50. * Filter the comment author's name for display.
  51. *
  52. * @since 1.2.0
  53. *
  54. * @param string $author The comment author's username.
  55. */
  56. $author = apply_filters( 'comment_author', $author );
  57. echo $author;
  58. }
  59. /**
  60. * Retrieve the email of the author of the current comment.
  61. *
  62. * @since 1.5.0
  63. *
  64. * @param int $comment_ID Optional. The ID of the comment for which to get the author's email. Default current comment.
  65. * @return string The current comment author's email
  66. */
  67. function get_comment_author_email( $comment_ID = 0 ) {
  68. $comment = get_comment( $comment_ID );
  69. /**
  70. * Filter the comment author's returned email address.
  71. *
  72. * @since 1.5.0
  73. *
  74. * @param string $comment_author_email The comment author's email address.
  75. */
  76. return apply_filters( 'get_comment_author_email', $comment->comment_author_email );
  77. }
  78. /**
  79. * Display the email of the author of the current global $comment.
  80. *
  81. * Care should be taken to protect the email address and assure that email
  82. * harvesters do not capture your commentors' email address. Most assume that
  83. * their email address will not appear in raw form on the blog. Doing so will
  84. * enable anyone, including those that people don't want to get the email
  85. * address and use it for their own means good and bad.
  86. *
  87. * @since 0.71
  88. *
  89. * @param int $comment_ID Optional. The ID of the comment for which to print the author's email. Default current comment.
  90. */
  91. function comment_author_email( $comment_ID = 0 ) {
  92. $author_email = get_comment_author_email( $comment_ID );
  93. /**
  94. * Filter the comment author's email for display.
  95. *
  96. * @since 1.2.0
  97. *
  98. * @param string $author_email The comment author's email address.
  99. */
  100. echo apply_filters( 'author_email', $author_email );
  101. }
  102. /**
  103. * Display the html email link to the author of the current comment.
  104. *
  105. * Care should be taken to protect the email address and assure that email
  106. * harvesters do not capture your commentors' email address. Most assume that
  107. * their email address will not appear in raw form on the blog. Doing so will
  108. * enable anyone, including those that people don't want to get the email
  109. * address and use it for their own means good and bad.
  110. *
  111. * @since 0.71
  112. *
  113. * @param string $linktext Optional. Text to display instead of the comment author's email address.
  114. * Default empty.
  115. * @param string $before Optional. Text or HTML to display before the email link. Default empty.
  116. * @param string $after Optional. Text or HTML to display after the email link. Default empty.
  117. */
  118. function comment_author_email_link( $linktext = '', $before = '', $after = '' ) {
  119. if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )
  120. echo $link;
  121. }
  122. /**
  123. * Return the html email link to the author of the current comment.
  124. *
  125. * Care should be taken to protect the email address and assure that email
  126. * harvesters do not capture your commentors' email address. Most assume that
  127. * their email address will not appear in raw form on the blog. Doing so will
  128. * enable anyone, including those that people don't want to get the email
  129. * address and use it for their own means good and bad.
  130. *
  131. * @global object $comment The current Comment row object.
  132. *
  133. * @since 2.7.0
  134. *
  135. * @param string $linktext Optional. Text to display instead of the comment author's email address.
  136. * Default empty.
  137. * @param string $before Optional. Text or HTML to display before the email link. Default empty.
  138. * @param string $after Optional. Text or HTML to display after the email link. Default empty.
  139. */
  140. function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) {
  141. global $comment;
  142. /**
  143. * Filter the comment author's email for display.
  144. *
  145. * Care should be taken to protect the email address and assure that email
  146. * harvesters do not capture your commenters' email address.
  147. *
  148. * @since 1.2.0
  149. *
  150. * @param string $comment_author_email The comment author's email address.
  151. */
  152. $email = apply_filters( 'comment_email', $comment->comment_author_email );
  153. if ((!empty($email)) && ($email != '@')) {
  154. $display = ($linktext != '') ? $linktext : $email;
  155. $return = $before;
  156. $return .= "<a href='mailto:$email'>$display</a>";
  157. $return .= $after;
  158. return $return;
  159. } else {
  160. return '';
  161. }
  162. }
  163. /**
  164. * Retrieve the HTML link to the URL of the author of the current comment.
  165. *
  166. * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
  167. * which falls back to the global comment variable if the $comment_ID argument is empty.
  168. *
  169. * @since 1.5.0
  170. *
  171. * @param int $comment_ID ID of the comment for which to get the author's link.
  172. * Default current comment.
  173. * @return string The comment author name or HTML link for author's URL.
  174. */
  175. function get_comment_author_link( $comment_ID = 0 ) {
  176. $url = get_comment_author_url( $comment_ID );
  177. $author = get_comment_author( $comment_ID );
  178. if ( empty( $url ) || 'http://' == $url )
  179. $return = $author;
  180. else
  181. $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
  182. /**
  183. * Filter the comment author's link for display.
  184. *
  185. * @since 1.5.0
  186. *
  187. * @param string $return The HTML-formatted comment author link.
  188. * Empty for an invalid URL.
  189. */
  190. return apply_filters( 'get_comment_author_link', $return );
  191. }
  192. /**
  193. * Display the html link to the url of the author of the current comment.
  194. *
  195. * @since 0.71
  196. *
  197. * @see get_comment_author_link() Echoes result
  198. *
  199. * @param int $comment_ID ID of the comment for which to print the author's
  200. * link. Default current comment.
  201. */
  202. function comment_author_link( $comment_ID = 0 ) {
  203. echo get_comment_author_link( $comment_ID );
  204. }
  205. /**
  206. * Retrieve the IP address of the author of the current comment.
  207. *
  208. * @since 1.5.0
  209. *
  210. * @param int $comment_ID ID of the comment for which to get the author's IP
  211. * address. Default current comment.
  212. * @return string Comment author's IP address.
  213. */
  214. function get_comment_author_IP( $comment_ID = 0 ) {
  215. $comment = get_comment( $comment_ID );
  216. /**
  217. * Filter the comment author's returned IP address.
  218. *
  219. * @since 1.5.0
  220. *
  221. * @param string $comment_author_IP The comment author's IP address.
  222. */
  223. return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP );
  224. }
  225. /**
  226. * Display the IP address of the author of the current comment.
  227. *
  228. * @since 0.71
  229. *
  230. * @param int $comment_ID ID of the comment for which to print the author's IP
  231. * address. Default current comment.
  232. */
  233. function comment_author_IP( $comment_ID = 0 ) {
  234. echo get_comment_author_IP( $comment_ID );
  235. }
  236. /**
  237. * Retrieve the url of the author of the current comment.
  238. *
  239. * @since 1.5.0
  240. *
  241. * @param int $comment_ID ID of the comment for which to get the author's URL.
  242. * Default current comment.
  243. * @return string
  244. */
  245. function get_comment_author_url( $comment_ID = 0 ) {
  246. $comment = get_comment( $comment_ID );
  247. $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
  248. $url = esc_url( $url, array('http', 'https') );
  249. /**
  250. * Filter the comment author's URL.
  251. *
  252. * @since 1.5.0
  253. *
  254. * @param string $url The comment author's URL.
  255. */
  256. return apply_filters( 'get_comment_author_url', $url );
  257. }
  258. /**
  259. * Display the url of the author of the current comment.
  260. *
  261. * @since 0.71
  262. *
  263. * @param int $comment_ID ID of the comment for which to print the author's URL.
  264. * Default current comment.
  265. */
  266. function comment_author_url( $comment_ID = 0 ) {
  267. $author_url = get_comment_author_url( $comment_ID );
  268. /**
  269. * Filter the comment author's URL for display.
  270. *
  271. * @since 1.2.0
  272. *
  273. * @param string $author_url The comment author's URL.
  274. */
  275. echo apply_filters( 'comment_url', $author_url );
  276. }
  277. /**
  278. * Retrieves the HTML link of the url of the author of the current comment.
  279. *
  280. * $linktext parameter is only used if the URL does not exist for the comment
  281. * author. If the URL does exist then the URL will be used and the $linktext
  282. * will be ignored.
  283. *
  284. * Encapsulate the HTML link between the $before and $after. So it will appear
  285. * in the order of $before, link, and finally $after.
  286. *
  287. * @since 1.5.0
  288. *
  289. * @param string $linktext Optional. The text to display instead of the comment
  290. * author's email address. Default empty.
  291. * @param string $before Optional. The text or HTML to display before the email link.
  292. * Default empty.
  293. * @param string $after Optional. The text or HTML to display after the email link.
  294. * Default empty.
  295. * @return string The HTML link between the $before and $after parameters.
  296. */
  297. function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
  298. $url = get_comment_author_url();
  299. $display = ($linktext != '') ? $linktext : $url;
  300. $display = str_replace( 'http://www.', '', $display );
  301. $display = str_replace( 'http://', '', $display );
  302. if ( '/' == substr($display, -1) )
  303. $display = substr($display, 0, -1);
  304. $return = "$before<a href='$url' rel='external'>$display</a>$after";
  305. /**
  306. * Filter the comment author's returned URL link.
  307. *
  308. * @since 1.5.0
  309. *
  310. * @param string $return The HTML-formatted comment author URL link.
  311. */
  312. return apply_filters( 'get_comment_author_url_link', $return );
  313. }
  314. /**
  315. * Displays the HTML link of the url of the author of the current comment.
  316. *
  317. * @since 0.71
  318. *
  319. * @param string $linktext Optional. Text to display instead of the comment author's
  320. * email address. Default empty.
  321. * @param string $before Optional. Text or HTML to display before the email link.
  322. * Default empty.
  323. * @param string $after Optional. Text or HTML to display after the email link.
  324. * Default empty.
  325. */
  326. function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
  327. echo get_comment_author_url_link( $linktext, $before, $after );
  328. }
  329. /**
  330. * Generates semantic classes for each comment element.
  331. *
  332. * @since 2.7.0
  333. *
  334. * @param string|array $class Optional. One or more classes to add to the class list.
  335. * Default empty.
  336. * @param int $comment_id Comment ID. Default current comment.
  337. * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
  338. * @param bool $echo Optional. Whether to cho or return the output.
  339. * Default true.
  340. */
  341. function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
  342. // Separates classes with a single space, collates classes for comment DIV
  343. $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
  344. if ( $echo)
  345. echo $class;
  346. else
  347. return $class;
  348. }
  349. /**
  350. * Returns the classes for the comment div as an array.
  351. *
  352. * @since 2.7.0
  353. *
  354. * @param string|array $class Optional. One or more classes to add to the class list. Default empty.
  355. * @param int $comment_id Comment ID. Default current comment.
  356. * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
  357. * @return array An array of classes.
  358. */
  359. function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
  360. global $comment_alt, $comment_depth, $comment_thread_alt;
  361. $comment = get_comment($comment_id);
  362. $classes = array();
  363. // Get the comment type (comment, trackback),
  364. $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
  365. // If the comment author has an id (registered), then print the log in name
  366. if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
  367. // For all registered users, 'byuser'
  368. $classes[] = 'byuser';
  369. $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
  370. // For comment authors who are the author of the post
  371. if ( $post = get_post($post_id) ) {
  372. if ( $comment->user_id === $post->post_author )
  373. $classes[] = 'bypostauthor';
  374. }
  375. }
  376. if ( empty($comment_alt) )
  377. $comment_alt = 0;
  378. if ( empty($comment_depth) )
  379. $comment_depth = 1;
  380. if ( empty($comment_thread_alt) )
  381. $comment_thread_alt = 0;
  382. if ( $comment_alt % 2 ) {
  383. $classes[] = 'odd';
  384. $classes[] = 'alt';
  385. } else {
  386. $classes[] = 'even';
  387. }
  388. $comment_alt++;
  389. // Alt for top-level comments
  390. if ( 1 == $comment_depth ) {
  391. if ( $comment_thread_alt % 2 ) {
  392. $classes[] = 'thread-odd';
  393. $classes[] = 'thread-alt';
  394. } else {
  395. $classes[] = 'thread-even';
  396. }
  397. $comment_thread_alt++;
  398. }
  399. $classes[] = "depth-$comment_depth";
  400. if ( !empty($class) ) {
  401. if ( !is_array( $class ) )
  402. $class = preg_split('#\s+#', $class);
  403. $classes = array_merge($classes, $class);
  404. }
  405. $classes = array_map('esc_attr', $classes);
  406. /**
  407. * Filter the returned CSS classes for the current comment.
  408. *
  409. * @since 2.7.0
  410. *
  411. * @param array $classes An array of comment classes.
  412. * @param string $class A comma-separated list of additional classes added to the list.
  413. * @param int $comment_id The comment id.
  414. * @param int|WP_Post $post_id The post ID or WP_Post object.
  415. */
  416. return apply_filters( 'comment_class', $classes, $class, $comment_id, $post_id );
  417. }
  418. /**
  419. * Retrieve the comment date of the current comment.
  420. *
  421. * @since 1.5.0
  422. *
  423. * @param string $d Optional. The format of the date. Default user's setting.
  424. * @param int $comment_ID ID of the comment for which to get the date. Default current comment.
  425. * @return string The comment's date.
  426. */
  427. function get_comment_date( $d = '', $comment_ID = 0 ) {
  428. $comment = get_comment( $comment_ID );
  429. if ( '' == $d )
  430. $date = mysql2date(get_option('date_format'), $comment->comment_date);
  431. else
  432. $date = mysql2date($d, $comment->comment_date);
  433. /**
  434. * Filter the returned comment date.
  435. *
  436. * @since 1.5.0
  437. *
  438. * @param string|int $date Formatted date string or Unix timestamp.
  439. * @param string $d The format of the date.
  440. * @param object $comment The comment object.
  441. */
  442. return apply_filters( 'get_comment_date', $date, $d, $comment );
  443. }
  444. /**
  445. * Display the comment date of the current comment.
  446. *
  447. * @since 0.71
  448. *
  449. * @param string $d Optional. The format of the date. Default user's settings.
  450. * @param int $comment_ID ID of the comment for which to print the date. Default current comment.
  451. */
  452. function comment_date( $d = '', $comment_ID = 0 ) {
  453. echo get_comment_date( $d, $comment_ID );
  454. }
  455. /**
  456. * Retrieve the excerpt of the current comment.
  457. *
  458. * Will cut each word and only output the first 20 words with '&hellip;' at the end.
  459. * If the word count is less than 20, then no truncating is done and no '&hellip;'
  460. * will appear.
  461. *
  462. * @since 1.5.0
  463. *
  464. * @param int $comment_ID ID of the comment for which to get the excerpt.
  465. * Default current comment.
  466. * @return string The maybe truncated comment with 20 words or less.
  467. */
  468. function get_comment_excerpt( $comment_ID = 0 ) {
  469. $comment = get_comment( $comment_ID );
  470. $comment_text = strip_tags($comment->comment_content);
  471. $blah = explode(' ', $comment_text);
  472. if (count($blah) > 20) {
  473. $k = 20;
  474. $use_dotdotdot = 1;
  475. } else {
  476. $k = count($blah);
  477. $use_dotdotdot = 0;
  478. }
  479. $excerpt = '';
  480. for ($i=0; $i<$k; $i++) {
  481. $excerpt .= $blah[$i] . ' ';
  482. }
  483. $excerpt .= ($use_dotdotdot) ? '&hellip;' : '';
  484. /**
  485. * Filter the retrieved comment excerpt.
  486. *
  487. * @since 1.5.0
  488. *
  489. * @param string $excerpt The comment excerpt text.
  490. */
  491. return apply_filters( 'get_comment_excerpt', $excerpt );
  492. }
  493. /**
  494. * Display the excerpt of the current comment.
  495. *
  496. * @since 1.2.0
  497. *
  498. * @param int $comment_ID ID of the comment for which to print the excerpt.
  499. * Default current comment.
  500. */
  501. function comment_excerpt( $comment_ID = 0 ) {
  502. $comment_excerpt = get_comment_excerpt($comment_ID);
  503. /**
  504. * Filter the comment excerpt for display.
  505. *
  506. * @since 1.2.0
  507. *
  508. * @param string $comment_excerpt The comment excerpt text.
  509. */
  510. echo apply_filters( 'comment_excerpt', $comment_excerpt );
  511. }
  512. /**
  513. * Retrieve the comment id of the current comment.
  514. *
  515. * @since 1.5.0
  516. *
  517. * @return int The comment ID.
  518. */
  519. function get_comment_ID() {
  520. global $comment;
  521. /**
  522. * Filter the returned comment ID.
  523. *
  524. * @since 1.5.0
  525. *
  526. * @param int $comment_ID The current comment ID.
  527. */
  528. return apply_filters( 'get_comment_ID', $comment->comment_ID );
  529. }
  530. /**
  531. * Display the comment id of the current comment.
  532. *
  533. * @since 0.71
  534. */
  535. function comment_ID() {
  536. echo get_comment_ID();
  537. }
  538. /**
  539. * Retrieve the link to a given comment.
  540. *
  541. * @since 1.5.0
  542. *
  543. * @see get_page_of_comment()
  544. *
  545. * @param mixed $comment Comment to retrieve. Default current comment.
  546. * @param array $args Optional. An array of arguments to override the defaults.
  547. * @return string The permalink to the given comment.
  548. */
  549. function get_comment_link( $comment = null, $args = array() ) {
  550. global $wp_rewrite, $in_comment_loop;
  551. $comment = get_comment($comment);
  552. // Backwards compat
  553. if ( ! is_array( $args ) ) {
  554. $args = array( 'page' => $args );
  555. }
  556. $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
  557. $args = wp_parse_args( $args, $defaults );
  558. if ( '' === $args['per_page'] && get_option('page_comments') )
  559. $args['per_page'] = get_option('comments_per_page');
  560. if ( empty($args['per_page']) ) {
  561. $args['per_page'] = 0;
  562. $args['page'] = 0;
  563. }
  564. if ( $args['per_page'] ) {
  565. if ( '' == $args['page'] )
  566. $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
  567. if ( $wp_rewrite->using_permalinks() )
  568. $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
  569. else
  570. $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
  571. } else {
  572. $link = get_permalink( $comment->comment_post_ID );
  573. }
  574. $link = $link . '#comment-' . $comment->comment_ID;
  575. /**
  576. * Filter the returned single comment permalink.
  577. *
  578. * @since 2.8.0
  579. *
  580. * @see get_page_of_comment()
  581. *
  582. * @param string $link The comment permalink with '#comment-$id' appended.
  583. * @param object $comment The current comment object.
  584. * @param array $args An array of arguments to override the defaults.
  585. */
  586. return apply_filters( 'get_comment_link', $link, $comment, $args );
  587. }
  588. /**
  589. * Retrieve the link to the current post comments.
  590. *
  591. * @since 1.5.0
  592. *
  593. * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
  594. * @return string The link to the comments.
  595. */
  596. function get_comments_link( $post_id = 0 ) {
  597. $comments_link = get_permalink( $post_id ) . '#comments';
  598. /**
  599. * Filter the returned post comments permalink.
  600. *
  601. * @since 3.6.0
  602. *
  603. * @param string $comments_link Post comments permalink with '#comments' appended.
  604. * @param int|WP_Post $post_id Post ID or WP_Post object.
  605. */
  606. return apply_filters( 'get_comments_link', $comments_link, $post_id );
  607. }
  608. /**
  609. * Display the link to the current post comments.
  610. *
  611. * @since 0.71
  612. *
  613. * @param string $deprecated Not Used.
  614. * @param bool $deprecated_2 Not Used.
  615. */
  616. function comments_link( $deprecated = '', $deprecated_2 = '' ) {
  617. if ( !empty( $deprecated ) )
  618. _deprecated_argument( __FUNCTION__, '0.72' );
  619. if ( !empty( $deprecated_2 ) )
  620. _deprecated_argument( __FUNCTION__, '1.3' );
  621. echo esc_url( get_comments_link() );
  622. }
  623. /**
  624. * Retrieve the amount of comments a post has.
  625. *
  626. * @since 1.5.0
  627. *
  628. * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
  629. * @return int The number of comments a post has.
  630. */
  631. function get_comments_number( $post_id = 0 ) {
  632. $post = get_post( $post_id );
  633. if ( ! $post ) {
  634. $count = 0;
  635. } else {
  636. $count = $post->comment_count;
  637. $post_id = $post->ID;
  638. }
  639. /**
  640. * Filter the returned comment count for a post.
  641. *
  642. * @since 1.5.0
  643. *
  644. * @param int $count Number of comments a post has.
  645. * @param int $post_id Post ID.
  646. */
  647. return apply_filters( 'get_comments_number', $count, $post_id );
  648. }
  649. /**
  650. * Display the language string for the number of comments the current post has.
  651. *
  652. * @since 0.71
  653. *
  654. * @param string $zero Optional. Text for no comments. Default false.
  655. * @param string $one Optional. Text for one comment. Default false.
  656. * @param string $more Optional. Text for more than one comment. Default false.
  657. * @param string $deprecated Not used.
  658. */
  659. function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
  660. if ( !empty( $deprecated ) )
  661. _deprecated_argument( __FUNCTION__, '1.3' );
  662. $number = get_comments_number();
  663. if ( $number > 1 )
  664. $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
  665. elseif ( $number == 0 )
  666. $output = ( false === $zero ) ? __('No Comments') : $zero;
  667. else // must be one
  668. $output = ( false === $one ) ? __('1 Comment') : $one;
  669. /**
  670. * Filter the comments count for display.
  671. *
  672. * @since 1.5.0
  673. *
  674. * @see _n()
  675. *
  676. * @param string $output A translatable string formatted based on whether the count
  677. * is equal to 0, 1, or 1+.
  678. * @param int $number The number of post comments.
  679. */
  680. echo apply_filters( 'comments_number', $output, $number );
  681. }
  682. /**
  683. * Retrieve the text of the current comment.
  684. *
  685. * @since 1.5.0
  686. *
  687. * @see Walker_Comment::comment()
  688. *
  689. * @param int $comment_ID ID of the comment for which to get the text. Default current comment.
  690. * @param array $args Optional. An array of arguments. Default empty.
  691. * @return string The comment content.
  692. */
  693. function get_comment_text( $comment_ID = 0, $args = array() ) {
  694. $comment = get_comment( $comment_ID );
  695. /**
  696. * Filter the text of a comment.
  697. *
  698. * @since 1.5.0
  699. *
  700. * @see Walker_Comment::comment()
  701. *
  702. * @param string $comment_content Text of the comment.
  703. * @param object $comment The comment object.
  704. * @param array $args An array of arguments.
  705. */
  706. return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args );
  707. }
  708. /**
  709. * Display the text of the current comment.
  710. *
  711. * @since 0.71
  712. *
  713. * @see Walker_Comment::comment()
  714. *
  715. * @param int $comment_ID ID of the comment for which to print the text. Default 0.
  716. * @param array $args Optional. An array of arguments. Default empty array. Default empty.
  717. */
  718. function comment_text( $comment_ID = 0, $args = array() ) {
  719. $comment = get_comment( $comment_ID );
  720. $comment_text = get_comment_text( $comment_ID , $args );
  721. /**
  722. * Filter the text of a comment to be displayed.
  723. *
  724. * @since 1.2.0
  725. *
  726. * @see Walker_Comment::comment()
  727. *
  728. * @param string $comment_text Text of the current comment.
  729. * @param object $comment The comment object.
  730. * @param array $args An array of arguments.
  731. */
  732. echo apply_filters( 'comment_text', $comment_text, $comment, $args );
  733. }
  734. /**
  735. * Retrieve the comment time of the current comment.
  736. *
  737. * @since 1.5.0
  738. *
  739. * @param string $d Optional. The format of the time. Default user's settings.
  740. * @param bool $gmt Optional. Whether to use the GMT date. Default false.
  741. * @param bool $translate Optional. Whether to translate the time (for use in feeds).
  742. * Default true.
  743. * @return string The formatted time.
  744. */
  745. function get_comment_time( $d = '', $gmt = false, $translate = true ) {
  746. global $comment;
  747. $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
  748. if ( '' == $d )
  749. $date = mysql2date(get_option('time_format'), $comment_date, $translate);
  750. else
  751. $date = mysql2date($d, $comment_date, $translate);
  752. /**
  753. * Filter the returned comment time.
  754. *
  755. * @since 1.5.0
  756. *
  757. * @param string|int $date The comment time, formatted as a date string or Unix timestamp.
  758. * @param string $d Date format.
  759. * @param bool $gmt Whether the GMT date is in use.
  760. * @param bool $translate Whether the time is translated.
  761. * @param object $comment The comment object.
  762. */
  763. return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment );
  764. }
  765. /**
  766. * Display the comment time of the current comment.
  767. *
  768. * @since 0.71
  769. *
  770. * @param string $d Optional. The format of the time. Default user's settings.
  771. */
  772. function comment_time( $d = '' ) {
  773. echo get_comment_time($d);
  774. }
  775. /**
  776. * Retrieve the comment type of the current comment.
  777. *
  778. * @since 1.5.0
  779. *
  780. * @param int $comment_ID ID of the comment for which to get the type. Default current comment.
  781. * @return string The comment type.
  782. */
  783. function get_comment_type( $comment_ID = 0 ) {
  784. $comment = get_comment( $comment_ID );
  785. if ( '' == $comment->comment_type )
  786. $comment->comment_type = 'comment';
  787. /**
  788. * Filter the returned comment type.
  789. *
  790. * @since 1.5.0
  791. *
  792. * @param string $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
  793. */
  794. return apply_filters( 'get_comment_type', $comment->comment_type );
  795. }
  796. /**
  797. * Display the comment type of the current comment.
  798. *
  799. * @since 0.71
  800. *
  801. * @param string $commenttxt Optional. String to display for comment type. Default false.
  802. * @param string $trackbacktxt Optional. String to display for trackback type. Default false.
  803. * @param string $pingbacktxt Optional. String to display for pingback type. Default false.
  804. */
  805. function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
  806. if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
  807. if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
  808. if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
  809. $type = get_comment_type();
  810. switch( $type ) {
  811. case 'trackback' :
  812. echo $trackbacktxt;
  813. break;
  814. case 'pingback' :
  815. echo $pingbacktxt;
  816. break;
  817. default :
  818. echo $commenttxt;
  819. }
  820. }
  821. /**
  822. * Retrieve The current post's trackback URL.
  823. *
  824. * There is a check to see if permalink's have been enabled and if so, will
  825. * retrieve the pretty path. If permalinks weren't enabled, the ID of the
  826. * current post is used and appended to the correct page to go to.
  827. *
  828. * @since 1.5.0
  829. *
  830. * @return string The trackback URL after being filtered.
  831. */
  832. function get_trackback_url() {
  833. if ( '' != get_option('permalink_structure') )
  834. $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
  835. else
  836. $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
  837. /**
  838. * Filter the returned trackback URL.
  839. *
  840. * @since 2.2.0
  841. *
  842. * @param string $tb_url The trackback URL.
  843. */
  844. return apply_filters( 'trackback_url', $tb_url );
  845. }
  846. /**
  847. * Display the current post's trackback URL.
  848. *
  849. * @since 0.71
  850. *
  851. * @param bool $deprecated_echo Not used.
  852. * @return void|string Should only be used to echo the trackback URL, use get_trackback_url()
  853. * for the result instead.
  854. */
  855. function trackback_url( $deprecated_echo = true ) {
  856. if ( $deprecated_echo !== true )
  857. _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
  858. if ( $deprecated_echo )
  859. echo get_trackback_url();
  860. else
  861. return get_trackback_url();
  862. }
  863. /**
  864. * Generate and display the RDF for the trackback information of current post.
  865. *
  866. * Deprecated in 3.0.0, and restored in 3.0.1.
  867. *
  868. * @since 0.71
  869. *
  870. * @param int $deprecated Not used (Was $timezone = 0).
  871. */
  872. function trackback_rdf( $deprecated = '' ) {
  873. if ( ! empty( $deprecated ) ) {
  874. _deprecated_argument( __FUNCTION__, '2.5' );
  875. }
  876. if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'W3C_Validator' ) ) {
  877. return;
  878. }
  879. echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  880. xmlns:dc="http://purl.org/dc/elements/1.1/"
  881. xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  882. <rdf:Description rdf:about="';
  883. the_permalink();
  884. echo '"'."\n";
  885. echo ' dc:identifier="';
  886. the_permalink();
  887. echo '"'."\n";
  888. echo ' dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
  889. echo ' trackback:ping="'.get_trackback_url().'"'." />\n";
  890. echo '</rdf:RDF>';
  891. }
  892. /**
  893. * Whether the current post is open for comments.
  894. *
  895. * @since 1.5.0
  896. *
  897. * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
  898. * @return bool True if the comments are open.
  899. */
  900. function comments_open( $post_id = null ) {
  901. $_post = get_post($post_id);
  902. $open = ( 'open' == $_post->comment_status );
  903. /**
  904. * Filter whether the current post is open for comments.
  905. *
  906. * @since 2.5.0
  907. *
  908. * @param bool $open Whether the current post is open for comments.
  909. * @param int|WP_Post $post_id The post ID or WP_Post object.
  910. */
  911. return apply_filters( 'comments_open', $open, $post_id );
  912. }
  913. /**
  914. * Whether the current post is open for pings.
  915. *
  916. * @since 1.5.0
  917. *
  918. * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
  919. * @return bool True if pings are accepted
  920. */
  921. function pings_open( $post_id = null ) {
  922. $_post = get_post($post_id);
  923. $open = ( 'open' == $_post->ping_status );
  924. /**
  925. * Filter whether the current post is open for pings.
  926. *
  927. * @since 2.5.0
  928. *
  929. * @param bool $open Whether the current post is open for pings.
  930. * @param int|WP_Post $post_id The post ID or WP_Post object.
  931. */
  932. return apply_filters( 'pings_open', $open, $post_id );
  933. }
  934. /**
  935. * Display form token for unfiltered comments.
  936. *
  937. * Will only display nonce token if the current user has permissions for
  938. * unfiltered html. Won't display the token for other users.
  939. *
  940. * The function was backported to 2.0.10 and was added to versions 2.1.3 and
  941. * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in
  942. * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.
  943. *
  944. * Backported to 2.0.10.
  945. *
  946. * @since 2.1.3
  947. */
  948. function wp_comment_form_unfiltered_html_nonce() {
  949. $post = get_post();
  950. $post_id = $post ? $post->ID : 0;
  951. if ( current_user_can( 'unfiltered_html' ) ) {
  952. wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
  953. echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
  954. }
  955. }
  956. /**
  957. * Load the comment template specified in $file.
  958. *
  959. * Will not display the comments template if not on single post or page, or if
  960. * the post does not have comments.
  961. *
  962. * Uses the WordPress database object to query for the comments. The comments
  963. * are passed through the 'comments_array' filter hook with the list of comments
  964. * and the post ID respectively.
  965. *
  966. * The $file path is passed through a filter hook called, 'comments_template'
  967. * which includes the template path and $file combined. Tries the $filtered path
  968. * first and if it fails it will require the default comment template from the
  969. * default theme. If either does not exist, then the WordPress process will be
  970. * halted. It is advised for that reason, that the default theme is not deleted.
  971. *
  972. * @todo Document globals
  973. * @uses $withcomments Will not try to get the comments if the post has none.
  974. *
  975. * @since 1.5.0
  976. *
  977. * @param string $file Optional. The file to load. Default '/comments.php'.
  978. * @param bool $separate_comments Optional. Whether to separate the comments by comment type.
  979. * Default false.
  980. * @return null Returns null if no comments appear.
  981. */
  982. function comments_template( $file = '/comments.php', $separate_comments = false ) {
  983. global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
  984. if ( !(is_single() || is_page() || $withcomments) || empty($post) )
  985. return;
  986. if ( empty($file) )
  987. $file = '/comments.php';
  988. $req = get_option('require_name_email');
  989. /*
  990. * Comment author information fetched from the comment cookies.
  991. * Uuses wp_get_current_commenter().
  992. */
  993. $commenter = wp_get_current_commenter();
  994. /*
  995. * The name of the current comment author escaped for use in attributes.
  996. * Escaped by sanitize_comment_cookies().
  997. */
  998. $comment_author = $commenter['comment_author'];
  999. /*
  1000. * The email address of the current comment author escaped for use in attributes.
  1001. * Escaped by sanitize_comment_cookies().
  1002. */
  1003. $comment_author_email = $commenter['comment_author_email'];
  1004. /*
  1005. * The url of the current comment author escaped for use in attributes.
  1006. */
  1007. $comment_author_url = esc_url($commenter['comment_author_url']);
  1008. /** @todo Use API instead of SELECTs. */
  1009. if ( $user_ID) {
  1010. $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));
  1011. } else if ( empty($comment_author) ) {
  1012. $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
  1013. } else {
  1014. $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));
  1015. }
  1016. /**
  1017. * Filter the comments array.
  1018. *
  1019. * @since 2.1.0
  1020. *
  1021. * @param array $comments Array of comments supplied to the comments template.
  1022. * @param int $post_ID Post ID.
  1023. */
  1024. $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
  1025. $comments = &$wp_query->comments;
  1026. $wp_query->comment_count = count($wp_query->comments);
  1027. update_comment_cache($wp_query->comments);
  1028. if ( $separate_comments ) {
  1029. $wp_query->comments_by_type = separate_comments($comments);
  1030. $comments_by_type = &$wp_query->comments_by_type;
  1031. }
  1032. $overridden_cpage = false;
  1033. if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
  1034. set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
  1035. $overridden_cpage = true;
  1036. }
  1037. if ( !defined('COMMENTS_TEMPLATE') )
  1038. define('COMMENTS_TEMPLATE', true);
  1039. $theme_template = get_stylesheet_directory() . $file;
  1040. /**
  1041. * Filter the path to the theme template file used for the comments template.
  1042. *
  1043. * @since 1.5.1
  1044. *
  1045. * @param string $theme_template The path to the theme template file.
  1046. */
  1047. $include = apply_filters( 'comments_template', $theme_template );
  1048. if ( file_exists( $include ) )
  1049. require( $include );
  1050. elseif ( file_exists( get_template_directory() . $file ) )
  1051. require( get_template_directory() . $file );
  1052. else // Backward compat code will be removed in a future release
  1053. require( ABSPATH . WPINC . '/theme-compat/comments.php');
  1054. }
  1055. /**
  1056. * Display the JS popup script to show a comment.
  1057. *
  1058. * If the $file parameter is empty, then the home page is assumed. The defaults
  1059. * for the window are 400px by 400px.
  1060. *
  1061. * For the comment link popup to work, this function has to be called or the
  1062. * normal comment link will be assumed.
  1063. *
  1064. * @global string $wpcommentspopupfile The URL to use for the popup window.
  1065. * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
  1066. *
  1067. * @since 0.71
  1068. *
  1069. * @param int $width Optional. The width of the popup window. Default 400.
  1070. * @param int $height Optional. The height of the popup window. Default 400.
  1071. * @param string $file Optional. Sets the location of the popup window.
  1072. */
  1073. function comments_popup_script( $width = 400, $height = 400, $file = '' ) {
  1074. global $wpcommentspopupfile, $wpcommentsjavascript;
  1075. if (empty ($file)) {
  1076. $wpcommentspopupfile = ''; // Use the index.
  1077. } else {
  1078. $wpcommentspopupfile = $file;
  1079. }
  1080. $wpcommentsjavascript = 1;
  1081. $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";
  1082. echo $javascript;
  1083. }
  1084. /**
  1085. * Displays the link to the comments popup window for the current post ID.
  1086. *
  1087. * Is not meant to be displayed on single posts and pages. Should be used
  1088. * on the lists of posts
  1089. *
  1090. * @global string $wpcommentspopupfile The URL to use for the popup window.
  1091. * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
  1092. *
  1093. * @since 0.71
  1094. *
  1095. * @param string $zero Optional. String to display when no comments. Default false.
  1096. * @param string $one Optional. String to display when only one comment is available.
  1097. * Default false.
  1098. * @param string $more Optional. String to display when there are more than one comment.
  1099. * Default false.
  1100. * @param string $css_class Optional. CSS class to use for comments. Default empty.
  1101. * @param string $none Optional. String to display when comments have been turned off.
  1102. * Default false.
  1103. * @return null Returns null on single posts and pages.
  1104. */
  1105. function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
  1106. global $wpcommentspopupfile, $wpcommentsjavascript;
  1107. $id = get_the_ID();
  1108. if ( false === $zero ) $zero = __( 'No Comments' );
  1109. if ( false === $one ) $one = __( '1 Comment' );
  1110. if ( false === $more ) $more = __( '% Comments' );
  1111. if ( false === $none ) $none = __( 'Comments Off' );
  1112. $number = get_comments_number( $id );
  1113. if ( 0 == $number && !comments_open() && !pings_open() ) {
  1114. echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
  1115. return;
  1116. }
  1117. if ( post_password_required() ) {
  1118. echo __('Enter your password to view comments.');
  1119. return;
  1120. }
  1121. echo '<a href="';
  1122. if ( $wpcommentsjavascript ) {
  1123. if ( empty( $wpcommentspopupfile ) )
  1124. $home = home_url();
  1125. else
  1126. $home = get_option('siteurl');
  1127. echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
  1128. echo '" onclick="wpopen(this.href); return false"';
  1129. } else { // if comments_popup_script() is not in the template, display simple comment link
  1130. if ( 0 == $number )
  1131. echo get_permalink() . '#respond';
  1132. else
  1133. comments_link();
  1134. echo '"';
  1135. }
  1136. if ( !empty( $css_class ) ) {
  1137. echo ' class="'.$css_class.'" ';
  1138. }
  1139. $title = the_title_attribute( array('echo' => 0 ) );
  1140. $attributes = '';
  1141. /**
  1142. * Filter the comments popup link attributes for display.
  1143. *
  1144. * @since 2.5.0
  1145. *
  1146. * @param string $attributes The comments popup link attributes. Default empty.
  1147. */
  1148. echo apply_filters( 'comments_popup_link_attributes', $attributes );
  1149. echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
  1150. comments_number( $zero, $one, $more );
  1151. echo '</a>';
  1152. }
  1153. /**
  1154. * Retrieve HTML content for reply to comment link.
  1155. *
  1156. * @since 2.7.0
  1157. *
  1158. * @param array $args {
  1159. * Optional. Override default arguments.
  1160. *
  1161. * @type string $add_below The first part of the selector used to identify the comment to respond below.
  1162. * The resulting value is passed as the first parameter to addComment.moveForm(),
  1163. * concatenated as $add_below-$comment->comment_ID. Default 'comment'.
  1164. * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
  1165. * to addComment.moveForm(), and appended to the link URL as a hash value.
  1166. * Default 'respond'.
  1167. * @type string $reply_text The text of the Reply link. Default 'Reply'.
  1168. * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.
  1169. * @type int $depth' The depth of the new comment. Must be greater than 0 and less than the value
  1170. * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
  1171. * @type string $before The text or HTML to add before the reply link. Default empty.
  1172. * @type string $after The text or HTML to add after the reply link. Default empty.
  1173. * }
  1174. * @param int $comment Comment being replied to. Default current comment.
  1175. * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
  1176. * Default current post.
  1177. * @return mixed Link to show comment form, if successful. False, if comments are closed.
  1178. */
  1179. function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
  1180. $defaults = array(
  1181. 'add_below' => 'comment',
  1182. 'respond_id' => 'respond',
  1183. 'reply_text' => __('Reply'),
  1184. 'login_text' => __('Log in to Reply'),
  1185. 'depth' => 0,
  1186. 'before' => '',
  1187. 'after' => ''
  1188. );
  1189. $args = wp_parse_args( $args, $defaults );
  1190. if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
  1191. return;
  1192. }
  1193. $add_below = $args['add_below'];
  1194. $respond_id = $args['respond_id'];
  1195. $reply_text = $args['reply_text'];
  1196. $comment = get_comment( $comment );
  1197. if ( empty( $post ) ) {
  1198. $post = $comment->comment_post_ID;
  1199. }
  1200. $post = get_post( $post );
  1201. if ( ! comments_open( $post->ID ) ) {
  1202. return false;
  1203. }
  1204. if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
  1205. $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $args['login_text'] . '</a>';
  1206. } else {
  1207. $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>";
  1208. }
  1209. /**
  1210. * Filter the comment reply link.
  1211. *
  1212. * @since 2.7.0
  1213. *
  1214. * @param string $link The HTML markup for the comment reply link.
  1215. * @param array $args An array of arguments overriding the defaults.
  1216. * @param object $comment The object of the comment being replied.
  1217. * @param WP_Post $post The WP_Post object.
  1218. */
  1219. return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
  1220. }
  1221. /**
  1222. * Displays the HTML content for reply to comment link.
  1223. *
  1224. * @since 2.7.0
  1225. *
  1226. * @see get_comment_reply_link()
  1227. *
  1228. * @param array $args Optional. Override default options.
  1229. * @param int $comment Comment being replied to. Default current comment.
  1230. * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
  1231. * Default current post.
  1232. * @return mixed Link to show comment form, if successful. False, if comments are closed.
  1233. */
  1234. function comment_reply_link($args = array(), $comment = null, $post = null) {
  1235. echo get_comment_reply_link($args, $comment, $post);
  1236. }
  1237. /**
  1238. * Retrieve HTML content for reply to post link.
  1239. *
  1240. * @since 2.7.0
  1241. *
  1242. * @param array $args {
  1243. * Optional. Override default arguments.
  1244. *
  1245. * @type string $add_below The first part of the selector used to identify the comment to respond below.
  1246. * The resulting value is passed as the first parameter to addComment.moveForm(),
  1247. * concatenated as $add_below-$comment->comment_ID. Default is 'post'.
  1248. * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
  1249. * to addComment.moveForm(), and appended to the link URL as a hash value.
  1250. * Default 'respond'.
  1251. * @type string $reply_text Text of the Reply link. Default is 'Leave a Comment'.
  1252. * @type string $login_text Text of the link to reply if logged out. Default is 'Log in to leave a Comment'.
  1253. * @type string $before Text or HTML to add before the reply link. Default empty.
  1254. * @type string $after Text or HTML to add after the reply link. Default empty.
  1255. * }
  1256. * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on.
  1257. * Default current post.
  1258. * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  1259. */
  1260. function get_post_reply_link($args = array(), $post = null) {
  1261. $defaults = array(
  1262. 'add_below' => 'post',
  1263. 'respond_id' => 'respond',
  1264. 'reply_text' => __('Leave a Comment'),
  1265. 'login_text' => __('Log in to leave a Comment'),
  1266. 'before' => '',
  1267. 'after' => '',
  1268. );
  1269. $args = wp_parse_args($args, $defaults);
  1270. $add_below = $args['add_below'];
  1271. $respond_id = $args['respond_id'];
  1272. $reply_text = $args['reply_text'];
  1273. $post = get_post($post);
  1274. if ( ! comments_open( $post->ID ) ) {
  1275. return false;
  1276. }
  1277. if ( get_option('comment_registration') && ! is_user_logged_in() ) {
  1278. $link = '<a rel="nofollow" href="' . wp_login_url( get_permalink() ) . '">' . $args['login_text'] . '</a>';
  1279. } else {
  1280. $link = "<a rel='nofollow' class='comment-reply-link' href='" . get_permalink($post->ID) . "#$respond_id' onclick='return addComment.moveForm(\"$add_below-$post->ID\", \"0\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
  1281. }
  1282. $formatted_link = $args['before'] . $link . $args['after'];
  1283. /**
  1284. * Filter the formatted post comments link HTML.
  1285. *
  1286. * @since 2.7.0
  1287. *
  1288. * @param string $formatted The HTML-formatted post comments link.
  1289. * @param int|WP_Post $post The post ID or WP_Post object.
  1290. */
  1291. return apply_filters( 'post_comments_link', $formatted_link, $post );
  1292. }
  1293. /**
  1294. * Displays the HTML content for reply to post link.
  1295. *
  1296. * @since 2.7.0
  1297. *
  1298. * @see get_post_reply_link()
  1299. *
  1300. * @param array $args Optional. Override default options,
  1301. * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
  1302. * Default current post.
  1303. * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  1304. */
  1305. function post_reply_link($args = array(), $post = null) {
  1306. echo get_post_reply_link($args, $post);
  1307. }
  1308. /**
  1309. * Retrieve HTML content for cancel comment reply link.
  1310. *
  1311. * @since 2.7.0
  1312. *
  1313. * @param string $text Optional. Text to display for cancel reply link. Default empty.
  1314. */
  1315. function get_cancel_comment_reply_link( $text = '' ) {
  1316. if ( empty($text) )
  1317. $text = __('Click here to cancel reply.');
  1318. $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
  1319. $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
  1320. $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
  1321. /**
  1322. * Filter the cancel comment reply link HTML.
  1323. *
  1324. * @since 2.7.0
  1325. *
  1326. * @param string $formatted_link The HTML-formatted cancel comment reply link.
  1327. * @param string $link Cancel comment reply link URL.
  1328. * @param string $text Cancel comment reply link text.
  1329. */
  1330. return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
  1331. }
  1332. /**
  1333. * Display HTML content for cancel comment reply link.
  1334. *
  1335. * @since 2.7.0
  1336. *
  1337. * @param string $text Optional. Text to display for cancel reply link. Default empty.
  1338. */
  1339. function cancel_comment_reply_link( $text = '' ) {
  1340. echo get_cancel_comment_reply_link($text);
  1341. }
  1342. /**
  1343. * Retrieve hidden input HTML for replying to comments.
  1344. *
  1345. * @since 3.0.0
  1346. *
  1347. * @param int $id Optional. Post ID. Default current post ID.
  1348. * @return string Hidden input HTML for replying to comments
  1349. */
  1350. function get_comment_id_fields( $id = 0 ) {
  1351. if ( empty( $id ) )
  1352. $id = get_the_ID();
  1353. $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
  1354. $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
  1355. $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
  1356. /**
  1357. * Filter the returned comment id fields.
  1358. *
  1359. * @since 3.0.0
  1360. *
  1361. * @param string $result The HTML-formatted hidden id field comment elements.
  1362. * @param int $id The post ID.
  1363. * @param int $replytoid The id of the comment being replied to.
  1364. */
  1365. return apply_filters( 'comment_id_fields', $result, $id, $replytoid );
  1366. }
  1367. /**
  1368. * Output hidden input HTML for replying to comments.
  1369. *
  1370. * @since 2.7.0
  1371. *
  1372. * @param int $id Optional. Post ID. Default current post ID.
  1373. */
  1374. function comment_id_fields( $id = 0 ) {
  1375. echo get_comment_id_fields( $id );
  1376. }
  1377. /**
  1378. * Display text based on comment reply status.
  1379. *
  1380. * Only affects users with Javascript disabled.
  1381. *
  1382. * @since 2.7.0
  1383. *
  1384. * @param string $noreplytext Optional. Text to display when not replying to a comment.
  1385. * Default false.
  1386. * @param string $replytext Op…

Large files files are truncated, but you can click here to view the full file