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