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