PageRenderTime 79ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/comment-template.php

https://bitbucket.org/broderboy/shannonbroder-wordpress
PHP | 2234 lines | 849 code | 193 blank | 1192 comment | 194 complexity | 37e15c37627c4183c4f4fcf736ef9b5f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-1.0

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 Post ID or WP_Post object. Default current 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 Post ID or WP_Post object. Default current post.
  629. * @return int The number of comments a post has.
  630. */
  631. function get_comments_number( $post_id = 0 ) {
  632. $post_id = absint( $post_id );
  633. if ( !$post_id )
  634. $post_id = get_the_ID();
  635. $post = get_post($post_id);
  636. if ( ! isset($post->comment_count) )
  637. $count = 0;
  638. else
  639. $count = $post->comment_count;
  640. /**
  641. * Filter the returned comment count for a post.
  642. *
  643. * @since 1.5.0
  644. *
  645. * @param int $count Nnumber of comments a post has.
  646. * @param int|WP_Post $post_id Post ID or WP_Post object.
  647. */
  648. return apply_filters( 'get_comments_number', $count, $post_id );
  649. }
  650. /**
  651. * Display the language string for the number of comments the current post has.
  652. *
  653. * @since 0.71
  654. *
  655. * @param string $zero Optional. Text for no comments. Default false.
  656. * @param string $one Optional. Text for one comment. Default false.
  657. * @param string $more Optional. Text for more than one comment. Default false.
  658. * @param string $deprecated Not used.
  659. */
  660. function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
  661. if ( !empty( $deprecated ) )
  662. _deprecated_argument( __FUNCTION__, '1.3' );
  663. $number = get_comments_number();
  664. if ( $number > 1 )
  665. $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
  666. elseif ( $number == 0 )
  667. $output = ( false === $zero ) ? __('No Comments') : $zero;
  668. else // must be one
  669. $output = ( false === $one ) ? __('1 Comment') : $one;
  670. /**
  671. * Filter the comments count for display.
  672. *
  673. * @since 1.5.0
  674. *
  675. * @see _n()
  676. *
  677. * @param string $output A translatable string formatted based on whether the count
  678. * is equal to 0, 1, or 1+.
  679. * @param int $number The number of post comments.
  680. */
  681. echo apply_filters( 'comments_number', $output, $number );
  682. }
  683. /**
  684. * Retrieve the text of the current comment.
  685. *
  686. * @since 1.5.0
  687. *
  688. * @see Walker_Comment::comment()
  689. *
  690. * @param int $comment_ID ID of the comment for which to get the text. Default current comment.
  691. * @param array $args Optional. An array of arguments. Default empty.
  692. * @return string The comment content.
  693. */
  694. function get_comment_text( $comment_ID = 0, $args = array() ) {
  695. $comment = get_comment( $comment_ID );
  696. /**
  697. * Filter the text of a comment.
  698. *
  699. * @since 1.5.0
  700. *
  701. * @see Walker_Comment::comment()
  702. *
  703. * @param string $comment_content Text of the comment.
  704. * @param object $comment The comment object.
  705. * @param array $args An array of arguments.
  706. */
  707. return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args );
  708. }
  709. /**
  710. * Display the text of the current comment.
  711. *
  712. * @since 0.71
  713. *
  714. * @see Walker_Comment::comment()
  715. *
  716. * @param int $comment_ID ID of the comment for which to print the text. Default 0.
  717. * @param array $args Optional. An array of arguments. Default empty array. Default empty.
  718. */
  719. function comment_text( $comment_ID = 0, $args = array() ) {
  720. $comment = get_comment( $comment_ID );
  721. $comment_text = get_comment_text( $comment_ID , $args );
  722. /**
  723. * Filter the text of a comment to be displayed.
  724. *
  725. * @since 1.2.0
  726. *
  727. * @see Walker_Comment::comment()
  728. *
  729. * @param string $comment_text Text of the current comment.
  730. * @param object $comment The comment object.
  731. * @param array $args An array of arguments.
  732. */
  733. echo apply_filters( 'comment_text', $comment_text, $comment, $args );
  734. }
  735. /**
  736. * Retrieve the comment time of the current comment.
  737. *
  738. * @since 1.5.0
  739. *
  740. * @param string $d Optional. The format of the time. Default user's settings.
  741. * @param bool $gmt Optional. Whether to use the GMT date. Default false.
  742. * @param bool $translate Optional. Whether to translate the time (for use in feeds).
  743. * Default true.
  744. * @return string The formatted time.
  745. */
  746. function get_comment_time( $d = '', $gmt = false, $translate = true ) {
  747. global $comment;
  748. $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
  749. if ( '' == $d )
  750. $date = mysql2date(get_option('time_format'), $comment_date, $translate);
  751. else
  752. $date = mysql2date($d, $comment_date, $translate);
  753. /**
  754. * Filter the returned comment time.
  755. *
  756. * @since 1.5.0
  757. *
  758. * @param string|int $date The comment time, formatted as a date string or Unix timestamp.
  759. * @param string $d Date format.
  760. * @param bool $gmt Whether the GMT date is in use.
  761. * @param bool $translate Whether the time is translated.
  762. * @param object $comment The comment object.
  763. */
  764. return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment );
  765. }
  766. /**
  767. * Display the comment time of the current comment.
  768. *
  769. * @since 0.71
  770. *
  771. * @param string $d Optional. The format of the time. Default user's settings.
  772. */
  773. function comment_time( $d = '' ) {
  774. echo get_comment_time($d);
  775. }
  776. /**
  777. * Retrieve the comment type of the current comment.
  778. *
  779. * @since 1.5.0
  780. *
  781. * @param int $comment_ID ID of the comment for which to get the type. Default current comment.
  782. * @return string The comment type.
  783. */
  784. function get_comment_type( $comment_ID = 0 ) {
  785. $comment = get_comment( $comment_ID );
  786. if ( '' == $comment->comment_type )
  787. $comment->comment_type = 'comment';
  788. /**
  789. * Filter the returned comment type.
  790. *
  791. * @since 1.5.0
  792. *
  793. * @param string $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
  794. */
  795. return apply_filters( 'get_comment_type', $comment->comment_type );
  796. }
  797. /**
  798. * Display the comment type of the current comment.
  799. *
  800. * @since 0.71
  801. *
  802. * @param string $commenttxt Optional. String to display for comment type. Default false.
  803. * @param string $trackbacktxt Optional. String to display for trackback type. Default false.
  804. * @param string $pingbacktxt Optional. String to display for pingback type. Default false.
  805. */
  806. function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
  807. if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
  808. if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
  809. if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
  810. $type = get_comment_type();
  811. switch( $type ) {
  812. case 'trackback' :
  813. echo $trackbacktxt;
  814. break;
  815. case 'pingback' :
  816. echo $pingbacktxt;
  817. break;
  818. default :
  819. echo $commenttxt;
  820. }
  821. }
  822. /**
  823. * Retrieve The current post's trackback URL.
  824. *
  825. * There is a check to see if permalink's have been enabled and if so, will
  826. * retrieve the pretty path. If permalinks weren't enabled, the ID of the
  827. * current post is used and appended to the correct page to go to.
  828. *
  829. * @since 1.5.0
  830. *
  831. * @return string The trackback URL after being filtered.
  832. */
  833. function get_trackback_url() {
  834. if ( '' != get_option('permalink_structure') )
  835. $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
  836. else
  837. $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
  838. /**
  839. * Filter the returned trackback URL.
  840. *
  841. * @since 2.2.0
  842. *
  843. * @param string $tb_url The trackback URL.
  844. */
  845. return apply_filters( 'trackback_url', $tb_url );
  846. }
  847. /**
  848. * Display the current post's trackback URL.
  849. *
  850. * @since 0.71
  851. *
  852. * @param bool $deprecated_echo Not used.
  853. * @return void|string Should only be used to echo the trackback URL, use get_trackback_url()
  854. * for the result instead.
  855. */
  856. function trackback_url( $deprecated_echo = true ) {
  857. if ( $deprecated_echo !== true )
  858. _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
  859. if ( $deprecated_echo )
  860. echo get_trackback_url();
  861. else
  862. return get_trackback_url();
  863. }
  864. /**
  865. * Generate and display the RDF for the trackback information of current post.
  866. *
  867. * Deprecated in 3.0.0, and restored in 3.0.1.
  868. *
  869. * @since 0.71
  870. *
  871. * @param int $deprecated Not used (Was $timezone = 0).
  872. */
  873. function trackback_rdf( $deprecated = '' ) {
  874. if ( ! empty( $deprecated ) ) {
  875. _deprecated_argument( __FUNCTION__, '2.5' );
  876. }
  877. if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'W3C_Validator' ) ) {
  878. return;
  879. }
  880. echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  881. xmlns:dc="http://purl.org/dc/elements/1.1/"
  882. xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  883. <rdf:Description rdf:about="';
  884. the_permalink();
  885. echo '"'."\n";
  886. echo ' dc:identifier="';
  887. the_permalink();
  888. echo '"'."\n";
  889. echo ' dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
  890. echo ' trackback:ping="'.get_trackback_url().'"'." />\n";
  891. echo '</rdf:RDF>';
  892. }
  893. /**
  894. * Whether the current post is open for comments.
  895. *
  896. * @since 1.5.0
  897. *
  898. * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
  899. * @return bool True if the comments are open.
  900. */
  901. function comments_open( $post_id = null ) {
  902. $_post = get_post($post_id);
  903. $open = ( 'open' == $_post->comment_status );
  904. /**
  905. * Filter whether the current post is open for comments.
  906. *
  907. * @since 2.5.0
  908. *
  909. * @param bool $open Whether the current post is open for comments.
  910. * @param int|WP_Post $post_id The post ID or WP_Post object.
  911. */
  912. return apply_filters( 'comments_open', $open, $post_id );
  913. }
  914. /**
  915. * Whether the current post is open for pings.
  916. *
  917. * @since 1.5.0
  918. *
  919. * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
  920. * @return bool True if pings are accepted
  921. */
  922. function pings_open( $post_id = null ) {
  923. $_post = get_post($post_id);
  924. $open = ( 'open' == $_post->ping_status );
  925. /**
  926. * Filter whether the current post is open for pings.
  927. *
  928. * @since 2.5.0
  929. *
  930. * @param bool $open Whether the current post is open for pings.
  931. * @param int|WP_Post $post_id The post ID or WP_Post object.
  932. */
  933. return apply_filters( 'pings_open', $open, $post_id );
  934. }
  935. /**
  936. * Display form token for unfiltered comments.
  937. *
  938. * Will only display nonce token if the current user has permissions for
  939. * unfiltered html. Won't display the token for other users.
  940. *
  941. * The function was backported to 2.0.10 and was added to versions 2.1.3 and
  942. * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in
  943. * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.
  944. *
  945. * Backported to 2.0.10.
  946. *
  947. * @since 2.1.3
  948. */
  949. function wp_comment_form_unfiltered_html_nonce() {
  950. $post = get_post();
  951. $post_id = $post ? $post->ID : 0;
  952. if ( current_user_can( 'unfiltered_html' ) ) {
  953. wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
  954. echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
  955. }
  956. }
  957. /**
  958. * Load the comment template specified in $file.
  959. *
  960. * Will not display the comments template if not on single post or page, or if
  961. * the post does not have comments.
  962. *
  963. * Uses the WordPress database object to query for the comments. The comments
  964. * are passed through the 'comments_array' filter hook with the list of comments
  965. * and the post ID respectively.
  966. *
  967. * The $file path is passed through a filter hook called, 'comments_template'
  968. * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
  969. * first and if it fails it will require the default comment template from the
  970. * default theme. If either does not exist, then the WordPress process will be
  971. * halted. It is advised for that reason, that the default theme is not deleted.
  972. *
  973. * @todo Document globals
  974. * @uses $withcomments Will not try to get the comments if the post has none.
  975. *
  976. * @since 1.5.0
  977. *
  978. * @param string $file Optional. The file to load. Default '/comments.php'.
  979. * @param bool $separate_comments Optional. Whether to separate the comments by comment type.
  980. * Default false.
  981. * @return null Returns null if no comments appear.
  982. */
  983. function comments_template( $file = '/comments.php', $separate_comments = false ) {
  984. global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
  985. if ( !(is_single() || is_page() || $withcomments) || empty($post) )
  986. return;
  987. if ( empty($file) )
  988. $file = '/comments.php';
  989. $req = get_option('require_name_email');
  990. /*
  991. * Comment author information fetched from the comment cookies.
  992. * Uuses wp_get_current_commenter().
  993. */
  994. $commenter = wp_get_current_commenter();
  995. /*
  996. * The name of the current comment author escaped for use in attributes.
  997. * Escaped by sanitize_comment_cookies().
  998. */
  999. $comment_author = $commenter['comment_author'];
  1000. /*
  1001. * The email address of the current comment author escaped for use in attributes.
  1002. * Escaped by sanitize_comment_cookies().
  1003. */
  1004. $comment_author_email = $commenter['comment_author_email'];
  1005. /*
  1006. * The url of the current comment author escaped for use in attributes.
  1007. */
  1008. $comment_author_url = esc_url($commenter['comment_author_url']);
  1009. /** @todo Use API instead of SELECTs. */
  1010. if ( $user_ID) {
  1011. $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));
  1012. } else if ( empty($comment_author) ) {
  1013. $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
  1014. } else {
  1015. $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));
  1016. }
  1017. /**
  1018. * Filter the comments array.
  1019. *
  1020. * @since 2.1.0
  1021. *
  1022. * @param array $comments Array of comments supplied to the comments template.
  1023. * @param int $post_ID Post ID.
  1024. */
  1025. $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
  1026. $comments = &$wp_query->comments;
  1027. $wp_query->comment_count = count($wp_query->comments);
  1028. update_comment_cache($wp_query->comments);
  1029. if ( $separate_comments ) {
  1030. $wp_query->comments_by_type = separate_comments($comments);
  1031. $comments_by_type = &$wp_query->comments_by_type;
  1032. }
  1033. $overridden_cpage = false;
  1034. if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
  1035. set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
  1036. $overridden_cpage = true;
  1037. }
  1038. if ( !defined('COMMENTS_TEMPLATE') )
  1039. define('COMMENTS_TEMPLATE', true);
  1040. $theme_template = STYLESHEETPATH . $file;
  1041. /**
  1042. * Filter the path to the theme template file used for the comments template.
  1043. *
  1044. * @since 1.5.1
  1045. *
  1046. * @param string $theme_template The path to the theme template file.
  1047. */
  1048. $include = apply_filters( 'comments_template', $theme_template );
  1049. if ( file_exists( $include ) )
  1050. require( $include );
  1051. elseif ( file_exists( TEMPLATEPATH . $file ) )
  1052. require( TEMPLATEPATH . $file );
  1053. else // Backward compat code will be removed in a future release
  1054. require( ABSPATH . WPINC . '/theme-compat/comments.php');
  1055. }
  1056. /**
  1057. * Display the JS popup script to show a comment.
  1058. *
  1059. * If the $file parameter is empty, then the home page is assumed. The defaults
  1060. * for the window are 400px by 400px.
  1061. *
  1062. * For the comment link popup to work, this function has to be called or the
  1063. * normal comment link will be assumed.
  1064. *
  1065. * @global string $wpcommentspopupfile The URL to use for the popup window.
  1066. * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
  1067. *
  1068. * @since 0.71
  1069. *
  1070. * @param int $width Optional. The width of the popup window. Default 400.
  1071. * @param int $height Optional. The height of the popup window. Default 400.
  1072. * @param string $file Optional. Sets the location of the popup window.
  1073. */
  1074. function comments_popup_script( $width = 400, $height = 400, $file = '' ) {
  1075. global $wpcommentspopupfile, $wpcommentsjavascript;
  1076. if (empty ($file)) {
  1077. $wpcommentspopupfile = ''; // Use the index.
  1078. } else {
  1079. $wpcommentspopupfile = $file;
  1080. }
  1081. $wpcommentsjavascript = 1;
  1082. $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";
  1083. echo $javascript;
  1084. }
  1085. /**
  1086. * Displays the link to the comments popup window for the current post ID.
  1087. *
  1088. * Is not meant to be displayed on single posts and pages. Should be used
  1089. * on the lists of posts
  1090. *
  1091. * @global string $wpcommentspopupfile The URL to use for the popup window.
  1092. * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
  1093. *
  1094. * @since 0.71
  1095. *
  1096. * @param string $zero Optional. String to display when no comments. Default false.
  1097. * @param string $one Optional. String to display when only one comment is available.
  1098. * Default false.
  1099. * @param string $more Optional. String to display when there are more than one comment.
  1100. * Default false.
  1101. * @param string $css_class Optional. CSS class to use for comments. Default empty.
  1102. * @param string $none Optional. String to display when comments have been turned off.
  1103. * Default false.
  1104. * @return null Returns null on single posts and pages.
  1105. */
  1106. function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
  1107. global $wpcommentspopupfile, $wpcommentsjavascript;
  1108. $id = get_the_ID();
  1109. if ( false === $zero ) $zero = __( 'No Comments' );
  1110. if ( false === $one ) $one = __( '1 Comment' );
  1111. if ( false === $more ) $more = __( '% Comments' );
  1112. if ( false === $none ) $none = __( 'Comments Off' );
  1113. $number = get_comments_number( $id );
  1114. if ( 0 == $number && !comments_open() && !pings_open() ) {
  1115. echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
  1116. return;
  1117. }
  1118. if ( post_password_required() ) {
  1119. echo __('Enter your password to view comments.');
  1120. return;
  1121. }
  1122. echo '<a href="';
  1123. if ( $wpcommentsjavascript ) {
  1124. if ( empty( $wpcommentspopupfile ) )
  1125. $home = home_url();
  1126. else
  1127. $home = get_option('siteurl');
  1128. echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
  1129. echo '" onclick="wpopen(this.href); return false"';
  1130. } else { // if comments_popup_script() is not in the template, display simple comment link
  1131. if ( 0 == $number )
  1132. echo get_permalink() . '#respond';
  1133. else
  1134. comments_link();
  1135. echo '"';
  1136. }
  1137. if ( !empty( $css_class ) ) {
  1138. echo ' class="'.$css_class.'" ';
  1139. }
  1140. $title = the_title_attribute( array('echo' => 0 ) );
  1141. $attributes = '';
  1142. /**
  1143. * Filter the comments popup link attributes for display.
  1144. *
  1145. * @since 2.5.0
  1146. *
  1147. * @param string $attributes The comments popup link attributes. Default empty.
  1148. */
  1149. echo apply_filters( 'comments_popup_link_attributes', $attributes );
  1150. echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
  1151. comments_number( $zero, $one, $more );
  1152. echo '</a>';
  1153. }
  1154. /**
  1155. * Retrieve HTML content for reply to comment link.
  1156. *
  1157. * @since 2.7.0
  1158. *
  1159. * @param array $args {
  1160. * Optional. Override default arguments.
  1161. *
  1162. * @type string $add_below The first part of the selector used to identify the comment to respond below.
  1163. * The resulting value is passed as the first parameter to addComment.moveForm(),
  1164. * concatenated as $add_below-$comment->comment_ID. Default 'comment'.
  1165. * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
  1166. * to addComment.moveForm(), and appended to the link URL as a hash value.
  1167. * Default 'respond'.
  1168. * @type string $reply_text The text of the Reply link. Default 'Reply'.
  1169. * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.
  1170. * @type int $depth' The depth of the new comment. Must be greater than 0 and less than the value
  1171. * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
  1172. * @type string $before The text or HTML to add before the reply link. Default empty.
  1173. * @type string $after The text or HTML to add after the reply link. Default empty.
  1174. * }
  1175. * @param int $comment Comment being replied to. Default current comment.
  1176. * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
  1177. * Default current post.
  1178. * @return mixed Link to show comment form, if successful. False, if comments are closed.
  1179. */
  1180. function get_comment_reply_link($args = array(), $comment = null, $post = null) {
  1181. $defaults = array(
  1182. 'add_below' => 'comment',
  1183. 'respond_id' => 'respond',
  1184. 'reply_text' => __('Reply'),
  1185. 'login_text' => __('Log in to Reply'),
  1186. 'depth' => 0,
  1187. 'before' => '',
  1188. 'after' => ''
  1189. );
  1190. $args = wp_parse_args($args, $defaults);
  1191. if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
  1192. return;
  1193. extract($args, EXTR_SKIP);
  1194. $comment = get_comment($comment);
  1195. if ( empty($post) )
  1196. $post = $comment->comment_post_ID;
  1197. $post = get_post($post);
  1198. if ( !comments_open($post->ID) )
  1199. return false;
  1200. $link = '';
  1201. if ( get_option('comment_registration') && ! is_user_logged_in() )
  1202. $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
  1203. else
  1204. $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>";
  1205. /**
  1206. * Filter the comment reply link.
  1207. *
  1208. * @since 2.7.0
  1209. *
  1210. * @param string $link The HTML markup for the comment reply link.
  1211. * @param array $args An array of arguments overriding the defaults.
  1212. * @param object $comment The object of the comment being replied.
  1213. * @param WP_Post $post The WP_Post object.
  1214. */
  1215. return apply_filters( 'comment_reply_link', $before . $link . $after, $args, $comment, $post );
  1216. }
  1217. /**
  1218. * Displays the HTML content for reply to comment link.
  1219. *
  1220. * @since 2.7.0
  1221. *
  1222. * @see get_comment_reply_link()
  1223. *
  1224. * @param array $args Optional. Override default options.
  1225. * @param int $comment Comment being replied to. Default current comment.
  1226. * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
  1227. * Default current post.
  1228. * @return mixed Link to show comment form, if successful. False, if comments are closed.
  1229. */
  1230. function comment_reply_link($args = array(), $comment = null, $post = null) {
  1231. echo get_comment_reply_link($args, $comment, $post);
  1232. }
  1233. /**
  1234. * Retrieve HTML content for reply to post link.
  1235. *
  1236. * @since 2.7.0
  1237. *
  1238. * @param array $args {
  1239. * Optional. Override default arguments.
  1240. *
  1241. * @type string $add_below The first part of the selector used to identify the comment to respond below.
  1242. * The resulting value is passed as the first parameter to addComment.moveForm(),
  1243. * concatenated as $add_below-$comment->comment_ID. Default is 'post'.
  1244. * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
  1245. * to addComment.moveForm(), and appended to the link URL as a hash value.
  1246. * Default 'respond'.
  1247. * @type string $reply_text Text of the Reply link. Default is 'Leave a Comment'.
  1248. * @type string $login_text Text of the link to reply if logged out. Default is 'Log in to leave a Comment'.
  1249. * @type string $before Text or HTML to add before the reply link. Default empty.
  1250. * @type string $after Text or HTML to add after the reply link. Default empty.
  1251. * }
  1252. * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on.
  1253. * Default current post.
  1254. * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  1255. */
  1256. function get_post_reply_link($args = array(), $post = null) {
  1257. $defaults = array(
  1258. 'add_below' => 'post',
  1259. 'respond_id' => 'respond',
  1260. 'reply_text' => __('Leave a Comment'),
  1261. 'login_text' => __('Log in to leave a Comment'),
  1262. 'before' => '',
  1263. 'after' => '',
  1264. );
  1265. $args = wp_parse_args($args, $defaults);
  1266. extract($args, EXTR_SKIP);
  1267. $post = get_post($post);
  1268. if ( !comments_open($post->ID) )
  1269. return false;
  1270. if ( get_option('comment_registration') && ! is_user_logged_in() )
  1271. $link = '<a rel="nofollow" href="' . wp_login_url( get_permalink() ) . '">' . $login_text . '</a>';
  1272. else
  1273. $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>";
  1274. $formatted_link = $before . $link . $after;
  1275. /**
  1276. * Filter the formatted post comments link HTML.
  1277. *
  1278. * @since 2.7.0
  1279. *
  1280. * @param string $formatted The HTML-formatted post comments link.
  1281. * @param int|WP_Post $post The post ID or WP_Post object.
  1282. */
  1283. return apply_filters( 'post_comments_link', $formatted_link, $post );
  1284. }
  1285. /**
  1286. * Displays the HTML content for reply to post link.
  1287. *
  1288. * @since 2.7.0
  1289. *
  1290. * @see get_post_reply_link()
  1291. *
  1292. * @param array $args Optional. Override default options,
  1293. * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
  1294. * Default current post.
  1295. * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  1296. */
  1297. function post_reply_link($args = array(), $post = null) {
  1298. echo get_post_reply_link($args, $post);
  1299. }
  1300. /**
  1301. * Retrieve HTML content for cancel comment reply link.
  1302. *
  1303. * @since 2.7.0
  1304. *
  1305. * @param string $text Optional. Text to display for cancel reply link. Default empty.
  1306. */
  1307. function get_cancel_comment_reply_link( $text = '' ) {
  1308. if ( empty($text) )
  1309. $text = __('Click here to cancel reply.');
  1310. $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
  1311. $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
  1312. $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
  1313. /**
  1314. * Filter the cancel comment reply link HTML.
  1315. *
  1316. * @since 2.7.0
  1317. *
  1318. * @param string $formatted_link The HTML-formatted cancel comment reply link.
  1319. * @param string $link Cancel comment reply link URL.
  1320. * @param string $text Cancel comment reply link text.
  1321. */
  1322. return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
  1323. }
  1324. /**
  1325. * Display HTML content for cancel comment reply link.
  1326. *
  1327. * @since 2.7.0
  1328. *
  1329. * @param string $text Optional. Text to display for cancel reply link. Default empty.
  1330. */
  1331. function cancel_comment_reply_link( $text = '' ) {
  1332. echo get_cancel_comment_reply_link($text);
  1333. }
  1334. /**
  1335. * Retrieve hidden input HTML for replying to comments.
  1336. *
  1337. * @since 3.0.0
  1338. *
  1339. * @param int $id Optional. Post ID. Default current post ID.
  1340. * @return string Hidden input HTML for replying to comments
  1341. */
  1342. function get_comment_id_fields( $id = 0 ) {
  1343. if ( empty( $id ) )
  1344. $id = get_the_ID();
  1345. $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
  1346. $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
  1347. $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
  1348. /**
  1349. * Filter the returned comment id fields.
  1350. *
  1351. * @since 3.0.0
  1352. *
  1353. * @param string $result The HTML-formatted hidden id field comment elements.
  1354. * @param int $id The post ID.
  1355. * @param int $replytoid The id of the comment being replied to.
  1356. */
  1357. return apply_filters( 'comment_id_fields', $result, $id, $replytoid );
  1358. }
  1359. /**
  1360. * Output hidden input HTML for replying to comments.
  1361. *
  1362. * @since 2.7.0
  1363. *
  1364. * @param int $id Optional. Post ID. Default current post ID.
  1365. */
  1366. function comment_id_fields( $id = 0 ) {
  1367. echo get_comment_id_fields( $id );
  1368. }
  1369. /**
  1370. * Display text based on comment reply status.
  1371. *
  1372. * Only affects users with Javascript disabled.
  1373. *
  1374. * @since 2.7.0
  1375. *
  1376. * @param string $noreplytext Optional. Text to display when not replying to a comment.
  1377. * Default false.
  1378. * @param string $replytext Optional. Text to display when replying to a comment.
  1379. * Default false. Accepts "%s" for the author of the comment
  1380. * being replied to.
  1381. * @param string $lin…

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