30 } else { |
32 } else { |
31 $author = $comment->comment_author; |
33 $author = $comment->comment_author; |
32 } |
34 } |
33 |
35 |
34 /** |
36 /** |
35 * Filter the returned comment author name. |
37 * Filters the returned comment author name. |
36 * |
38 * |
37 * @since 1.5.0 |
39 * @since 1.5.0 |
38 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
40 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
39 * |
41 * |
|
42 * @param string $author The comment author's username. |
|
43 * @param int $comment_ID The comment ID. |
|
44 * @param WP_Comment $comment The comment object. |
|
45 */ |
|
46 return apply_filters( 'get_comment_author', $author, $comment->comment_ID, $comment ); |
|
47 } |
|
48 |
|
49 /** |
|
50 * Displays the author of the current comment. |
|
51 * |
|
52 * @since 0.71 |
|
53 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
|
54 * |
|
55 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author. |
|
56 * Default current comment. |
|
57 */ |
|
58 function comment_author( $comment_ID = 0 ) { |
|
59 $comment = get_comment( $comment_ID ); |
|
60 $author = get_comment_author( $comment ); |
|
61 |
|
62 /** |
|
63 * Filters the comment author's name for display. |
|
64 * |
|
65 * @since 1.2.0 |
|
66 * @since 4.1.0 The `$comment_ID` parameter was added. |
|
67 * |
40 * @param string $author The comment author's username. |
68 * @param string $author The comment author's username. |
41 * @param int $comment_ID The comment ID. |
69 * @param int $comment_ID The comment ID. |
42 * @param object $comment The comment object. |
70 */ |
43 */ |
71 echo apply_filters( 'comment_author', $author, $comment->comment_ID ); |
44 return apply_filters( 'get_comment_author', $author, $comment_ID, $comment ); |
72 } |
45 } |
73 |
46 |
74 /** |
47 /** |
75 * Retrieve the email of the author of the current comment. |
48 * Displays the author of the current comment. |
76 * |
|
77 * @since 1.5.0 |
|
78 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
|
79 * |
|
80 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email. |
|
81 * Default current comment. |
|
82 * @return string The current comment author's email |
|
83 */ |
|
84 function get_comment_author_email( $comment_ID = 0 ) { |
|
85 $comment = get_comment( $comment_ID ); |
|
86 |
|
87 /** |
|
88 * Filters the comment author's returned email address. |
|
89 * |
|
90 * @since 1.5.0 |
|
91 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
|
92 * |
|
93 * @param string $comment_author_email The comment author's email address. |
|
94 * @param int $comment_ID The comment ID. |
|
95 * @param WP_Comment $comment The comment object. |
|
96 */ |
|
97 return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment->comment_ID, $comment ); |
|
98 } |
|
99 |
|
100 /** |
|
101 * Display the email of the author of the current global $comment. |
|
102 * |
|
103 * Care should be taken to protect the email address and assure that email |
|
104 * harvesters do not capture your commentors' email address. Most assume that |
|
105 * their email address will not appear in raw form on the site. Doing so will |
|
106 * enable anyone, including those that people don't want to get the email |
|
107 * address and use it for their own means good and bad. |
49 * |
108 * |
50 * @since 0.71 |
109 * @since 0.71 |
51 * |
110 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
52 * @param int $comment_ID Optional. The ID of the comment for which to print the author. Default current comment. |
111 * |
53 */ |
112 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's email. |
54 function comment_author( $comment_ID = 0 ) { |
113 * Default current comment. |
55 $author = get_comment_author( $comment_ID ); |
114 */ |
56 |
115 function comment_author_email( $comment_ID = 0 ) { |
57 /** |
116 $comment = get_comment( $comment_ID ); |
58 * Filter the comment author's name for display. |
117 $author_email = get_comment_author_email( $comment ); |
|
118 |
|
119 /** |
|
120 * Filters the comment author's email for display. |
59 * |
121 * |
60 * @since 1.2.0 |
122 * @since 1.2.0 |
61 * @since 4.1.0 The `$comment_ID` parameter was added. |
123 * @since 4.1.0 The `$comment_ID` parameter was added. |
62 * |
124 * |
63 * @param string $author The comment author's username. |
125 * @param string $author_email The comment author's email address. |
64 * @param int $comment_ID The comment ID. |
126 * @param int $comment_ID The comment ID. |
65 */ |
127 */ |
66 $author = apply_filters( 'comment_author', $author, $comment_ID ); |
128 echo apply_filters( 'author_email', $author_email, $comment->comment_ID ); |
67 echo $author; |
129 } |
68 } |
130 |
69 |
131 /** |
70 /** |
132 * Display the html email link to the author of the current comment. |
71 * Retrieve the email of the author of the current comment. |
|
72 * |
|
73 * @since 1.5.0 |
|
74 * |
|
75 * @param int $comment_ID Optional. The ID of the comment for which to get the author's email. Default current comment. |
|
76 * @return string The current comment author's email |
|
77 */ |
|
78 function get_comment_author_email( $comment_ID = 0 ) { |
|
79 $comment = get_comment( $comment_ID ); |
|
80 |
|
81 /** |
|
82 * Filter the comment author's returned email address. |
|
83 * |
|
84 * @since 1.5.0 |
|
85 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
|
86 * |
|
87 * @param string $comment_author_email The comment author's email address. |
|
88 * @param int $comment_ID The comment ID. |
|
89 * @param object $comment The comment object. |
|
90 */ |
|
91 return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment_ID, $comment ); |
|
92 } |
|
93 |
|
94 /** |
|
95 * Display the email of the author of the current global $comment. |
|
96 * |
133 * |
97 * Care should be taken to protect the email address and assure that email |
134 * Care should be taken to protect the email address and assure that email |
98 * harvesters do not capture your commentors' email address. Most assume that |
135 * harvesters do not capture your commentors' email address. Most assume that |
99 * their email address will not appear in raw form on the blog. Doing so will |
136 * their email address will not appear in raw form on the site. Doing so will |
100 * enable anyone, including those that people don't want to get the email |
137 * enable anyone, including those that people don't want to get the email |
101 * address and use it for their own means good and bad. |
138 * address and use it for their own means good and bad. |
102 * |
139 * |
103 * @since 0.71 |
140 * @since 0.71 |
104 * |
141 * @since 4.6.0 Added the `$comment` parameter. |
105 * @param int $comment_ID Optional. The ID of the comment for which to print the author's email. Default current comment. |
142 * |
106 */ |
143 * @param string $linktext Optional. Text to display instead of the comment author's email address. |
107 function comment_author_email( $comment_ID = 0 ) { |
144 * Default empty. |
108 $author_email = get_comment_author_email( $comment_ID ); |
145 * @param string $before Optional. Text or HTML to display before the email link. Default empty. |
109 |
146 * @param string $after Optional. Text or HTML to display after the email link. Default empty. |
110 /** |
147 * @param int|WP_Comment $comment Optional. Comment ID or WP_Comment object. Default is the current comment. |
111 * Filter the comment author's email for display. |
148 */ |
112 * |
149 function comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) { |
113 * @since 1.2.0 |
150 if ( $link = get_comment_author_email_link( $linktext, $before, $after, $comment ) ) { |
114 * @since 4.1.0 The `$comment_ID` parameter was added. |
151 echo $link; |
115 * |
152 } |
116 * @param string $author_email The comment author's email address. |
153 } |
117 * @param int $comment_ID The comment ID. |
154 |
118 */ |
155 /** |
119 echo apply_filters( 'author_email', $author_email, $comment_ID ); |
156 * Return the html email link to the author of the current comment. |
120 } |
|
121 |
|
122 /** |
|
123 * Display the html email link to the author of the current comment. |
|
124 * |
157 * |
125 * Care should be taken to protect the email address and assure that email |
158 * Care should be taken to protect the email address and assure that email |
126 * harvesters do not capture your commentors' email address. Most assume that |
159 * harvesters do not capture your commentors' email address. Most assume that |
127 * their email address will not appear in raw form on the blog. Doing so will |
160 * their email address will not appear in raw form on the site. Doing so will |
128 * enable anyone, including those that people don't want to get the email |
161 * enable anyone, including those that people don't want to get the email |
129 * address and use it for their own means good and bad. |
162 * address and use it for their own means good and bad. |
130 * |
163 * |
131 * @since 0.71 |
|
132 * |
|
133 * @param string $linktext Optional. Text to display instead of the comment author's email address. |
|
134 * Default empty. |
|
135 * @param string $before Optional. Text or HTML to display before the email link. Default empty. |
|
136 * @param string $after Optional. Text or HTML to display after the email link. Default empty. |
|
137 */ |
|
138 function comment_author_email_link( $linktext = '', $before = '', $after = '' ) { |
|
139 if ( $link = get_comment_author_email_link( $linktext, $before, $after ) ) |
|
140 echo $link; |
|
141 } |
|
142 |
|
143 /** |
|
144 * Return the html email link to the author of the current comment. |
|
145 * |
|
146 * Care should be taken to protect the email address and assure that email |
|
147 * harvesters do not capture your commentors' email address. Most assume that |
|
148 * their email address will not appear in raw form on the blog. Doing so will |
|
149 * enable anyone, including those that people don't want to get the email |
|
150 * address and use it for their own means good and bad. |
|
151 * |
|
152 * @global object $comment The current Comment row object. |
|
153 * |
|
154 * @since 2.7.0 |
164 * @since 2.7.0 |
155 * |
165 * @since 4.6.0 Added the `$comment` parameter. |
156 * @param string $linktext Optional. Text to display instead of the comment author's email address. |
166 * |
157 * Default empty. |
167 * @param string $linktext Optional. Text to display instead of the comment author's email address. |
158 * @param string $before Optional. Text or HTML to display before the email link. Default empty. |
168 * Default empty. |
159 * @param string $after Optional. Text or HTML to display after the email link. Default empty. |
169 * @param string $before Optional. Text or HTML to display before the email link. Default empty. |
160 */ |
170 * @param string $after Optional. Text or HTML to display after the email link. Default empty. |
161 function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) { |
171 * @param int|WP_Comment $comment Optional. Comment ID or WP_Comment object. Default is the current comment. |
162 global $comment; |
172 * @return string HTML markup for the comment author email link. By default, the email address is obfuscated |
163 |
173 * via the {@see 'comment_email'} filter with antispambot(). |
164 /** |
174 */ |
165 * Filter the comment author's email for display. |
175 function get_comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) { |
|
176 $comment = get_comment( $comment ); |
|
177 |
|
178 /** |
|
179 * Filters the comment author's email for display. |
166 * |
180 * |
167 * Care should be taken to protect the email address and assure that email |
181 * Care should be taken to protect the email address and assure that email |
168 * harvesters do not capture your commenter's email address. |
182 * harvesters do not capture your commenter's email address. |
169 * |
183 * |
170 * @since 1.2.0 |
184 * @since 1.2.0 |
171 * @since 4.1.0 The `$comment` parameter was added. |
185 * @since 4.1.0 The `$comment` parameter was added. |
172 * |
186 * |
173 * @param string $comment_author_email The comment author's email address. |
187 * @param string $comment_author_email The comment author's email address. |
174 * @param object $comment The comment object. |
188 * @param WP_Comment $comment The comment object. |
175 */ |
189 */ |
176 $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment ); |
190 $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment ); |
|
191 |
177 if ((!empty($email)) && ($email != '@')) { |
192 if ((!empty($email)) && ($email != '@')) { |
178 $display = ($linktext != '') ? $linktext : $email; |
193 $display = ($linktext != '') ? $linktext : $email; |
179 $return = $before; |
194 $return = $before; |
180 $return .= "<a href='mailto:$email'>$display</a>"; |
195 $return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) ); |
181 $return .= $after; |
196 $return .= $after; |
182 return $return; |
197 return $return; |
183 } else { |
198 } else { |
184 return ''; |
199 return ''; |
185 } |
200 } |
190 * |
205 * |
191 * Both get_comment_author_url() and get_comment_author() rely on get_comment(), |
206 * Both get_comment_author_url() and get_comment_author() rely on get_comment(), |
192 * which falls back to the global comment variable if the $comment_ID argument is empty. |
207 * which falls back to the global comment variable if the $comment_ID argument is empty. |
193 * |
208 * |
194 * @since 1.5.0 |
209 * @since 1.5.0 |
195 * |
210 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
196 * @param int $comment_ID ID of the comment for which to get the author's link. |
211 * |
197 * Default current comment. |
212 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link. |
|
213 * Default current comment. |
198 * @return string The comment author name or HTML link for author's URL. |
214 * @return string The comment author name or HTML link for author's URL. |
199 */ |
215 */ |
200 function get_comment_author_link( $comment_ID = 0 ) { |
216 function get_comment_author_link( $comment_ID = 0 ) { |
201 $url = get_comment_author_url( $comment_ID ); |
217 $comment = get_comment( $comment_ID ); |
202 $author = get_comment_author( $comment_ID ); |
218 $url = get_comment_author_url( $comment ); |
|
219 $author = get_comment_author( $comment ); |
203 |
220 |
204 if ( empty( $url ) || 'http://' == $url ) |
221 if ( empty( $url ) || 'http://' == $url ) |
205 $return = $author; |
222 $return = $author; |
206 else |
223 else |
207 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; |
224 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; |
208 |
225 |
209 /** |
226 /** |
210 * Filter the comment author's link for display. |
227 * Filters the comment author's link for display. |
211 * |
228 * |
212 * @since 1.5.0 |
229 * @since 1.5.0 |
213 * @since 4.1.0 The `$author` and `$comment_ID` parameters were added. |
230 * @since 4.1.0 The `$author` and `$comment_ID` parameters were added. |
214 * |
231 * |
215 * @param string $return The HTML-formatted comment author link. |
232 * @param string $return The HTML-formatted comment author link. |
216 * Empty for an invalid URL. |
233 * Empty for an invalid URL. |
217 * @param string $author The comment author's username. |
234 * @param string $author The comment author's username. |
218 * @param int $comment_ID The comment ID. |
235 * @param int $comment_ID The comment ID. |
219 */ |
236 */ |
220 return apply_filters( 'get_comment_author_link', $return, $author, $comment_ID ); |
237 return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID ); |
221 } |
238 } |
222 |
239 |
223 /** |
240 /** |
224 * Display the html link to the url of the author of the current comment. |
241 * Display the html link to the url of the author of the current comment. |
225 * |
242 * |
226 * @since 0.71 |
243 * @since 0.71 |
227 * |
244 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
228 * @see get_comment_author_link() Echoes result |
245 * |
229 * |
246 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link. |
230 * @param int $comment_ID ID of the comment for which to print the author's |
247 * Default current comment. |
231 * link. Default current comment. |
|
232 */ |
248 */ |
233 function comment_author_link( $comment_ID = 0 ) { |
249 function comment_author_link( $comment_ID = 0 ) { |
234 echo get_comment_author_link( $comment_ID ); |
250 echo get_comment_author_link( $comment_ID ); |
235 } |
251 } |
236 |
252 |
237 /** |
253 /** |
238 * Retrieve the IP address of the author of the current comment. |
254 * Retrieve the IP address of the author of the current comment. |
239 * |
255 * |
240 * @since 1.5.0 |
256 * @since 1.5.0 |
241 * |
257 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
242 * @param int $comment_ID ID of the comment for which to get the author's IP |
258 * |
243 * address. Default current comment. |
259 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address. |
|
260 * Default current comment. |
244 * @return string Comment author's IP address. |
261 * @return string Comment author's IP address. |
245 */ |
262 */ |
246 function get_comment_author_IP( $comment_ID = 0 ) { |
263 function get_comment_author_IP( $comment_ID = 0 ) { |
247 $comment = get_comment( $comment_ID ); |
264 $comment = get_comment( $comment_ID ); |
248 |
265 |
249 /** |
266 /** |
250 * Filter the comment author's returned IP address. |
267 * Filters the comment author's returned IP address. |
251 * |
268 * |
252 * @since 1.5.0 |
269 * @since 1.5.0 |
253 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
270 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
254 * |
271 * |
255 * @param string $comment_author_IP The comment author's IP address. |
272 * @param string $comment_author_IP The comment author's IP address. |
256 * @param int $comment_ID The comment ID. |
273 * @param int $comment_ID The comment ID. |
257 * @param object $comment The comment object. |
274 * @param WP_Comment $comment The comment object. |
258 */ |
275 */ |
259 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment_ID, $comment ); |
276 return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment ); |
260 } |
277 } |
261 |
278 |
262 /** |
279 /** |
263 * Display the IP address of the author of the current comment. |
280 * Display the IP address of the author of the current comment. |
264 * |
281 * |
265 * @since 0.71 |
282 * @since 0.71 |
266 * |
283 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
267 * @param int $comment_ID ID of the comment for which to print the author's IP |
284 * |
268 * address. Default current comment. |
285 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address. |
|
286 * Default current comment. |
269 */ |
287 */ |
270 function comment_author_IP( $comment_ID = 0 ) { |
288 function comment_author_IP( $comment_ID = 0 ) { |
271 echo get_comment_author_IP( $comment_ID ); |
289 echo esc_html( get_comment_author_IP( $comment_ID ) ); |
272 } |
290 } |
273 |
291 |
274 /** |
292 /** |
275 * Retrieve the url of the author of the current comment. |
293 * Retrieve the url of the author of the current comment. |
276 * |
294 * |
277 * @since 1.5.0 |
295 * @since 1.5.0 |
278 * |
296 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
279 * @param int $comment_ID ID of the comment for which to get the author's URL. |
297 * |
280 * Default current comment. |
298 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL. |
281 * @return string |
299 * Default current comment. |
|
300 * @return string Comment author URL. |
282 */ |
301 */ |
283 function get_comment_author_url( $comment_ID = 0 ) { |
302 function get_comment_author_url( $comment_ID = 0 ) { |
284 $comment = get_comment( $comment_ID ); |
303 $comment = get_comment( $comment_ID ); |
285 $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url; |
304 $url = ''; |
286 $url = esc_url( $url, array('http', 'https') ); |
305 $id = 0; |
287 |
306 if ( ! empty( $comment ) ) { |
288 /** |
307 $author_url = ( 'http://' == $comment->comment_author_url ) ? '' : $comment->comment_author_url; |
289 * Filter the comment author's URL. |
308 $url = esc_url( $author_url, array( 'http', 'https' ) ); |
|
309 $id = $comment->comment_ID; |
|
310 } |
|
311 |
|
312 /** |
|
313 * Filters the comment author's URL. |
290 * |
314 * |
291 * @since 1.5.0 |
315 * @since 1.5.0 |
292 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
316 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
293 * |
317 * |
294 * @param string $url The comment author's URL. |
318 * @param string $url The comment author's URL. |
295 * @param int $comment_ID The comment ID. |
319 * @param int $comment_ID The comment ID. |
296 * @param object $comment The comment object. |
320 * @param WP_Comment $comment The comment object. |
297 */ |
321 */ |
298 return apply_filters( 'get_comment_author_url', $url, $comment_ID, $comment ); |
322 return apply_filters( 'get_comment_author_url', $url, $id, $comment ); |
299 } |
323 } |
300 |
324 |
301 /** |
325 /** |
302 * Display the url of the author of the current comment. |
326 * Display the url of the author of the current comment. |
303 * |
327 * |
304 * @since 0.71 |
328 * @since 0.71 |
305 * |
329 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
306 * @param int $comment_ID ID of the comment for which to print the author's URL. |
330 * |
307 * Default current comment. |
331 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL. |
|
332 * Default current comment. |
308 */ |
333 */ |
309 function comment_author_url( $comment_ID = 0 ) { |
334 function comment_author_url( $comment_ID = 0 ) { |
310 $author_url = get_comment_author_url( $comment_ID ); |
335 $comment = get_comment( $comment_ID ); |
311 |
336 $author_url = get_comment_author_url( $comment ); |
312 /** |
337 |
313 * Filter the comment author's URL for display. |
338 /** |
|
339 * Filters the comment author's URL for display. |
314 * |
340 * |
315 * @since 1.2.0 |
341 * @since 1.2.0 |
316 * @since 4.1.0 The `$comment_ID` parameter was added. |
342 * @since 4.1.0 The `$comment_ID` parameter was added. |
317 * |
343 * |
318 * @param string $author_url The comment author's URL. |
344 * @param string $author_url The comment author's URL. |
319 * @param int $comment_ID The comment ID. |
345 * @param int $comment_ID The comment ID. |
320 */ |
346 */ |
321 echo apply_filters( 'comment_url', $author_url, $comment_ID ); |
347 echo apply_filters( 'comment_url', $author_url, $comment->comment_ID ); |
322 } |
348 } |
323 |
349 |
324 /** |
350 /** |
325 * Retrieves the HTML link of the url of the author of the current comment. |
351 * Retrieves the HTML link of the url of the author of the current comment. |
326 * |
352 * |
528 * Will cut each word and only output the first 20 words with '…' at the end. |
574 * Will cut each word and only output the first 20 words with '…' at the end. |
529 * If the word count is less than 20, then no truncating is done and no '…' |
575 * If the word count is less than 20, then no truncating is done and no '…' |
530 * will appear. |
576 * will appear. |
531 * |
577 * |
532 * @since 1.5.0 |
578 * @since 1.5.0 |
533 * |
579 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
534 * @param int $comment_ID ID of the comment for which to get the excerpt. |
580 * |
535 * Default current comment. |
581 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt. |
|
582 * Default current comment. |
536 * @return string The maybe truncated comment with 20 words or less. |
583 * @return string The maybe truncated comment with 20 words or less. |
537 */ |
584 */ |
538 function get_comment_excerpt( $comment_ID = 0 ) { |
585 function get_comment_excerpt( $comment_ID = 0 ) { |
539 $comment = get_comment( $comment_ID ); |
586 $comment = get_comment( $comment_ID ); |
540 $comment_text = strip_tags($comment->comment_content); |
587 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); |
541 $blah = explode(' ', $comment_text); |
588 $words = explode( ' ', $comment_text ); |
542 |
589 |
543 if (count($blah) > 20) { |
590 /** |
544 $k = 20; |
591 * Filters the amount of words used in the comment excerpt. |
545 $use_dotdotdot = 1; |
592 * |
546 } else { |
593 * @since 4.4.0 |
547 $k = count($blah); |
594 * |
548 $use_dotdotdot = 0; |
595 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. |
549 } |
596 */ |
550 |
597 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 ); |
551 $excerpt = ''; |
598 |
552 for ($i=0; $i<$k; $i++) { |
599 $use_ellipsis = count( $words ) > $comment_excerpt_length; |
553 $excerpt .= $blah[$i] . ' '; |
600 if ( $use_ellipsis ) { |
554 } |
601 $words = array_slice( $words, 0, $comment_excerpt_length ); |
555 $excerpt .= ($use_dotdotdot) ? '…' : ''; |
602 } |
556 |
603 |
557 /** |
604 $excerpt = trim( join( ' ', $words ) ); |
558 * Filter the retrieved comment excerpt. |
605 if ( $use_ellipsis ) { |
|
606 $excerpt .= '…'; |
|
607 } |
|
608 /** |
|
609 * Filters the retrieved comment excerpt. |
559 * |
610 * |
560 * @since 1.5.0 |
611 * @since 1.5.0 |
561 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
612 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. |
562 * |
613 * |
563 * @param string $excerpt The comment excerpt text. |
614 * @param string $excerpt The comment excerpt text. |
564 * @param int $comment_ID The comment ID. |
615 * @param int $comment_ID The comment ID. |
565 * @param object $comment The comment object. |
616 * @param WP_Comment $comment The comment object. |
566 */ |
617 */ |
567 return apply_filters( 'get_comment_excerpt', $excerpt, $comment_ID, $comment ); |
618 return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment ); |
568 } |
619 } |
569 |
620 |
570 /** |
621 /** |
571 * Display the excerpt of the current comment. |
622 * Display the excerpt of the current comment. |
572 * |
623 * |
573 * @since 1.2.0 |
624 * @since 1.2.0 |
574 * |
625 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
575 * @param int $comment_ID ID of the comment for which to print the excerpt. |
626 * |
576 * Default current comment. |
627 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the excerpt. |
|
628 * Default current comment. |
577 */ |
629 */ |
578 function comment_excerpt( $comment_ID = 0 ) { |
630 function comment_excerpt( $comment_ID = 0 ) { |
579 $comment_excerpt = get_comment_excerpt($comment_ID); |
631 $comment = get_comment( $comment_ID ); |
580 |
632 $comment_excerpt = get_comment_excerpt( $comment ); |
581 /** |
633 |
582 * Filter the comment excerpt for display. |
634 /** |
|
635 * Filters the comment excerpt for display. |
583 * |
636 * |
584 * @since 1.2.0 |
637 * @since 1.2.0 |
585 * @since 4.1.0 The `$comment_ID` parameter was added. |
638 * @since 4.1.0 The `$comment_ID` parameter was added. |
586 * |
639 * |
587 * @param string $comment_excerpt The comment excerpt text. |
640 * @param string $comment_excerpt The comment excerpt text. |
588 * @param int $comment_ID The comment ID. |
641 * @param int $comment_ID The comment ID. |
589 */ |
642 */ |
590 echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment_ID ); |
643 echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment->comment_ID ); |
591 } |
644 } |
592 |
645 |
593 /** |
646 /** |
594 * Retrieve the comment id of the current comment. |
647 * Retrieve the comment id of the current comment. |
595 * |
648 * |
596 * @since 1.5.0 |
649 * @since 1.5.0 |
597 * |
650 * |
598 * @return int The comment ID. |
651 * @return int The comment ID. |
599 */ |
652 */ |
600 function get_comment_ID() { |
653 function get_comment_ID() { |
601 global $comment; |
654 $comment = get_comment(); |
602 |
655 |
603 /** |
656 /** |
604 * Filter the returned comment ID. |
657 * Filters the returned comment ID. |
605 * |
658 * |
606 * @since 1.5.0 |
659 * @since 1.5.0 |
607 * @since 4.1.0 The `$comment_ID` parameter was added. |
660 * @since 4.1.0 The `$comment_ID` parameter was added. |
608 * |
661 * |
609 * @param int $comment_ID The current comment ID. |
662 * @param int $comment_ID The current comment ID. |
610 * @param object $comment The comment object. |
663 * @param WP_Comment $comment The comment object. |
611 */ |
664 */ |
612 return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment ); |
665 return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment ); |
613 } |
666 } |
614 |
667 |
615 /** |
668 /** |
623 |
676 |
624 /** |
677 /** |
625 * Retrieve the link to a given comment. |
678 * Retrieve the link to a given comment. |
626 * |
679 * |
627 * @since 1.5.0 |
680 * @since 1.5.0 |
|
681 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument. |
628 * |
682 * |
629 * @see get_page_of_comment() |
683 * @see get_page_of_comment() |
630 * |
684 * |
631 * @param mixed $comment Comment to retrieve. Default current comment. |
685 * @global WP_Rewrite $wp_rewrite |
632 * @param array $args Optional. An array of arguments to override the defaults. |
686 * @global bool $in_comment_loop |
|
687 * |
|
688 * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment. |
|
689 * @param array $args { |
|
690 * An array of optional arguments to override the defaults. |
|
691 * |
|
692 * @type string $type Passed to get_page_of_comment(). |
|
693 * @type int $page Current page of comments, for calculating comment pagination. |
|
694 * @type int $per_page Per-page value for comment pagination. |
|
695 * @type int $max_depth Passed to get_page_of_comment(). |
|
696 * @type int|string $cpage Value to use for the comment's "comment-page" or "cpage" value. |
|
697 * If provided, this value overrides any value calculated from `$page` |
|
698 * and `$per_page`. |
|
699 * } |
633 * @return string The permalink to the given comment. |
700 * @return string The permalink to the given comment. |
634 */ |
701 */ |
635 function get_comment_link( $comment = null, $args = array() ) { |
702 function get_comment_link( $comment = null, $args = array() ) { |
636 global $wp_rewrite, $in_comment_loop; |
703 global $wp_rewrite, $in_comment_loop; |
637 |
704 |
638 $comment = get_comment($comment); |
705 $comment = get_comment($comment); |
639 |
706 |
640 // Backwards compat |
707 // Back-compat. |
641 if ( ! is_array( $args ) ) { |
708 if ( ! is_array( $args ) ) { |
642 $args = array( 'page' => $args ); |
709 $args = array( 'page' => $args ); |
643 } |
710 } |
644 |
711 |
645 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); |
712 $defaults = array( |
|
713 'type' => 'all', |
|
714 'page' => '', |
|
715 'per_page' => '', |
|
716 'max_depth' => '', |
|
717 'cpage' => null, |
|
718 ); |
646 $args = wp_parse_args( $args, $defaults ); |
719 $args = wp_parse_args( $args, $defaults ); |
647 |
720 |
648 if ( '' === $args['per_page'] && get_option('page_comments') ) |
721 $link = get_permalink( $comment->comment_post_ID ); |
649 $args['per_page'] = get_option('comments_per_page'); |
722 |
650 |
723 // The 'cpage' param takes precedence. |
651 if ( empty($args['per_page']) ) { |
724 if ( ! is_null( $args['cpage'] ) ) { |
652 $args['per_page'] = 0; |
725 $cpage = $args['cpage']; |
653 $args['page'] = 0; |
726 |
654 } |
727 // No 'cpage' is provided, so we calculate one. |
655 |
|
656 if ( $args['per_page'] ) { |
|
657 if ( '' == $args['page'] ) |
|
658 $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args ); |
|
659 |
|
660 if ( $wp_rewrite->using_permalinks() ) |
|
661 $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment' ); |
|
662 else |
|
663 $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ); |
|
664 } else { |
728 } else { |
665 $link = get_permalink( $comment->comment_post_ID ); |
729 if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) { |
|
730 $args['per_page'] = get_option('comments_per_page'); |
|
731 } |
|
732 |
|
733 if ( empty( $args['per_page'] ) ) { |
|
734 $args['per_page'] = 0; |
|
735 $args['page'] = 0; |
|
736 } |
|
737 |
|
738 $cpage = $args['page']; |
|
739 |
|
740 if ( '' == $cpage ) { |
|
741 if ( ! empty( $in_comment_loop ) ) { |
|
742 $cpage = get_query_var( 'cpage' ); |
|
743 } else { |
|
744 // Requires a database hit, so we only do it when we can't figure out from context. |
|
745 $cpage = get_page_of_comment( $comment->comment_ID, $args ); |
|
746 } |
|
747 } |
|
748 |
|
749 /* |
|
750 * If the default page displays the oldest comments, the permalinks for comments on the default page |
|
751 * do not need a 'cpage' query var. |
|
752 */ |
|
753 if ( 'oldest' === get_option( 'default_comments_page' ) && 1 === $cpage ) { |
|
754 $cpage = ''; |
|
755 } |
|
756 } |
|
757 |
|
758 if ( $cpage && get_option( 'page_comments' ) ) { |
|
759 if ( $wp_rewrite->using_permalinks() ) { |
|
760 if ( $cpage ) { |
|
761 $link = trailingslashit( $link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage; |
|
762 } |
|
763 |
|
764 $link = user_trailingslashit( $link, 'comment' ); |
|
765 } elseif ( $cpage ) { |
|
766 $link = add_query_arg( 'cpage', $cpage, $link ); |
|
767 } |
|
768 |
|
769 } |
|
770 |
|
771 if ( $wp_rewrite->using_permalinks() ) { |
|
772 $link = user_trailingslashit( $link, 'comment' ); |
666 } |
773 } |
667 |
774 |
668 $link = $link . '#comment-' . $comment->comment_ID; |
775 $link = $link . '#comment-' . $comment->comment_ID; |
669 /** |
776 |
670 * Filter the returned single comment permalink. |
777 /** |
|
778 * Filters the returned single comment permalink. |
671 * |
779 * |
672 * @since 2.8.0 |
780 * @since 2.8.0 |
|
781 * @since 4.4.0 Added the `$cpage` parameter. |
673 * |
782 * |
674 * @see get_page_of_comment() |
783 * @see get_page_of_comment() |
675 * |
784 * |
676 * @param string $link The comment permalink with '#comment-$id' appended. |
785 * @param string $link The comment permalink with '#comment-$id' appended. |
677 * @param object $comment The current comment object. |
786 * @param WP_Comment $comment The current comment object. |
678 * @param array $args An array of arguments to override the defaults. |
787 * @param array $args An array of arguments to override the defaults. |
679 */ |
788 * @param int $cpage The calculated 'cpage' value. |
680 return apply_filters( 'get_comment_link', $link, $comment, $args ); |
789 */ |
681 } |
790 return apply_filters( 'get_comment_link', $link, $comment, $args, $cpage ); |
682 |
791 } |
683 /** |
792 |
684 * Retrieve the link to the current post comments. |
793 /** |
|
794 * Retrieves the link to the current post comments. |
685 * |
795 * |
686 * @since 1.5.0 |
796 * @since 1.5.0 |
687 * |
797 * |
688 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
798 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
689 * @return string The link to the comments. |
799 * @return string The link to the comments. |
690 */ |
800 */ |
691 function get_comments_link( $post_id = 0 ) { |
801 function get_comments_link( $post_id = 0 ) { |
692 $comments_link = get_permalink( $post_id ) . '#comments'; |
802 $hash = get_comments_number( $post_id ) ? '#comments' : '#respond'; |
693 /** |
803 $comments_link = get_permalink( $post_id ) . $hash; |
694 * Filter the returned post comments permalink. |
804 |
|
805 /** |
|
806 * Filters the returned post comments permalink. |
695 * |
807 * |
696 * @since 3.6.0 |
808 * @since 3.6.0 |
697 * |
809 * |
698 * @param string $comments_link Post comments permalink with '#comments' appended. |
810 * @param string $comments_link Post comments permalink with '#comments' appended. |
699 * @param int|WP_Post $post_id Post ID or WP_Post object. |
811 * @param int|WP_Post $post_id Post ID or WP_Post object. |
1157 * The url of the current comment author escaped for use in attributes. |
1323 * The url of the current comment author escaped for use in attributes. |
1158 */ |
1324 */ |
1159 $comment_author_url = esc_url($commenter['comment_author_url']); |
1325 $comment_author_url = esc_url($commenter['comment_author_url']); |
1160 |
1326 |
1161 $comment_args = array( |
1327 $comment_args = array( |
1162 'order' => 'ASC', |
|
1163 'orderby' => 'comment_date_gmt', |
1328 'orderby' => 'comment_date_gmt', |
|
1329 'order' => 'ASC', |
1164 'status' => 'approve', |
1330 'status' => 'approve', |
1165 'post_id' => $post->ID, |
1331 'post_id' => $post->ID, |
|
1332 'no_found_rows' => false, |
|
1333 'update_comment_meta_cache' => false, // We lazy-load comment meta for performance. |
1166 ); |
1334 ); |
|
1335 |
|
1336 if ( get_option('thread_comments') ) { |
|
1337 $comment_args['hierarchical'] = 'threaded'; |
|
1338 } else { |
|
1339 $comment_args['hierarchical'] = false; |
|
1340 } |
1167 |
1341 |
1168 if ( $user_ID ) { |
1342 if ( $user_ID ) { |
1169 $comment_args['include_unapproved'] = array( $user_ID ); |
1343 $comment_args['include_unapproved'] = array( $user_ID ); |
1170 } elseif ( ! empty( $comment_author_email ) ) { |
1344 } elseif ( ! empty( $comment_author_email ) ) { |
1171 $comment_args['include_unapproved'] = array( $comment_author_email ); |
1345 $comment_args['include_unapproved'] = array( $comment_author_email ); |
1172 } |
1346 } |
1173 |
1347 |
1174 $comments = get_comments( $comment_args ); |
1348 $per_page = 0; |
1175 |
1349 if ( get_option( 'page_comments' ) ) { |
1176 /** |
1350 $per_page = (int) get_query_var( 'comments_per_page' ); |
1177 * Filter the comments array. |
1351 if ( 0 === $per_page ) { |
|
1352 $per_page = (int) get_option( 'comments_per_page' ); |
|
1353 } |
|
1354 |
|
1355 $comment_args['number'] = $per_page; |
|
1356 $page = (int) get_query_var( 'cpage' ); |
|
1357 |
|
1358 if ( $page ) { |
|
1359 $comment_args['offset'] = ( $page - 1 ) * $per_page; |
|
1360 } elseif ( 'oldest' === get_option( 'default_comments_page' ) ) { |
|
1361 $comment_args['offset'] = 0; |
|
1362 } else { |
|
1363 // If fetching the first page of 'newest', we need a top-level comment count. |
|
1364 $top_level_query = new WP_Comment_Query(); |
|
1365 $top_level_args = array( |
|
1366 'count' => true, |
|
1367 'orderby' => false, |
|
1368 'post_id' => $post->ID, |
|
1369 'status' => 'approve', |
|
1370 ); |
|
1371 |
|
1372 if ( $comment_args['hierarchical'] ) { |
|
1373 $top_level_args['parent'] = 0; |
|
1374 } |
|
1375 |
|
1376 if ( isset( $comment_args['include_unapproved'] ) ) { |
|
1377 $top_level_args['include_unapproved'] = $comment_args['include_unapproved']; |
|
1378 } |
|
1379 |
|
1380 $top_level_count = $top_level_query->query( $top_level_args ); |
|
1381 |
|
1382 $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; |
|
1383 } |
|
1384 } |
|
1385 |
|
1386 /** |
|
1387 * Filters the arguments used to query comments in comments_template(). |
|
1388 * |
|
1389 * @since 4.5.0 |
|
1390 * |
|
1391 * @see WP_Comment_Query::__construct() |
|
1392 * |
|
1393 * @param array $comment_args { |
|
1394 * Array of WP_Comment_Query arguments. |
|
1395 * |
|
1396 * @type string|array $orderby Field(s) to order by. |
|
1397 * @type string $order Order of results. Accepts 'ASC' or 'DESC'. |
|
1398 * @type string $status Comment status. |
|
1399 * @type array $include_unapproved Array of IDs or email addresses whose unapproved comments |
|
1400 * will be included in results. |
|
1401 * @type int $post_id ID of the post. |
|
1402 * @type bool $no_found_rows Whether to refrain from querying for found rows. |
|
1403 * @type bool $update_comment_meta_cache Whether to prime cache for comment meta. |
|
1404 * @type bool|string $hierarchical Whether to query for comments hierarchically. |
|
1405 * @type int $offset Comment offset. |
|
1406 * @type int $number Number of comments to fetch. |
|
1407 * } |
|
1408 */ |
|
1409 $comment_args = apply_filters( 'comments_template_query_args', $comment_args ); |
|
1410 $comment_query = new WP_Comment_Query( $comment_args ); |
|
1411 $_comments = $comment_query->comments; |
|
1412 |
|
1413 // Trees must be flattened before they're passed to the walker. |
|
1414 if ( $comment_args['hierarchical'] ) { |
|
1415 $comments_flat = array(); |
|
1416 foreach ( $_comments as $_comment ) { |
|
1417 $comments_flat[] = $_comment; |
|
1418 $comment_children = $_comment->get_children( array( |
|
1419 'format' => 'flat', |
|
1420 'status' => $comment_args['status'], |
|
1421 'orderby' => $comment_args['orderby'] |
|
1422 ) ); |
|
1423 |
|
1424 foreach ( $comment_children as $comment_child ) { |
|
1425 $comments_flat[] = $comment_child; |
|
1426 } |
|
1427 } |
|
1428 } else { |
|
1429 $comments_flat = $_comments; |
|
1430 } |
|
1431 |
|
1432 /** |
|
1433 * Filters the comments array. |
1178 * |
1434 * |
1179 * @since 2.1.0 |
1435 * @since 2.1.0 |
1180 * |
1436 * |
1181 * @param array $comments Array of comments supplied to the comments template. |
1437 * @param array $comments Array of comments supplied to the comments template. |
1182 * @param int $post_ID Post ID. |
1438 * @param int $post_ID Post ID. |
1183 */ |
1439 */ |
1184 $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); |
1440 $wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID ); |
|
1441 |
1185 $comments = &$wp_query->comments; |
1442 $comments = &$wp_query->comments; |
1186 $wp_query->comment_count = count($wp_query->comments); |
1443 $wp_query->comment_count = count($wp_query->comments); |
1187 update_comment_cache($wp_query->comments); |
1444 $wp_query->max_num_comment_pages = $comment_query->max_num_pages; |
1188 |
1445 |
1189 if ( $separate_comments ) { |
1446 if ( $separate_comments ) { |
1190 $wp_query->comments_by_type = separate_comments($comments); |
1447 $wp_query->comments_by_type = separate_comments($comments); |
1191 $comments_by_type = &$wp_query->comments_by_type; |
1448 $comments_by_type = &$wp_query->comments_by_type; |
|
1449 } else { |
|
1450 $wp_query->comments_by_type = array(); |
1192 } |
1451 } |
1193 |
1452 |
1194 $overridden_cpage = false; |
1453 $overridden_cpage = false; |
1195 if ( '' == get_query_var('cpage') && get_option('page_comments') ) { |
1454 if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) { |
1196 set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 ); |
1455 set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 ); |
1197 $overridden_cpage = true; |
1456 $overridden_cpage = true; |
1198 } |
1457 } |
1199 |
1458 |
1200 if ( !defined('COMMENTS_TEMPLATE') ) |
1459 if ( !defined('COMMENTS_TEMPLATE') ) |
1201 define('COMMENTS_TEMPLATE', true); |
1460 define('COMMENTS_TEMPLATE', true); |
1202 |
1461 |
1203 $theme_template = STYLESHEETPATH . $file; |
1462 $theme_template = STYLESHEETPATH . $file; |
1204 /** |
1463 /** |
1205 * Filter the path to the theme template file used for the comments template. |
1464 * Filters the path to the theme template file used for the comments template. |
1206 * |
1465 * |
1207 * @since 1.5.1 |
1466 * @since 1.5.1 |
1208 * |
1467 * |
1209 * @param string $theme_template The path to the theme template file. |
1468 * @param string $theme_template The path to the theme template file. |
1210 */ |
1469 */ |
1645 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; |
1876 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; |
1646 |
1877 |
1647 if ( 0 == $replytoid ) |
1878 if ( 0 == $replytoid ) |
1648 echo $noreplytext; |
1879 echo $noreplytext; |
1649 else { |
1880 else { |
|
1881 // Sets the global so that template tags can be used in the comment form. |
1650 $comment = get_comment($replytoid); |
1882 $comment = get_comment($replytoid); |
1651 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author(); |
1883 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>' : get_comment_author( $comment ); |
1652 printf( $replytext, $author ); |
1884 printf( $replytext, $author ); |
1653 } |
1885 } |
1654 } |
1886 } |
1655 |
1887 |
1656 /** |
1888 /** |
1657 * HTML comment list class. |
1889 * List comments. |
1658 * |
1890 * |
1659 * @uses Walker |
1891 * Used in the comments.php template to list comments for a particular post. |
|
1892 * |
1660 * @since 2.7.0 |
1893 * @since 2.7.0 |
1661 */ |
|
1662 class Walker_Comment extends Walker { |
|
1663 /** |
|
1664 * What the class handles. |
|
1665 * |
|
1666 * @see Walker::$tree_type |
|
1667 * |
|
1668 * @since 2.7.0 |
|
1669 * @var string |
|
1670 */ |
|
1671 public $tree_type = 'comment'; |
|
1672 |
|
1673 /** |
|
1674 * DB fields to use. |
|
1675 * |
|
1676 * @see Walker::$db_fields |
|
1677 * |
|
1678 * @since 2.7.0 |
|
1679 * @var array |
|
1680 */ |
|
1681 public $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID'); |
|
1682 |
|
1683 /** |
|
1684 * Start the list before the elements are added. |
|
1685 * |
|
1686 * @see Walker::start_lvl() |
|
1687 * |
|
1688 * @since 2.7.0 |
|
1689 * |
|
1690 * @param string $output Passed by reference. Used to append additional content. |
|
1691 * @param int $depth Depth of comment. |
|
1692 * @param array $args Uses 'style' argument for type of HTML list. |
|
1693 */ |
|
1694 public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
1695 $GLOBALS['comment_depth'] = $depth + 1; |
|
1696 |
|
1697 switch ( $args['style'] ) { |
|
1698 case 'div': |
|
1699 break; |
|
1700 case 'ol': |
|
1701 $output .= '<ol class="children">' . "\n"; |
|
1702 break; |
|
1703 case 'ul': |
|
1704 default: |
|
1705 $output .= '<ul class="children">' . "\n"; |
|
1706 break; |
|
1707 } |
|
1708 } |
|
1709 |
|
1710 /** |
|
1711 * End the list of items after the elements are added. |
|
1712 * |
|
1713 * @see Walker::end_lvl() |
|
1714 * |
|
1715 * @since 2.7.0 |
|
1716 * |
|
1717 * @param string $output Passed by reference. Used to append additional content. |
|
1718 * @param int $depth Depth of comment. |
|
1719 * @param array $args Will only append content if style argument value is 'ol' or 'ul'. |
|
1720 */ |
|
1721 public function end_lvl( &$output, $depth = 0, $args = array() ) { |
|
1722 $GLOBALS['comment_depth'] = $depth + 1; |
|
1723 |
|
1724 switch ( $args['style'] ) { |
|
1725 case 'div': |
|
1726 break; |
|
1727 case 'ol': |
|
1728 $output .= "</ol><!-- .children -->\n"; |
|
1729 break; |
|
1730 case 'ul': |
|
1731 default: |
|
1732 $output .= "</ul><!-- .children -->\n"; |
|
1733 break; |
|
1734 } |
|
1735 } |
|
1736 |
|
1737 /** |
|
1738 * Traverse elements to create list from elements. |
|
1739 * |
|
1740 * This function is designed to enhance Walker::display_element() to |
|
1741 * display children of higher nesting levels than selected inline on |
|
1742 * the highest depth level displayed. This prevents them being orphaned |
|
1743 * at the end of the comment list. |
|
1744 * |
|
1745 * Example: max_depth = 2, with 5 levels of nested content. |
|
1746 * 1 |
|
1747 * 1.1 |
|
1748 * 1.1.1 |
|
1749 * 1.1.1.1 |
|
1750 * 1.1.1.1.1 |
|
1751 * 1.1.2 |
|
1752 * 1.1.2.1 |
|
1753 * 2 |
|
1754 * 2.2 |
|
1755 * |
|
1756 * @see Walker::display_element() |
|
1757 * @see wp_list_comments() |
|
1758 * |
|
1759 * @since 2.7.0 |
|
1760 * |
|
1761 * @param object $element Data object. |
|
1762 * @param array $children_elements List of elements to continue traversing. |
|
1763 * @param int $max_depth Max depth to traverse. |
|
1764 * @param int $depth Depth of current element. |
|
1765 * @param array $args An array of arguments. |
|
1766 * @param string $output Passed by reference. Used to append additional content. |
|
1767 * @return null Null on failure with no changes to parameters. |
|
1768 */ |
|
1769 public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
|
1770 |
|
1771 if ( !$element ) |
|
1772 return; |
|
1773 |
|
1774 $id_field = $this->db_fields['id']; |
|
1775 $id = $element->$id_field; |
|
1776 |
|
1777 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
|
1778 |
|
1779 // If we're at the max depth, and the current element still has children, loop over those and display them at this level |
|
1780 // This is to prevent them being orphaned to the end of the list. |
|
1781 if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) { |
|
1782 foreach ( $children_elements[ $id ] as $child ) |
|
1783 $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output ); |
|
1784 |
|
1785 unset( $children_elements[ $id ] ); |
|
1786 } |
|
1787 |
|
1788 } |
|
1789 |
|
1790 /** |
|
1791 * Start the element output. |
|
1792 * |
|
1793 * @since 2.7.0 |
|
1794 * |
|
1795 * @see Walker::start_el() |
|
1796 * @see wp_list_comments() |
|
1797 * |
|
1798 * @param string $output Passed by reference. Used to append additional content. |
|
1799 * @param object $comment Comment data object. |
|
1800 * @param int $depth Depth of comment in reference to parents. |
|
1801 * @param array $args An array of arguments. |
|
1802 */ |
|
1803 public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) { |
|
1804 $depth++; |
|
1805 $GLOBALS['comment_depth'] = $depth; |
|
1806 $GLOBALS['comment'] = $comment; |
|
1807 |
|
1808 if ( !empty( $args['callback'] ) ) { |
|
1809 ob_start(); |
|
1810 call_user_func( $args['callback'], $comment, $args, $depth ); |
|
1811 $output .= ob_get_clean(); |
|
1812 return; |
|
1813 } |
|
1814 |
|
1815 if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) { |
|
1816 ob_start(); |
|
1817 $this->ping( $comment, $depth, $args ); |
|
1818 $output .= ob_get_clean(); |
|
1819 } elseif ( 'html5' === $args['format'] ) { |
|
1820 ob_start(); |
|
1821 $this->html5_comment( $comment, $depth, $args ); |
|
1822 $output .= ob_get_clean(); |
|
1823 } else { |
|
1824 ob_start(); |
|
1825 $this->comment( $comment, $depth, $args ); |
|
1826 $output .= ob_get_clean(); |
|
1827 } |
|
1828 } |
|
1829 |
|
1830 /** |
|
1831 * Ends the element output, if needed. |
|
1832 * |
|
1833 * @since 2.7.0 |
|
1834 * |
|
1835 * @see Walker::end_el() |
|
1836 * @see wp_list_comments() |
|
1837 * |
|
1838 * @param string $output Passed by reference. Used to append additional content. |
|
1839 * @param object $comment The comment object. Default current comment. |
|
1840 * @param int $depth Depth of comment. |
|
1841 * @param array $args An array of arguments. |
|
1842 */ |
|
1843 public function end_el( &$output, $comment, $depth = 0, $args = array() ) { |
|
1844 if ( !empty( $args['end-callback'] ) ) { |
|
1845 ob_start(); |
|
1846 call_user_func( $args['end-callback'], $comment, $args, $depth ); |
|
1847 $output .= ob_get_clean(); |
|
1848 return; |
|
1849 } |
|
1850 if ( 'div' == $args['style'] ) |
|
1851 $output .= "</div><!-- #comment-## -->\n"; |
|
1852 else |
|
1853 $output .= "</li><!-- #comment-## -->\n"; |
|
1854 } |
|
1855 |
|
1856 /** |
|
1857 * Output a pingback comment. |
|
1858 * |
|
1859 * @access protected |
|
1860 * @since 3.6.0 |
|
1861 * |
|
1862 * @see wp_list_comments() |
|
1863 * |
|
1864 * @param object $comment The comment object. |
|
1865 * @param int $depth Depth of comment. |
|
1866 * @param array $args An array of arguments. |
|
1867 */ |
|
1868 protected function ping( $comment, $depth, $args ) { |
|
1869 $tag = ( 'div' == $args['style'] ) ? 'div' : 'li'; |
|
1870 ?> |
|
1871 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>> |
|
1872 <div class="comment-body"> |
|
1873 <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?> |
|
1874 </div> |
|
1875 <?php |
|
1876 } |
|
1877 |
|
1878 /** |
|
1879 * Output a single comment. |
|
1880 * |
|
1881 * @access protected |
|
1882 * @since 3.6.0 |
|
1883 * |
|
1884 * @see wp_list_comments() |
|
1885 * |
|
1886 * @param object $comment Comment to display. |
|
1887 * @param int $depth Depth of comment. |
|
1888 * @param array $args An array of arguments. |
|
1889 */ |
|
1890 protected function comment( $comment, $depth, $args ) { |
|
1891 if ( 'div' == $args['style'] ) { |
|
1892 $tag = 'div'; |
|
1893 $add_below = 'comment'; |
|
1894 } else { |
|
1895 $tag = 'li'; |
|
1896 $add_below = 'div-comment'; |
|
1897 } |
|
1898 ?> |
|
1899 <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '' ); ?> id="comment-<?php comment_ID(); ?>"> |
|
1900 <?php if ( 'div' != $args['style'] ) : ?> |
|
1901 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body"> |
|
1902 <?php endif; ?> |
|
1903 <div class="comment-author vcard"> |
|
1904 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?> |
|
1905 <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?> |
|
1906 </div> |
|
1907 <?php if ( '0' == $comment->comment_approved ) : ?> |
|
1908 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em> |
|
1909 <br /> |
|
1910 <?php endif; ?> |
|
1911 |
|
1912 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>"> |
|
1913 <?php |
|
1914 /* translators: 1: date, 2: time */ |
|
1915 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' ); |
|
1916 ?> |
|
1917 </div> |
|
1918 |
|
1919 <?php comment_text( get_comment_id(), array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> |
|
1920 |
|
1921 <?php |
|
1922 comment_reply_link( array_merge( $args, array( |
|
1923 'add_below' => $add_below, |
|
1924 'depth' => $depth, |
|
1925 'max_depth' => $args['max_depth'], |
|
1926 'before' => '<div class="reply">', |
|
1927 'after' => '</div>' |
|
1928 ) ) ); |
|
1929 ?> |
|
1930 |
|
1931 <?php if ( 'div' != $args['style'] ) : ?> |
|
1932 </div> |
|
1933 <?php endif; ?> |
|
1934 <?php |
|
1935 } |
|
1936 |
|
1937 /** |
|
1938 * Output a comment in the HTML5 format. |
|
1939 * |
|
1940 * @access protected |
|
1941 * @since 3.6.0 |
|
1942 * |
|
1943 * @see wp_list_comments() |
|
1944 * |
|
1945 * @param object $comment Comment to display. |
|
1946 * @param int $depth Depth of comment. |
|
1947 * @param array $args An array of arguments. |
|
1948 */ |
|
1949 protected function html5_comment( $comment, $depth, $args ) { |
|
1950 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; |
|
1951 ?> |
|
1952 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '' ); ?>> |
|
1953 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> |
|
1954 <footer class="comment-meta"> |
|
1955 <div class="comment-author vcard"> |
|
1956 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?> |
|
1957 <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?> |
|
1958 </div><!-- .comment-author --> |
|
1959 |
|
1960 <div class="comment-metadata"> |
|
1961 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>"> |
|
1962 <time datetime="<?php comment_time( 'c' ); ?>"> |
|
1963 <?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), get_comment_time() ); ?> |
|
1964 </time> |
|
1965 </a> |
|
1966 <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?> |
|
1967 </div><!-- .comment-metadata --> |
|
1968 |
|
1969 <?php if ( '0' == $comment->comment_approved ) : ?> |
|
1970 <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p> |
|
1971 <?php endif; ?> |
|
1972 </footer><!-- .comment-meta --> |
|
1973 |
|
1974 <div class="comment-content"> |
|
1975 <?php comment_text(); ?> |
|
1976 </div><!-- .comment-content --> |
|
1977 |
|
1978 <?php |
|
1979 comment_reply_link( array_merge( $args, array( |
|
1980 'add_below' => 'div-comment', |
|
1981 'depth' => $depth, |
|
1982 'max_depth' => $args['max_depth'], |
|
1983 'before' => '<div class="reply">', |
|
1984 'after' => '</div>' |
|
1985 ) ) ); |
|
1986 ?> |
|
1987 </article><!-- .comment-body --> |
|
1988 <?php |
|
1989 } |
|
1990 } |
|
1991 |
|
1992 /** |
|
1993 * List comments. |
|
1994 * |
|
1995 * Used in the comments.php template to list comments for a particular post. |
|
1996 * |
|
1997 * @since 2.7.0 |
|
1998 * |
1894 * |
1999 * @see WP_Query->comments |
1895 * @see WP_Query->comments |
|
1896 * |
|
1897 * @global WP_Query $wp_query |
|
1898 * @global int $comment_alt |
|
1899 * @global int $comment_depth |
|
1900 * @global int $comment_thread_alt |
|
1901 * @global bool $overridden_cpage |
|
1902 * @global bool $in_comment_loop |
2000 * |
1903 * |
2001 * @param string|array $args { |
1904 * @param string|array $args { |
2002 * Optional. Formatting options. |
1905 * Optional. Formatting options. |
2003 * |
1906 * |
2004 * @type object $walker Instance of a Walker class to list comments. Default null. |
1907 * @type object $walker Instance of a Walker class to list comments. Default null. |
2134 return $output; |
2104 return $output; |
2135 } |
2105 } |
2136 } |
2106 } |
2137 |
2107 |
2138 /** |
2108 /** |
2139 * Output a complete commenting form for use within a template. |
2109 * Outputs a complete commenting form for use within a template. |
2140 * |
2110 * |
2141 * Most strings and form fields may be controlled through the $args array passed |
2111 * Most strings and form fields may be controlled through the $args array passed |
2142 * into the function, while you may also choose to use the comment_form_default_fields |
2112 * into the function, while you may also choose to use the {@see 'comment_form_default_fields'} |
2143 * filter to modify the array of default fields if you'd just like to add a new |
2113 * filter to modify the array of default fields if you'd just like to add a new |
2144 * one or remove a single field. All fields are also individually passed through |
2114 * one or remove a single field. All fields are also individually passed through |
2145 * a filter of the form comment_form_field_$name where $name is the key used |
2115 * a filter of the {@see 'comment_form_field_$name'} where $name is the key used |
2146 * in the array of fields. |
2116 * in the array of fields. |
2147 * |
2117 * |
2148 * @since 3.0.0 |
2118 * @since 3.0.0 |
2149 * @since 4.1.0 Introduced the 'class_submit' argument. |
2119 * @since 4.1.0 Introduced the 'class_submit' argument. |
2150 * @since 4.2.0 Introduced 'submit_button' and 'submit_fields' arguments. |
2120 * @since 4.2.0 Introduced the 'submit_button' and 'submit_fields' arguments. |
|
2121 * @since 4.4.0 Introduced the 'class_form', 'title_reply_before', 'title_reply_after', |
|
2122 * 'cancel_reply_before', and 'cancel_reply_after' arguments. |
|
2123 * @since 4.5.0 The 'author', 'email', and 'url' form fields are limited to 245, 100, |
|
2124 * and 200 characters, respectively. |
|
2125 * @since 4.6.0 Introduced the 'action' argument. |
|
2126 * @since 4.9.6 Introduced the 'cookies' default comment field. |
2151 * |
2127 * |
2152 * @param array $args { |
2128 * @param array $args { |
2153 * Optional. Default arguments and form fields to override. |
2129 * Optional. Default arguments and form fields to override. |
2154 * |
2130 * |
2155 * @type array $fields { |
2131 * @type array $fields { |
2156 * Default comment fields, filterable by default via the 'comment_form_default_fields' hook. |
2132 * Default comment fields, filterable by default via the {@see 'comment_form_default_fields'} hook. |
2157 * |
2133 * |
2158 * @type string $author Comment author field HTML. |
2134 * @type string $author Comment author field HTML. |
2159 * @type string $email Comment author email field HTML. |
2135 * @type string $email Comment author email field HTML. |
2160 * @type string $url Comment author URL field HTML. |
2136 * @type string $url Comment author URL field HTML. |
|
2137 * @type string $cookies Comment cookie opt-in field HTML. |
2161 * } |
2138 * } |
2162 * @type string $comment_field The comment textarea field HTML. |
2139 * @type string $comment_field The comment textarea field HTML. |
2163 * @type string $must_log_in HTML element for a 'must be logged in to comment' message. |
2140 * @type string $must_log_in HTML element for a 'must be logged in to comment' message. |
2164 * @type string $logged_in_as HTML element for a 'logged in as [user]' message. |
2141 * @type string $logged_in_as HTML element for a 'logged in as [user]' message. |
2165 * @type string $comment_notes_before HTML element for a message displayed before the comment form. |
2142 * @type string $comment_notes_before HTML element for a message displayed before the comment fields |
|
2143 * if the user is not logged in. |
2166 * Default 'Your email address will not be published.'. |
2144 * Default 'Your email address will not be published.'. |
2167 * @type string $comment_notes_after HTML element for a message displayed after the comment form. |
2145 * @type string $comment_notes_after HTML element for a message displayed after the textarea field. |
2168 * Default 'You may use these HTML tags and attributes ...'. |
2146 * @type string $action The comment form element action attribute. Default '/wp-comments-post.php'. |
2169 * @type string $id_form The comment form element id attribute. Default 'commentform'. |
2147 * @type string $id_form The comment form element id attribute. Default 'commentform'. |
2170 * @type string $id_submit The comment submit element id attribute. Default 'submit'. |
2148 * @type string $id_submit The comment submit element id attribute. Default 'submit'. |
|
2149 * @type string $class_form The comment form element class attribute. Default 'comment-form'. |
2171 * @type string $class_submit The comment submit element class attribute. Default 'submit'. |
2150 * @type string $class_submit The comment submit element class attribute. Default 'submit'. |
2172 * @type string $name_submit The comment submit element name attribute. Default 'submit'. |
2151 * @type string $name_submit The comment submit element name attribute. Default 'submit'. |
2173 * @type string $title_reply The translatable 'reply' button label. Default 'Leave a Reply'. |
2152 * @type string $title_reply The translatable 'reply' button label. Default 'Leave a Reply'. |
2174 * @type string $title_reply_to The translatable 'reply-to' button label. Default 'Leave a Reply to %s', |
2153 * @type string $title_reply_to The translatable 'reply-to' button label. Default 'Leave a Reply to %s', |
2175 * where %s is the author of the comment being replied to. |
2154 * where %s is the author of the comment being replied to. |
|
2155 * @type string $title_reply_before HTML displayed before the comment form title. |
|
2156 * Default: '<h3 id="reply-title" class="comment-reply-title">'. |
|
2157 * @type string $title_reply_after HTML displayed after the comment form title. |
|
2158 * Default: '</h3>'. |
|
2159 * @type string $cancel_reply_before HTML displayed before the cancel reply link. |
|
2160 * @type string $cancel_reply_after HTML displayed after the cancel reply link. |
2176 * @type string $cancel_reply_link The translatable 'cancel reply' button label. Default 'Cancel reply'. |
2161 * @type string $cancel_reply_link The translatable 'cancel reply' button label. Default 'Cancel reply'. |
2177 * @type string $label_submit The translatable 'submit' button label. Default 'Post a comment'. |
2162 * @type string $label_submit The translatable 'submit' button label. Default 'Post a comment'. |
2178 * @type string $submit_button HTML format for the Submit button. |
2163 * @type string $submit_button HTML format for the Submit button. |
2179 * Default: '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'. |
2164 * Default: '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'. |
2180 * @type string $submit_field HTML format for the markup surrounding the Submit button and comment hidden |
2165 * @type string $submit_field HTML format for the markup surrounding the Submit button and comment hidden |
2181 * fields. Default: '<p class="form-submit">%1$s %2$s</a>', where %1$s is the |
2166 * fields. Default: '<p class="form-submit">%1$s %2$s</p>', where %1$s is the |
2182 * submit button markup and %2$s is the comment hidden fields. |
2167 * submit button markup and %2$s is the comment hidden fields. |
2183 * @type string $format The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'. |
2168 * @type string $format The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'. |
2184 * } |
2169 * } |
2185 * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post. |
2170 * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post. |
2186 */ |
2171 */ |
2187 function comment_form( $args = array(), $post_id = null ) { |
2172 function comment_form( $args = array(), $post_id = null ) { |
2188 if ( null === $post_id ) |
2173 if ( null === $post_id ) |
2189 $post_id = get_the_ID(); |
2174 $post_id = get_the_ID(); |
2190 |
2175 |
|
2176 // Exit the function when comments for the post are closed. |
|
2177 if ( ! comments_open( $post_id ) ) { |
|
2178 /** |
|
2179 * Fires after the comment form if comments are closed. |
|
2180 * |
|
2181 * @since 3.0.0 |
|
2182 */ |
|
2183 do_action( 'comment_form_comments_closed' ); |
|
2184 |
|
2185 return; |
|
2186 } |
|
2187 |
2191 $commenter = wp_get_current_commenter(); |
2188 $commenter = wp_get_current_commenter(); |
2192 $user = wp_get_current_user(); |
2189 $user = wp_get_current_user(); |
2193 $user_identity = $user->exists() ? $user->display_name : ''; |
2190 $user_identity = $user->exists() ? $user->display_name : ''; |
2194 |
2191 |
2195 $args = wp_parse_args( $args ); |
2192 $args = wp_parse_args( $args ); |
2196 if ( ! isset( $args['format'] ) ) |
2193 if ( ! isset( $args['format'] ) ) |
2197 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml'; |
2194 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml'; |
2198 |
2195 |
2199 $req = get_option( 'require_name_email' ); |
2196 $req = get_option( 'require_name_email' ); |
2200 $aria_req = ( $req ? " aria-required='true'" : '' ); |
|
2201 $html_req = ( $req ? " required='required'" : '' ); |
2197 $html_req = ( $req ? " required='required'" : '' ); |
2202 $html5 = 'html5' === $args['format']; |
2198 $html5 = 'html5' === $args['format']; |
2203 $fields = array( |
2199 $fields = array( |
2204 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2200 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2205 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req . ' /></p>', |
2201 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $html_req . ' /></p>', |
2206 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2202 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2207 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>', |
2203 '<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"' . $html_req . ' /></p>', |
2208 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . |
2204 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . |
2209 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>', |
2205 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', |
2210 ); |
2206 ); |
2211 |
2207 |
2212 $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' ); |
2208 if ( has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ) && get_option( 'show_comments_cookies_opt_in' ) ) { |
2213 |
2209 $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"'; |
2214 /** |
2210 $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . |
2215 * Filter the default comment form fields. |
2211 '<label for="wp-comment-cookies-consent">' . __( 'Save my name, email, and website in this browser for the next time I comment.' ) . '</label></p>'; |
|
2212 |
|
2213 // Ensure that the passed fields include cookies consent. |
|
2214 if ( isset( $args['fields'] ) && ! isset( $args['fields']['cookies'] ) ) { |
|
2215 $args['fields']['cookies'] = $fields['cookies']; |
|
2216 } |
|
2217 } |
|
2218 |
|
2219 $required_text = sprintf( ' ' . __( 'Required fields are marked %s' ), '<span class="required">*</span>' ); |
|
2220 |
|
2221 /** |
|
2222 * Filters the default comment form fields. |
2216 * |
2223 * |
2217 * @since 3.0.0 |
2224 * @since 3.0.0 |
2218 * |
2225 * |
2219 * @param array $fields The default comment fields. |
2226 * @param array $fields The default comment fields. |
2220 */ |
2227 */ |
2221 $fields = apply_filters( 'comment_form_default_fields', $fields ); |
2228 $fields = apply_filters( 'comment_form_default_fields', $fields ); |
2222 $defaults = array( |
2229 $defaults = array( |
2223 'fields' => $fields, |
2230 'fields' => $fields, |
2224 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-describedby="form-allowed-tags" aria-required="true" required="required"></textarea></p>', |
2231 '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" required="required"></textarea></p>', |
2225 /** This filter is documented in wp-includes/link-template.php */ |
2232 /** This filter is documented in wp-includes/link-template.php */ |
2226 '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>', |
2233 'must_log_in' => '<p class="must-log-in">' . sprintf( |
|
2234 /* translators: %s: login URL */ |
|
2235 __( 'You must be <a href="%s">logged in</a> to post a comment.' ), |
|
2236 wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) |
|
2237 ) . '</p>', |
2227 /** This filter is documented in wp-includes/link-template.php */ |
2238 /** This filter is documented in wp-includes/link-template.php */ |
2228 '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>', |
2239 'logged_in_as' => '<p class="logged-in-as">' . sprintf( |
|
2240 /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ |
|
2241 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), |
|
2242 get_edit_user_link(), |
|
2243 /* translators: %s: user name */ |
|
2244 esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), |
|
2245 $user_identity, |
|
2246 wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) |
|
2247 ) . '</p>', |
2229 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . '</p>', |
2248 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . '</p>', |
2230 'comment_notes_after' => '<p class="form-allowed-tags" id="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>', |
2249 'comment_notes_after' => '', |
|
2250 'action' => site_url( '/wp-comments-post.php' ), |
2231 'id_form' => 'commentform', |
2251 'id_form' => 'commentform', |
2232 'id_submit' => 'submit', |
2252 'id_submit' => 'submit', |
|
2253 'class_form' => 'comment-form', |
2233 'class_submit' => 'submit', |
2254 'class_submit' => 'submit', |
2234 'name_submit' => 'submit', |
2255 'name_submit' => 'submit', |
2235 'title_reply' => __( 'Leave a Reply' ), |
2256 'title_reply' => __( 'Leave a Reply' ), |
2236 'title_reply_to' => __( 'Leave a Reply to %s' ), |
2257 'title_reply_to' => __( 'Leave a Reply to %s' ), |
|
2258 'title_reply_before' => '<h3 id="reply-title" class="comment-reply-title">', |
|
2259 'title_reply_after' => '</h3>', |
|
2260 'cancel_reply_before' => ' <small>', |
|
2261 'cancel_reply_after' => '</small>', |
2237 'cancel_reply_link' => __( 'Cancel reply' ), |
2262 'cancel_reply_link' => __( 'Cancel reply' ), |
2238 'label_submit' => __( 'Post Comment' ), |
2263 'label_submit' => __( 'Post Comment' ), |
2239 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />', |
2264 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />', |
2240 'submit_field' => '<p class="form-submit">%1$s %2$s</p>', |
2265 'submit_field' => '<p class="form-submit">%1$s %2$s</p>', |
2241 'format' => 'xhtml', |
2266 'format' => 'xhtml', |
2242 ); |
2267 ); |
2243 |
2268 |
2244 /** |
2269 /** |
2245 * Filter the comment form default arguments. |
2270 * Filters the comment form default arguments. |
2246 * |
2271 * |
2247 * Use 'comment_form_default_fields' to filter the comment fields. |
2272 * Use {@see 'comment_form_default_fields'} to filter the comment fields. |
2248 * |
2273 * |
2249 * @since 3.0.0 |
2274 * @since 3.0.0 |
2250 * |
2275 * |
2251 * @param array $defaults The default comment form arguments. |
2276 * @param array $defaults The default comment form arguments. |
2252 */ |
2277 */ |
2253 $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) ); |
2278 $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) ); |
2254 |
2279 |
2255 if ( comments_open( $post_id ) ) : ?> |
2280 // Ensure that the filtered args contain all required default values. |
2256 <?php |
2281 $args = array_merge( $defaults, $args ); |
|
2282 |
|
2283 /** |
|
2284 * Fires before the comment form. |
|
2285 * |
|
2286 * @since 3.0.0 |
|
2287 */ |
|
2288 do_action( 'comment_form_before' ); |
|
2289 ?> |
|
2290 <div id="respond" class="comment-respond"> |
|
2291 <?php |
|
2292 echo $args['title_reply_before']; |
|
2293 |
|
2294 comment_form_title( $args['title_reply'], $args['title_reply_to'] ); |
|
2295 |
|
2296 echo $args['cancel_reply_before']; |
|
2297 |
|
2298 cancel_comment_reply_link( $args['cancel_reply_link'] ); |
|
2299 |
|
2300 echo $args['cancel_reply_after']; |
|
2301 |
|
2302 echo $args['title_reply_after']; |
|
2303 |
|
2304 if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : |
|
2305 echo $args['must_log_in']; |
2257 /** |
2306 /** |
2258 * Fires before the comment form. |
2307 * Fires after the HTML-formatted 'must log in after' message in the comment form. |
2259 * |
2308 * |
2260 * @since 3.0.0 |
2309 * @since 3.0.0 |
2261 */ |
2310 */ |
2262 do_action( 'comment_form_before' ); |
2311 do_action( 'comment_form_must_log_in_after' ); |
2263 ?> |
2312 else : ?> |
2264 <div id="respond" class="comment-respond"> |
2313 <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' : ''; ?>> |
2265 <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> |
2314 <?php |
2266 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?> |
2315 /** |
2267 <?php echo $args['must_log_in']; ?> |
2316 * Fires at the top of the comment form, inside the form tag. |
2268 <?php |
2317 * |
|
2318 * @since 3.0.0 |
|
2319 */ |
|
2320 do_action( 'comment_form_top' ); |
|
2321 |
|
2322 if ( is_user_logged_in() ) : |
2269 /** |
2323 /** |
2270 * Fires after the HTML-formatted 'must log in after' message in the comment form. |
2324 * Filters the 'logged in' message for the comment form for display. |
2271 * |
2325 * |
2272 * @since 3.0.0 |
2326 * @since 3.0.0 |
|
2327 * |
|
2328 * @param string $args_logged_in The logged-in-as HTML-formatted message. |
|
2329 * @param array $commenter An array containing the comment author's |
|
2330 * username, email, and URL. |
|
2331 * @param string $user_identity If the commenter is a registered user, |
|
2332 * the display name, blank otherwise. |
2273 */ |
2333 */ |
2274 do_action( 'comment_form_must_log_in_after' ); |
2334 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); |
2275 ?> |
2335 |
2276 <?php else : ?> |
2336 /** |
2277 <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' : ''; ?>> |
2337 * Fires after the is_user_logged_in() check in the comment form. |
2278 <?php |
2338 * |
|
2339 * @since 3.0.0 |
|
2340 * |
|
2341 * @param array $commenter An array containing the comment author's |
|
2342 * username, email, and URL. |
|
2343 * @param string $user_identity If the commenter is a registered user, |
|
2344 * the display name, blank otherwise. |
|
2345 */ |
|
2346 do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); |
|
2347 |
|
2348 else : |
|
2349 |
|
2350 echo $args['comment_notes_before']; |
|
2351 |
|
2352 endif; |
|
2353 |
|
2354 // Prepare an array of all fields, including the textarea |
|
2355 $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields']; |
|
2356 |
|
2357 /** |
|
2358 * Filters the comment form fields, including the textarea. |
|
2359 * |
|
2360 * @since 4.4.0 |
|
2361 * |
|
2362 * @param array $comment_fields The comment fields. |
|
2363 */ |
|
2364 $comment_fields = apply_filters( 'comment_form_fields', $comment_fields ); |
|
2365 |
|
2366 // Get an array of field names, excluding the textarea |
|
2367 $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) ); |
|
2368 |
|
2369 // Get the first and the last field name, excluding the textarea |
|
2370 $first_field = reset( $comment_field_keys ); |
|
2371 $last_field = end( $comment_field_keys ); |
|
2372 |
|
2373 foreach ( $comment_fields as $name => $field ) { |
|
2374 |
|
2375 if ( 'comment' === $name ) { |
|
2376 |
2279 /** |
2377 /** |
2280 * Fires at the top of the comment form, inside the form tag. |
2378 * Filters the content of the comment textarea field for display. |
2281 * |
|
2282 * @since 3.0.0 |
|
2283 */ |
|
2284 do_action( 'comment_form_top' ); |
|
2285 ?> |
|
2286 <?php if ( is_user_logged_in() ) : ?> |
|
2287 <?php |
|
2288 /** |
|
2289 * Filter the 'logged in' message for the comment form for display. |
|
2290 * |
|
2291 * @since 3.0.0 |
|
2292 * |
|
2293 * @param string $args_logged_in The logged-in-as HTML-formatted message. |
|
2294 * @param array $commenter An array containing the comment author's |
|
2295 * username, email, and URL. |
|
2296 * @param string $user_identity If the commenter is a registered user, |
|
2297 * the display name, blank otherwise. |
|
2298 */ |
|
2299 echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); |
|
2300 ?> |
|
2301 <?php |
|
2302 /** |
|
2303 * Fires after the is_user_logged_in() check in the comment form. |
|
2304 * |
|
2305 * @since 3.0.0 |
|
2306 * |
|
2307 * @param array $commenter An array containing the comment author's |
|
2308 * username, email, and URL. |
|
2309 * @param string $user_identity If the commenter is a registered user, |
|
2310 * the display name, blank otherwise. |
|
2311 */ |
|
2312 do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); |
|
2313 ?> |
|
2314 <?php else : ?> |
|
2315 <?php echo $args['comment_notes_before']; ?> |
|
2316 <?php |
|
2317 /** |
|
2318 * Fires before the comment fields in the comment form. |
|
2319 * |
|
2320 * @since 3.0.0 |
|
2321 */ |
|
2322 do_action( 'comment_form_before_fields' ); |
|
2323 foreach ( (array) $args['fields'] as $name => $field ) { |
|
2324 /** |
|
2325 * Filter a comment form field for display. |
|
2326 * |
|
2327 * The dynamic portion of the filter hook, `$name`, refers to the name |
|
2328 * of the comment form field. Such as 'author', 'email', or 'url'. |
|
2329 * |
|
2330 * @since 3.0.0 |
|
2331 * |
|
2332 * @param string $field The HTML-formatted output of the comment form field. |
|
2333 */ |
|
2334 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; |
|
2335 } |
|
2336 /** |
|
2337 * Fires after the comment fields in the comment form. |
|
2338 * |
|
2339 * @since 3.0.0 |
|
2340 */ |
|
2341 do_action( 'comment_form_after_fields' ); |
|
2342 ?> |
|
2343 <?php endif; ?> |
|
2344 <?php |
|
2345 /** |
|
2346 * Filter the content of the comment textarea field for display. |
|
2347 * |
2379 * |
2348 * @since 3.0.0 |
2380 * @since 3.0.0 |
2349 * |
2381 * |
2350 * @param string $args_comment_field The content of the comment textarea field. |
2382 * @param string $args_comment_field The content of the comment textarea field. |
2351 */ |
2383 */ |
2352 echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); |
2384 echo apply_filters( 'comment_form_field_comment', $field ); |
2353 ?> |
2385 |
2354 <?php echo $args['comment_notes_after']; ?> |
2386 echo $args['comment_notes_after']; |
2355 |
2387 |
2356 <?php |
2388 } elseif ( ! is_user_logged_in() ) { |
2357 $submit_button = sprintf( |
2389 |
2358 $args['submit_button'], |
2390 if ( $first_field === $name ) { |
2359 esc_attr( $args['name_submit'] ), |
2391 /** |
2360 esc_attr( $args['id_submit'] ), |
2392 * Fires before the comment fields in the comment form, excluding the textarea. |
2361 esc_attr( $args['class_submit'] ), |
2393 * |
2362 esc_attr( $args['label_submit'] ) |
2394 * @since 3.0.0 |
2363 ); |
2395 */ |
|
2396 do_action( 'comment_form_before_fields' ); |
|
2397 } |
2364 |
2398 |
2365 /** |
2399 /** |
2366 * Filter the submit button for the comment form to display. |
2400 * Filters a comment form field for display. |
2367 * |
2401 * |
2368 * @since 4.2.0 |
2402 * The dynamic portion of the filter hook, `$name`, refers to the name |
|
2403 * of the comment form field. Such as 'author', 'email', or 'url'. |
2369 * |
2404 * |
2370 * @param string $submit_button HTML markup for the submit button. |
2405 * @since 3.0.0 |
2371 * @param array $args Arguments passed to `comment_form()`. |
2406 * |
|
2407 * @param string $field The HTML-formatted output of the comment form field. |
2372 */ |
2408 */ |
2373 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args ); |
2409 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; |
2374 |
2410 |
2375 $submit_field = sprintf( |
2411 if ( $last_field === $name ) { |
2376 $args['submit_field'], |
2412 /** |
2377 $submit_button, |
2413 * Fires after the comment fields in the comment form, excluding the textarea. |
2378 get_comment_id_fields( $post_id ) |
2414 * |
2379 ); |
2415 * @since 3.0.0 |
2380 |
2416 */ |
2381 /** |
2417 do_action( 'comment_form_after_fields' ); |
2382 * Filter the submit field for the comment form to display. |
2418 } |
2383 * |
2419 } |
2384 * The submit field includes the submit button, hidden fields for the |
2420 } |
2385 * comment form, and any wrapper markup. |
2421 |
2386 * |
2422 $submit_button = sprintf( |
2387 * @since 4.2.0 |
2423 $args['submit_button'], |
2388 * |
2424 esc_attr( $args['name_submit'] ), |
2389 * @param string $submit_field HTML markup for the submit field. |
2425 esc_attr( $args['id_submit'] ), |
2390 * @param array $args Arguments passed to comment_form(). |
2426 esc_attr( $args['class_submit'] ), |
2391 */ |
2427 esc_attr( $args['label_submit'] ) |
2392 echo apply_filters( 'comment_form_submit_field', $submit_field, $args ); |
2428 ); |
2393 |
2429 |
2394 /** |
2430 /** |
2395 * Fires at the bottom of the comment form, inside the closing </form> tag. |
2431 * Filters the submit button for the comment form to display. |
2396 * |
2432 * |
2397 * @since 1.5.0 |
2433 * @since 4.2.0 |
2398 * |
2434 * |
2399 * @param int $post_id The post ID. |
2435 * @param string $submit_button HTML markup for the submit button. |
2400 */ |
2436 * @param array $args Arguments passed to `comment_form()`. |
2401 do_action( 'comment_form', $post_id ); |
2437 */ |
2402 ?> |
2438 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args ); |
2403 </form> |
2439 |
2404 <?php endif; ?> |
2440 $submit_field = sprintf( |
2405 </div><!-- #respond --> |
2441 $args['submit_field'], |
2406 <?php |
2442 $submit_button, |
2407 /** |
2443 get_comment_id_fields( $post_id ) |
2408 * Fires after the comment form. |
2444 ); |
2409 * |
2445 |
2410 * @since 3.0.0 |
2446 /** |
2411 */ |
2447 * Filters the submit field for the comment form to display. |
2412 do_action( 'comment_form_after' ); |
2448 * |
2413 else : |
2449 * The submit field includes the submit button, hidden fields for the |
2414 /** |
2450 * comment form, and any wrapper markup. |
2415 * Fires after the comment form if comments are closed. |
2451 * |
2416 * |
2452 * @since 4.2.0 |
2417 * @since 3.0.0 |
2453 * |
2418 */ |
2454 * @param string $submit_field HTML markup for the submit field. |
2419 do_action( 'comment_form_comments_closed' ); |
2455 * @param array $args Arguments passed to comment_form(). |
2420 endif; |
2456 */ |
2421 } |
2457 echo apply_filters( 'comment_form_submit_field', $submit_field, $args ); |
|
2458 |
|
2459 /** |
|
2460 * Fires at the bottom of the comment form, inside the closing </form> tag. |
|
2461 * |
|
2462 * @since 1.5.0 |
|
2463 * |
|
2464 * @param int $post_id The post ID. |
|
2465 */ |
|
2466 do_action( 'comment_form', $post_id ); |
|
2467 ?> |
|
2468 </form> |
|
2469 <?php endif; ?> |
|
2470 </div><!-- #respond --> |
|
2471 <?php |
|
2472 |
|
2473 /** |
|
2474 * Fires after the comment form. |
|
2475 * |
|
2476 * @since 3.0.0 |
|
2477 */ |
|
2478 do_action( 'comment_form_after' ); |
|
2479 } |