author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Core Comment API |
0 | 4 |
* |
5 |
* @package WordPress |
|
6 |
* @subpackage Comment |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
19 | 10 |
* Checks whether a comment passes internal checks to be allowed to add. |
0 | 11 |
* |
5 | 12 |
* If manual comment moderation is set in the administration, then all checks, |
16 | 13 |
* regardless of their type and substance, will fail and the function will |
5 | 14 |
* return false. |
0 | 15 |
* |
16 |
* If the number of links exceeds the amount in the administration, then the |
|
16 | 17 |
* check fails. If any of the parameter contents contain any disallowed words, |
0 | 18 |
* then the check fails. |
19 |
* |
|
5 | 20 |
* If the comment author was approved before, then the comment is automatically |
16 | 21 |
* approved. |
0 | 22 |
* |
5 | 23 |
* If all checks pass, the function will return true. |
0 | 24 |
* |
25 |
* @since 1.2.0 |
|
5 | 26 |
* |
27 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 28 |
* |
5 | 29 |
* @param string $author Comment author name. |
30 |
* @param string $email Comment author email. |
|
31 |
* @param string $url Comment author URL. |
|
32 |
* @param string $comment Content of the comment. |
|
33 |
* @param string $user_ip Comment author IP address. |
|
34 |
* @param string $user_agent Comment author User-Agent. |
|
35 |
* @param string $comment_type Comment type, either user-submitted comment, |
|
9 | 36 |
* trackback, or pingback. |
5 | 37 |
* @return bool If all checks pass, true, otherwise false. |
0 | 38 |
*/ |
9 | 39 |
function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type ) { |
0 | 40 |
global $wpdb; |
41 |
||
5 | 42 |
// If manual moderation is enabled, skip all checks and return false. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
43 |
if ( '1' === get_option( 'comment_moderation' ) ) { |
5 | 44 |
return false; |
9 | 45 |
} |
5 | 46 |
|
47 |
/** This filter is documented in wp-includes/comment-template.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
$comment = apply_filters( 'comment_text', $comment, null, array() ); |
0 | 49 |
|
5 | 50 |
// Check for the number of external links if a max allowed number is set. |
16 | 51 |
$max_links = get_option( 'comment_max_links' ); |
52 |
if ( $max_links ) { |
|
0 | 53 |
$num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out ); |
5 | 54 |
|
55 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* Filters the number of links found in a comment. |
5 | 57 |
* |
58 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
* @since 4.7.0 Added the `$comment` parameter. |
5 | 60 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
* @param int $num_links The number of links found. |
5 | 62 |
* @param string $url Comment author's URL. Included in allowed links total. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
* @param string $comment Content of the comment. |
5 | 64 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
$num_links = apply_filters( 'comment_max_links_url', $num_links, $url, $comment ); |
5 | 66 |
|
67 |
/* |
|
68 |
* If the number of links in the comment exceeds the allowed amount, |
|
69 |
* fail the check by returning false. |
|
70 |
*/ |
|
9 | 71 |
if ( $num_links >= $max_links ) { |
0 | 72 |
return false; |
9 | 73 |
} |
0 | 74 |
} |
75 |
||
9 | 76 |
$mod_keys = trim( get_option( 'moderation_keys' ) ); |
5 | 77 |
|
78 |
// If moderation 'keys' (keywords) are set, process them. |
|
9 | 79 |
if ( ! empty( $mod_keys ) ) { |
80 |
$words = explode( "\n", $mod_keys ); |
|
81 |
||
82 |
foreach ( (array) $words as $word ) { |
|
83 |
$word = trim( $word ); |
|
0 | 84 |
|
5 | 85 |
// Skip empty lines. |
9 | 86 |
if ( empty( $word ) ) { |
0 | 87 |
continue; |
9 | 88 |
} |
0 | 89 |
|
5 | 90 |
/* |
91 |
* Do some escaping magic so that '#' (number of) characters in the spam |
|
92 |
* words don't break things: |
|
93 |
*/ |
|
9 | 94 |
$word = preg_quote( $word, '#' ); |
0 | 95 |
|
5 | 96 |
/* |
97 |
* Check the comment fields for moderation keywords. If any are found, |
|
98 |
* fail the check for the given field by returning false. |
|
99 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
100 |
$pattern = "#$word#iu"; |
9 | 101 |
if ( preg_match( $pattern, $author ) ) { |
102 |
return false; |
|
103 |
} |
|
104 |
if ( preg_match( $pattern, $email ) ) { |
|
105 |
return false; |
|
106 |
} |
|
107 |
if ( preg_match( $pattern, $url ) ) { |
|
108 |
return false; |
|
109 |
} |
|
110 |
if ( preg_match( $pattern, $comment ) ) { |
|
111 |
return false; |
|
112 |
} |
|
113 |
if ( preg_match( $pattern, $user_ip ) ) { |
|
114 |
return false; |
|
115 |
} |
|
116 |
if ( preg_match( $pattern, $user_agent ) ) { |
|
117 |
return false; |
|
118 |
} |
|
0 | 119 |
} |
120 |
} |
|
121 |
||
5 | 122 |
/* |
123 |
* Check if the option to approve comments by previously-approved authors is enabled. |
|
124 |
* |
|
125 |
* If it is enabled, check whether the comment author has a previously-approved comment, |
|
126 |
* as well as whether there are any moderation keywords (if set) present in the author |
|
127 |
* email address. If both checks pass, return true. Otherwise, return false. |
|
128 |
*/ |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
129 |
if ( '1' === get_option( 'comment_previously_approved' ) ) { |
16 | 130 |
if ( 'trackback' !== $comment_type && 'pingback' !== $comment_type && '' !== $author && '' !== $email ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
$comment_user = get_user_by( 'email', wp_unslash( $email ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
if ( ! empty( $comment_user->ID ) ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
133 |
$ok_to_comment = $wpdb->get_var( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
134 |
$wpdb->prepare( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
135 |
"SELECT comment_approved |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
136 |
FROM $wpdb->comments |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
137 |
WHERE user_id = %d |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
138 |
AND comment_approved = '1' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
139 |
LIMIT 1", |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
140 |
$comment_user->ID |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
141 |
) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
142 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
// expected_slashed ($author, $email) |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
145 |
$ok_to_comment = $wpdb->get_var( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
146 |
$wpdb->prepare( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
147 |
"SELECT comment_approved |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
148 |
FROM $wpdb->comments |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
149 |
WHERE comment_author = %s |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
150 |
AND comment_author_email = %s |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
151 |
AND comment_approved = '1' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
152 |
LIMIT 1", |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
153 |
$author, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
154 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
155 |
) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
156 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
158 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
159 |
if ( '1' === $ok_to_comment && ( empty( $mod_keys ) || ! str_contains( $email, $mod_keys ) ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
160 |
return true; |
9 | 161 |
} else { |
0 | 162 |
return false; |
9 | 163 |
} |
0 | 164 |
} else { |
165 |
return false; |
|
166 |
} |
|
167 |
} |
|
168 |
return true; |
|
169 |
} |
|
170 |
||
171 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
172 |
* Retrieves the approved comments for a post. |
0 | 173 |
* |
174 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
* @since 4.1.0 Refactored to leverage WP_Comment_Query over a direct query. |
0 | 176 |
* |
16 | 177 |
* @param int $post_id The ID of the post. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
178 |
* @param array $args { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
* Optional. See WP_Comment_Query::__construct() for information on accepted arguments. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
180 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
181 |
* @type int $status Comment status to limit results by. Defaults to approved comments. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
182 |
* @type int $post_id Limit results to those affiliated with a given post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
183 |
* @type string $order How to order retrieved comments. Default 'ASC'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
184 |
* } |
19 | 185 |
* @return WP_Comment[]|int[]|int The approved comments, or number of comments if `$count` |
186 |
* argument is true. |
|
0 | 187 |
*/ |
5 | 188 |
function get_approved_comments( $post_id, $args = array() ) { |
189 |
if ( ! $post_id ) { |
|
190 |
return array(); |
|
191 |
} |
|
192 |
||
16 | 193 |
$defaults = array( |
5 | 194 |
'status' => 1, |
195 |
'post_id' => $post_id, |
|
196 |
'order' => 'ASC', |
|
197 |
); |
|
16 | 198 |
$parsed_args = wp_parse_args( $args, $defaults ); |
5 | 199 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
200 |
$query = new WP_Comment_Query(); |
16 | 201 |
return $query->query( $parsed_args ); |
0 | 202 |
} |
203 |
||
204 |
/** |
|
205 |
* Retrieves comment data given a comment ID or comment object. |
|
206 |
* |
|
207 |
* If an object is passed then the comment data will be cached and then returned |
|
208 |
* after being passed through a filter. If the comment is empty, then the global |
|
209 |
* comment variable will be used, if it is set. |
|
210 |
* |
|
211 |
* @since 2.0.0 |
|
5 | 212 |
* |
16 | 213 |
* @global WP_Comment $comment Global comment object. |
0 | 214 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
* @param WP_Comment|string|int $comment Comment to retrieve. |
16 | 216 |
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
217 |
* correspond to a WP_Comment object, an associative array, or a numeric array, |
|
218 |
* respectively. Default OBJECT. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
* @return WP_Comment|array|null Depends on $output value. |
0 | 220 |
*/ |
18 | 221 |
function get_comment( $comment = null, $output = OBJECT ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
$comment = $GLOBALS['comment']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
if ( $comment instanceof WP_Comment ) { |
0 | 227 |
$_comment = $comment; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
} elseif ( is_object( $comment ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
$_comment = new WP_Comment( $comment ); |
0 | 230 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
$_comment = WP_Comment::get_instance( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
if ( ! $_comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
return null; |
0 | 236 |
} |
237 |
||
5 | 238 |
/** |
239 |
* Fires after a comment is retrieved. |
|
240 |
* |
|
241 |
* @since 2.3.0 |
|
242 |
* |
|
16 | 243 |
* @param WP_Comment $_comment Comment data. |
5 | 244 |
*/ |
245 |
$_comment = apply_filters( 'get_comment', $_comment ); |
|
0 | 246 |
|
18 | 247 |
if ( OBJECT === $output ) { |
0 | 248 |
return $_comment; |
18 | 249 |
} elseif ( ARRAY_A === $output ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
return $_comment->to_array(); |
18 | 251 |
} elseif ( ARRAY_N === $output ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
return array_values( $_comment->to_array() ); |
0 | 253 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
return $_comment; |
0 | 255 |
} |
256 |
||
257 |
/** |
|
19 | 258 |
* Retrieves a list of comments. |
0 | 259 |
* |
260 |
* The comment list can be for the blog as a whole or for an individual post. |
|
261 |
* |
|
5 | 262 |
* @since 2.7.0 |
0 | 263 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
* @param string|array $args Optional. Array or string of arguments. See WP_Comment_Query::__construct() |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
* for information on accepted arguments. Default empty string. |
19 | 266 |
* @return WP_Comment[]|int[]|int List of comments or number of found comments if `$count` argument is true. |
0 | 267 |
*/ |
268 |
function get_comments( $args = '' ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
269 |
$query = new WP_Comment_Query(); |
0 | 270 |
return $query->query( $args ); |
271 |
} |
|
272 |
||
273 |
/** |
|
19 | 274 |
* Retrieves all of the WordPress supported comment statuses. |
0 | 275 |
* |
276 |
* Comments have a limited set of valid status values, this provides the comment |
|
277 |
* status values and descriptions. |
|
278 |
* |
|
279 |
* @since 2.7.0 |
|
280 |
* |
|
16 | 281 |
* @return string[] List of comment status labels keyed by status. |
0 | 282 |
*/ |
283 |
function get_comment_statuses() { |
|
284 |
$status = array( |
|
9 | 285 |
'hold' => __( 'Unapproved' ), |
286 |
'approve' => _x( 'Approved', 'comment status' ), |
|
287 |
'spam' => _x( 'Spam', 'comment status' ), |
|
288 |
'trash' => _x( 'Trash', 'comment status' ), |
|
0 | 289 |
); |
290 |
||
291 |
return $status; |
|
292 |
} |
|
293 |
||
294 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
* Gets the default comment status for a post type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
* @param string $post_type Optional. Post type. Default 'post'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
* @param string $comment_type Optional. Comment type. Default 'comment'. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
301 |
* @return string Either 'open' or 'closed'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
switch ( $comment_type ) { |
9 | 305 |
case 'pingback': |
306 |
case 'trackback': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
$supports = 'trackbacks'; |
9 | 308 |
$option = 'ping'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
break; |
9 | 310 |
default: |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
$supports = 'comments'; |
9 | 312 |
$option = 'comment'; |
16 | 313 |
break; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
// Set the status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
if ( 'page' === $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
$status = 'closed'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
} elseif ( post_type_supports( $post_type, $supports ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
$status = get_option( "default_{$option}_status" ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
$status = 'closed'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
* Filters the default comment status for the given post type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
* @param string $status Default status for the given post type, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
* either 'open' or 'closed'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
* @param string $post_type Post type. Default is `post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
* @param string $comment_type Type of comment. Default is `comment`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
*/ |
9 | 335 |
return apply_filters( 'get_default_comment_status', $status, $post_type, $comment_type ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
/** |
19 | 339 |
* Retrieves the date the last comment was modified. |
0 | 340 |
* |
341 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
* @since 4.7.0 Replaced caching the modified date in a local static variable |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
* with the Object Cache API. |
5 | 344 |
* |
345 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 346 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
* @param string $timezone Which timezone to use in reference to 'gmt', 'blog', or 'server' locations. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
* @return string|false Last comment modified date on success, false on failure. |
0 | 349 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
function get_lastcommentmodified( $timezone = 'server' ) { |
0 | 351 |
global $wpdb; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
$timezone = strtolower( $timezone ); |
9 | 354 |
$key = "lastcommentmodified:$timezone"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
$comment_modified_date = wp_cache_get( $key, 'timeinfo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
if ( false !== $comment_modified_date ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
return $comment_modified_date; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
switch ( $timezone ) { |
0 | 362 |
case 'gmt': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
$comment_modified_date = $wpdb->get_var( "SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" ); |
0 | 364 |
break; |
365 |
case 'blog': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
$comment_modified_date = $wpdb->get_var( "SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" ); |
0 | 367 |
break; |
368 |
case 'server': |
|
16 | 369 |
$add_seconds_server = gmdate( 'Z' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
$comment_modified_date = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server ) ); |
0 | 372 |
break; |
373 |
} |
|
374 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
if ( $comment_modified_date ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
wp_cache_set( $key, $comment_modified_date, 'timeinfo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
return $comment_modified_date; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
return false; |
0 | 382 |
} |
383 |
||
384 |
/** |
|
16 | 385 |
* Retrieves the total comment counts for the whole site or a single post. |
0 | 386 |
* |
387 |
* @since 2.0.0 |
|
5 | 388 |
* |
16 | 389 |
* @param int $post_id Optional. Restrict the comment counts to the given post. Default 0, which indicates that |
390 |
* comment counts for the whole site will be retrieved. |
|
19 | 391 |
* @return int[] { |
16 | 392 |
* The number of comments keyed by their status. |
393 |
* |
|
394 |
* @type int $approved The number of approved comments. |
|
395 |
* @type int $awaiting_moderation The number of comments awaiting moderation (a.k.a. pending). |
|
396 |
* @type int $spam The number of spam comments. |
|
397 |
* @type int $trash The number of trashed comments. |
|
398 |
* @type int $post-trashed The number of comments for posts that are in the trash. |
|
399 |
* @type int $total_comments The total number of non-trashed comments, including spam. |
|
400 |
* @type int $all The total number of pending or approved comments. |
|
401 |
* } |
|
0 | 402 |
*/ |
403 |
function get_comment_count( $post_id = 0 ) { |
|
404 |
$post_id = (int) $post_id; |
|
405 |
||
406 |
$comment_count = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
'approved' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
'awaiting_moderation' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
'spam' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
'trash' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
'post-trashed' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
'total_comments' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
'all' => 0, |
0 | 414 |
); |
415 |
||
19 | 416 |
$args = array( |
417 |
'count' => true, |
|
418 |
'update_comment_meta_cache' => false, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
'orderby' => 'none', |
19 | 420 |
); |
421 |
if ( $post_id > 0 ) { |
|
422 |
$args['post_id'] = $post_id; |
|
0 | 423 |
} |
19 | 424 |
$mapping = array( |
425 |
'approved' => 'approve', |
|
426 |
'awaiting_moderation' => 'hold', |
|
427 |
'spam' => 'spam', |
|
428 |
'trash' => 'trash', |
|
429 |
'post-trashed' => 'post-trashed', |
|
430 |
); |
|
431 |
$comment_count = array(); |
|
432 |
foreach ( $mapping as $key => $value ) { |
|
433 |
$comment_count[ $key ] = get_comments( array_merge( $args, array( 'status' => $value ) ) ); |
|
434 |
} |
|
435 |
||
436 |
$comment_count['all'] = $comment_count['approved'] + $comment_count['awaiting_moderation']; |
|
437 |
$comment_count['total_comments'] = $comment_count['all'] + $comment_count['spam']; |
|
0 | 438 |
|
16 | 439 |
return array_map( 'intval', $comment_count ); |
0 | 440 |
} |
441 |
||
442 |
// |
|
16 | 443 |
// Comment meta functions. |
0 | 444 |
// |
445 |
||
446 |
/** |
|
19 | 447 |
* Adds meta data field to a comment. |
0 | 448 |
* |
449 |
* @since 2.9.0 |
|
16 | 450 |
* |
451 |
* @link https://developer.wordpress.org/reference/functions/add_comment_meta/ |
|
0 | 452 |
* |
16 | 453 |
* @param int $comment_id Comment ID. |
454 |
* @param string $meta_key Metadata name. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
455 |
* @param mixed $meta_value Metadata value. Arrays and objects are stored as serialized data and |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
456 |
* will be returned as the same type when retrieved. Other data types will |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
457 |
* be stored as strings in the database: |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
458 |
* - false is stored and retrieved as an empty string ('') |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
459 |
* - true is stored and retrieved as '1' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
460 |
* - numbers (both integer and float) are stored and retrieved as strings |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
461 |
* Must be serializable if non-scalar. |
16 | 462 |
* @param bool $unique Optional. Whether the same key should not be added. |
463 |
* Default false. |
|
18 | 464 |
* @return int|false Meta ID on success, false on failure. |
0 | 465 |
*/ |
9 | 466 |
function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) { |
467 |
return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); |
|
0 | 468 |
} |
469 |
||
470 |
/** |
|
19 | 471 |
* Removes metadata matching criteria from a comment. |
0 | 472 |
* |
473 |
* You can match based on the key, or key and value. Removing based on key and |
|
474 |
* value, will keep from removing duplicate metadata with the same key. It also |
|
475 |
* allows removing all metadata matching key, if needed. |
|
476 |
* |
|
477 |
* @since 2.9.0 |
|
16 | 478 |
* |
479 |
* @link https://developer.wordpress.org/reference/functions/delete_comment_meta/ |
|
0 | 480 |
* |
16 | 481 |
* @param int $comment_id Comment ID. |
482 |
* @param string $meta_key Metadata name. |
|
483 |
* @param mixed $meta_value Optional. Metadata value. If provided, |
|
484 |
* rows will only be removed that match the value. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
485 |
* Must be serializable if non-scalar. Default empty string. |
0 | 486 |
* @return bool True on success, false on failure. |
487 |
*/ |
|
9 | 488 |
function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) { |
489 |
return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); |
|
0 | 490 |
} |
491 |
||
492 |
/** |
|
19 | 493 |
* Retrieves comment meta field for a comment. |
0 | 494 |
* |
495 |
* @since 2.9.0 |
|
16 | 496 |
* |
497 |
* @link https://developer.wordpress.org/reference/functions/get_comment_meta/ |
|
0 | 498 |
* |
16 | 499 |
* @param int $comment_id Comment ID. |
500 |
* @param string $key Optional. The meta key to retrieve. By default, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
501 |
* returns data for all keys. Default empty string. |
16 | 502 |
* @param bool $single Optional. Whether to return a single value. |
18 | 503 |
* This parameter has no effect if `$key` is not specified. |
16 | 504 |
* Default false. |
18 | 505 |
* @return mixed An array of values if `$single` is false. |
506 |
* The value of meta data field if `$single` is true. |
|
507 |
* False for an invalid `$comment_id` (non-numeric, zero, or negative value). |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
508 |
* An empty array if a valid but non-existing comment ID is passed and `$single` is false. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
509 |
* An empty string if a valid but non-existing comment ID is passed and `$single` is true. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
510 |
* Note: Non-serialized values are returned as strings: |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
511 |
* - false values are returned as empty strings ('') |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
512 |
* - true values are returned as '1' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
513 |
* - numbers are returned as strings |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
514 |
* Arrays and objects retain their original type. |
0 | 515 |
*/ |
9 | 516 |
function get_comment_meta( $comment_id, $key = '', $single = false ) { |
517 |
return get_metadata( 'comment', $comment_id, $key, $single ); |
|
0 | 518 |
} |
519 |
||
520 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
521 |
* Queue comment meta for lazy-loading. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
522 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
523 |
* @since 6.3.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
524 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
525 |
* @param array $comment_ids List of comment IDs. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
526 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
527 |
function wp_lazyload_comment_meta( array $comment_ids ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
528 |
if ( empty( $comment_ids ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
529 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
530 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
531 |
$lazyloader = wp_metadata_lazyloader(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
532 |
$lazyloader->queue_objects( 'comment', $comment_ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
533 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
534 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
535 |
/** |
19 | 536 |
* Updates comment meta field based on comment ID. |
0 | 537 |
* |
538 |
* Use the $prev_value parameter to differentiate between meta fields with the |
|
539 |
* same key and comment ID. |
|
540 |
* |
|
541 |
* If the meta field for the comment does not exist, it will be added. |
|
542 |
* |
|
543 |
* @since 2.9.0 |
|
16 | 544 |
* |
545 |
* @link https://developer.wordpress.org/reference/functions/update_comment_meta/ |
|
0 | 546 |
* |
16 | 547 |
* @param int $comment_id Comment ID. |
548 |
* @param string $meta_key Metadata key. |
|
549 |
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
|
550 |
* @param mixed $prev_value Optional. Previous value to check before updating. |
|
551 |
* If specified, only update existing metadata entries with |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
552 |
* this value. Otherwise, update all entries. Default empty string. |
16 | 553 |
* @return int|bool Meta ID if the key didn't exist, true on successful update, |
554 |
* false on failure or if the value passed to the function |
|
555 |
* is the same as the one that is already in the database. |
|
0 | 556 |
*/ |
9 | 557 |
function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) { |
558 |
return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
/** |
0 | 562 |
* Sets the cookies used to store an unauthenticated commentator's identity. Typically used |
563 |
* to recall previous comments by this commentator that are still held in moderation. |
|
564 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
* @since 4.9.6 The `$cookies_consent` parameter was added. |
0 | 567 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
* @param WP_Comment $comment Comment object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
* @param WP_User $user Comment author's user object. The user may not exist. |
16 | 570 |
* @param bool $cookies_consent Optional. Comment author's consent to store cookies. Default true. |
0 | 571 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
function wp_set_comment_cookies( $comment, $user, $cookies_consent = true ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
// If the user already exists, or the user opted out of cookies, don't set cookies. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
if ( $user->exists() ) { |
0 | 575 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
if ( false === $cookies_consent ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
// Remove any existing cookies. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
$past = time() - YEAR_IN_SECONDS; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
setcookie( 'comment_author_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
setcookie( 'comment_author_email_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
setcookie( 'comment_author_url_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
} |
0 | 587 |
|
5 | 588 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
* Filters the lifetime of the comment cookie in seconds. |
5 | 590 |
* |
591 |
* @since 2.8.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
592 |
* @since 6.6.0 The default $seconds value changed from 30000000 to YEAR_IN_SECONDS. |
5 | 593 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
594 |
* @param int $seconds Comment cookie lifetime. Default YEAR_IN_SECONDS. |
5 | 595 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
596 |
$comment_cookie_lifetime = time() + apply_filters( 'comment_cookie_lifetime', YEAR_IN_SECONDS ); |
16 | 597 |
|
598 |
$secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) ); |
|
599 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
setcookie( 'comment_author_url_' . COOKIEHASH, esc_url( $comment->comment_author_url ), $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
0 | 603 |
} |
604 |
||
605 |
/** |
|
606 |
* Sanitizes the cookies sent to the user already. |
|
607 |
* |
|
608 |
* Will only do anything if the cookies have already been created for the user. |
|
609 |
* Mostly used after cookies had been sent to use elsewhere. |
|
610 |
* |
|
611 |
* @since 2.0.4 |
|
612 |
*/ |
|
613 |
function sanitize_comment_cookies() { |
|
9 | 614 |
if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ) { |
5 | 615 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* Filters the comment author's name cookie before it is set. |
5 | 617 |
* |
618 |
* When this filter hook is evaluated in wp_filter_comment(), |
|
619 |
* the comment author's name string is passed. |
|
620 |
* |
|
621 |
* @since 1.5.0 |
|
622 |
* |
|
623 |
* @param string $author_cookie The comment author name cookie. |
|
624 |
*/ |
|
18 | 625 |
$comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE[ 'comment_author_' . COOKIEHASH ] ); |
626 |
$comment_author = wp_unslash( $comment_author ); |
|
627 |
$comment_author = esc_attr( $comment_author ); |
|
628 |
||
9 | 629 |
$_COOKIE[ 'comment_author_' . COOKIEHASH ] = $comment_author; |
0 | 630 |
} |
631 |
||
9 | 632 |
if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) { |
5 | 633 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
* Filters the comment author's email cookie before it is set. |
5 | 635 |
* |
636 |
* When this filter hook is evaluated in wp_filter_comment(), |
|
637 |
* the comment author's email string is passed. |
|
638 |
* |
|
639 |
* @since 1.5.0 |
|
640 |
* |
|
641 |
* @param string $author_email_cookie The comment author email cookie. |
|
642 |
*/ |
|
18 | 643 |
$comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ); |
644 |
$comment_author_email = wp_unslash( $comment_author_email ); |
|
645 |
$comment_author_email = esc_attr( $comment_author_email ); |
|
646 |
||
9 | 647 |
$_COOKIE[ 'comment_author_email_' . COOKIEHASH ] = $comment_author_email; |
0 | 648 |
} |
649 |
||
9 | 650 |
if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) { |
5 | 651 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
* Filters the comment author's URL cookie before it is set. |
5 | 653 |
* |
654 |
* When this filter hook is evaluated in wp_filter_comment(), |
|
655 |
* the comment author's URL string is passed. |
|
656 |
* |
|
657 |
* @since 1.5.0 |
|
658 |
* |
|
659 |
* @param string $author_url_cookie The comment author URL cookie. |
|
660 |
*/ |
|
18 | 661 |
$comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ); |
662 |
$comment_author_url = wp_unslash( $comment_author_url ); |
|
663 |
||
9 | 664 |
$_COOKIE[ 'comment_author_url_' . COOKIEHASH ] = $comment_author_url; |
0 | 665 |
} |
666 |
} |
|
667 |
||
668 |
/** |
|
669 |
* Validates whether this comment is allowed to be made. |
|
670 |
* |
|
671 |
* @since 2.0.0 |
|
16 | 672 |
* @since 4.7.0 The `$avoid_die` parameter was added, allowing the function |
673 |
* to return a WP_Error object instead of dying. |
|
674 |
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`. |
|
5 | 675 |
* |
676 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 677 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
* @param array $commentdata Contains information on the comment. |
16 | 679 |
* @param bool $wp_error When true, a disallowed comment will result in the function |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
680 |
* returning a WP_Error object, rather than executing wp_die(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
681 |
* Default false. |
16 | 682 |
* @return int|string|WP_Error Allowed comments return the approval status (0|1|'spam'|'trash'). |
683 |
* If `$wp_error` is true, disallowed comments return a WP_Error. |
|
0 | 684 |
*/ |
16 | 685 |
function wp_allow_comment( $commentdata, $wp_error = false ) { |
0 | 686 |
global $wpdb; |
687 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
688 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
689 |
* Simple duplicate check. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
690 |
* expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
691 |
*/ |
5 | 692 |
$dupe = $wpdb->prepare( |
693 |
"SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ", |
|
694 |
wp_unslash( $commentdata['comment_post_ID'] ), |
|
695 |
wp_unslash( $commentdata['comment_parent'] ), |
|
696 |
wp_unslash( $commentdata['comment_author'] ) |
|
697 |
); |
|
698 |
if ( $commentdata['comment_author_email'] ) { |
|
699 |
$dupe .= $wpdb->prepare( |
|
9 | 700 |
'AND comment_author_email = %s ', |
5 | 701 |
wp_unslash( $commentdata['comment_author_email'] ) |
702 |
); |
|
703 |
} |
|
704 |
$dupe .= $wpdb->prepare( |
|
9 | 705 |
') AND comment_content = %s LIMIT 1', |
5 | 706 |
wp_unslash( $commentdata['comment_content'] ) |
707 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
709 |
$dupe_id = $wpdb->get_var( $dupe ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
* Filters the ID, if any, of the duplicate comment found when creating a new comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
* Return an empty value from this filter to allow what WP considers a duplicate comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
* @param int $dupe_id ID of the comment identified as a duplicate. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
* @param array $commentdata Data for the comment being created. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
720 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
721 |
$dupe_id = apply_filters( 'duplicate_comment_id', $dupe_id, $commentdata ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
722 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
if ( $dupe_id ) { |
5 | 724 |
/** |
725 |
* Fires immediately after a duplicate comment is detected. |
|
726 |
* |
|
727 |
* @since 3.0.0 |
|
728 |
* |
|
729 |
* @param array $commentdata Comment data. |
|
730 |
*/ |
|
0 | 731 |
do_action( 'comment_duplicate_trigger', $commentdata ); |
9 | 732 |
|
733 |
/** |
|
734 |
* Filters duplicate comment error message. |
|
735 |
* |
|
736 |
* @since 5.2.0 |
|
737 |
* |
|
738 |
* @param string $comment_duplicate_message Duplicate comment error message. |
|
739 |
*/ |
|
740 |
$comment_duplicate_message = apply_filters( 'comment_duplicate_message', __( 'Duplicate comment detected; it looks as though you’ve already said that!' ) ); |
|
741 |
||
16 | 742 |
if ( $wp_error ) { |
9 | 743 |
return new WP_Error( 'comment_duplicate', $comment_duplicate_message, 409 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
if ( wp_doing_ajax() ) { |
9 | 746 |
die( $comment_duplicate_message ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
|
9 | 749 |
wp_die( $comment_duplicate_message, 409 ); |
5 | 750 |
} |
0 | 751 |
} |
752 |
||
5 | 753 |
/** |
754 |
* Fires immediately before a comment is marked approved. |
|
755 |
* |
|
756 |
* Allows checking for comment flooding. |
|
757 |
* |
|
758 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
* @since 4.7.0 The `$avoid_die` parameter was added. |
16 | 760 |
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`. |
5 | 761 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
762 |
* @param string $comment_author_ip Comment author's IP address. |
5 | 763 |
* @param string $comment_author_email Comment author's email. |
764 |
* @param string $comment_date_gmt GMT date the comment was posted. |
|
16 | 765 |
* @param bool $wp_error Whether to return a WP_Error object instead of executing |
766 |
* wp_die() or die() if a comment flood is occurring. |
|
5 | 767 |
*/ |
768 |
do_action( |
|
769 |
'check_comment_flood', |
|
770 |
$commentdata['comment_author_IP'], |
|
771 |
$commentdata['comment_author_email'], |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
$commentdata['comment_date_gmt'], |
16 | 773 |
$wp_error |
5 | 774 |
); |
775 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
777 |
* Filters whether a comment is part of a comment flood. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
* The default check is wp_check_comment_flood(). See check_comment_flood_db(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
* @since 4.7.0 |
16 | 782 |
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`. |
7
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 |
* @param bool $is_flood Is a comment flooding occurring? Default false. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
785 |
* @param string $comment_author_ip Comment author's IP address. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
* @param string $comment_author_email Comment author's email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
* @param string $comment_date_gmt GMT date the comment was posted. |
16 | 788 |
* @param bool $wp_error Whether to return a WP_Error object instead of executing |
789 |
* wp_die() or die() if a comment flood is occurring. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
$is_flood = apply_filters( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
'wp_is_comment_flood', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
$commentdata['comment_author_IP'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
$commentdata['comment_author_email'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
$commentdata['comment_date_gmt'], |
16 | 797 |
$wp_error |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
if ( $is_flood ) { |
9 | 801 |
/** This filter is documented in wp-includes/comment-template.php */ |
802 |
$comment_flood_message = apply_filters( 'comment_flood_message', __( 'You are posting comments too quickly. Slow down.' ) ); |
|
803 |
||
804 |
return new WP_Error( 'comment_flood', $comment_flood_message, 429 ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
807 |
return wp_check_comment_data( $commentdata ); |
0 | 808 |
} |
809 |
||
810 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
* Hooks WP's native database-based comment-flood check. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
812 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
813 |
* This wrapper maintains backward compatibility with plugins that expect to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
814 |
* be able to unhook the legacy check_comment_flood_db() function from |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
* 'check_comment_flood' using remove_action(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
817 |
* @since 2.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
818 |
* @since 4.7.0 Converted to be an add_filter() wrapper. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
function check_comment_flood_db() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
821 |
add_filter( 'wp_is_comment_flood', 'wp_check_comment_flood', 10, 5 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* Checks whether comment flooding is occurring. |
0 | 826 |
* |
827 |
* Won't run, if current user can manage options, so to not block |
|
828 |
* administrators. |
|
829 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
* @since 4.7.0 |
5 | 831 |
* |
832 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 833 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
* @param bool $is_flood Is a comment flooding occurring? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
* @param string $ip Comment author's IP address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
* @param string $email Comment author's email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* @param string $date MySQL time string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
* @param bool $avoid_die When true, a disallowed comment will result in the function |
16 | 839 |
* returning without executing wp_die() or die(). Default false. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
* @return bool Whether comment flooding is occurring. |
0 | 841 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
function wp_check_comment_flood( $is_flood, $ip, $email, $date, $avoid_die = false ) { |
0 | 843 |
global $wpdb; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
// Another callback has declared a flood. Trust it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
if ( true === $is_flood ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
return $is_flood; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
|
16 | 850 |
// Don't throttle admins or moderators. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
if ( current_user_can( 'manage_options' ) || current_user_can( 'moderate_comments' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
} |
16 | 854 |
|
0 | 855 |
$hour_ago = gmdate( 'Y-m-d H:i:s', time() - HOUR_IN_SECONDS ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
if ( is_user_logged_in() ) { |
9 | 858 |
$user = get_current_user_id(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
$check_column = '`user_id`'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
} else { |
9 | 861 |
$user = $ip; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
$check_column = '`comment_author_IP`'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
|
16 | 865 |
$sql = $wpdb->prepare( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
"SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( $check_column = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
$hour_ago, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
$user, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
); |
16 | 871 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
$lasttime = $wpdb->get_var( $sql ); |
16 | 873 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
if ( $lasttime ) { |
9 | 875 |
$time_lastcomment = mysql2date( 'U', $lasttime, false ); |
876 |
$time_newcomment = mysql2date( 'U', $date, false ); |
|
16 | 877 |
|
5 | 878 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
* Filters the comment flood status. |
5 | 880 |
* |
881 |
* @since 2.1.0 |
|
882 |
* |
|
883 |
* @param bool $bool Whether a comment flood is occurring. Default false. |
|
884 |
* @param int $time_lastcomment Timestamp of when the last comment was posted. |
|
885 |
* @param int $time_newcomment Timestamp of when the new comment was posted. |
|
886 |
*/ |
|
887 |
$flood_die = apply_filters( 'comment_flood_filter', false, $time_lastcomment, $time_newcomment ); |
|
16 | 888 |
|
0 | 889 |
if ( $flood_die ) { |
5 | 890 |
/** |
891 |
* Fires before the comment flood message is triggered. |
|
892 |
* |
|
893 |
* @since 1.5.0 |
|
894 |
* |
|
895 |
* @param int $time_lastcomment Timestamp of when the last comment was posted. |
|
896 |
* @param int $time_newcomment Timestamp of when the new comment was posted. |
|
897 |
*/ |
|
898 |
do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment ); |
|
9 | 899 |
|
16 | 900 |
if ( $avoid_die ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
} else { |
9 | 903 |
/** |
904 |
* Filters the comment flood error message. |
|
905 |
* |
|
906 |
* @since 5.2.0 |
|
907 |
* |
|
908 |
* @param string $comment_flood_message Comment flood error message. |
|
909 |
*/ |
|
910 |
$comment_flood_message = apply_filters( 'comment_flood_message', __( 'You are posting comments too quickly. Slow down.' ) ); |
|
911 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
if ( wp_doing_ajax() ) { |
9 | 913 |
die( $comment_flood_message ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
|
9 | 916 |
wp_die( $comment_flood_message, 429 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
} |
0 | 918 |
} |
919 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
return false; |
0 | 922 |
} |
923 |
||
924 |
/** |
|
925 |
* Separates an array of comments into an array keyed by comment_type. |
|
926 |
* |
|
927 |
* @since 2.7.0 |
|
928 |
* |
|
9 | 929 |
* @param WP_Comment[] $comments Array of comments |
930 |
* @return WP_Comment[] Array of comments keyed by comment_type. |
|
0 | 931 |
*/ |
9 | 932 |
function separate_comments( &$comments ) { |
933 |
$comments_by_type = array( |
|
934 |
'comment' => array(), |
|
935 |
'trackback' => array(), |
|
936 |
'pingback' => array(), |
|
937 |
'pings' => array(), |
|
938 |
); |
|
16 | 939 |
|
940 |
$count = count( $comments ); |
|
941 |
||
0 | 942 |
for ( $i = 0; $i < $count; $i++ ) { |
9 | 943 |
$type = $comments[ $i ]->comment_type; |
16 | 944 |
|
9 | 945 |
if ( empty( $type ) ) { |
0 | 946 |
$type = 'comment'; |
9 | 947 |
} |
16 | 948 |
|
9 | 949 |
$comments_by_type[ $type ][] = &$comments[ $i ]; |
16 | 950 |
|
951 |
if ( 'trackback' === $type || 'pingback' === $type ) { |
|
9 | 952 |
$comments_by_type['pings'][] = &$comments[ $i ]; |
953 |
} |
|
0 | 954 |
} |
955 |
||
956 |
return $comments_by_type; |
|
957 |
} |
|
958 |
||
959 |
/** |
|
19 | 960 |
* Calculates the total number of comment pages. |
0 | 961 |
* |
962 |
* @since 2.7.0 |
|
5 | 963 |
* |
0 | 964 |
* @uses Walker_Comment |
965 |
* |
|
16 | 966 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
* |
16 | 968 |
* @param WP_Comment[] $comments Optional. Array of WP_Comment objects. Defaults to `$wp_query->comments`. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
969 |
* @param int $per_page Optional. Comments per page. Defaults to the value of `comments_per_page` |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
970 |
* query var, option of the same name, or 1 (in that order). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
971 |
* @param bool $threaded Optional. Control over flat or threaded comments. Defaults to the value |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
972 |
* of `thread_comments` option. |
0 | 973 |
* @return int Number of comment pages. |
974 |
*/ |
|
975 |
function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) { |
|
976 |
global $wp_query; |
|
977 |
||
9 | 978 |
if ( null === $comments && null === $per_page && null === $threaded && ! empty( $wp_query->max_num_comment_pages ) ) { |
0 | 979 |
return $wp_query->max_num_comment_pages; |
9 | 980 |
} |
981 |
||
982 |
if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) { |
|
0 | 983 |
$comments = $wp_query->comments; |
9 | 984 |
} |
985 |
||
986 |
if ( empty( $comments ) ) { |
|
0 | 987 |
return 0; |
9 | 988 |
} |
0 | 989 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
if ( ! get_option( 'page_comments' ) ) { |
0 | 991 |
return 1; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
} |
0 | 993 |
|
9 | 994 |
if ( ! isset( $per_page ) ) { |
995 |
$per_page = (int) get_query_var( 'comments_per_page' ); |
|
996 |
} |
|
997 |
if ( 0 === $per_page ) { |
|
998 |
$per_page = (int) get_option( 'comments_per_page' ); |
|
999 |
} |
|
1000 |
if ( 0 === $per_page ) { |
|
0 | 1001 |
return 1; |
9 | 1002 |
} |
1003 |
||
1004 |
if ( ! isset( $threaded ) ) { |
|
1005 |
$threaded = get_option( 'thread_comments' ); |
|
1006 |
} |
|
0 | 1007 |
|
1008 |
if ( $threaded ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1009 |
$walker = new Walker_Comment(); |
9 | 1010 |
$count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page ); |
0 | 1011 |
} else { |
1012 |
$count = ceil( count( $comments ) / $per_page ); |
|
1013 |
} |
|
1014 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1015 |
return (int) $count; |
0 | 1016 |
} |
1017 |
||
1018 |
/** |
|
19 | 1019 |
* Calculates what page number a comment will appear on for comment paging. |
0 | 1020 |
* |
1021 |
* @since 2.7.0 |
|
1022 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1023 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1025 |
* @param int $comment_id Comment ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
* @param array $args { |
16 | 1027 |
* Array of optional arguments. |
1028 |
* |
|
1029 |
* @type string $type Limit paginated comments to those matching a given type. |
|
1030 |
* Accepts 'comment', 'trackback', 'pingback', 'pings' |
|
1031 |
* (trackbacks and pingbacks), or 'all'. Default 'all'. |
|
1032 |
* @type int $per_page Per-page count to use when calculating pagination. |
|
1033 |
* Defaults to the value of the 'comments_per_page' option. |
|
1034 |
* @type int|string $max_depth If greater than 1, comment page will be determined |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1035 |
* for the top-level parent `$comment_id`. |
16 | 1036 |
* Defaults to the value of the 'thread_comments_depth' option. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1037 |
* } |
0 | 1038 |
* @return int|null Comment page number or null on error. |
1039 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1040 |
function get_page_of_comment( $comment_id, $args = array() ) { |
0 | 1041 |
global $wpdb; |
1042 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
$page = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1045 |
$comment = get_comment( $comment_id ); |
16 | 1046 |
if ( ! $comment ) { |
0 | 1047 |
return; |
9 | 1048 |
} |
1049 |
||
1050 |
$defaults = array( |
|
1051 |
'type' => 'all', |
|
1052 |
'page' => '', |
|
1053 |
'per_page' => '', |
|
1054 |
'max_depth' => '', |
|
1055 |
); |
|
1056 |
$args = wp_parse_args( $args, $defaults ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
$original_args = $args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
// Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
if ( get_option( 'page_comments' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
if ( '' === $args['per_page'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
$args['per_page'] = get_query_var( 'comments_per_page' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
if ( '' === $args['per_page'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
$args['per_page'] = get_option( 'comments_per_page' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
|
9 | 1070 |
if ( empty( $args['per_page'] ) ) { |
0 | 1071 |
$args['per_page'] = 0; |
9 | 1072 |
$args['page'] = 0; |
0 | 1073 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
if ( $args['per_page'] < 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
$page = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1079 |
if ( null === $page ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
if ( '' === $args['max_depth'] ) { |
9 | 1081 |
if ( get_option( 'thread_comments' ) ) { |
1082 |
$args['max_depth'] = get_option( 'thread_comments_depth' ); |
|
1083 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
$args['max_depth'] = -1; |
9 | 1085 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
|
16 | 1088 |
// Find this comment's top-level parent if threading is enabled. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1089 |
if ( $args['max_depth'] > 1 && '0' !== $comment->comment_parent ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
return get_page_of_comment( $comment->comment_parent, $args ); |
9 | 1091 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
$comment_args = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
'type' => $args['type'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
'post_id' => $comment->comment_post_ID, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
'fields' => 'ids', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
'count' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
'status' => 'approve', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1099 |
'orderby' => 'none', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
'parent' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
'date_query' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
'column' => "$wpdb->comments.comment_date_gmt", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
'before' => $comment->comment_date_gmt, |
9 | 1105 |
), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
|
16 | 1109 |
if ( is_user_logged_in() ) { |
1110 |
$comment_args['include_unapproved'] = array( get_current_user_id() ); |
|
1111 |
} else { |
|
1112 |
$unapproved_email = wp_get_unapproved_comment_author_email(); |
|
1113 |
||
1114 |
if ( $unapproved_email ) { |
|
1115 |
$comment_args['include_unapproved'] = array( $unapproved_email ); |
|
1116 |
} |
|
1117 |
} |
|
1118 |
||
1119 |
/** |
|
1120 |
* Filters the arguments used to query comments in get_page_of_comment(). |
|
1121 |
* |
|
1122 |
* @since 5.5.0 |
|
1123 |
* |
|
1124 |
* @see WP_Comment_Query::__construct() |
|
1125 |
* |
|
1126 |
* @param array $comment_args { |
|
1127 |
* Array of WP_Comment_Query arguments. |
|
1128 |
* |
|
1129 |
* @type string $type Limit paginated comments to those matching a given type. |
|
1130 |
* Accepts 'comment', 'trackback', 'pingback', 'pings' |
|
1131 |
* (trackbacks and pingbacks), or 'all'. Default 'all'. |
|
1132 |
* @type int $post_id ID of the post. |
|
1133 |
* @type string $fields Comment fields to return. |
|
1134 |
* @type bool $count Whether to return a comment count (true) or array |
|
1135 |
* of comment objects (false). |
|
1136 |
* @type string $status Comment status. |
|
1137 |
* @type int $parent Parent ID of comment to retrieve children of. |
|
1138 |
* @type array $date_query Date query clauses to limit comments by. See WP_Date_Query. |
|
1139 |
* @type array $include_unapproved Array of IDs or email addresses whose unapproved comments |
|
1140 |
* will be included in paginated comments. |
|
1141 |
* } |
|
1142 |
*/ |
|
1143 |
$comment_args = apply_filters( 'get_page_of_comment_query_args', $comment_args ); |
|
1144 |
||
9 | 1145 |
$comment_query = new WP_Comment_Query(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
$older_comment_count = $comment_query->query( $comment_args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
// No older comments? Then it's page #1. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1149 |
if ( 0 === $older_comment_count ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
$page = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
|
16 | 1152 |
// Divide comments older than this one by comments per page to get this comment's page number. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1154 |
$page = (int) ceil( ( $older_comment_count + 1 ) / $args['per_page'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
} |
0 | 1156 |
} |
1157 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1159 |
* Filters the calculated page on which a comment appears. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
* @since 4.4.0 |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1162 |
* @since 4.7.0 Introduced the `$comment_id` parameter. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
* @param int $page Comment page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
* Arguments used to calculate pagination. These include arguments auto-detected by the function, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
* based on query vars, system settings, etc. For pristine arguments passed to the function, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
* see `$original_args`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
* @type string $type Type of comments to count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
* @type int $page Calculated current page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
* @type int $per_page Calculated number of comments per page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
* @type int $max_depth Maximum comment threading depth allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
* @param array $original_args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
* Array of arguments passed to the function. Some or all of these may not be set. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
* @type string $type Type of comments to count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
* @type int $page Current comment page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
* @type int $per_page Number of comments per page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
* @type int $max_depth Maximum comment threading depth allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
* } |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1183 |
* @param int $comment_id ID of the comment. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1185 |
return apply_filters( 'get_page_of_comment', (int) $page, $args, $original_args, $comment_id ); |
7
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 |
* Retrieves the maximum character lengths for the comment form fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
* |
16 | 1195 |
* @return int[] Array of maximum lengths keyed by field name. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1196 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
function wp_get_comment_fields_max_lengths() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1198 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1199 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1200 |
$lengths = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
'comment_author' => 245, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1202 |
'comment_author_email' => 100, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1203 |
'comment_author_url' => 200, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
'comment_content' => 65525, |
0 | 1205 |
); |
1206 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
if ( $wpdb->is_mysql ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1208 |
foreach ( $lengths as $column => $length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
$col_length = $wpdb->get_col_length( $wpdb->comments, $column ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
$max_length = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
|
16 | 1212 |
// No point if we can't get the DB column lengths. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
if ( is_wp_error( $col_length ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
if ( ! is_array( $col_length ) && (int) $col_length > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
$max_length = (int) $col_length; |
18 | 1219 |
} elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && (int) $col_length['length'] > 0 ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
$max_length = (int) $col_length['length']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1221 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
if ( ! empty( $col_length['type'] ) && 'byte' === $col_length['type'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1223 |
$max_length = $max_length - 10; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
if ( $max_length > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
$lengths[ $column ] = $max_length; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
* Filters the lengths for the comment form fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
* |
16 | 1238 |
* @param int[] $lengths Array of maximum lengths keyed by field name. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
return apply_filters( 'wp_get_comment_fields_max_lengths', $lengths ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
* Compares the lengths of comment data against the maximum character limits. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1248 |
* @param array $comment_data Array of arguments for inserting a comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
* @return WP_Error|true WP_Error when a comment field exceeds the limit, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
* otherwise true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
function wp_check_comment_data_max_lengths( $comment_data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
$max_lengths = wp_get_comment_fields_max_lengths(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
if ( isset( $comment_data['comment_author'] ) && mb_strlen( $comment_data['comment_author'], '8bit' ) > $max_lengths['comment_author'] ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1256 |
return new WP_Error( 'comment_author_column_length', __( '<strong>Error:</strong> Your name is too long.' ), 200 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
if ( isset( $comment_data['comment_author_email'] ) && strlen( $comment_data['comment_author_email'] ) > $max_lengths['comment_author_email'] ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1260 |
return new WP_Error( 'comment_author_email_column_length', __( '<strong>Error:</strong> Your email address is too long.' ), 200 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1262 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
if ( isset( $comment_data['comment_author_url'] ) && strlen( $comment_data['comment_author_url'] ) > $max_lengths['comment_author_url'] ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1264 |
return new WP_Error( 'comment_author_url_column_length', __( '<strong>Error:</strong> Your URL is too long.' ), 200 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
if ( isset( $comment_data['comment_content'] ) && mb_strlen( $comment_data['comment_content'], '8bit' ) > $max_lengths['comment_content'] ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1268 |
return new WP_Error( 'comment_content_column_length', __( '<strong>Error:</strong> Your comment is too long.' ), 200 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
return true; |
0 | 1272 |
} |
1273 |
||
1274 |
/** |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1275 |
* Checks whether comment data passes internal checks or has disallowed content. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1276 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1277 |
* @since 6.7.0 |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1278 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1279 |
* @global wpdb $wpdb WordPress database abstraction object. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1280 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1281 |
* @param array $comment_data Array of arguments for inserting a comment. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1282 |
* @return int|string|WP_Error The approval status on success (0|1|'spam'|'trash'), |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1283 |
* WP_Error otherwise. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1284 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1285 |
function wp_check_comment_data( $comment_data ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1286 |
global $wpdb; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1287 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1288 |
if ( ! empty( $comment_data['user_id'] ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1289 |
$user = get_userdata( $comment_data['user_id'] ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1290 |
$post_author = (int) $wpdb->get_var( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1291 |
$wpdb->prepare( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1292 |
"SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1293 |
$comment_data['comment_post_ID'] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1294 |
) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1295 |
); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1296 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1297 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1298 |
if ( isset( $user ) && ( $comment_data['user_id'] === $post_author || $user->has_cap( 'moderate_comments' ) ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1299 |
// The author and the admins get respect. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1300 |
$approved = 1; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1301 |
} else { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1302 |
// Everyone else's comments will be checked. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1303 |
if ( check_comment( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1304 |
$comment_data['comment_author'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1305 |
$comment_data['comment_author_email'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1306 |
$comment_data['comment_author_url'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1307 |
$comment_data['comment_content'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1308 |
$comment_data['comment_author_IP'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1309 |
$comment_data['comment_agent'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1310 |
$comment_data['comment_type'] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1311 |
) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1312 |
$approved = 1; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1313 |
} else { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1314 |
$approved = 0; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1315 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1316 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1317 |
if ( wp_check_comment_disallowed_list( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1318 |
$comment_data['comment_author'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1319 |
$comment_data['comment_author_email'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1320 |
$comment_data['comment_author_url'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1321 |
$comment_data['comment_content'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1322 |
$comment_data['comment_author_IP'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1323 |
$comment_data['comment_agent'] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1324 |
) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1325 |
$approved = EMPTY_TRASH_DAYS ? 'trash' : 'spam'; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1326 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1327 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1328 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1329 |
/** |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1330 |
* Filters a comment's approval status before it is set. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1331 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1332 |
* @since 2.1.0 |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1333 |
* @since 4.9.0 Returning a WP_Error value from the filter will short-circuit comment insertion |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1334 |
* and allow skipping further processing. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1335 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1336 |
* @param int|string|WP_Error $approved The approval status. Accepts 1, 0, 'spam', 'trash', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1337 |
* or WP_Error. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1338 |
* @param array $commentdata Comment data. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1339 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1340 |
return apply_filters( 'pre_comment_approved', $approved, $comment_data ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1341 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1342 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1343 |
/** |
16 | 1344 |
* Checks if a comment contains disallowed characters or words. |
0 | 1345 |
* |
16 | 1346 |
* @since 5.5.0 |
0 | 1347 |
* |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1348 |
* @param string $author The author of the comment. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1349 |
* @param string $email The email of the comment. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1350 |
* @param string $url The url used in the comment. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1351 |
* @param string $comment The comment content. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1352 |
* @param string $user_ip The comment author's IP address. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1353 |
* @param string $user_agent The author's browser user agent. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1354 |
* @return bool True if the comment contains disallowed content, false otherwise. |
0 | 1355 |
*/ |
16 | 1356 |
function wp_check_comment_disallowed_list( $author, $email, $url, $comment, $user_ip, $user_agent ) { |
5 | 1357 |
/** |
16 | 1358 |
* Fires before the comment is tested for disallowed characters or words. |
5 | 1359 |
* |
1360 |
* @since 1.5.0 |
|
16 | 1361 |
* @deprecated 5.5.0 Use {@see 'wp_check_comment_disallowed_list'} instead. |
5 | 1362 |
* |
1363 |
* @param string $author Comment author. |
|
1364 |
* @param string $email Comment author's email. |
|
1365 |
* @param string $url Comment author's URL. |
|
1366 |
* @param string $comment Comment content. |
|
1367 |
* @param string $user_ip Comment author's IP address. |
|
1368 |
* @param string $user_agent Comment author's browser user agent. |
|
1369 |
*/ |
|
16 | 1370 |
do_action_deprecated( |
1371 |
'wp_blacklist_check', |
|
1372 |
array( $author, $email, $url, $comment, $user_ip, $user_agent ), |
|
1373 |
'5.5.0', |
|
1374 |
'wp_check_comment_disallowed_list', |
|
1375 |
__( 'Please consider writing more inclusive code.' ) |
|
1376 |
); |
|
1377 |
||
1378 |
/** |
|
1379 |
* Fires before the comment is tested for disallowed characters or words. |
|
1380 |
* |
|
1381 |
* @since 5.5.0 |
|
1382 |
* |
|
1383 |
* @param string $author Comment author. |
|
1384 |
* @param string $email Comment author's email. |
|
1385 |
* @param string $url Comment author's URL. |
|
1386 |
* @param string $comment Comment content. |
|
1387 |
* @param string $user_ip Comment author's IP address. |
|
1388 |
* @param string $user_agent Comment author's browser user agent. |
|
1389 |
*/ |
|
1390 |
do_action( 'wp_check_comment_disallowed_list', $author, $email, $url, $comment, $user_ip, $user_agent ); |
|
1391 |
||
1392 |
$mod_keys = trim( get_option( 'disallowed_keys' ) ); |
|
1393 |
if ( '' === $mod_keys ) { |
|
1394 |
return false; // If moderation keys are empty. |
|
9 | 1395 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
|
16 | 1397 |
// Ensure HTML tags are not being used to bypass the list of disallowed characters and words. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
$comment_without_html = wp_strip_all_tags( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
|
9 | 1400 |
$words = explode( "\n", $mod_keys ); |
0 | 1401 |
|
1402 |
foreach ( (array) $words as $word ) { |
|
9 | 1403 |
$word = trim( $word ); |
0 | 1404 |
|
16 | 1405 |
// Skip empty lines. |
9 | 1406 |
if ( empty( $word ) ) { |
1407 |
continue; } |
|
0 | 1408 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1409 |
// Do some escaping magic so that '#' chars in the spam words don't break things: |
9 | 1410 |
$word = preg_quote( $word, '#' ); |
0 | 1411 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1412 |
$pattern = "#$word#iu"; |
9 | 1413 |
if ( preg_match( $pattern, $author ) |
1414 |
|| preg_match( $pattern, $email ) |
|
1415 |
|| preg_match( $pattern, $url ) |
|
1416 |
|| preg_match( $pattern, $comment ) |
|
1417 |
|| preg_match( $pattern, $comment_without_html ) |
|
1418 |
|| preg_match( $pattern, $user_ip ) |
|
1419 |
|| preg_match( $pattern, $user_agent ) |
|
1420 |
) { |
|
0 | 1421 |
return true; |
9 | 1422 |
} |
0 | 1423 |
} |
1424 |
return false; |
|
1425 |
} |
|
1426 |
||
1427 |
/** |
|
16 | 1428 |
* Retrieves the total comment counts for the whole site or a single post. |
0 | 1429 |
* |
1430 |
* The comment stats are cached and then retrieved, if they already exist in the |
|
1431 |
* cache. |
|
1432 |
* |
|
16 | 1433 |
* @see get_comment_count() Which handles fetching the live comment counts. |
1434 |
* |
|
0 | 1435 |
* @since 2.5.0 |
1436 |
* |
|
16 | 1437 |
* @param int $post_id Optional. Restrict the comment counts to the given post. Default 0, which indicates that |
1438 |
* comment counts for the whole site will be retrieved. |
|
1439 |
* @return stdClass { |
|
1440 |
* The number of comments keyed by their status. |
|
1441 |
* |
|
1442 |
* @type int $approved The number of approved comments. |
|
1443 |
* @type int $moderated The number of comments awaiting moderation (a.k.a. pending). |
|
1444 |
* @type int $spam The number of spam comments. |
|
1445 |
* @type int $trash The number of trashed comments. |
|
1446 |
* @type int $post-trashed The number of comments for posts that are in the trash. |
|
1447 |
* @type int $total_comments The total number of non-trashed comments, including spam. |
|
1448 |
* @type int $all The total number of pending or approved comments. |
|
1449 |
* } |
|
0 | 1450 |
*/ |
1451 |
function wp_count_comments( $post_id = 0 ) { |
|
1452 |
$post_id = (int) $post_id; |
|
1453 |
||
5 | 1454 |
/** |
16 | 1455 |
* Filters the comments count for a given post or the whole site. |
5 | 1456 |
* |
1457 |
* @since 2.7.0 |
|
1458 |
* |
|
16 | 1459 |
* @param array|stdClass $count An empty array or an object containing comment counts. |
1460 |
* @param int $post_id The post ID. Can be 0 to represent the whole site. |
|
5 | 1461 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1462 |
$filtered = apply_filters( 'wp_count_comments', array(), $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1463 |
if ( ! empty( $filtered ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
return $filtered; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
$count = wp_cache_get( "comments-{$post_id}", 'counts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
if ( false !== $count ) { |
0 | 1469 |
return $count; |
1470 |
} |
|
1471 |
||
9 | 1472 |
$stats = get_comment_count( $post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
$stats['moderated'] = $stats['awaiting_moderation']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
unset( $stats['awaiting_moderation'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1475 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
$stats_object = (object) $stats; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1477 |
wp_cache_set( "comments-{$post_id}", $stats_object, 'counts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1478 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
return $stats_object; |
0 | 1480 |
} |
1481 |
||
1482 |
/** |
|
1483 |
* Trashes or deletes a comment. |
|
1484 |
* |
|
16 | 1485 |
* The comment is moved to Trash instead of permanently deleted unless Trash is |
1486 |
* disabled, item is already in the Trash, or $force_delete is true. |
|
0 | 1487 |
* |
1488 |
* The post comment count will be updated if the comment was approved and has a |
|
1489 |
* post ID available. |
|
1490 |
* |
|
1491 |
* @since 2.0.0 |
|
5 | 1492 |
* |
1493 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 1494 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
16 | 1496 |
* @param bool $force_delete Whether to bypass Trash and force deletion. Default false. |
0 | 1497 |
* @return bool True on success, false on failure. |
1498 |
*/ |
|
9 | 1499 |
function wp_delete_comment( $comment_id, $force_delete = false ) { |
0 | 1500 |
global $wpdb; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1501 |
|
16 | 1502 |
$comment = get_comment( $comment_id ); |
1503 |
if ( ! $comment ) { |
|
0 | 1504 |
return false; |
9 | 1505 |
} |
1506 |
||
16 | 1507 |
if ( ! $force_delete && EMPTY_TRASH_DAYS && ! in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ), true ) ) { |
9 | 1508 |
return wp_trash_comment( $comment_id ); |
1509 |
} |
|
0 | 1510 |
|
5 | 1511 |
/** |
1512 |
* Fires immediately before a comment is deleted from the database. |
|
1513 |
* |
|
1514 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1516 |
* |
19 | 1517 |
* @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
|
1518 |
* @param WP_Comment $comment The comment to be deleted. |
5 | 1519 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1520 |
do_action( 'delete_comment', $comment->comment_ID, $comment ); |
0 | 1521 |
|
1522 |
// Move children up a level. |
|
9 | 1523 |
$children = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID ) ); |
1524 |
if ( ! empty( $children ) ) { |
|
1525 |
$wpdb->update( $wpdb->comments, array( 'comment_parent' => $comment->comment_parent ), array( 'comment_parent' => $comment->comment_ID ) ); |
|
1526 |
clean_comment_cache( $children ); |
|
0 | 1527 |
} |
1528 |
||
16 | 1529 |
// Delete metadata. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1530 |
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) ); |
9 | 1531 |
foreach ( $meta_ids as $mid ) { |
0 | 1532 |
delete_metadata_by_mid( 'comment', $mid ); |
9 | 1533 |
} |
1534 |
||
1535 |
if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) { |
|
0 | 1536 |
return false; |
9 | 1537 |
} |
5 | 1538 |
|
1539 |
/** |
|
1540 |
* Fires immediately after a comment is deleted from the database. |
|
1541 |
* |
|
1542 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1543 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1544 |
* |
19 | 1545 |
* @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
|
1546 |
* @param WP_Comment $comment The deleted comment. |
5 | 1547 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1548 |
do_action( 'deleted_comment', $comment->comment_ID, $comment ); |
0 | 1549 |
|
1550 |
$post_id = $comment->comment_post_ID; |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1551 |
if ( $post_id && '1' === $comment->comment_approved ) { |
9 | 1552 |
wp_update_comment_count( $post_id ); |
1553 |
} |
|
0 | 1554 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1555 |
clean_comment_cache( $comment->comment_ID ); |
0 | 1556 |
|
5 | 1557 |
/** This action is documented in wp-includes/comment.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
do_action( 'wp_set_comment_status', $comment->comment_ID, 'delete' ); |
5 | 1559 |
|
9 | 1560 |
wp_transition_comment_status( 'delete', $comment->comment_approved, $comment ); |
16 | 1561 |
|
0 | 1562 |
return true; |
1563 |
} |
|
1564 |
||
1565 |
/** |
|
1566 |
* Moves a comment to the Trash |
|
1567 |
* |
|
16 | 1568 |
* If Trash is disabled, comment is permanently deleted. |
0 | 1569 |
* |
1570 |
* @since 2.9.0 |
|
1571 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
0 | 1573 |
* @return bool True on success, false on failure. |
1574 |
*/ |
|
9 | 1575 |
function wp_trash_comment( $comment_id ) { |
1576 |
if ( ! EMPTY_TRASH_DAYS ) { |
|
1577 |
return wp_delete_comment( $comment_id, true ); |
|
1578 |
} |
|
1579 |
||
16 | 1580 |
$comment = get_comment( $comment_id ); |
1581 |
if ( ! $comment ) { |
|
0 | 1582 |
return false; |
9 | 1583 |
} |
0 | 1584 |
|
5 | 1585 |
/** |
1586 |
* Fires immediately before a comment is sent to the Trash. |
|
1587 |
* |
|
1588 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1590 |
* |
19 | 1591 |
* @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
|
1592 |
* @param WP_Comment $comment The comment to be trashed. |
5 | 1593 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1594 |
do_action( 'trash_comment', $comment->comment_ID, $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
if ( wp_set_comment_status( $comment, 'trash' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1598 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1599 |
add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1600 |
add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); |
5 | 1601 |
|
1602 |
/** |
|
1603 |
* Fires immediately after a comment is sent to Trash. |
|
1604 |
* |
|
1605 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1606 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1607 |
* |
19 | 1608 |
* @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
|
1609 |
* @param WP_Comment $comment The trashed comment. |
5 | 1610 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1611 |
do_action( 'trashed_comment', $comment->comment_ID, $comment ); |
16 | 1612 |
|
0 | 1613 |
return true; |
1614 |
} |
|
1615 |
||
1616 |
return false; |
|
1617 |
} |
|
1618 |
||
1619 |
/** |
|
1620 |
* Removes a comment from the Trash |
|
1621 |
* |
|
1622 |
* @since 2.9.0 |
|
1623 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1624 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
0 | 1625 |
* @return bool True on success, false on failure. |
1626 |
*/ |
|
9 | 1627 |
function wp_untrash_comment( $comment_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1628 |
$comment = get_comment( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
if ( ! $comment ) { |
0 | 1630 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
} |
0 | 1632 |
|
5 | 1633 |
/** |
1634 |
* Fires immediately before a comment is restored from the Trash. |
|
1635 |
* |
|
1636 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1638 |
* |
19 | 1639 |
* @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
|
1640 |
* @param WP_Comment $comment The comment to be untrashed. |
5 | 1641 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1642 |
do_action( 'untrash_comment', $comment->comment_ID, $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1643 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1644 |
$status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); |
9 | 1645 |
if ( empty( $status ) ) { |
0 | 1646 |
$status = '0'; |
9 | 1647 |
} |
0 | 1648 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1649 |
if ( wp_set_comment_status( $comment, $status ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1650 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
16 | 1652 |
|
5 | 1653 |
/** |
1654 |
* Fires immediately after a comment is restored from the Trash. |
|
1655 |
* |
|
1656 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1657 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1658 |
* |
19 | 1659 |
* @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
|
1660 |
* @param WP_Comment $comment The untrashed comment. |
5 | 1661 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1662 |
do_action( 'untrashed_comment', $comment->comment_ID, $comment ); |
16 | 1663 |
|
0 | 1664 |
return true; |
1665 |
} |
|
1666 |
||
1667 |
return false; |
|
1668 |
} |
|
1669 |
||
1670 |
/** |
|
19 | 1671 |
* Marks a comment as Spam. |
0 | 1672 |
* |
1673 |
* @since 2.9.0 |
|
1674 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1675 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
0 | 1676 |
* @return bool True on success, false on failure. |
1677 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1678 |
function wp_spam_comment( $comment_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1679 |
$comment = get_comment( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1680 |
if ( ! $comment ) { |
0 | 1681 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1682 |
} |
0 | 1683 |
|
5 | 1684 |
/** |
1685 |
* Fires immediately before a comment is marked as Spam. |
|
1686 |
* |
|
1687 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1688 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1689 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1690 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1691 |
* @param WP_Comment $comment The comment to be marked as spam. |
5 | 1692 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1693 |
do_action( 'spam_comment', $comment->comment_ID, $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1694 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1695 |
if ( wp_set_comment_status( $comment, 'spam' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1696 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1697 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1698 |
add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); |
16 | 1700 |
|
5 | 1701 |
/** |
1702 |
* Fires immediately after a comment is marked as Spam. |
|
1703 |
* |
|
1704 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1705 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1706 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1707 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1708 |
* @param WP_Comment $comment The comment marked as spam. |
5 | 1709 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
do_action( 'spammed_comment', $comment->comment_ID, $comment ); |
16 | 1711 |
|
0 | 1712 |
return true; |
1713 |
} |
|
1714 |
||
1715 |
return false; |
|
1716 |
} |
|
1717 |
||
1718 |
/** |
|
19 | 1719 |
* Removes a comment from the Spam. |
0 | 1720 |
* |
1721 |
* @since 2.9.0 |
|
1722 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1723 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
0 | 1724 |
* @return bool True on success, false on failure. |
1725 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1726 |
function wp_unspam_comment( $comment_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1727 |
$comment = get_comment( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1728 |
if ( ! $comment ) { |
0 | 1729 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1730 |
} |
0 | 1731 |
|
5 | 1732 |
/** |
1733 |
* Fires immediately before a comment is unmarked as Spam. |
|
1734 |
* |
|
1735 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1736 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1737 |
* |
19 | 1738 |
* @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
|
1739 |
* @param WP_Comment $comment The comment to be unmarked as spam. |
5 | 1740 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1741 |
do_action( 'unspam_comment', $comment->comment_ID, $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
$status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); |
9 | 1744 |
if ( empty( $status ) ) { |
0 | 1745 |
$status = '0'; |
9 | 1746 |
} |
0 | 1747 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1748 |
if ( wp_set_comment_status( $comment, $status ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1749 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
16 | 1751 |
|
5 | 1752 |
/** |
1753 |
* Fires immediately after a comment is unmarked as Spam. |
|
1754 |
* |
|
1755 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1756 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1757 |
* |
19 | 1758 |
* @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
|
1759 |
* @param WP_Comment $comment The comment unmarked as spam. |
5 | 1760 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1761 |
do_action( 'unspammed_comment', $comment->comment_ID, $comment ); |
16 | 1762 |
|
0 | 1763 |
return true; |
1764 |
} |
|
1765 |
||
1766 |
return false; |
|
1767 |
} |
|
1768 |
||
1769 |
/** |
|
19 | 1770 |
* Retrieves the status of a comment by comment ID. |
0 | 1771 |
* |
1772 |
* @since 1.0.0 |
|
1773 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1774 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object |
16 | 1775 |
* @return string|false Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure. |
0 | 1776 |
*/ |
9 | 1777 |
function wp_get_comment_status( $comment_id ) { |
1778 |
$comment = get_comment( $comment_id ); |
|
1779 |
if ( ! $comment ) { |
|
0 | 1780 |
return false; |
9 | 1781 |
} |
0 | 1782 |
|
1783 |
$approved = $comment->comment_approved; |
|
1784 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1785 |
if ( null === $approved ) { |
0 | 1786 |
return false; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1787 |
} elseif ( '1' === $approved ) { |
0 | 1788 |
return 'approved'; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1789 |
} elseif ( '0' === $approved ) { |
0 | 1790 |
return 'unapproved'; |
16 | 1791 |
} elseif ( 'spam' === $approved ) { |
0 | 1792 |
return 'spam'; |
16 | 1793 |
} elseif ( 'trash' === $approved ) { |
0 | 1794 |
return 'trash'; |
9 | 1795 |
} else { |
0 | 1796 |
return false; |
9 | 1797 |
} |
0 | 1798 |
} |
1799 |
||
1800 |
/** |
|
19 | 1801 |
* Calls hooks for when a comment status transition occurs. |
0 | 1802 |
* |
1803 |
* Calls hooks for comment status transitions. If the new comment status is not the same |
|
1804 |
* as the previous comment status, then two hooks will be ran, the first is |
|
16 | 1805 |
* {@see 'transition_comment_status'} with new status, old status, and comment data. |
1806 |
* The next action called is {@see 'comment_$old_status_to_$new_status'}. It has |
|
1807 |
* the comment data. |
|
0 | 1808 |
* |
16 | 1809 |
* The final action will run whether or not the comment statuses are the same. |
1810 |
* The action is named {@see 'comment_$new_status_$comment->comment_type'}. |
|
0 | 1811 |
* |
1812 |
* @since 2.7.0 |
|
1813 |
* |
|
16 | 1814 |
* @param string $new_status New comment status. |
1815 |
* @param string $old_status Previous comment status. |
|
1816 |
* @param WP_Comment $comment Comment object. |
|
0 | 1817 |
*/ |
9 | 1818 |
function wp_transition_comment_status( $new_status, $old_status, $comment ) { |
5 | 1819 |
/* |
16 | 1820 |
* Translate raw statuses to human-readable formats for the hooks. |
5 | 1821 |
* This is not a complete list of comment status, it's only the ones |
16 | 1822 |
* that need to be renamed. |
5 | 1823 |
*/ |
0 | 1824 |
$comment_statuses = array( |
1825 |
0 => 'unapproved', |
|
16 | 1826 |
'hold' => 'unapproved', // wp_set_comment_status() uses "hold". |
0 | 1827 |
1 => 'approved', |
16 | 1828 |
'approve' => 'approved', // wp_set_comment_status() uses "approve". |
0 | 1829 |
); |
9 | 1830 |
if ( isset( $comment_statuses[ $new_status ] ) ) { |
1831 |
$new_status = $comment_statuses[ $new_status ]; |
|
1832 |
} |
|
1833 |
if ( isset( $comment_statuses[ $old_status ] ) ) { |
|
1834 |
$old_status = $comment_statuses[ $old_status ]; |
|
1835 |
} |
|
0 | 1836 |
|
16 | 1837 |
// Call the hooks. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1838 |
if ( $new_status !== $old_status ) { |
5 | 1839 |
/** |
1840 |
* Fires when the comment status is in transition. |
|
1841 |
* |
|
1842 |
* @since 2.7.0 |
|
1843 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1844 |
* @param string $new_status The new comment status. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1845 |
* @param string $old_status The old comment status. |
16 | 1846 |
* @param WP_Comment $comment Comment object. |
5 | 1847 |
*/ |
1848 |
do_action( 'transition_comment_status', $new_status, $old_status, $comment ); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1849 |
|
5 | 1850 |
/** |
1851 |
* Fires when the comment status is in transition from one specific status to another. |
|
1852 |
* |
|
1853 |
* The dynamic portions of the hook name, `$old_status`, and `$new_status`, |
|
1854 |
* refer to the old and new comment statuses, respectively. |
|
1855 |
* |
|
19 | 1856 |
* Possible hook names include: |
1857 |
* |
|
1858 |
* - `comment_unapproved_to_approved` |
|
1859 |
* - `comment_spam_to_approved` |
|
1860 |
* - `comment_approved_to_unapproved` |
|
1861 |
* - `comment_spam_to_unapproved` |
|
1862 |
* - `comment_unapproved_to_spam` |
|
1863 |
* - `comment_approved_to_spam` |
|
1864 |
* |
|
5 | 1865 |
* @since 2.7.0 |
1866 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1867 |
* @param WP_Comment $comment Comment object. |
5 | 1868 |
*/ |
1869 |
do_action( "comment_{$old_status}_to_{$new_status}", $comment ); |
|
0 | 1870 |
} |
5 | 1871 |
/** |
1872 |
* Fires when the status of a specific comment type is in transition. |
|
1873 |
* |
|
1874 |
* The dynamic portions of the hook name, `$new_status`, and `$comment->comment_type`, |
|
1875 |
* refer to the new comment status, and the type of comment, respectively. |
|
1876 |
* |
|
19 | 1877 |
* Typical comment types include 'comment', 'pingback', or 'trackback'. |
1878 |
* |
|
1879 |
* Possible hook names include: |
|
1880 |
* |
|
1881 |
* - `comment_approved_comment` |
|
1882 |
* - `comment_approved_pingback` |
|
1883 |
* - `comment_approved_trackback` |
|
1884 |
* - `comment_unapproved_comment` |
|
1885 |
* - `comment_unapproved_pingback` |
|
1886 |
* - `comment_unapproved_trackback` |
|
1887 |
* - `comment_spam_comment` |
|
1888 |
* - `comment_spam_pingback` |
|
1889 |
* - `comment_spam_trackback` |
|
5 | 1890 |
* |
1891 |
* @since 2.7.0 |
|
1892 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1893 |
* @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
|
1894 |
* @param WP_Comment $comment Comment object. |
5 | 1895 |
*/ |
1896 |
do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment ); |
|
0 | 1897 |
} |
1898 |
||
1899 |
/** |
|
19 | 1900 |
* Clears the lastcommentmodified cached value when a comment status is changed. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1901 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1902 |
* Deletes the lastcommentmodified cache key when a comment enters or leaves |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1903 |
* 'approved' status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1904 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1905 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1906 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1907 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1908 |
* @param string $new_status The new comment status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1909 |
* @param string $old_status The old comment status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1910 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1911 |
function _clear_modified_cache_on_transition_comment_status( $new_status, $old_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
if ( 'approved' === $new_status || 'approved' === $old_status ) { |
19 | 1913 |
$data = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1914 |
foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { |
19 | 1915 |
$data[] = "lastcommentmodified:$timezone"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1916 |
} |
19 | 1917 |
wp_cache_delete_multiple( $data, 'timeinfo' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1919 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1921 |
/** |
19 | 1922 |
* Gets current commenter's name, email, and URL. |
0 | 1923 |
* |
1924 |
* Expects cookies content to already be sanitized. User of this function might |
|
1925 |
* wish to recheck the returned array for validity. |
|
1926 |
* |
|
1927 |
* @see sanitize_comment_cookies() Use to sanitize cookies |
|
1928 |
* |
|
1929 |
* @since 2.0.4 |
|
1930 |
* |
|
16 | 1931 |
* @return array { |
1932 |
* An array of current commenter variables. |
|
1933 |
* |
|
1934 |
* @type string $comment_author The name of the current commenter, or an empty string. |
|
1935 |
* @type string $comment_author_email The email address of the current commenter, or an empty string. |
|
1936 |
* @type string $comment_author_url The URL address of the current commenter, or an empty string. |
|
1937 |
* } |
|
0 | 1938 |
*/ |
1939 |
function wp_get_current_commenter() { |
|
1940 |
// Cookies should already be sanitized. |
|
1941 |
||
1942 |
$comment_author = ''; |
|
9 | 1943 |
if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ) { |
1944 |
$comment_author = $_COOKIE[ 'comment_author_' . COOKIEHASH ]; |
|
1945 |
} |
|
0 | 1946 |
|
1947 |
$comment_author_email = ''; |
|
9 | 1948 |
if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) { |
1949 |
$comment_author_email = $_COOKIE[ 'comment_author_email_' . COOKIEHASH ]; |
|
1950 |
} |
|
0 | 1951 |
|
1952 |
$comment_author_url = ''; |
|
9 | 1953 |
if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) { |
1954 |
$comment_author_url = $_COOKIE[ 'comment_author_url_' . COOKIEHASH ]; |
|
1955 |
} |
|
0 | 1956 |
|
5 | 1957 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1958 |
* Filters the current commenter's name, email, and URL. |
5 | 1959 |
* |
1960 |
* @since 3.1.0 |
|
1961 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1962 |
* @param array $comment_author_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1963 |
* An array of current commenter variables. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1964 |
* |
16 | 1965 |
* @type string $comment_author The name of the current commenter, or an empty string. |
1966 |
* @type string $comment_author_email The email address of the current commenter, or an empty string. |
|
1967 |
* @type string $comment_author_url The URL address of the current commenter, or an empty string. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1968 |
* } |
5 | 1969 |
*/ |
9 | 1970 |
return apply_filters( 'wp_get_current_commenter', compact( 'comment_author', 'comment_author_email', 'comment_author_url' ) ); |
1971 |
} |
|
1972 |
||
1973 |
/** |
|
19 | 1974 |
* Gets unapproved comment author's email. |
9 | 1975 |
* |
1976 |
* Used to allow the commenter to see their pending comment. |
|
1977 |
* |
|
1978 |
* @since 5.1.0 |
|
18 | 1979 |
* @since 5.7.0 The window within which the author email for an unapproved comment |
1980 |
* can be retrieved was extended to 10 minutes. |
|
9 | 1981 |
* |
1982 |
* @return string The unapproved comment author's email (when supplied). |
|
1983 |
*/ |
|
1984 |
function wp_get_unapproved_comment_author_email() { |
|
1985 |
$commenter_email = ''; |
|
1986 |
||
1987 |
if ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) { |
|
1988 |
$comment_id = (int) $_GET['unapproved']; |
|
1989 |
$comment = get_comment( $comment_id ); |
|
1990 |
||
1991 |
if ( $comment && hash_equals( $_GET['moderation-hash'], wp_hash( $comment->comment_date_gmt ) ) ) { |
|
18 | 1992 |
// The comment will only be viewable by the comment author for 10 minutes. |
1993 |
$comment_preview_expires = strtotime( $comment->comment_date_gmt . '+10 minutes' ); |
|
16 | 1994 |
|
1995 |
if ( time() < $comment_preview_expires ) { |
|
1996 |
$commenter_email = $comment->comment_author_email; |
|
1997 |
} |
|
9 | 1998 |
} |
1999 |
} |
|
2000 |
||
2001 |
if ( ! $commenter_email ) { |
|
2002 |
$commenter = wp_get_current_commenter(); |
|
2003 |
$commenter_email = $commenter['comment_author_email']; |
|
2004 |
} |
|
2005 |
||
2006 |
return $commenter_email; |
|
0 | 2007 |
} |
2008 |
||
2009 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2010 |
* Inserts a comment into the database. |
0 | 2011 |
* |
2012 |
* @since 2.0.0 |
|
16 | 2013 |
* @since 4.4.0 Introduced the `$comment_meta` argument. |
2014 |
* @since 5.5.0 Default value for `$comment_type` argument changed to `comment`. |
|
5 | 2015 |
* |
2016 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 2017 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2018 |
* @param array $commentdata { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2019 |
* Array of arguments for inserting a new comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2020 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2021 |
* @type string $comment_agent The HTTP user agent of the `$comment_author` when |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2022 |
* the comment was submitted. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2023 |
* @type int|string $comment_approved Whether the comment has been approved. Default 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2024 |
* @type string $comment_author The name of the author of the comment. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2025 |
* @type string $comment_author_email The email address of the `$comment_author`. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
* @type string $comment_author_IP The IP address of the `$comment_author`. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
* @type string $comment_author_url The URL address of the `$comment_author`. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
* @type string $comment_content The content of the comment. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
* @type string $comment_date The date the comment was submitted. To set the date |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2030 |
* manually, `$comment_date_gmt` must also be specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2031 |
* Default is the current time. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2032 |
* @type string $comment_date_gmt The date the comment was submitted in the GMT timezone. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2033 |
* Default is `$comment_date` in the site's GMT timezone. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2034 |
* @type int $comment_karma The karma of the comment. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
* @type int $comment_parent ID of this comment's parent, if any. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2036 |
* @type int $comment_post_ID ID of the post that relates to the comment, if any. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2037 |
* Default 0. |
16 | 2038 |
* @type string $comment_type Comment type. Default 'comment'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2039 |
* @type array $comment_meta Optional. Array of key/value pairs to be stored in commentmeta for the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
* new comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2041 |
* @type int $user_id ID of the user who submitted the comment. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2042 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2043 |
* @return int|false The new comment's ID on success, false on failure. |
0 | 2044 |
*/ |
5 | 2045 |
function wp_insert_comment( $commentdata ) { |
0 | 2046 |
global $wpdb; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2047 |
|
5 | 2048 |
$data = wp_unslash( $commentdata ); |
2049 |
||
9 | 2050 |
$comment_author = ! isset( $data['comment_author'] ) ? '' : $data['comment_author']; |
5 | 2051 |
$comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email']; |
9 | 2052 |
$comment_author_url = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url']; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2053 |
$comment_author_ip = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP']; |
9 | 2054 |
|
2055 |
$comment_date = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date']; |
|
5 | 2056 |
$comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt']; |
2057 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2058 |
$comment_post_id = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID']; |
9 | 2059 |
$comment_content = ! isset( $data['comment_content'] ) ? '' : $data['comment_content']; |
2060 |
$comment_karma = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma']; |
|
2061 |
$comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved']; |
|
2062 |
$comment_agent = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent']; |
|
16 | 2063 |
$comment_type = empty( $data['comment_type'] ) ? 'comment' : $data['comment_type']; |
9 | 2064 |
$comment_parent = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent']; |
2065 |
||
2066 |
$user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id']; |
|
5 | 2067 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2068 |
$compacted = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2069 |
'comment_post_ID' => $comment_post_id, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2070 |
'comment_author_IP' => $comment_author_ip, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2071 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2072 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2073 |
$compacted += compact( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2074 |
'comment_author', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2075 |
'comment_author_email', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2076 |
'comment_author_url', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2077 |
'comment_date', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2078 |
'comment_date_gmt', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2079 |
'comment_content', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2080 |
'comment_karma', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2081 |
'comment_approved', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2082 |
'comment_agent', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2083 |
'comment_type', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2084 |
'comment_parent', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2085 |
'user_id' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2086 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2087 |
|
5 | 2088 |
if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) { |
2089 |
return false; |
|
2090 |
} |
|
0 | 2091 |
|
2092 |
$id = (int) $wpdb->insert_id; |
|
2093 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2094 |
if ( 1 === (int) $comment_approved ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2095 |
wp_update_comment_count( $comment_post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2096 |
|
19 | 2097 |
$data = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2098 |
foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { |
19 | 2099 |
$data[] = "lastcommentmodified:$timezone"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2100 |
} |
19 | 2101 |
wp_cache_delete_multiple( $data, 'timeinfo' ); |
5 | 2102 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2103 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2104 |
clean_comment_cache( $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2105 |
|
5 | 2106 |
$comment = get_comment( $id ); |
2107 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2108 |
// If metadata is provided, store it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2109 |
if ( isset( $commentdata['comment_meta'] ) && is_array( $commentdata['comment_meta'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
foreach ( $commentdata['comment_meta'] as $meta_key => $meta_value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
add_comment_meta( $comment->comment_ID, $meta_key, $meta_value, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2112 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2114 |
|
5 | 2115 |
/** |
2116 |
* Fires immediately after a comment is inserted into the database. |
|
2117 |
* |
|
2118 |
* @since 2.8.0 |
|
2119 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2120 |
* @param int $id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2121 |
* @param WP_Comment $comment Comment object. |
5 | 2122 |
*/ |
2123 |
do_action( 'wp_insert_comment', $id, $comment ); |
|
0 | 2124 |
|
2125 |
return $id; |
|
2126 |
} |
|
2127 |
||
2128 |
/** |
|
2129 |
* Filters and sanitizes comment data. |
|
2130 |
* |
|
2131 |
* Sets the comment data 'filtered' field to true when finished. This can be |
|
2132 |
* checked as to whether the comment should be filtered and to keep from |
|
2133 |
* filtering the same comment more than once. |
|
2134 |
* |
|
2135 |
* @since 2.0.0 |
|
2136 |
* |
|
2137 |
* @param array $commentdata Contains information on the comment. |
|
2138 |
* @return array Parsed comment information. |
|
2139 |
*/ |
|
9 | 2140 |
function wp_filter_comment( $commentdata ) { |
5 | 2141 |
if ( isset( $commentdata['user_ID'] ) ) { |
2142 |
/** |
|
16 | 2143 |
* Filters the comment author's user ID before it is set. |
5 | 2144 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2145 |
* The first time this filter is evaluated, `user_ID` is checked |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2146 |
* (for back-compat), followed by the standard `user_id` value. |
5 | 2147 |
* |
2148 |
* @since 1.5.0 |
|
2149 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2150 |
* @param int $user_id The comment author's user ID. |
5 | 2151 |
*/ |
2152 |
$commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] ); |
|
2153 |
} elseif ( isset( $commentdata['user_id'] ) ) { |
|
2154 |
/** This filter is documented in wp-includes/comment.php */ |
|
2155 |
$commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_id'] ); |
|
2156 |
} |
|
2157 |
||
2158 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2159 |
* Filters the comment author's browser user agent before it is set. |
5 | 2160 |
* |
2161 |
* @since 1.5.0 |
|
2162 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2163 |
* @param string $comment_agent The comment author's browser user agent. |
5 | 2164 |
*/ |
2165 |
$commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '' ) ); |
|
2166 |
/** This filter is documented in wp-includes/comment.php */ |
|
2167 |
$commentdata['comment_author'] = apply_filters( 'pre_comment_author_name', $commentdata['comment_author'] ); |
|
2168 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2169 |
* Filters the comment content before it is set. |
5 | 2170 |
* |
2171 |
* @since 1.5.0 |
|
2172 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2173 |
* @param string $comment_content The comment content. |
5 | 2174 |
*/ |
2175 |
$commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] ); |
|
2176 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
* Filters the comment author's IP address before it is set. |
5 | 2178 |
* |
2179 |
* @since 1.5.0 |
|
2180 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2181 |
* @param string $comment_author_ip The comment author's IP address. |
5 | 2182 |
*/ |
2183 |
$commentdata['comment_author_IP'] = apply_filters( 'pre_comment_user_ip', $commentdata['comment_author_IP'] ); |
|
2184 |
/** This filter is documented in wp-includes/comment.php */ |
|
2185 |
$commentdata['comment_author_url'] = apply_filters( 'pre_comment_author_url', $commentdata['comment_author_url'] ); |
|
2186 |
/** This filter is documented in wp-includes/comment.php */ |
|
2187 |
$commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2188 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2189 |
$commentdata['filtered'] = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2190 |
|
0 | 2191 |
return $commentdata; |
2192 |
} |
|
2193 |
||
2194 |
/** |
|
19 | 2195 |
* Determines whether a comment should be blocked because of comment flood. |
0 | 2196 |
* |
2197 |
* @since 2.1.0 |
|
2198 |
* |
|
16 | 2199 |
* @param bool $block Whether plugin has already blocked comment. |
2200 |
* @param int $time_lastcomment Timestamp for last comment. |
|
2201 |
* @param int $time_newcomment Timestamp for new comment. |
|
0 | 2202 |
* @return bool Whether comment should be blocked. |
2203 |
*/ |
|
9 | 2204 |
function wp_throttle_comment_flood( $block, $time_lastcomment, $time_newcomment ) { |
16 | 2205 |
if ( $block ) { // A plugin has already blocked... we'll let that decision stand. |
0 | 2206 |
return $block; |
9 | 2207 |
} |
2208 |
if ( ( $time_newcomment - $time_lastcomment ) < 15 ) { |
|
0 | 2209 |
return true; |
9 | 2210 |
} |
0 | 2211 |
return false; |
2212 |
} |
|
2213 |
||
2214 |
/** |
|
2215 |
* Adds a new comment to the database. |
|
2216 |
* |
|
2217 |
* Filters new comment to ensure that the fields are sanitized and valid before |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2218 |
* inserting comment into database. Calls {@see 'comment_post'} action with comment ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2219 |
* and whether comment is approved by WordPress. Also has {@see 'preprocess_comment'} |
0 | 2220 |
* filter for processing the comment data before the function handles it. |
2221 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
* We use `REMOTE_ADDR` here directly. If you are behind a proxy, you should ensure |
0 | 2223 |
* that it is properly set, such as in wp-config.php, for your environment. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2224 |
* |
5 | 2225 |
* See {@link https://core.trac.wordpress.org/ticket/9235} |
0 | 2226 |
* |
2227 |
* @since 1.5.0 |
|
16 | 2228 |
* @since 4.3.0 Introduced the `comment_agent` and `comment_author_IP` arguments. |
2229 |
* @since 4.7.0 The `$avoid_die` parameter was added, allowing the function |
|
2230 |
* to return a WP_Error object instead of dying. |
|
2231 |
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`. |
|
2232 |
* @since 5.5.0 Introduced the `comment_type` argument. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2233 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2234 |
* @see wp_insert_comment() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2235 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2237 |
* @param array $commentdata { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
* Comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2240 |
* @type string $comment_author The name of the comment author. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
* @type string $comment_author_email The comment author email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2242 |
* @type string $comment_author_url The comment author URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2243 |
* @type string $comment_content The content of the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
* @type string $comment_date The date the comment was submitted. Default is the current time. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2245 |
* @type string $comment_date_gmt The date the comment was submitted in the GMT timezone. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2246 |
* Default is `$comment_date` in the GMT timezone. |
16 | 2247 |
* @type string $comment_type Comment type. Default 'comment'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2248 |
* @type int $comment_parent The ID of this comment's parent, if any. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2249 |
* @type int $comment_post_ID The ID of the post that relates to the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2250 |
* @type int $user_id The ID of the user who submitted the comment. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2251 |
* @type int $user_ID Kept for backward-compatibility. Use `$user_id` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2252 |
* @type string $comment_agent Comment author user agent. Default is the value of 'HTTP_USER_AGENT' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2253 |
* in the `$_SERVER` superglobal sent in the original request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2254 |
* @type string $comment_author_IP Comment author IP address in IPv4 format. Default is the value of |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2255 |
* 'REMOTE_ADDR' in the `$_SERVER` superglobal sent in the original request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2256 |
* } |
16 | 2257 |
* @param bool $wp_error Should errors be returned as WP_Error objects instead of |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2258 |
* executing wp_die()? Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2259 |
* @return int|false|WP_Error The ID of the comment on success, false or WP_Error on failure. |
0 | 2260 |
*/ |
16 | 2261 |
function wp_new_comment( $commentdata, $wp_error = false ) { |
5 | 2262 |
global $wpdb; |
2263 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2264 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2265 |
* Normalize `user_ID` to `user_id`, but pass the old key |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2266 |
* to the `preprocess_comment` filter for backward compatibility. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2267 |
*/ |
5 | 2268 |
if ( isset( $commentdata['user_ID'] ) ) { |
16 | 2269 |
$commentdata['user_ID'] = (int) $commentdata['user_ID']; |
2270 |
$commentdata['user_id'] = $commentdata['user_ID']; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2271 |
} elseif ( isset( $commentdata['user_id'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2272 |
$commentdata['user_id'] = (int) $commentdata['user_id']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2273 |
$commentdata['user_ID'] = $commentdata['user_id']; |
5 | 2274 |
} |
2275 |
||
2276 |
$prefiltered_user_id = ( isset( $commentdata['user_id'] ) ) ? (int) $commentdata['user_id'] : 0; |
|
2277 |
||
18 | 2278 |
if ( ! isset( $commentdata['comment_author_IP'] ) ) { |
2279 |
$commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR']; |
|
2280 |
} |
|
2281 |
||
2282 |
if ( ! isset( $commentdata['comment_agent'] ) ) { |
|
2283 |
$commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
|
2284 |
} |
|
2285 |
||
5 | 2286 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2287 |
* Filters a comment's data before it is sanitized and inserted into the database. |
5 | 2288 |
* |
2289 |
* @since 1.5.0 |
|
18 | 2290 |
* @since 5.6.0 Comment data includes the `comment_agent` and `comment_author_IP` values. |
5 | 2291 |
* |
2292 |
* @param array $commentdata Comment data. |
|
2293 |
*/ |
|
2294 |
$commentdata = apply_filters( 'preprocess_comment', $commentdata ); |
|
0 | 2295 |
|
2296 |
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID']; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2297 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2298 |
// Normalize `user_ID` to `user_id` again, after the filter. |
5 | 2299 |
if ( isset( $commentdata['user_ID'] ) && $prefiltered_user_id !== (int) $commentdata['user_ID'] ) { |
16 | 2300 |
$commentdata['user_ID'] = (int) $commentdata['user_ID']; |
2301 |
$commentdata['user_id'] = $commentdata['user_ID']; |
|
5 | 2302 |
} elseif ( isset( $commentdata['user_id'] ) ) { |
0 | 2303 |
$commentdata['user_id'] = (int) $commentdata['user_id']; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2304 |
$commentdata['user_ID'] = $commentdata['user_id']; |
5 | 2305 |
} |
0 | 2306 |
|
9 | 2307 |
$commentdata['comment_parent'] = isset( $commentdata['comment_parent'] ) ? absint( $commentdata['comment_parent'] ) : 0; |
16 | 2308 |
|
2309 |
$parent_status = ( $commentdata['comment_parent'] > 0 ) ? wp_get_comment_status( $commentdata['comment_parent'] ) : ''; |
|
2310 |
||
2311 |
$commentdata['comment_parent'] = ( 'approved' === $parent_status || 'unapproved' === $parent_status ) ? $commentdata['comment_parent'] : 0; |
|
0 | 2312 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2313 |
$commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2314 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2315 |
$commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 ); |
0 | 2316 |
|
5 | 2317 |
if ( empty( $commentdata['comment_date'] ) ) { |
9 | 2318 |
$commentdata['comment_date'] = current_time( 'mysql' ); |
5 | 2319 |
} |
2320 |
||
2321 |
if ( empty( $commentdata['comment_date_gmt'] ) ) { |
|
2322 |
$commentdata['comment_date_gmt'] = current_time( 'mysql', 1 ); |
|
2323 |
} |
|
0 | 2324 |
|
16 | 2325 |
if ( empty( $commentdata['comment_type'] ) ) { |
2326 |
$commentdata['comment_type'] = 'comment'; |
|
2327 |
} |
|
2328 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2329 |
$commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2330 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2331 |
if ( is_wp_error( $commentdata['comment_approved'] ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2332 |
return $commentdata['comment_approved']; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2333 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2334 |
|
9 | 2335 |
$commentdata = wp_filter_comment( $commentdata ); |
0 | 2336 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2337 |
if ( ! in_array( $commentdata['comment_approved'], array( 'trash', 'spam' ), true ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2338 |
// Validate the comment again after filters are applied to comment data. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2339 |
$commentdata['comment_approved'] = wp_check_comment_data( $commentdata ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2340 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2341 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2342 |
if ( is_wp_error( $commentdata['comment_approved'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2343 |
return $commentdata['comment_approved']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2344 |
} |
0 | 2345 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2346 |
$comment_id = wp_insert_comment( $commentdata ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2347 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2348 |
if ( ! $comment_id ) { |
5 | 2349 |
$fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' ); |
2350 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2351 |
foreach ( $fields as $field ) { |
5 | 2352 |
if ( isset( $commentdata[ $field ] ) ) { |
2353 |
$commentdata[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, $field, $commentdata[ $field ] ); |
|
2354 |
} |
|
2355 |
} |
|
2356 |
||
2357 |
$commentdata = wp_filter_comment( $commentdata ); |
|
2358 |
||
16 | 2359 |
$commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2360 |
if ( is_wp_error( $commentdata['comment_approved'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2361 |
return $commentdata['comment_approved']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2362 |
} |
5 | 2363 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2364 |
$comment_id = wp_insert_comment( $commentdata ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2365 |
if ( ! $comment_id ) { |
5 | 2366 |
return false; |
2367 |
} |
|
2368 |
} |
|
2369 |
||
2370 |
/** |
|
2371 |
* Fires immediately after a comment is inserted into the database. |
|
2372 |
* |
|
2373 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2374 |
* @since 4.5.0 The `$commentdata` parameter was added. |
5 | 2375 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2376 |
* @param int $comment_id The comment ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2377 |
* @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2378 |
* @param array $commentdata Comment data. |
5 | 2379 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2380 |
do_action( 'comment_post', $comment_id, $commentdata['comment_approved'], $commentdata ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2381 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2382 |
return $comment_id; |
0 | 2383 |
} |
2384 |
||
2385 |
/** |
|
19 | 2386 |
* Sends a comment moderation notification to the comment moderator. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2387 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2388 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2389 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2390 |
* @param int $comment_id ID of the comment. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2391 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2392 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2393 |
function wp_new_comment_notify_moderator( $comment_id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2394 |
$comment = get_comment( $comment_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2395 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2396 |
// Only send notifications for pending comments. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2397 |
$maybe_notify = ( '0' === $comment->comment_approved ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2398 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2399 |
/** This filter is documented in wp-includes/pluggable.php */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2400 |
$maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2401 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2402 |
if ( ! $maybe_notify ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2403 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2404 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2405 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2406 |
return wp_notify_moderator( $comment_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2407 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2408 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2409 |
/** |
19 | 2410 |
* Sends a notification of a new comment to the post author. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2411 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2412 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2413 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2414 |
* Uses the {@see 'notify_post_author'} filter to determine whether the post author |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2415 |
* should be notified when a new comment is added, overriding site setting. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2416 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2417 |
* @param int $comment_id Comment ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2418 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2419 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2420 |
function wp_new_comment_notify_postauthor( $comment_id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2421 |
$comment = get_comment( $comment_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2422 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2423 |
$maybe_notify = get_option( 'comments_notify' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2424 |
|
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 |
* Filters whether to send the post author new comment notification emails, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2427 |
* overriding the site setting. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2428 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2429 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2430 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2431 |
* @param bool $maybe_notify Whether to notify the post author about the new comment. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2432 |
* @param int $comment_id The ID of the comment for the notification. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2433 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2434 |
$maybe_notify = apply_filters( 'notify_post_author', $maybe_notify, $comment_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2435 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2436 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2437 |
* wp_notify_postauthor() checks if notifying the author of their own comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2438 |
* By default, it won't, but filters can override this. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2439 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2440 |
if ( ! $maybe_notify ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2441 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2442 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2443 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2444 |
// Only send notifications for approved comments. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2445 |
if ( ! isset( $comment->comment_approved ) || '1' !== $comment->comment_approved ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2446 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2447 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2448 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2449 |
return wp_notify_postauthor( $comment_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2450 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2451 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2452 |
/** |
0 | 2453 |
* Sets the status of a comment. |
2454 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2455 |
* The {@see 'wp_set_comment_status'} action is called after the comment is handled. |
0 | 2456 |
* If the comment status is not in the list, then false is returned. |
2457 |
* |
|
2458 |
* @since 1.0.0 |
|
2459 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2460 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2461 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2462 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2463 |
* @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'. |
16 | 2464 |
* @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default false. |
0 | 2465 |
* @return bool|WP_Error True on success, false or WP_Error on failure. |
2466 |
*/ |
|
9 | 2467 |
function wp_set_comment_status( $comment_id, $comment_status, $wp_error = false ) { |
0 | 2468 |
global $wpdb; |
2469 |
||
2470 |
switch ( $comment_status ) { |
|
2471 |
case 'hold': |
|
2472 |
case '0': |
|
2473 |
$status = '0'; |
|
2474 |
break; |
|
2475 |
case 'approve': |
|
2476 |
case '1': |
|
2477 |
$status = '1'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2478 |
add_action( 'wp_set_comment_status', 'wp_new_comment_notify_postauthor' ); |
0 | 2479 |
break; |
2480 |
case 'spam': |
|
2481 |
$status = 'spam'; |
|
2482 |
break; |
|
2483 |
case 'trash': |
|
2484 |
$status = 'trash'; |
|
2485 |
break; |
|
2486 |
default: |
|
2487 |
return false; |
|
2488 |
} |
|
2489 |
||
9 | 2490 |
$comment_old = clone get_comment( $comment_id ); |
2491 |
||
2492 |
if ( ! $wpdb->update( $wpdb->comments, array( 'comment_approved' => $status ), array( 'comment_ID' => $comment_old->comment_ID ) ) ) { |
|
2493 |
if ( $wp_error ) { |
|
16 | 2494 |
return new WP_Error( 'db_update_error', __( 'Could not update comment status.' ), $wpdb->last_error ); |
9 | 2495 |
} else { |
0 | 2496 |
return false; |
9 | 2497 |
} |
0 | 2498 |
} |
2499 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2500 |
clean_comment_cache( $comment_old->comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2501 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2502 |
$comment = get_comment( $comment_old->comment_ID ); |
0 | 2503 |
|
5 | 2504 |
/** |
18 | 2505 |
* Fires immediately after transitioning a comment's status from one to another in the database |
2506 |
* and removing the comment from the object cache, but prior to all status transition hooks. |
|
5 | 2507 |
* |
2508 |
* @since 1.5.0 |
|
2509 |
* |
|
19 | 2510 |
* @param string $comment_id Comment ID as a numeric string. |
18 | 2511 |
* @param string $comment_status Current comment status. Possible values include |
2512 |
* 'hold', '0', 'approve', '1', 'spam', and 'trash'. |
|
5 | 2513 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2514 |
do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); |
5 | 2515 |
|
9 | 2516 |
wp_transition_comment_status( $comment_status, $comment_old->comment_approved, $comment ); |
2517 |
||
2518 |
wp_update_comment_count( $comment->comment_post_ID ); |
|
0 | 2519 |
|
2520 |
return true; |
|
2521 |
} |
|
2522 |
||
2523 |
/** |
|
2524 |
* Updates an existing comment in the database. |
|
2525 |
* |
|
2526 |
* Filters the comment and makes sure certain fields are valid before updating. |
|
2527 |
* |
|
2528 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2529 |
* @since 4.9.0 Add updating comment meta during comment update. |
16 | 2530 |
* @since 5.5.0 The `$wp_error` parameter was added. |
2531 |
* @since 5.5.0 The return values for an invalid comment or post ID |
|
2532 |
* were changed to false instead of 0. |
|
5 | 2533 |
* |
2534 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 2535 |
* |
2536 |
* @param array $commentarr Contains information on the comment. |
|
16 | 2537 |
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. |
2538 |
* @return int|false|WP_Error The value 1 if the comment was updated, 0 if not updated. |
|
2539 |
* False or a WP_Error object on failure. |
|
0 | 2540 |
*/ |
16 | 2541 |
function wp_update_comment( $commentarr, $wp_error = false ) { |
0 | 2542 |
global $wpdb; |
2543 |
||
16 | 2544 |
// First, get all of the original fields. |
9 | 2545 |
$comment = get_comment( $commentarr['comment_ID'], ARRAY_A ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2546 |
|
5 | 2547 |
if ( empty( $comment ) ) { |
16 | 2548 |
if ( $wp_error ) { |
2549 |
return new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) ); |
|
2550 |
} else { |
|
2551 |
return false; |
|
2552 |
} |
|
5 | 2553 |
} |
2554 |
||
2555 |
// Make sure that the comment post ID is valid (if specified). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2556 |
if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) { |
16 | 2557 |
if ( $wp_error ) { |
2558 |
return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) ); |
|
2559 |
} else { |
|
2560 |
return false; |
|
2561 |
} |
|
5 | 2562 |
} |
0 | 2563 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2564 |
$filter_comment = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2565 |
if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2566 |
$filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2567 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2568 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2569 |
if ( $filter_comment ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2570 |
add_filter( 'pre_comment_content', 'wp_filter_kses' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2571 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2572 |
|
0 | 2573 |
// Escape data pulled from DB. |
9 | 2574 |
$comment = wp_slash( $comment ); |
0 | 2575 |
|
2576 |
$old_status = $comment['comment_approved']; |
|
2577 |
||
2578 |
// Merge old and new fields with new fields overwriting old ones. |
|
9 | 2579 |
$commentarr = array_merge( $comment, $commentarr ); |
0 | 2580 |
|
2581 |
$commentarr = wp_filter_comment( $commentarr ); |
|
2582 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2583 |
if ( $filter_comment ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2584 |
remove_filter( 'pre_comment_content', 'wp_filter_kses' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2585 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2586 |
|
0 | 2587 |
// Now extract the merged array. |
5 | 2588 |
$data = wp_unslash( $commentarr ); |
2589 |
||
2590 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2591 |
* Filters the comment content before it is updated in the database. |
5 | 2592 |
* |
2593 |
* @since 1.5.0 |
|
2594 |
* |
|
2595 |
* @param string $comment_content The comment data. |
|
2596 |
*/ |
|
2597 |
$data['comment_content'] = apply_filters( 'comment_save_pre', $data['comment_content'] ); |
|
2598 |
||
2599 |
$data['comment_date_gmt'] = get_gmt_from_date( $data['comment_date'] ); |
|
2600 |
||
2601 |
if ( ! isset( $data['comment_approved'] ) ) { |
|
2602 |
$data['comment_approved'] = 1; |
|
16 | 2603 |
} elseif ( 'hold' === $data['comment_approved'] ) { |
5 | 2604 |
$data['comment_approved'] = 0; |
16 | 2605 |
} elseif ( 'approve' === $data['comment_approved'] ) { |
5 | 2606 |
$data['comment_approved'] = 1; |
2607 |
} |
|
2608 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2609 |
$comment_id = $data['comment_ID']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2610 |
$comment_post_id = $data['comment_post_ID']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2611 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2612 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2613 |
* Filters the comment data immediately before it is updated in the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2614 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2615 |
* Note: data being passed to the filter is already unslashed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2616 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2617 |
* @since 4.7.0 |
16 | 2618 |
* @since 5.5.0 Returning a WP_Error value from the filter will short-circuit comment update |
2619 |
* and allow skipping further processing. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2620 |
* |
16 | 2621 |
* @param array|WP_Error $data The new, processed comment data, or WP_Error. |
2622 |
* @param array $comment The old, unslashed comment data. |
|
2623 |
* @param array $commentarr The new, raw comment data. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2624 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2625 |
$data = apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2626 |
|
16 | 2627 |
// Do not carry on on failure. |
2628 |
if ( is_wp_error( $data ) ) { |
|
2629 |
if ( $wp_error ) { |
|
2630 |
return $data; |
|
2631 |
} else { |
|
2632 |
return false; |
|
2633 |
} |
|
2634 |
} |
|
2635 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2636 |
$keys = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2637 |
'comment_post_ID', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2638 |
'comment_author', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2639 |
'comment_author_email', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2640 |
'comment_author_url', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2641 |
'comment_author_IP', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2642 |
'comment_date', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2643 |
'comment_date_gmt', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2644 |
'comment_content', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2645 |
'comment_karma', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2646 |
'comment_approved', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2647 |
'comment_agent', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2648 |
'comment_type', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2649 |
'comment_parent', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2650 |
'user_id', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2651 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2652 |
|
5 | 2653 |
$data = wp_array_slice_assoc( $data, $keys ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2654 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2655 |
$result = $wpdb->update( $wpdb->comments, $data, array( 'comment_ID' => $comment_id ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2656 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2657 |
if ( false === $result ) { |
16 | 2658 |
if ( $wp_error ) { |
2659 |
return new WP_Error( 'db_update_error', __( 'Could not update comment in the database.' ), $wpdb->last_error ); |
|
2660 |
} else { |
|
2661 |
return false; |
|
2662 |
} |
|
2663 |
} |
|
2664 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2665 |
// If metadata is provided, store it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2666 |
if ( isset( $commentarr['comment_meta'] ) && is_array( $commentarr['comment_meta'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2667 |
foreach ( $commentarr['comment_meta'] as $meta_key => $meta_value ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2668 |
update_comment_meta( $comment_id, $meta_key, $meta_value ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2669 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2670 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2671 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2672 |
clean_comment_cache( $comment_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2673 |
wp_update_comment_count( $comment_post_id ); |
16 | 2674 |
|
5 | 2675 |
/** |
2676 |
* Fires immediately after a comment is updated in the database. |
|
2677 |
* |
|
2678 |
* The hook also fires immediately before comment status transition hooks are fired. |
|
2679 |
* |
|
2680 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2681 |
* @since 4.6.0 Added the `$data` parameter. |
5 | 2682 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2683 |
* @param int $comment_id The comment ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2684 |
* @param array $data Comment data. |
5 | 2685 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2686 |
do_action( 'edit_comment', $comment_id, $data ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2687 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2688 |
$comment = get_comment( $comment_id ); |
16 | 2689 |
|
9 | 2690 |
wp_transition_comment_status( $comment->comment_approved, $old_status, $comment ); |
16 | 2691 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2692 |
return $result; |
0 | 2693 |
} |
2694 |
||
2695 |
/** |
|
19 | 2696 |
* Determines whether to defer comment counting. |
0 | 2697 |
* |
2698 |
* When setting $defer to true, all post comment counts will not be updated |
|
2699 |
* until $defer is set to false. When $defer is set to false, then all |
|
2700 |
* previously deferred updated post comment counts will then be automatically |
|
2701 |
* updated without having to call wp_update_comment_count() after. |
|
2702 |
* |
|
2703 |
* @since 2.5.0 |
|
2704 |
* |
|
2705 |
* @param bool $defer |
|
5 | 2706 |
* @return bool |
0 | 2707 |
*/ |
9 | 2708 |
function wp_defer_comment_counting( $defer = null ) { |
0 | 2709 |
static $_defer = false; |
2710 |
||
9 | 2711 |
if ( is_bool( $defer ) ) { |
0 | 2712 |
$_defer = $defer; |
16 | 2713 |
// Flush any deferred counts. |
9 | 2714 |
if ( ! $defer ) { |
0 | 2715 |
wp_update_comment_count( null, true ); |
9 | 2716 |
} |
0 | 2717 |
} |
2718 |
||
2719 |
return $_defer; |
|
2720 |
} |
|
2721 |
||
2722 |
/** |
|
2723 |
* Updates the comment count for post(s). |
|
2724 |
* |
|
2725 |
* When $do_deferred is false (is by default) and the comments have been set to |
|
2726 |
* be deferred, the post_id will be added to a queue, which will be updated at a |
|
2727 |
* later date and only updated once per post ID. |
|
2728 |
* |
|
2729 |
* If the comments have not be set up to be deferred, then the post will be |
|
2730 |
* updated. When $do_deferred is set to true, then all previous deferred post |
|
2731 |
* IDs will be updated along with the current $post_id. |
|
2732 |
* |
|
2733 |
* @since 2.1.0 |
|
16 | 2734 |
* |
0 | 2735 |
* @see wp_update_comment_count_now() For what could cause a false return value |
2736 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2737 |
* @param int|null $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2738 |
* @param bool $do_deferred Optional. Whether to process previously deferred |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2739 |
* post comment counts. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2740 |
* @return bool|void True on success, false on failure or if post with ID does |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2741 |
* not exist. |
0 | 2742 |
*/ |
9 | 2743 |
function wp_update_comment_count( $post_id, $do_deferred = false ) { |
0 | 2744 |
static $_deferred = array(); |
2745 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2746 |
if ( empty( $post_id ) && ! $do_deferred ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2747 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2748 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2749 |
|
0 | 2750 |
if ( $do_deferred ) { |
9 | 2751 |
$_deferred = array_unique( $_deferred ); |
0 | 2752 |
foreach ( $_deferred as $i => $_post_id ) { |
9 | 2753 |
wp_update_comment_count_now( $_post_id ); |
2754 |
unset( $_deferred[ $i ] ); |
|
2755 |
/** @todo Move this outside of the foreach and reset $_deferred to an array instead */ |
|
0 | 2756 |
} |
2757 |
} |
|
2758 |
||
2759 |
if ( wp_defer_comment_counting() ) { |
|
2760 |
$_deferred[] = $post_id; |
|
2761 |
return true; |
|
9 | 2762 |
} elseif ( $post_id ) { |
2763 |
return wp_update_comment_count_now( $post_id ); |
|
0 | 2764 |
} |
2765 |
} |
|
2766 |
||
2767 |
/** |
|
2768 |
* Updates the comment count for the post. |
|
2769 |
* |
|
2770 |
* @since 2.5.0 |
|
5 | 2771 |
* |
2772 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 2773 |
* |
2774 |
* @param int $post_id Post ID |
|
16 | 2775 |
* @return bool True on success, false if the post does not exist. |
0 | 2776 |
*/ |
9 | 2777 |
function wp_update_comment_count_now( $post_id ) { |
0 | 2778 |
global $wpdb; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2779 |
|
0 | 2780 |
$post_id = (int) $post_id; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2781 |
|
9 | 2782 |
if ( ! $post_id ) { |
0 | 2783 |
return false; |
9 | 2784 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2785 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2786 |
wp_cache_delete( 'comments-0', 'counts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2787 |
wp_cache_delete( "comments-{$post_id}", 'counts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2788 |
|
16 | 2789 |
$post = get_post( $post_id ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2790 |
|
16 | 2791 |
if ( ! $post ) { |
0 | 2792 |
return false; |
9 | 2793 |
} |
0 | 2794 |
|
2795 |
$old = (int) $post->comment_count; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2796 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2797 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2798 |
* Filters a post's comment count before it is updated in the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2799 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2800 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2801 |
* |
16 | 2802 |
* @param int|null $new The new comment count. Default null. |
2803 |
* @param int $old The old comment count. |
|
2804 |
* @param int $post_id Post ID. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2805 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2806 |
$new = apply_filters( 'pre_wp_update_comment_count_now', null, $old, $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2807 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2808 |
if ( is_null( $new ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2809 |
$new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2810 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2811 |
$new = (int) $new; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2812 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2813 |
|
9 | 2814 |
$wpdb->update( $wpdb->posts, array( 'comment_count' => $new ), array( 'ID' => $post_id ) ); |
0 | 2815 |
|
2816 |
clean_post_cache( $post ); |
|
2817 |
||
5 | 2818 |
/** |
2819 |
* Fires immediately after a post's comment count is updated in the database. |
|
2820 |
* |
|
2821 |
* @since 2.3.0 |
|
2822 |
* |
|
2823 |
* @param int $post_id Post ID. |
|
2824 |
* @param int $new The new comment count. |
|
2825 |
* @param int $old The old comment count. |
|
2826 |
*/ |
|
2827 |
do_action( 'wp_update_comment_count', $post_id, $new, $old ); |
|
9 | 2828 |
|
2829 |
/** This action is documented in wp-includes/post.php */ |
|
2830 |
do_action( "edit_post_{$post->post_type}", $post_id, $post ); |
|
2831 |
||
5 | 2832 |
/** This action is documented in wp-includes/post.php */ |
2833 |
do_action( 'edit_post', $post_id, $post ); |
|
0 | 2834 |
|
2835 |
return true; |
|
2836 |
} |
|
2837 |
||
2838 |
// |
|
2839 |
// Ping and trackback functions. |
|
2840 |
// |
|
2841 |
||
2842 |
/** |
|
2843 |
* Finds a pingback server URI based on the given URL. |
|
2844 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2845 |
* Checks the HTML for the rel="pingback" link and X-Pingback headers. It does |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2846 |
* a check for the X-Pingback headers first and returns that, if available. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2847 |
* The check for the rel="pingback" has more overhead than just the header. |
0 | 2848 |
* |
2849 |
* @since 1.5.0 |
|
2850 |
* |
|
16 | 2851 |
* @param string $url URL to ping. |
18 | 2852 |
* @param string $deprecated Not Used. |
16 | 2853 |
* @return string|false String containing URI on success, false on failure. |
0 | 2854 |
*/ |
2855 |
function discover_pingback_server_uri( $url, $deprecated = '' ) { |
|
9 | 2856 |
if ( ! empty( $deprecated ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
_deprecated_argument( __FUNCTION__, '2.7.0' ); |
9 | 2858 |
} |
0 | 2859 |
|
2860 |
$pingback_str_dquote = 'rel="pingback"'; |
|
2861 |
$pingback_str_squote = 'rel=\'pingback\''; |
|
2862 |
||
2863 |
/** @todo Should use Filter Extension or custom preg_match instead. */ |
|
9 | 2864 |
$parsed_url = parse_url( $url ); |
2865 |
||
2866 |
if ( ! isset( $parsed_url['host'] ) ) { // Not a URL. This should never happen. |
|
0 | 2867 |
return false; |
9 | 2868 |
} |
0 | 2869 |
|
16 | 2870 |
// Do not search for a pingback server on our own uploads. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2871 |
$uploads_dir = wp_get_upload_dir(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2872 |
if ( str_starts_with( $url, $uploads_dir['baseurl'] ) ) { |
0 | 2873 |
return false; |
9 | 2874 |
} |
2875 |
||
2876 |
$response = wp_safe_remote_head( |
|
2877 |
$url, |
|
2878 |
array( |
|
2879 |
'timeout' => 2, |
|
2880 |
'httpversion' => '1.0', |
|
2881 |
) |
|
2882 |
); |
|
2883 |
||
2884 |
if ( is_wp_error( $response ) ) { |
|
0 | 2885 |
return false; |
9 | 2886 |
} |
2887 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2888 |
if ( wp_remote_retrieve_header( $response, 'X-Pingback' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2889 |
return wp_remote_retrieve_header( $response, 'X-Pingback' ); |
9 | 2890 |
} |
0 | 2891 |
|
2892 |
// Not an (x)html, sgml, or xml page, no use going further. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2893 |
if ( preg_match( '#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'Content-Type' ) ) ) { |
0 | 2894 |
return false; |
9 | 2895 |
} |
0 | 2896 |
|
16 | 2897 |
// Now do a GET since we're going to look in the HTML headers (and we're sure it's not a binary file). |
9 | 2898 |
$response = wp_safe_remote_get( |
2899 |
$url, |
|
2900 |
array( |
|
2901 |
'timeout' => 2, |
|
2902 |
'httpversion' => '1.0', |
|
2903 |
) |
|
2904 |
); |
|
2905 |
||
2906 |
if ( is_wp_error( $response ) ) { |
|
0 | 2907 |
return false; |
9 | 2908 |
} |
0 | 2909 |
|
2910 |
$contents = wp_remote_retrieve_body( $response ); |
|
2911 |
||
9 | 2912 |
$pingback_link_offset_dquote = strpos( $contents, $pingback_str_dquote ); |
2913 |
$pingback_link_offset_squote = strpos( $contents, $pingback_str_squote ); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2914 |
|
0 | 2915 |
if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) { |
9 | 2916 |
$quote = ( $pingback_link_offset_dquote ) ? '"' : '\''; |
16 | 2917 |
$pingback_link_offset = ( '"' === $quote ) ? $pingback_link_offset_dquote : $pingback_link_offset_squote; |
2918 |
$pingback_href_pos = strpos( $contents, 'href=', $pingback_link_offset ); |
|
9 | 2919 |
$pingback_href_start = $pingback_href_pos + 6; |
16 | 2920 |
$pingback_href_end = strpos( $contents, $quote, $pingback_href_start ); |
0 | 2921 |
$pingback_server_url_len = $pingback_href_end - $pingback_href_start; |
9 | 2922 |
$pingback_server_url = substr( $contents, $pingback_href_start, $pingback_server_url_len ); |
0 | 2923 |
|
16 | 2924 |
// We may find rel="pingback" but an incomplete pingback URL. |
0 | 2925 |
if ( $pingback_server_url_len > 0 ) { // We got it! |
2926 |
return $pingback_server_url; |
|
2927 |
} |
|
2928 |
} |
|
2929 |
||
2930 |
return false; |
|
2931 |
} |
|
2932 |
||
2933 |
/** |
|
19 | 2934 |
* Performs all pingbacks, enclosures, trackbacks, and sends to pingback services. |
0 | 2935 |
* |
2936 |
* @since 2.1.0 |
|
18 | 2937 |
* @since 5.6.0 Introduced `do_all_pings` action hook for individual services. |
0 | 2938 |
*/ |
2939 |
function do_all_pings() { |
|
18 | 2940 |
/** |
2941 |
* Fires immediately after the `do_pings` event to hook services individually. |
|
2942 |
* |
|
2943 |
* @since 5.6.0 |
|
2944 |
*/ |
|
2945 |
do_action( 'do_all_pings' ); |
|
2946 |
} |
|
2947 |
||
2948 |
/** |
|
19 | 2949 |
* Performs all pingbacks. |
18 | 2950 |
* |
2951 |
* @since 5.6.0 |
|
2952 |
*/ |
|
2953 |
function do_all_pingbacks() { |
|
16 | 2954 |
$pings = get_posts( |
2955 |
array( |
|
2956 |
'post_type' => get_post_types(), |
|
2957 |
'suppress_filters' => false, |
|
2958 |
'nopaging' => true, |
|
2959 |
'meta_key' => '_pingme', |
|
2960 |
'fields' => 'ids', |
|
2961 |
) |
|
2962 |
); |
|
2963 |
||
2964 |
foreach ( $pings as $ping ) { |
|
2965 |
delete_post_meta( $ping, '_pingme' ); |
|
2966 |
pingback( null, $ping ); |
|
0 | 2967 |
} |
18 | 2968 |
} |
2969 |
||
2970 |
/** |
|
19 | 2971 |
* Performs all enclosures. |
18 | 2972 |
* |
2973 |
* @since 5.6.0 |
|
2974 |
*/ |
|
2975 |
function do_all_enclosures() { |
|
16 | 2976 |
$enclosures = get_posts( |
2977 |
array( |
|
2978 |
'post_type' => get_post_types(), |
|
2979 |
'suppress_filters' => false, |
|
2980 |
'nopaging' => true, |
|
2981 |
'meta_key' => '_encloseme', |
|
2982 |
'fields' => 'ids', |
|
2983 |
) |
|
2984 |
); |
|
2985 |
||
2986 |
foreach ( $enclosures as $enclosure ) { |
|
2987 |
delete_post_meta( $enclosure, '_encloseme' ); |
|
2988 |
do_enclose( null, $enclosure ); |
|
9 | 2989 |
} |
18 | 2990 |
} |
2991 |
||
2992 |
/** |
|
19 | 2993 |
* Performs all trackbacks. |
18 | 2994 |
* |
2995 |
* @since 5.6.0 |
|
2996 |
*/ |
|
2997 |
function do_all_trackbacks() { |
|
16 | 2998 |
$trackbacks = get_posts( |
2999 |
array( |
|
3000 |
'post_type' => get_post_types(), |
|
3001 |
'suppress_filters' => false, |
|
3002 |
'nopaging' => true, |
|
3003 |
'meta_key' => '_trackbackme', |
|
3004 |
'fields' => 'ids', |
|
3005 |
) |
|
3006 |
); |
|
3007 |
||
3008 |
foreach ( $trackbacks as $trackback ) { |
|
3009 |
delete_post_meta( $trackback, '_trackbackme' ); |
|
3010 |
do_trackbacks( $trackback ); |
|
3011 |
} |
|
0 | 3012 |
} |
3013 |
||
3014 |
/** |
|
19 | 3015 |
* Performs trackbacks. |
0 | 3016 |
* |
3017 |
* @since 1.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3018 |
* @since 4.7.0 `$post` can be a WP_Post object. |
5 | 3019 |
* |
3020 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 3021 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3022 |
* @param int|WP_Post $post Post ID or object to do trackbacks on. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3023 |
* @return void|false Returns false on failure. |
0 | 3024 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3025 |
function do_trackbacks( $post ) { |
0 | 3026 |
global $wpdb; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3027 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3028 |
$post = get_post( $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3029 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3030 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3031 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3032 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3033 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3034 |
$to_ping = get_to_ping( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3035 |
$pinged = get_pung( $post ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3036 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3037 |
if ( empty( $to_ping ) ) { |
9 | 3038 |
$wpdb->update( $wpdb->posts, array( 'to_ping' => '' ), array( 'ID' => $post->ID ) ); |
0 | 3039 |
return; |
3040 |
} |
|
3041 |
||
9 | 3042 |
if ( empty( $post->post_excerpt ) ) { |
5 | 3043 |
/** This filter is documented in wp-includes/post-template.php */ |
3044 |
$excerpt = apply_filters( 'the_content', $post->post_content, $post->ID ); |
|
3045 |
} else { |
|
3046 |
/** This filter is documented in wp-includes/post-template.php */ |
|
3047 |
$excerpt = apply_filters( 'the_excerpt', $post->post_excerpt ); |
|
3048 |
} |
|
3049 |
||
9 | 3050 |
$excerpt = str_replace( ']]>', ']]>', $excerpt ); |
3051 |
$excerpt = wp_html_excerpt( $excerpt, 252, '…' ); |
|
0 | 3052 |
|
3053 |
/** This filter is documented in wp-includes/post-template.php */ |
|
5 | 3054 |
$post_title = apply_filters( 'the_title', $post->post_title, $post->ID ); |
9 | 3055 |
$post_title = strip_tags( $post_title ); |
0 | 3056 |
|
3057 |
if ( $to_ping ) { |
|
3058 |
foreach ( (array) $to_ping as $tb_ping ) { |
|
9 | 3059 |
$tb_ping = trim( $tb_ping ); |
16 | 3060 |
if ( ! in_array( $tb_ping, $pinged, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3061 |
trackback( $tb_ping, $post_title, $excerpt, $post->ID ); |
0 | 3062 |
$pinged[] = $tb_ping; |
3063 |
} else { |
|
9 | 3064 |
$wpdb->query( |
3065 |
$wpdb->prepare( |
|
3066 |
"UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, |
|
3067 |
'')) WHERE ID = %d", |
|
3068 |
$tb_ping, |
|
3069 |
$post->ID |
|
3070 |
) |
|
3071 |
); |
|
0 | 3072 |
} |
3073 |
} |
|
3074 |
} |
|
3075 |
} |
|
3076 |
||
3077 |
/** |
|
3078 |
* Sends pings to all of the ping site services. |
|
3079 |
* |
|
3080 |
* @since 1.2.0 |
|
3081 |
* |
|
5 | 3082 |
* @param int $post_id Post ID. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3083 |
* @return int Same post ID as provided. |
0 | 3084 |
*/ |
5 | 3085 |
function generic_ping( $post_id = 0 ) { |
9 | 3086 |
$services = get_option( 'ping_sites' ); |
3087 |
||
3088 |
$services = explode( "\n", $services ); |
|
0 | 3089 |
foreach ( (array) $services as $service ) { |
9 | 3090 |
$service = trim( $service ); |
16 | 3091 |
if ( '' !== $service ) { |
9 | 3092 |
weblog_ping( $service ); |
3093 |
} |
|
0 | 3094 |
} |
3095 |
||
3096 |
return $post_id; |
|
3097 |
} |
|
3098 |
||
3099 |
/** |
|
3100 |
* Pings back the links found in a post. |
|
3101 |
* |
|
3102 |
* @since 0.71 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3103 |
* @since 4.7.0 `$post` can be a WP_Post object. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3104 |
* @since 6.8.0 Returns an array of pingback statuses indexed by link. |
0 | 3105 |
* |
16 | 3106 |
* @param string $content Post content to check for links. If empty will retrieve from post. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3107 |
* @param int|WP_Post $post Post ID or object. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3108 |
* @return array<string, bool> An array of pingback statuses indexed by link. |
0 | 3109 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3110 |
function pingback( $content, $post ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3111 |
require_once ABSPATH . WPINC . '/class-IXR.php'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3112 |
require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php'; |
16 | 3113 |
|
3114 |
// Original code by Mort (http://mort.mine.nu:8080). |
|
0 | 3115 |
$post_links = array(); |
3116 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3117 |
$post = get_post( $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3118 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
if ( ! $post ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3120 |
return array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3122 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3123 |
$pung = get_pung( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3124 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3125 |
if ( empty( $content ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3126 |
$content = $post->post_content; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
} |
0 | 3128 |
|
16 | 3129 |
/* |
3130 |
* Step 1. |
|
3131 |
* Parsing the post, external links (if any) are stored in the $post_links array. |
|
3132 |
*/ |
|
0 | 3133 |
$post_links_temp = wp_extract_urls( $content ); |
3134 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3135 |
$ping_status = array(); |
16 | 3136 |
/* |
3137 |
* Step 2. |
|
3138 |
* Walking through the links array. |
|
3139 |
* First we get rid of links pointing to sites, not to specific files. |
|
3140 |
* Example: |
|
3141 |
* http://dummy-weblog.org |
|
3142 |
* http://dummy-weblog.org/ |
|
3143 |
* http://dummy-weblog.org/post.php |
|
3144 |
* We don't wanna ping first and second types, even if they have a valid <link/>. |
|
3145 |
*/ |
|
3146 |
foreach ( (array) $post_links_temp as $link_test ) { |
|
3147 |
// If we haven't pung it already and it isn't a link to itself. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3148 |
if ( ! in_array( $link_test, $pung, true ) && ( url_to_postid( $link_test ) !== $post->ID ) |
16 | 3149 |
// Also, let's never ping local attachments. |
3150 |
&& ! is_local_attachment( $link_test ) |
|
3151 |
) { |
|
3152 |
$test = parse_url( $link_test ); |
|
3153 |
if ( $test ) { |
|
9 | 3154 |
if ( isset( $test['query'] ) ) { |
0 | 3155 |
$post_links[] = $link_test; |
16 | 3156 |
} elseif ( isset( $test['path'] ) && ( '/' !== $test['path'] ) && ( '' !== $test['path'] ) ) { |
0 | 3157 |
$post_links[] = $link_test; |
9 | 3158 |
} |
0 | 3159 |
} |
16 | 3160 |
} |
3161 |
} |
|
0 | 3162 |
|
3163 |
$post_links = array_unique( $post_links ); |
|
16 | 3164 |
|
5 | 3165 |
/** |
3166 |
* Fires just before pinging back links found in a post. |
|
3167 |
* |
|
3168 |
* @since 2.0.0 |
|
3169 |
* |
|
9 | 3170 |
* @param string[] $post_links Array of link URLs to be checked (passed by reference). |
3171 |
* @param string[] $pung Array of link URLs already pinged (passed by reference). |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3172 |
* @param int $post_id The post ID. |
5 | 3173 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3174 |
do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post->ID ) ); |
0 | 3175 |
|
3176 |
foreach ( (array) $post_links as $pagelinkedto ) { |
|
3177 |
$pingback_server_url = discover_pingback_server_uri( $pagelinkedto ); |
|
3178 |
||
3179 |
if ( $pingback_server_url ) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3180 |
// Allow an additional 60 seconds for each pingback to complete. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3181 |
if ( function_exists( 'set_time_limit' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3182 |
set_time_limit( 60 ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3183 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3184 |
|
16 | 3185 |
// Now, the RPC call. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3186 |
$pagelinkedfrom = get_permalink( $post ); |
0 | 3187 |
|
16 | 3188 |
// Using a timeout of 3 seconds should be enough to cover slow servers. |
9 | 3189 |
$client = new WP_HTTP_IXR_Client( $pingback_server_url ); |
0 | 3190 |
$client->timeout = 3; |
5 | 3191 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3192 |
* Filters the user agent sent when pinging-back a URL. |
5 | 3193 |
* |
3194 |
* @since 2.9.0 |
|
3195 |
* |
|
3196 |
* @param string $concat_useragent The user agent concatenated with ' -- WordPress/' |
|
3197 |
* and the WordPress version. |
|
3198 |
* @param string $useragent The useragent. |
|
3199 |
* @param string $pingback_server_url The server URL being linked to. |
|
3200 |
* @param string $pagelinkedto URL of page linked to. |
|
3201 |
* @param string $pagelinkedfrom URL of page linked from. |
|
3202 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3203 |
$client->useragent = apply_filters( 'pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo( 'version' ), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom ); |
16 | 3204 |
// When set to true, this outputs debug messages by itself. |
0 | 3205 |
$client->debug = false; |
3206 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3207 |
$status = $client->query( 'pingback.ping', $pagelinkedfrom, $pagelinkedto ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3208 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3209 |
if ( $status // Ping registered. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3210 |
|| ( isset( $client->error->code ) && 48 === $client->error->code ) // Already registered. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3211 |
) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3212 |
add_ping( $post, $pagelinkedto ); |
9 | 3213 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3214 |
$ping_status[ $pagelinkedto ] = $status; |
0 | 3215 |
} |
3216 |
} |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3217 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3218 |
return $ping_status; |
0 | 3219 |
} |
3220 |
||
3221 |
/** |
|
19 | 3222 |
* Checks whether blog is public before returning sites. |
0 | 3223 |
* |
3224 |
* @since 2.1.0 |
|
3225 |
* |
|
3226 |
* @param mixed $sites Will return if blog is public, will not return if not public. |
|
3227 |
* @return mixed Empty string if blog is not public, returns $sites, if site is public. |
|
3228 |
*/ |
|
9 | 3229 |
function privacy_ping_filter( $sites ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3230 |
if ( '0' !== get_option( 'blog_public' ) ) { |
0 | 3231 |
return $sites; |
9 | 3232 |
} else { |
0 | 3233 |
return ''; |
9 | 3234 |
} |
0 | 3235 |
} |
3236 |
||
3237 |
/** |
|
19 | 3238 |
* Sends a Trackback. |
0 | 3239 |
* |
3240 |
* Updates database when sending trackback to prevent duplicates. |
|
3241 |
* |
|
3242 |
* @since 0.71 |
|
5 | 3243 |
* |
3244 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 3245 |
* |
3246 |
* @param string $trackback_url URL to send trackbacks. |
|
16 | 3247 |
* @param string $title Title of post. |
3248 |
* @param string $excerpt Excerpt of post. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3249 |
* @param int $post_id Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3250 |
* @return int|false|void Database query from update. |
0 | 3251 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3252 |
function trackback( $trackback_url, $title, $excerpt, $post_id ) { |
0 | 3253 |
global $wpdb; |
3254 |
||
9 | 3255 |
if ( empty( $trackback_url ) ) { |
0 | 3256 |
return; |
9 | 3257 |
} |
3258 |
||
3259 |
$options = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3260 |
$options['timeout'] = 10; |
9 | 3261 |
$options['body'] = array( |
3262 |
'title' => $title, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3263 |
'url' => get_permalink( $post_id ), |
9 | 3264 |
'blog_name' => get_option( 'blogname' ), |
3265 |
'excerpt' => $excerpt, |
|
0 | 3266 |
); |
3267 |
||
3268 |
$response = wp_safe_remote_post( $trackback_url, $options ); |
|
3269 |
||
9 | 3270 |
if ( is_wp_error( $response ) ) { |
0 | 3271 |
return; |
9 | 3272 |
} |
3273 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3274 |
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $post_id ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3275 |
return $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $post_id ) ); |
0 | 3276 |
} |
3277 |
||
3278 |
/** |
|
19 | 3279 |
* Sends a pingback. |
0 | 3280 |
* |
3281 |
* @since 1.2.0 |
|
3282 |
* |
|
3283 |
* @param string $server Host of blog to connect to. |
|
3284 |
* @param string $path Path to send the ping. |
|
3285 |
*/ |
|
9 | 3286 |
function weblog_ping( $server = '', $path = '' ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3287 |
require_once ABSPATH . WPINC . '/class-IXR.php'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3288 |
require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php'; |
16 | 3289 |
|
3290 |
// Using a timeout of 3 seconds should be enough to cover slow servers. |
|
3291 |
$client = new WP_HTTP_IXR_Client( $server, ( ( ! strlen( trim( $path ) ) || ( '/' === $path ) ) ? false : $path ) ); |
|
9 | 3292 |
$client->timeout = 3; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3293 |
$client->useragent .= ' -- WordPress/' . get_bloginfo( 'version' ); |
0 | 3294 |
|
16 | 3295 |
// When set to true, this outputs debug messages by itself. |
0 | 3296 |
$client->debug = false; |
9 | 3297 |
$home = trailingslashit( home_url() ); |
16 | 3298 |
if ( ! $client->query( 'weblogUpdates.extendedPing', get_option( 'blogname' ), $home, get_bloginfo( 'rss2_url' ) ) ) { // Then try a normal ping. |
9 | 3299 |
$client->query( 'weblogUpdates.ping', get_option( 'blogname' ), $home ); |
3300 |
} |
|
0 | 3301 |
} |
3302 |
||
3303 |
/** |
|
19 | 3304 |
* Default filter attached to pingback_ping_source_uri to validate the pingback's Source URI. |
0 | 3305 |
* |
3306 |
* @since 3.5.1 |
|
16 | 3307 |
* |
0 | 3308 |
* @see wp_http_validate_url() |
3309 |
* |
|
3310 |
* @param string $source_uri |
|
3311 |
* @return string |
|
3312 |
*/ |
|
3313 |
function pingback_ping_source_uri( $source_uri ) { |
|
3314 |
return (string) wp_http_validate_url( $source_uri ); |
|
3315 |
} |
|
3316 |
||
3317 |
/** |
|
3318 |
* Default filter attached to xmlrpc_pingback_error. |
|
3319 |
* |
|
3320 |
* Returns a generic pingback error code unless the error code is 48, |
|
3321 |
* which reports that the pingback is already registered. |
|
3322 |
* |
|
3323 |
* @since 3.5.1 |
|
16 | 3324 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3325 |
* @link https://www.hixie.ch/specs/pingback/pingback#TOC3 |
0 | 3326 |
* |
3327 |
* @param IXR_Error $ixr_error |
|
3328 |
* @return IXR_Error |
|
3329 |
*/ |
|
3330 |
function xmlrpc_pingback_error( $ixr_error ) { |
|
16 | 3331 |
if ( 48 === $ixr_error->code ) { |
0 | 3332 |
return $ixr_error; |
9 | 3333 |
} |
0 | 3334 |
return new IXR_Error( 0, '' ); |
3335 |
} |
|
3336 |
||
3337 |
// |
|
16 | 3338 |
// Cache. |
0 | 3339 |
// |
3340 |
||
3341 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3342 |
* Removes a comment from the object cache. |
0 | 3343 |
* |
3344 |
* @since 2.3.0 |
|
3345 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3346 |
* @param int|array $ids Comment ID or an array of comment IDs to remove from cache. |
0 | 3347 |
*/ |
9 | 3348 |
function clean_comment_cache( $ids ) { |
19 | 3349 |
$comment_ids = (array) $ids; |
3350 |
wp_cache_delete_multiple( $comment_ids, 'comment' ); |
|
3351 |
foreach ( $comment_ids as $id ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3352 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3353 |
* Fires immediately after a comment has been removed from the object cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3354 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3355 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3356 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3357 |
* @param int $id Comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3358 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3359 |
do_action( 'clean_comment_cache', $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3360 |
} |
0 | 3361 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3362 |
wp_cache_set_comments_last_changed(); |
0 | 3363 |
} |
3364 |
||
3365 |
/** |
|
3366 |
* Updates the comment cache of given comments. |
|
3367 |
* |
|
3368 |
* Will add the comments in $comments to the cache. If comment ID already exists |
|
3369 |
* in the comment cache then it will not be updated. The comment is added to the |
|
3370 |
* cache using the comment group with the key using the ID of the comments. |
|
3371 |
* |
|
3372 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3373 |
* @since 4.4.0 Introduced the `$update_meta_cache` parameter. |
0 | 3374 |
* |
9 | 3375 |
* @param WP_Comment[] $comments Array of comment objects |
3376 |
* @param bool $update_meta_cache Whether to update commentmeta cache. Default true. |
|
0 | 3377 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
function update_comment_cache( $comments, $update_meta_cache = true ) { |
19 | 3379 |
$data = array(); |
9 | 3380 |
foreach ( (array) $comments as $comment ) { |
19 | 3381 |
$data[ $comment->comment_ID ] = $comment; |
9 | 3382 |
} |
19 | 3383 |
wp_cache_add_multiple( $data, 'comment' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3384 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3385 |
if ( $update_meta_cache ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3386 |
// Avoid `wp_list_pluck()` in case `$comments` is passed by reference. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3387 |
$comment_ids = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3388 |
foreach ( $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3389 |
$comment_ids[] = $comment->comment_ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3390 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3391 |
update_meta_cache( 'comment', $comment_ids ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3392 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3393 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3394 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3395 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3396 |
* Adds any comments from the given IDs to the cache that do not already exist in cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3397 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3398 |
* @since 4.4.0 |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3399 |
* @since 6.1.0 This function is no longer marked as "private". |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3400 |
* @since 6.3.0 Use wp_lazyload_comment_meta() for lazy-loading of comment meta. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3401 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3402 |
* @see update_comment_cache() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3403 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3404 |
* |
9 | 3405 |
* @param int[] $comment_ids Array of comment IDs. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3406 |
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3407 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3408 |
function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3409 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3410 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3411 |
$non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' ); |
9 | 3412 |
if ( ! empty( $non_cached_ids ) ) { |
18 | 3413 |
$fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3414 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3415 |
update_comment_cache( $fresh_comments, false ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3416 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3417 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3418 |
if ( $update_meta_cache ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3419 |
wp_lazyload_comment_meta( $comment_ids ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3420 |
} |
0 | 3421 |
} |
3422 |
||
3423 |
// |
|
16 | 3424 |
// Internal. |
0 | 3425 |
// |
3426 |
||
3427 |
/** |
|
19 | 3428 |
* Closes comments on old posts on the fly, without any extra DB queries. Hooked to the_posts. |
0 | 3429 |
* |
16 | 3430 |
* @since 2.7.0 |
0 | 3431 |
* @access private |
3432 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3433 |
* @param WP_Post $posts Post data object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3434 |
* @param WP_Query $query Query object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3435 |
* @return array |
0 | 3436 |
*/ |
3437 |
function _close_comments_for_old_posts( $posts, $query ) { |
|
9 | 3438 |
if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) { |
0 | 3439 |
return $posts; |
9 | 3440 |
} |
0 | 3441 |
|
5 | 3442 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3443 |
* Filters the list of post types to automatically close comments for. |
5 | 3444 |
* |
3445 |
* @since 3.2.0 |
|
3446 |
* |
|
9 | 3447 |
* @param string[] $post_types An array of post type names. |
5 | 3448 |
*/ |
0 | 3449 |
$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); |
16 | 3450 |
if ( ! in_array( $posts[0]->post_type, $post_types, true ) ) { |
0 | 3451 |
return $posts; |
9 | 3452 |
} |
0 | 3453 |
|
3454 |
$days_old = (int) get_option( 'close_comments_days_old' ); |
|
9 | 3455 |
if ( ! $days_old ) { |
0 | 3456 |
return $posts; |
9 | 3457 |
} |
0 | 3458 |
|
3459 |
if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { |
|
3460 |
$posts[0]->comment_status = 'closed'; |
|
9 | 3461 |
$posts[0]->ping_status = 'closed'; |
0 | 3462 |
} |
3463 |
||
3464 |
return $posts; |
|
3465 |
} |
|
3466 |
||
3467 |
/** |
|
19 | 3468 |
* Closes comments on an old post. Hooked to comments_open and pings_open. |
0 | 3469 |
* |
16 | 3470 |
* @since 2.7.0 |
0 | 3471 |
* @access private |
3472 |
* |
|
16 | 3473 |
* @param bool $open Comments open or closed. |
3474 |
* @param int $post_id Post ID. |
|
0 | 3475 |
* @return bool $open |
3476 |
*/ |
|
3477 |
function _close_comments_for_old_post( $open, $post_id ) { |
|
9 | 3478 |
if ( ! $open ) { |
0 | 3479 |
return $open; |
9 | 3480 |
} |
3481 |
||
3482 |
if ( ! get_option( 'close_comments_for_old_posts' ) ) { |
|
0 | 3483 |
return $open; |
9 | 3484 |
} |
3485 |
||
3486 |
$days_old = (int) get_option( 'close_comments_days_old' ); |
|
3487 |
if ( ! $days_old ) { |
|
0 | 3488 |
return $open; |
9 | 3489 |
} |
3490 |
||
3491 |
$post = get_post( $post_id ); |
|
0 | 3492 |
|
5 | 3493 |
/** This filter is documented in wp-includes/comment.php */ |
0 | 3494 |
$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); |
16 | 3495 |
if ( ! in_array( $post->post_type, $post_types, true ) ) { |
0 | 3496 |
return $open; |
9 | 3497 |
} |
0 | 3498 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3499 |
// Undated drafts should not show up as comments closed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3500 |
if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3501 |
return $open; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3502 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3503 |
|
9 | 3504 |
if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { |
0 | 3505 |
return false; |
9 | 3506 |
} |
0 | 3507 |
|
3508 |
return $open; |
|
3509 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3510 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3511 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3512 |
* Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3513 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3514 |
* This function expects unslashed data, as opposed to functions such as `wp_new_comment()` which |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3515 |
* expect slashed data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3516 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3517 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3518 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
* @param array $comment_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3520 |
* Comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3521 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3522 |
* @type string|int $comment_post_ID The ID of the post that relates to the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3523 |
* @type string $author The name of the comment author. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3524 |
* @type string $email The comment author email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3525 |
* @type string $url The comment author URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3526 |
* @type string $comment The content of the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3527 |
* @type string|int $comment_parent The ID of this comment's parent, if any. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3528 |
* @type string $_wp_unfiltered_html_comment The nonce value for allowing unfiltered HTML. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3529 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3530 |
* @return WP_Comment|WP_Error A WP_Comment object on success, a WP_Error object on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3531 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3532 |
function wp_handle_comment_submission( $comment_data ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3533 |
$comment_post_id = 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3534 |
$comment_author = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3535 |
$comment_author_email = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3536 |
$comment_author_url = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3537 |
$comment_content = ''; |
16 | 3538 |
$comment_parent = 0; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3539 |
$user_id = 0; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3540 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3541 |
if ( isset( $comment_data['comment_post_ID'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3542 |
$comment_post_id = (int) $comment_data['comment_post_ID']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3543 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3544 |
if ( isset( $comment_data['author'] ) && is_string( $comment_data['author'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3545 |
$comment_author = trim( strip_tags( $comment_data['author'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3546 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3547 |
if ( isset( $comment_data['email'] ) && is_string( $comment_data['email'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3548 |
$comment_author_email = trim( $comment_data['email'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3549 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3550 |
if ( isset( $comment_data['url'] ) && is_string( $comment_data['url'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3551 |
$comment_author_url = trim( $comment_data['url'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3552 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3553 |
if ( isset( $comment_data['comment'] ) && is_string( $comment_data['comment'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3554 |
$comment_content = trim( $comment_data['comment'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3555 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3556 |
if ( isset( $comment_data['comment_parent'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3557 |
$comment_parent = absint( $comment_data['comment_parent'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3558 |
$comment_parent_object = get_comment( $comment_parent ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3559 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3560 |
if ( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3561 |
0 !== $comment_parent && |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3562 |
( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3563 |
! $comment_parent_object instanceof WP_Comment || |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3564 |
0 === (int) $comment_parent_object->comment_approved |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3565 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3566 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3567 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3568 |
* Fires when a comment reply is attempted to an unapproved comment. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3569 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3570 |
* @since 6.2.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3571 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3572 |
* @param int $comment_post_id Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3573 |
* @param int $comment_parent Parent comment ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3574 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3575 |
do_action( 'comment_reply_to_unapproved_comment', $comment_post_id, $comment_parent ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3576 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3577 |
return new WP_Error( 'comment_reply_to_unapproved_comment', __( 'Sorry, replies to unapproved comments are not allowed.' ), 403 ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3578 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3581 |
$post = get_post( $comment_post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3583 |
if ( empty( $post->comment_status ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3584 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3585 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3586 |
* Fires when a comment is attempted on a post that does not exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3587 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3588 |
* @since 1.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3589 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3590 |
* @param int $comment_post_id Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3591 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3592 |
do_action( 'comment_id_not_found', $comment_post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3593 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3594 |
return new WP_Error( 'comment_id_not_found' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3595 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3596 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3597 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3598 |
// get_post_status() will get the parent status for attachments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3599 |
$status = get_post_status( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3600 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3601 |
if ( ( 'private' === $status ) && ! current_user_can( 'read_post', $comment_post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3602 |
return new WP_Error( 'comment_id_not_found' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3603 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3604 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3605 |
$status_obj = get_post_status_object( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3606 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3607 |
if ( ! comments_open( $comment_post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3608 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3609 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3610 |
* Fires when a comment is attempted on a post that has comments closed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3611 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3612 |
* @since 1.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3613 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3614 |
* @param int $comment_post_id Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3615 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3616 |
do_action( 'comment_closed', $comment_post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3617 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3618 |
return new WP_Error( 'comment_closed', __( 'Sorry, comments are closed for this item.' ), 403 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3619 |
|
16 | 3620 |
} elseif ( 'trash' === $status ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3621 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3622 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3623 |
* Fires when a comment is attempted on a trashed post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3624 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3625 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3626 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3627 |
* @param int $comment_post_id Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3628 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3629 |
do_action( 'comment_on_trash', $comment_post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3630 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3631 |
return new WP_Error( 'comment_on_trash' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3632 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3633 |
} elseif ( ! $status_obj->public && ! $status_obj->private ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3634 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3635 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3636 |
* Fires when a comment is attempted on a post in draft mode. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3637 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3638 |
* @since 1.5.1 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3639 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3640 |
* @param int $comment_post_id Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3641 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3642 |
do_action( 'comment_on_draft', $comment_post_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3643 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3644 |
if ( current_user_can( 'read_post', $comment_post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3645 |
return new WP_Error( 'comment_on_draft', __( 'Sorry, comments are not allowed for this item.' ), 403 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3646 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3647 |
return new WP_Error( 'comment_on_draft' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3648 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3649 |
} elseif ( post_password_required( $comment_post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3650 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3651 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3652 |
* Fires when a comment is attempted on a password-protected post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3654 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3655 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3656 |
* @param int $comment_post_id Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3657 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3658 |
do_action( 'comment_on_password_protected', $comment_post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3660 |
return new WP_Error( 'comment_on_password_protected' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3661 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3663 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3664 |
* Fires before a comment is posted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3665 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3666 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3667 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3668 |
* @param int $comment_post_id Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3669 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3670 |
do_action( 'pre_comment_on_post', $comment_post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3671 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
|
16 | 3673 |
// If the user is logged in. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3674 |
$user = wp_get_current_user(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3675 |
if ( $user->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3676 |
if ( empty( $user->display_name ) ) { |
9 | 3677 |
$user->display_name = $user->user_login; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3678 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3679 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3680 |
$comment_author = $user->display_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3681 |
$comment_author_email = $user->user_email; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3682 |
$comment_author_url = $user->user_url; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3683 |
$user_id = $user->ID; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3684 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3685 |
if ( current_user_can( 'unfiltered_html' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3686 |
if ( ! isset( $comment_data['_wp_unfiltered_html_comment'] ) |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3687 |
|| ! wp_verify_nonce( $comment_data['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_id ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3688 |
) { |
16 | 3689 |
kses_remove_filters(); // Start with a clean slate. |
3690 |
kses_init_filters(); // Set up the filters. |
|
9 | 3691 |
remove_filter( 'pre_comment_content', 'wp_filter_post_kses' ); |
3692 |
add_filter( 'pre_comment_content', 'wp_filter_kses' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3693 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3694 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3695 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3696 |
if ( get_option( 'comment_registration' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3697 |
return new WP_Error( 'not_logged_in', __( 'Sorry, you must be logged in to comment.' ), 403 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3698 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3699 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3700 |
|
16 | 3701 |
$comment_type = 'comment'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3702 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3703 |
if ( get_option( 'require_name_email' ) && ! $user->exists() ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3704 |
if ( '' === $comment_author_email || '' === $comment_author ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3705 |
return new WP_Error( 'require_name_email', __( '<strong>Error:</strong> Please fill the required fields.' ), 200 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3706 |
} elseif ( ! is_email( $comment_author_email ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3707 |
return new WP_Error( 'require_valid_email', __( '<strong>Error:</strong> Please enter a valid email address.' ), 200 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3708 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3709 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3710 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3711 |
$commentdata = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3712 |
'comment_post_ID' => $comment_post_id, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3713 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3714 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3715 |
$commentdata += compact( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3716 |
'comment_author', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3717 |
'comment_author_email', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3718 |
'comment_author_url', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
'comment_content', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3720 |
'comment_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3721 |
'comment_parent', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3722 |
'user_id' |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3723 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3724 |
|
9 | 3725 |
/** |
3726 |
* Filters whether an empty comment should be allowed. |
|
3727 |
* |
|
3728 |
* @since 5.1.0 |
|
3729 |
* |
|
3730 |
* @param bool $allow_empty_comment Whether to allow empty comments. Default false. |
|
3731 |
* @param array $commentdata Array of comment data to be sent to wp_insert_comment(). |
|
3732 |
*/ |
|
3733 |
$allow_empty_comment = apply_filters( 'allow_empty_comment', false, $commentdata ); |
|
3734 |
if ( '' === $comment_content && ! $allow_empty_comment ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3735 |
return new WP_Error( 'require_valid_comment', __( '<strong>Error:</strong> Please type your comment text.' ), 200 ); |
9 | 3736 |
} |
3737 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3738 |
$check_max_lengths = wp_check_comment_data_max_lengths( $commentdata ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3739 |
if ( is_wp_error( $check_max_lengths ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3740 |
return $check_max_lengths; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3742 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3743 |
$comment_id = wp_new_comment( wp_slash( $commentdata ), true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
if ( is_wp_error( $comment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
return $comment_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
if ( ! $comment_id ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3749 |
return new WP_Error( 'comment_save_error', __( '<strong>Error:</strong> The comment could not be saved. Please try again later.' ), 500 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3750 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3751 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3752 |
return get_comment( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3753 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3754 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3755 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3756 |
* Registers the personal data exporter for comments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3757 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3758 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3759 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3760 |
* @param array[] $exporters An array of personal data exporters. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3761 |
* @return array[] An array of personal data exporters. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3762 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3763 |
function wp_register_comment_personal_data_exporter( $exporters ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3764 |
$exporters['wordpress-comments'] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3765 |
'exporter_friendly_name' => __( 'WordPress Comments' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3766 |
'callback' => 'wp_comments_personal_data_exporter', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3767 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3768 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3769 |
return $exporters; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3770 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3771 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3772 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3773 |
* Finds and exports personal data associated with an email address from the comments table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3774 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3775 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3776 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3777 |
* @param string $email_address The comment author email address. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3778 |
* @param int $page Comment page number. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3779 |
* @return array { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3780 |
* An array of personal data. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3781 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3782 |
* @type array[] $data An array of personal data arrays. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3783 |
* @type bool $done Whether the exporter is finished. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3784 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3785 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3786 |
function wp_comments_personal_data_exporter( $email_address, $page = 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3787 |
// Limit us to 500 comments at a time to avoid timing out. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3788 |
$number = 500; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3789 |
$page = (int) $page; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3790 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3791 |
$data_to_export = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3792 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3793 |
$comments = get_comments( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3794 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3795 |
'author_email' => $email_address, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3796 |
'number' => $number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3797 |
'paged' => $page, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3798 |
'orderby' => 'comment_ID', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3799 |
'order' => 'ASC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3800 |
'update_comment_meta_cache' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3801 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3802 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3803 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3804 |
$comment_prop_to_export = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3805 |
'comment_author' => __( 'Comment Author' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3806 |
'comment_author_email' => __( 'Comment Author Email' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3807 |
'comment_author_url' => __( 'Comment Author URL' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3808 |
'comment_author_IP' => __( 'Comment Author IP' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3809 |
'comment_agent' => __( 'Comment Author User Agent' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3810 |
'comment_date' => __( 'Comment Date' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3811 |
'comment_content' => __( 'Comment Content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3812 |
'comment_link' => __( 'Comment URL' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3813 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3814 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3815 |
foreach ( (array) $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3816 |
$comment_data_to_export = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3817 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3818 |
foreach ( $comment_prop_to_export as $key => $name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3819 |
$value = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3820 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3821 |
switch ( $key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3822 |
case 'comment_author': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3823 |
case 'comment_author_email': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3824 |
case 'comment_author_url': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
case 'comment_author_IP': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3826 |
case 'comment_agent': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3827 |
case 'comment_date': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3828 |
$value = $comment->{$key}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3829 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3830 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3831 |
case 'comment_content': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3832 |
$value = get_comment_text( $comment->comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3833 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3834 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3835 |
case 'comment_link': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3836 |
$value = get_comment_link( $comment->comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3837 |
$value = sprintf( |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3838 |
'<a href="%s" target="_blank">%s</a>', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3839 |
esc_url( $value ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3840 |
esc_html( $value ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3841 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3842 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3843 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3844 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3845 |
if ( ! empty( $value ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3846 |
$comment_data_to_export[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3847 |
'name' => $name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3848 |
'value' => $value, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3849 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3850 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3851 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3852 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3853 |
$data_to_export[] = array( |
16 | 3854 |
'group_id' => 'comments', |
3855 |
'group_label' => __( 'Comments' ), |
|
3856 |
'group_description' => __( 'User’s comment data.' ), |
|
3857 |
'item_id' => "comment-{$comment->comment_ID}", |
|
3858 |
'data' => $comment_data_to_export, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3859 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3860 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3861 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3862 |
$done = count( $comments ) < $number; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3863 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3864 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3865 |
'data' => $data_to_export, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3866 |
'done' => $done, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3867 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3868 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3869 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3870 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3871 |
* Registers the personal data eraser for comments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3872 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3873 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3874 |
* |
16 | 3875 |
* @param array $erasers An array of personal data erasers. |
3876 |
* @return array An array of personal data erasers. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3877 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3878 |
function wp_register_comment_personal_data_eraser( $erasers ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3879 |
$erasers['wordpress-comments'] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3880 |
'eraser_friendly_name' => __( 'WordPress Comments' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3881 |
'callback' => 'wp_comments_personal_data_eraser', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3882 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3883 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3884 |
return $erasers; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3885 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3886 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3887 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3888 |
* Erases personal data associated with an email address from the comments table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3889 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3890 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3891 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3892 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3893 |
* |
16 | 3894 |
* @param string $email_address The comment author email address. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3895 |
* @param int $page Comment page number. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3896 |
* @return array { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3897 |
* Data removal results. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3898 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3899 |
* @type bool $items_removed Whether items were actually removed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3900 |
* @type bool $items_retained Whether items were retained. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3901 |
* @type string[] $messages An array of messages to add to the personal data export file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3902 |
* @type bool $done Whether the eraser is finished. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3903 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3904 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3905 |
function wp_comments_personal_data_eraser( $email_address, $page = 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3906 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3907 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3908 |
if ( empty( $email_address ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3909 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3910 |
'items_removed' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3911 |
'items_retained' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3912 |
'messages' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3913 |
'done' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3915 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3917 |
// Limit us to 500 comments at a time to avoid timing out. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3918 |
$number = 500; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3919 |
$page = (int) $page; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3920 |
$items_removed = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3921 |
$items_retained = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3922 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3923 |
$comments = get_comments( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3924 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3925 |
'author_email' => $email_address, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3926 |
'number' => $number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3927 |
'paged' => $page, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3928 |
'orderby' => 'comment_ID', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3929 |
'order' => 'ASC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3930 |
'include_unapproved' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3931 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3932 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3933 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3934 |
/* translators: Name of a comment's author after being anonymized. */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3935 |
$anon_author = __( 'Anonymous' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3936 |
$messages = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3937 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3938 |
foreach ( (array) $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3939 |
$anonymized_comment = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3940 |
$anonymized_comment['comment_agent'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3941 |
$anonymized_comment['comment_author'] = $anon_author; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3942 |
$anonymized_comment['comment_author_email'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3943 |
$anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data( 'ip', $comment->comment_author_IP ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3944 |
$anonymized_comment['comment_author_url'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3945 |
$anonymized_comment['user_id'] = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3946 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3947 |
$comment_id = (int) $comment->comment_ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3948 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3949 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3950 |
* Filters whether to anonymize the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3951 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3952 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3953 |
* |
16 | 3954 |
* @param bool|string $anon_message Whether to apply the comment anonymization (bool) or a custom |
3955 |
* message (string). Default true. |
|
3956 |
* @param WP_Comment $comment WP_Comment object. |
|
3957 |
* @param array $anonymized_comment Anonymized comment data. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3958 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3959 |
$anon_message = apply_filters( 'wp_anonymize_comment', true, $comment, $anonymized_comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3960 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3961 |
if ( true !== $anon_message ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3962 |
if ( $anon_message && is_string( $anon_message ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3963 |
$messages[] = esc_html( $anon_message ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3964 |
} else { |
16 | 3965 |
/* translators: %d: Comment ID. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3966 |
$messages[] = sprintf( __( 'Comment %d contains personal data but could not be anonymized.' ), $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3967 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3968 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3969 |
$items_retained = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3970 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3971 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3972 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3973 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3974 |
$args = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3975 |
'comment_ID' => $comment_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3976 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3977 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3978 |
$updated = $wpdb->update( $wpdb->comments, $anonymized_comment, $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3979 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3980 |
if ( $updated ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3981 |
$items_removed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3982 |
clean_comment_cache( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3983 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3984 |
$items_retained = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3985 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3986 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3987 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3988 |
$done = count( $comments ) < $number; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3989 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3990 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
'items_removed' => $items_removed, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3992 |
'items_retained' => $items_retained, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
'messages' => $messages, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3994 |
'done' => $done, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3995 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3996 |
} |
9 | 3997 |
|
3998 |
/** |
|
3999 |
* Sets the last changed time for the 'comment' cache group. |
|
4000 |
* |
|
4001 |
* @since 5.0.0 |
|
4002 |
*/ |
|
4003 |
function wp_cache_set_comments_last_changed() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4004 |
wp_cache_set_last_changed( 'comment' ); |
9 | 4005 |
} |
16 | 4006 |
|
4007 |
/** |
|
4008 |
* Updates the comment type for a batch of comments. |
|
4009 |
* |
|
4010 |
* @since 5.5.0 |
|
4011 |
* |
|
4012 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
4013 |
*/ |
|
4014 |
function _wp_batch_update_comment_type() { |
|
4015 |
global $wpdb; |
|
4016 |
||
4017 |
$lock_name = 'update_comment_type.lock'; |
|
4018 |
||
4019 |
// Try to lock. |
|
4020 |
$lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time() ) ); |
|
4021 |
||
4022 |
if ( ! $lock_result ) { |
|
4023 |
$lock_result = get_option( $lock_name ); |
|
4024 |
||
4025 |
// Bail if we were unable to create a lock, or if the existing lock is still valid. |
|
4026 |
if ( ! $lock_result || ( $lock_result > ( time() - HOUR_IN_SECONDS ) ) ) { |
|
4027 |
wp_schedule_single_event( time() + ( 5 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' ); |
|
4028 |
return; |
|
4029 |
} |
|
4030 |
} |
|
4031 |
||
4032 |
// Update the lock, as by this point we've definitely got a lock, just need to fire the actions. |
|
4033 |
update_option( $lock_name, time() ); |
|
4034 |
||
4035 |
// Check if there's still an empty comment type. |
|
4036 |
$empty_comment_type = $wpdb->get_var( |
|
4037 |
"SELECT comment_ID FROM $wpdb->comments |
|
4038 |
WHERE comment_type = '' |
|
4039 |
LIMIT 1" |
|
4040 |
); |
|
4041 |
||
4042 |
// No empty comment type, we're done here. |
|
4043 |
if ( ! $empty_comment_type ) { |
|
4044 |
update_option( 'finished_updating_comment_type', true ); |
|
4045 |
delete_option( $lock_name ); |
|
4046 |
return; |
|
4047 |
} |
|
4048 |
||
4049 |
// Empty comment type found? We'll need to run this script again. |
|
4050 |
wp_schedule_single_event( time() + ( 2 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' ); |
|
4051 |
||
4052 |
/** |
|
4053 |
* Filters the comment batch size for updating the comment type. |
|
4054 |
* |
|
4055 |
* @since 5.5.0 |
|
4056 |
* |
|
4057 |
* @param int $comment_batch_size The comment batch size. Default 100. |
|
4058 |
*/ |
|
4059 |
$comment_batch_size = (int) apply_filters( 'wp_update_comment_type_batch_size', 100 ); |
|
4060 |
||
4061 |
// Get the IDs of the comments to update. |
|
4062 |
$comment_ids = $wpdb->get_col( |
|
4063 |
$wpdb->prepare( |
|
4064 |
"SELECT comment_ID |
|
4065 |
FROM {$wpdb->comments} |
|
4066 |
WHERE comment_type = '' |
|
4067 |
ORDER BY comment_ID DESC |
|
4068 |
LIMIT %d", |
|
4069 |
$comment_batch_size |
|
4070 |
) |
|
4071 |
); |
|
4072 |
||
4073 |
if ( $comment_ids ) { |
|
4074 |
$comment_id_list = implode( ',', $comment_ids ); |
|
4075 |
||
4076 |
// Update the `comment_type` field value to be `comment` for the next batch of comments. |
|
4077 |
$wpdb->query( |
|
4078 |
"UPDATE {$wpdb->comments} |
|
4079 |
SET comment_type = 'comment' |
|
4080 |
WHERE comment_type = '' |
|
4081 |
AND comment_ID IN ({$comment_id_list})" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
4082 |
); |
|
4083 |
||
4084 |
// Make sure to clean the comment cache. |
|
4085 |
clean_comment_cache( $comment_ids ); |
|
4086 |
} |
|
4087 |
||
4088 |
delete_option( $lock_name ); |
|
4089 |
} |
|
4090 |
||
4091 |
/** |
|
4092 |
* In order to avoid the _wp_batch_update_comment_type() job being accidentally removed, |
|
4093 |
* check that it's still scheduled while we haven't finished updating comment types. |
|
4094 |
* |
|
4095 |
* @ignore |
|
4096 |
* @since 5.5.0 |
|
4097 |
*/ |
|
4098 |
function _wp_check_for_scheduled_update_comment_type() { |
|
4099 |
if ( ! get_option( 'finished_updating_comment_type' ) && ! wp_next_scheduled( 'wp_update_comment_type_batch' ) ) { |
|
4100 |
wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'wp_update_comment_type_batch' ); |
|
4101 |
} |
|
4102 |
} |