/wp-includes/comment-template.php

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