author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
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 |
/** |
|
5 | 10 |
* Check 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, |
13 |
* regardless of their type and whitelist, will fail and the function will |
|
14 |
* return false. |
|
0 | 15 |
* |
16 |
* If the number of links exceeds the amount in the administration, then the |
|
17 |
* check fails. If any of the parameter contents match the blacklist of words, |
|
18 |
* then the check fails. |
|
19 |
* |
|
5 | 20 |
* If the comment author was approved before, then the comment is automatically |
21 |
* whitelisted. |
|
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, |
|
36 |
* trackback, or pingback. |
|
37 |
* @return bool If all checks pass, true, otherwise false. |
|
0 | 38 |
*/ |
39 |
function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) { |
|
40 |
global $wpdb; |
|
41 |
||
5 | 42 |
// If manual moderation is enabled, skip all checks and return false. |
0 | 43 |
if ( 1 == get_option('comment_moderation') ) |
5 | 44 |
return false; |
45 |
||
46 |
/** 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
|
47 |
$comment = apply_filters( 'comment_text', $comment, null, array() ); |
0 | 48 |
|
5 | 49 |
// Check for the number of external links if a max allowed number is set. |
0 | 50 |
if ( $max_links = get_option( 'comment_max_links' ) ) { |
51 |
$num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out ); |
|
5 | 52 |
|
53 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
* Filters the number of links found in a comment. |
5 | 55 |
* |
56 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* @since 4.7.0 Added the `$comment` parameter. |
5 | 58 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
* @param int $num_links The number of links found. |
5 | 60 |
* @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
|
61 |
* @param string $comment Content of the comment. |
5 | 62 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
$num_links = apply_filters( 'comment_max_links_url', $num_links, $url, $comment ); |
5 | 64 |
|
65 |
/* |
|
66 |
* If the number of links in the comment exceeds the allowed amount, |
|
67 |
* fail the check by returning false. |
|
68 |
*/ |
|
0 | 69 |
if ( $num_links >= $max_links ) |
70 |
return false; |
|
71 |
} |
|
72 |
||
73 |
$mod_keys = trim(get_option('moderation_keys')); |
|
5 | 74 |
|
75 |
// If moderation 'keys' (keywords) are set, process them. |
|
0 | 76 |
if ( !empty($mod_keys) ) { |
77 |
$words = explode("\n", $mod_keys ); |
|
78 |
||
79 |
foreach ( (array) $words as $word) { |
|
80 |
$word = trim($word); |
|
81 |
||
5 | 82 |
// Skip empty lines. |
0 | 83 |
if ( empty($word) ) |
84 |
continue; |
|
85 |
||
5 | 86 |
/* |
87 |
* Do some escaping magic so that '#' (number of) characters in the spam |
|
88 |
* words don't break things: |
|
89 |
*/ |
|
0 | 90 |
$word = preg_quote($word, '#'); |
91 |
||
5 | 92 |
/* |
93 |
* Check the comment fields for moderation keywords. If any are found, |
|
94 |
* fail the check for the given field by returning false. |
|
95 |
*/ |
|
0 | 96 |
$pattern = "#$word#i"; |
97 |
if ( preg_match($pattern, $author) ) return false; |
|
98 |
if ( preg_match($pattern, $email) ) return false; |
|
99 |
if ( preg_match($pattern, $url) ) return false; |
|
100 |
if ( preg_match($pattern, $comment) ) return false; |
|
101 |
if ( preg_match($pattern, $user_ip) ) return false; |
|
102 |
if ( preg_match($pattern, $user_agent) ) return false; |
|
103 |
} |
|
104 |
} |
|
105 |
||
5 | 106 |
/* |
107 |
* Check if the option to approve comments by previously-approved authors is enabled. |
|
108 |
* |
|
109 |
* If it is enabled, check whether the comment author has a previously-approved comment, |
|
110 |
* as well as whether there are any moderation keywords (if set) present in the author |
|
111 |
* email address. If both checks pass, return true. Otherwise, return false. |
|
112 |
*/ |
|
0 | 113 |
if ( 1 == get_option('comment_whitelist')) { |
114 |
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
|
115 |
$comment_user = get_user_by( 'email', wp_unslash( $email ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
if ( ! empty( $comment_user->ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
$ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE user_id = %d AND comment_approved = '1' LIMIT 1", $comment_user->ID ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
// expected_slashed ($author, $email) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
$ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE comment_author = %s AND comment_author_email = %s and comment_approved = '1' LIMIT 1", $author, $email ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
} |
0 | 122 |
if ( ( 1 == $ok_to_comment ) && |
123 |
( empty($mod_keys) || false === strpos( $email, $mod_keys) ) ) |
|
124 |
return true; |
|
125 |
else |
|
126 |
return false; |
|
127 |
} else { |
|
128 |
return false; |
|
129 |
} |
|
130 |
} |
|
131 |
return true; |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* Retrieve the approved comments for post $post_id. |
|
136 |
* |
|
137 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
* @since 4.1.0 Refactored to leverage WP_Comment_Query over a direct query. |
0 | 139 |
* |
5 | 140 |
* @param int $post_id The ID of the post. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* @param array $args Optional. See WP_Comment_Query::__construct() for information on accepted arguments. |
5 | 142 |
* @return int|array $comments The approved comments, or number of comments if `$count` |
143 |
* argument is true. |
|
0 | 144 |
*/ |
5 | 145 |
function get_approved_comments( $post_id, $args = array() ) { |
146 |
if ( ! $post_id ) { |
|
147 |
return array(); |
|
148 |
} |
|
149 |
||
150 |
$defaults = array( |
|
151 |
'status' => 1, |
|
152 |
'post_id' => $post_id, |
|
153 |
'order' => 'ASC', |
|
154 |
); |
|
155 |
$r = wp_parse_args( $args, $defaults ); |
|
156 |
||
157 |
$query = new WP_Comment_Query; |
|
158 |
return $query->query( $r ); |
|
0 | 159 |
} |
160 |
||
161 |
/** |
|
162 |
* Retrieves comment data given a comment ID or comment object. |
|
163 |
* |
|
164 |
* If an object is passed then the comment data will be cached and then returned |
|
165 |
* after being passed through a filter. If the comment is empty, then the global |
|
166 |
* comment variable will be used, if it is set. |
|
167 |
* |
|
168 |
* @since 2.0.0 |
|
5 | 169 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
* @global WP_Comment $comment |
0 | 171 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
* @param WP_Comment|string|int $comment Comment to retrieve. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
* a WP_Comment object, an associative array, or a numeric array, respectively. Default OBJECT. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
* @return WP_Comment|array|null Depends on $output value. |
0 | 176 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
function get_comment( &$comment = null, $output = OBJECT ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
$comment = $GLOBALS['comment']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
if ( $comment instanceof WP_Comment ) { |
0 | 183 |
$_comment = $comment; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
} elseif ( is_object( $comment ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
$_comment = new WP_Comment( $comment ); |
0 | 186 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
$_comment = WP_Comment::get_instance( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
if ( ! $_comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
return null; |
0 | 192 |
} |
193 |
||
5 | 194 |
/** |
195 |
* Fires after a comment is retrieved. |
|
196 |
* |
|
197 |
* @since 2.3.0 |
|
198 |
* |
|
199 |
* @param mixed $_comment Comment data. |
|
200 |
*/ |
|
201 |
$_comment = apply_filters( 'get_comment', $_comment ); |
|
0 | 202 |
|
203 |
if ( $output == OBJECT ) { |
|
204 |
return $_comment; |
|
205 |
} elseif ( $output == ARRAY_A ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
return $_comment->to_array(); |
0 | 207 |
} elseif ( $output == ARRAY_N ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
return array_values( $_comment->to_array() ); |
0 | 209 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
return $_comment; |
0 | 211 |
} |
212 |
||
213 |
/** |
|
214 |
* Retrieve a list of comments. |
|
215 |
* |
|
216 |
* The comment list can be for the blog as a whole or for an individual post. |
|
217 |
* |
|
5 | 218 |
* @since 2.7.0 |
0 | 219 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
* @param string|array $args Optional. Array or string of arguments. See WP_Comment_Query::__construct() |
5 | 221 |
* for information on accepted arguments. Default empty. |
222 |
* @return int|array List of comments or number of found comments if `$count` argument is true. |
|
0 | 223 |
*/ |
224 |
function get_comments( $args = '' ) { |
|
225 |
$query = new WP_Comment_Query; |
|
226 |
return $query->query( $args ); |
|
227 |
} |
|
228 |
||
229 |
/** |
|
230 |
* Retrieve all of the WordPress supported comment statuses. |
|
231 |
* |
|
232 |
* Comments have a limited set of valid status values, this provides the comment |
|
233 |
* status values and descriptions. |
|
234 |
* |
|
235 |
* @since 2.7.0 |
|
236 |
* |
|
237 |
* @return array List of comment statuses. |
|
238 |
*/ |
|
239 |
function get_comment_statuses() { |
|
240 |
$status = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
'hold' => __( 'Unapproved' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
'approve' => _x( 'Approved', 'comment status' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
'spam' => _x( 'Spam', 'comment status' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
'trash' => _x( 'Trash', 'comment status' ), |
0 | 245 |
); |
246 |
||
247 |
return $status; |
|
248 |
} |
|
249 |
||
250 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* Gets the default comment status for a post type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* @param string $post_type Optional. Post type. Default 'post'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
* @param string $comment_type Optional. Comment type. Default 'comment'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
* @return string Expected return value is 'open' or 'closed'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
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
|
260 |
switch ( $comment_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
case 'pingback' : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
case 'trackback' : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
$supports = 'trackbacks'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
$option = 'ping'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
default : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
$supports = 'comments'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
$option = 'comment'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
// Set the status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
if ( 'page' === $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
$status = 'closed'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
} elseif ( post_type_supports( $post_type, $supports ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
$status = get_option( "default_{$option}_status" ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
$status = 'closed'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
* 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
|
282 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
* @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
|
286 |
* either 'open' or 'closed'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* @param string $post_type Post type. Default is `post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
* @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
|
289 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
return apply_filters( 'get_default_comment_status' , $status, $post_type, $comment_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
/** |
0 | 294 |
* The date the last comment was modified. |
295 |
* |
|
296 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
* @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
|
298 |
* with the Object Cache API. |
5 | 299 |
* |
300 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 301 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
* @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
|
303 |
* @return string|false Last comment modified date on success, false on failure. |
0 | 304 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
function get_lastcommentmodified( $timezone = 'server' ) { |
0 | 306 |
global $wpdb; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
$timezone = strtolower( $timezone ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
$key = "lastcommentmodified:$timezone"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
$comment_modified_date = wp_cache_get( $key, 'timeinfo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
if ( false !== $comment_modified_date ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
return $comment_modified_date; |
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 |
switch ( $timezone ) { |
0 | 317 |
case 'gmt': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
$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 | 319 |
break; |
320 |
case 'blog': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
$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 | 322 |
break; |
323 |
case 'server': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
$add_seconds_server = date( 'Z' ); |
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 |
$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 | 327 |
break; |
328 |
} |
|
329 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
if ( $comment_modified_date ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
wp_cache_set( $key, $comment_modified_date, 'timeinfo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
return $comment_modified_date; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
return false; |
0 | 337 |
} |
338 |
||
339 |
/** |
|
340 |
* The amount of comments in a post or total comments. |
|
341 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
* A lot like wp_count_comments(), in that they both return comment stats (albeit with different types). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
* The wp_count_comments() actually caches, but this function does not. |
0 | 344 |
* |
345 |
* @since 2.0.0 |
|
5 | 346 |
* |
347 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 348 |
* |
349 |
* @param int $post_id Optional. Comment amount in post if > 0, else total comments blog wide. |
|
350 |
* @return array The amount of spam, approved, awaiting moderation, and total comments. |
|
351 |
*/ |
|
352 |
function get_comment_count( $post_id = 0 ) { |
|
353 |
global $wpdb; |
|
354 |
||
355 |
$post_id = (int) $post_id; |
|
356 |
||
357 |
$where = ''; |
|
358 |
if ( $post_id > 0 ) { |
|
359 |
$where = $wpdb->prepare("WHERE comment_post_ID = %d", $post_id); |
|
360 |
} |
|
361 |
||
362 |
$totals = (array) $wpdb->get_results(" |
|
363 |
SELECT comment_approved, COUNT( * ) AS total |
|
364 |
FROM {$wpdb->comments} |
|
365 |
{$where} |
|
366 |
GROUP BY comment_approved |
|
367 |
", ARRAY_A); |
|
368 |
||
369 |
$comment_count = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
'approved' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
'awaiting_moderation' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
'spam' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
'trash' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
'post-trashed' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
'total_comments' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
'all' => 0, |
0 | 377 |
); |
378 |
||
379 |
foreach ( $totals as $row ) { |
|
380 |
switch ( $row['comment_approved'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
case 'trash': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
$comment_count['trash'] = $row['total']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
case 'post-trashed': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
$comment_count['post-trashed'] = $row['total']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
break; |
0 | 387 |
case 'spam': |
388 |
$comment_count['spam'] = $row['total']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
$comment_count['total_comments'] += $row['total']; |
0 | 390 |
break; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
case '1': |
0 | 392 |
$comment_count['approved'] = $row['total']; |
393 |
$comment_count['total_comments'] += $row['total']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
$comment_count['all'] += $row['total']; |
0 | 395 |
break; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
case '0': |
0 | 397 |
$comment_count['awaiting_moderation'] = $row['total']; |
398 |
$comment_count['total_comments'] += $row['total']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
$comment_count['all'] += $row['total']; |
0 | 400 |
break; |
401 |
default: |
|
402 |
break; |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
return $comment_count; |
|
407 |
} |
|
408 |
||
409 |
// |
|
410 |
// Comment meta functions |
|
411 |
// |
|
412 |
||
413 |
/** |
|
414 |
* Add meta data field to a comment. |
|
415 |
* |
|
416 |
* @since 2.9.0 |
|
5 | 417 |
* @link https://codex.wordpress.org/Function_Reference/add_comment_meta |
0 | 418 |
* |
419 |
* @param int $comment_id Comment ID. |
|
420 |
* @param string $meta_key Metadata name. |
|
421 |
* @param mixed $meta_value Metadata value. |
|
422 |
* @param bool $unique Optional, default is false. Whether the same key should not be added. |
|
423 |
* @return int|bool Meta ID on success, false on failure. |
|
424 |
*/ |
|
425 |
function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
$added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
if ( $added ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
wp_cache_set( 'last_changed', microtime(), 'comment' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
return $added; |
0 | 431 |
} |
432 |
||
433 |
/** |
|
434 |
* Remove metadata matching criteria from a comment. |
|
435 |
* |
|
436 |
* You can match based on the key, or key and value. Removing based on key and |
|
437 |
* value, will keep from removing duplicate metadata with the same key. It also |
|
438 |
* allows removing all metadata matching key, if needed. |
|
439 |
* |
|
440 |
* @since 2.9.0 |
|
5 | 441 |
* @link https://codex.wordpress.org/Function_Reference/delete_comment_meta |
0 | 442 |
* |
443 |
* @param int $comment_id comment ID |
|
444 |
* @param string $meta_key Metadata name. |
|
445 |
* @param mixed $meta_value Optional. Metadata value. |
|
446 |
* @return bool True on success, false on failure. |
|
447 |
*/ |
|
448 |
function delete_comment_meta($comment_id, $meta_key, $meta_value = '') { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
$deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
if ( $deleted ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
wp_cache_set( 'last_changed', microtime(), 'comment' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
return $deleted; |
0 | 454 |
} |
455 |
||
456 |
/** |
|
457 |
* Retrieve comment meta field for a comment. |
|
458 |
* |
|
459 |
* @since 2.9.0 |
|
5 | 460 |
* @link https://codex.wordpress.org/Function_Reference/get_comment_meta |
0 | 461 |
* |
462 |
* @param int $comment_id Comment ID. |
|
463 |
* @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. |
|
464 |
* @param bool $single Whether to return a single value. |
|
465 |
* @return mixed Will be an array if $single is false. Will be value of meta data field if $single |
|
466 |
* is true. |
|
467 |
*/ |
|
468 |
function get_comment_meta($comment_id, $key = '', $single = false) { |
|
469 |
return get_metadata('comment', $comment_id, $key, $single); |
|
470 |
} |
|
471 |
||
472 |
/** |
|
473 |
* Update comment meta field based on comment ID. |
|
474 |
* |
|
475 |
* Use the $prev_value parameter to differentiate between meta fields with the |
|
476 |
* same key and comment ID. |
|
477 |
* |
|
478 |
* If the meta field for the comment does not exist, it will be added. |
|
479 |
* |
|
480 |
* @since 2.9.0 |
|
5 | 481 |
* @link https://codex.wordpress.org/Function_Reference/update_comment_meta |
0 | 482 |
* |
483 |
* @param int $comment_id Comment ID. |
|
484 |
* @param string $meta_key Metadata key. |
|
485 |
* @param mixed $meta_value Metadata value. |
|
486 |
* @param mixed $prev_value Optional. Previous value to check before removing. |
|
5 | 487 |
* @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
0 | 488 |
*/ |
489 |
function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
$updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
if ( $updated ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
wp_cache_set( 'last_changed', microtime(), 'comment' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
return $updated; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
* Queues comments for metadata lazy-loading. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
* @param array $comments Array of comment objects. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
function wp_queue_comments_for_comment_meta_lazyload( $comments ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
// Don't use `wp_list_pluck()` to avoid by-reference manipulation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
$comment_ids = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
if ( is_array( $comments ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
foreach ( $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
if ( $comment instanceof WP_Comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
$comment_ids[] = $comment->comment_ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
if ( $comment_ids ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
$lazyloader = wp_metadata_lazyloader(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
$lazyloader->queue_objects( 'comment', $comment_ids ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
} |
0 | 519 |
} |
520 |
||
521 |
/** |
|
522 |
* Sets the cookies used to store an unauthenticated commentator's identity. Typically used |
|
523 |
* to recall previous comments by this commentator that are still held in moderation. |
|
524 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
* @since 4.9.6 The `$cookies_consent` parameter was added. |
0 | 527 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
* @param WP_Comment $comment Comment object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
* @param WP_User $user Comment author's user object. The user may not exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
* @param boolean $cookies_consent Optional. Comment author's consent to store cookies. Default true. |
0 | 531 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
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
|
533 |
// 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
|
534 |
if ( $user->exists() ) { |
0 | 535 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
if ( false === $cookies_consent ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
// Remove any existing cookies. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
$past = time() - YEAR_IN_SECONDS; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
setcookie( 'comment_author_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
setcookie( 'comment_author_email_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
setcookie( 'comment_author_url_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
} |
0 | 547 |
|
5 | 548 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
* Filters the lifetime of the comment cookie in seconds. |
5 | 550 |
* |
551 |
* @since 2.8.0 |
|
552 |
* |
|
553 |
* @param int $seconds Comment cookie lifetime. Default 30000000. |
|
554 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
$comment_cookie_lifetime = time() + apply_filters( 'comment_cookie_lifetime', 30000000 ); |
5 | 556 |
$secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
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
|
558 |
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
|
559 |
setcookie( 'comment_author_url_' . COOKIEHASH, esc_url( $comment->comment_author_url ), $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
0 | 560 |
} |
561 |
||
562 |
/** |
|
563 |
* Sanitizes the cookies sent to the user already. |
|
564 |
* |
|
565 |
* Will only do anything if the cookies have already been created for the user. |
|
566 |
* Mostly used after cookies had been sent to use elsewhere. |
|
567 |
* |
|
568 |
* @since 2.0.4 |
|
569 |
*/ |
|
570 |
function sanitize_comment_cookies() { |
|
5 | 571 |
if ( isset( $_COOKIE['comment_author_' . COOKIEHASH] ) ) { |
572 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
* Filters the comment author's name cookie before it is set. |
5 | 574 |
* |
575 |
* When this filter hook is evaluated in wp_filter_comment(), |
|
576 |
* the comment author's name string is passed. |
|
577 |
* |
|
578 |
* @since 1.5.0 |
|
579 |
* |
|
580 |
* @param string $author_cookie The comment author name cookie. |
|
581 |
*/ |
|
582 |
$comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE['comment_author_' . COOKIEHASH] ); |
|
0 | 583 |
$comment_author = wp_unslash($comment_author); |
584 |
$comment_author = esc_attr($comment_author); |
|
5 | 585 |
$_COOKIE['comment_author_' . COOKIEHASH] = $comment_author; |
0 | 586 |
} |
587 |
||
5 | 588 |
if ( isset( $_COOKIE['comment_author_email_' . COOKIEHASH] ) ) { |
589 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
* Filters the comment author's email cookie before it is set. |
5 | 591 |
* |
592 |
* When this filter hook is evaluated in wp_filter_comment(), |
|
593 |
* the comment author's email string is passed. |
|
594 |
* |
|
595 |
* @since 1.5.0 |
|
596 |
* |
|
597 |
* @param string $author_email_cookie The comment author email cookie. |
|
598 |
*/ |
|
599 |
$comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE['comment_author_email_' . COOKIEHASH] ); |
|
0 | 600 |
$comment_author_email = wp_unslash($comment_author_email); |
601 |
$comment_author_email = esc_attr($comment_author_email); |
|
602 |
$_COOKIE['comment_author_email_'.COOKIEHASH] = $comment_author_email; |
|
603 |
} |
|
604 |
||
5 | 605 |
if ( isset( $_COOKIE['comment_author_url_' . COOKIEHASH] ) ) { |
606 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* Filters the comment author's URL cookie before it is set. |
5 | 608 |
* |
609 |
* When this filter hook is evaluated in wp_filter_comment(), |
|
610 |
* the comment author's URL string is passed. |
|
611 |
* |
|
612 |
* @since 1.5.0 |
|
613 |
* |
|
614 |
* @param string $author_url_cookie The comment author URL cookie. |
|
615 |
*/ |
|
616 |
$comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE['comment_author_url_' . COOKIEHASH] ); |
|
0 | 617 |
$comment_author_url = wp_unslash($comment_author_url); |
618 |
$_COOKIE['comment_author_url_'.COOKIEHASH] = $comment_author_url; |
|
619 |
} |
|
620 |
} |
|
621 |
||
622 |
/** |
|
623 |
* Validates whether this comment is allowed to be made. |
|
624 |
* |
|
625 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
* @since 4.7.0 The `$avoid_die` parameter was added, allowing the function to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* return a WP_Error object instead of dying. |
5 | 628 |
* |
629 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 630 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
* @param array $commentdata Contains information on the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
* @param bool $avoid_die When true, a disallowed comment will result in the function |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
* 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
|
634 |
* Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
* @return int|string|WP_Error Allowed comments return the approval status (0|1|'spam'). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* If `$avoid_die` is true, disallowed comments return a WP_Error. |
0 | 637 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
function wp_allow_comment( $commentdata, $avoid_die = false ) { |
0 | 639 |
global $wpdb; |
640 |
||
641 |
// Simple duplicate check |
|
642 |
// expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) |
|
5 | 643 |
$dupe = $wpdb->prepare( |
644 |
"SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ", |
|
645 |
wp_unslash( $commentdata['comment_post_ID'] ), |
|
646 |
wp_unslash( $commentdata['comment_parent'] ), |
|
647 |
wp_unslash( $commentdata['comment_author'] ) |
|
648 |
); |
|
649 |
if ( $commentdata['comment_author_email'] ) { |
|
650 |
$dupe .= $wpdb->prepare( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
"AND comment_author_email = %s ", |
5 | 652 |
wp_unslash( $commentdata['comment_author_email'] ) |
653 |
); |
|
654 |
} |
|
655 |
$dupe .= $wpdb->prepare( |
|
656 |
") AND comment_content = %s LIMIT 1", |
|
657 |
wp_unslash( $commentdata['comment_content'] ) |
|
658 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
$dupe_id = $wpdb->get_var( $dupe ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
662 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
* 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
|
664 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
665 |
* 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
|
666 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
667 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
* @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
|
670 |
* @param array $commentdata Data for the comment being created. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
$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
|
673 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
if ( $dupe_id ) { |
5 | 675 |
/** |
676 |
* Fires immediately after a duplicate comment is detected. |
|
677 |
* |
|
678 |
* @since 3.0.0 |
|
679 |
* |
|
680 |
* @param array $commentdata Comment data. |
|
681 |
*/ |
|
0 | 682 |
do_action( 'comment_duplicate_trigger', $commentdata ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
if ( true === $avoid_die ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
return new WP_Error( 'comment_duplicate', __( 'Duplicate comment detected; it looks as though you’ve already said that!' ), 409 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
if ( wp_doing_ajax() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
die( __('Duplicate comment detected; it looks as though you’ve already said that!') ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
wp_die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ), 409 ); |
5 | 691 |
} |
0 | 692 |
} |
693 |
||
5 | 694 |
/** |
695 |
* Fires immediately before a comment is marked approved. |
|
696 |
* |
|
697 |
* Allows checking for comment flooding. |
|
698 |
* |
|
699 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
* @since 4.7.0 The `$avoid_die` parameter was added. |
5 | 701 |
* |
702 |
* @param string $comment_author_IP Comment author's IP address. |
|
703 |
* @param string $comment_author_email Comment author's email. |
|
704 |
* @param string $comment_date_gmt GMT date the comment was posted. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
* @param bool $avoid_die Whether to prevent executing wp_die() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
* or die() if a comment flood is occurring. |
5 | 707 |
*/ |
708 |
do_action( |
|
709 |
'check_comment_flood', |
|
710 |
$commentdata['comment_author_IP'], |
|
711 |
$commentdata['comment_author_email'], |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
$commentdata['comment_date_gmt'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
$avoid_die |
5 | 714 |
); |
715 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
* 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
|
718 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
* 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
|
720 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
721 |
* @since 4.7.0 |
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 |
* @param bool $is_flood Is a comment flooding occurring? Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
* @param string $comment_author_IP Comment author's IP address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
725 |
* @param string $comment_author_email Comment author's email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
726 |
* @param string $comment_date_gmt GMT date the comment was posted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
* @param bool $avoid_die Whether to prevent executing wp_die() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
* or die() if a comment flood is occurring. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
$is_flood = apply_filters( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
'wp_is_comment_flood', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
$commentdata['comment_author_IP'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
734 |
$commentdata['comment_author_email'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
$commentdata['comment_date_gmt'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
736 |
$avoid_die |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
if ( $is_flood ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
return new WP_Error( 'comment_flood', __( 'You are posting comments too quickly. Slow down.' ), 429 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
|
5 | 743 |
if ( ! empty( $commentdata['user_id'] ) ) { |
744 |
$user = get_userdata( $commentdata['user_id'] ); |
|
745 |
$post_author = $wpdb->get_var( $wpdb->prepare( |
|
746 |
"SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", |
|
747 |
$commentdata['comment_post_ID'] |
|
748 |
) ); |
|
0 | 749 |
} |
750 |
||
5 | 751 |
if ( isset( $user ) && ( $commentdata['user_id'] == $post_author || $user->has_cap( 'moderate_comments' ) ) ) { |
0 | 752 |
// The author and the admins get respect. |
753 |
$approved = 1; |
|
5 | 754 |
} else { |
0 | 755 |
// Everyone else's comments will be checked. |
5 | 756 |
if ( check_comment( |
757 |
$commentdata['comment_author'], |
|
758 |
$commentdata['comment_author_email'], |
|
759 |
$commentdata['comment_author_url'], |
|
760 |
$commentdata['comment_content'], |
|
761 |
$commentdata['comment_author_IP'], |
|
762 |
$commentdata['comment_agent'], |
|
763 |
$commentdata['comment_type'] |
|
764 |
) ) { |
|
0 | 765 |
$approved = 1; |
5 | 766 |
} else { |
0 | 767 |
$approved = 0; |
5 | 768 |
} |
769 |
||
770 |
if ( wp_blacklist_check( |
|
771 |
$commentdata['comment_author'], |
|
772 |
$commentdata['comment_author_email'], |
|
773 |
$commentdata['comment_author_url'], |
|
774 |
$commentdata['comment_content'], |
|
775 |
$commentdata['comment_author_IP'], |
|
776 |
$commentdata['comment_agent'] |
|
777 |
) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
$approved = EMPTY_TRASH_DAYS ? 'trash' : 'spam'; |
5 | 779 |
} |
0 | 780 |
} |
781 |
||
5 | 782 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
783 |
* Filters a comment's approval status before it is set. |
5 | 784 |
* |
785 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
* @since 4.9.0 Returning a WP_Error value from the filter will shortcircuit comment insertion and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
* allow skipping further processing. |
5 | 788 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
* @param bool|string|WP_Error $approved The approval status. Accepts 1, 0, 'spam' or WP_Error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
* @param array $commentdata Comment data. |
5 | 791 |
*/ |
0 | 792 |
$approved = apply_filters( 'pre_comment_approved', $approved, $commentdata ); |
793 |
return $approved; |
|
794 |
} |
|
795 |
||
796 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
* Hooks WP's native database-based comment-flood check. |
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 |
* 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
|
800 |
* 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
|
801 |
* 'check_comment_flood' using remove_action(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
* @since 2.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
* @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
|
805 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
function check_comment_flood_db() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
807 |
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
|
808 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
810 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
* Checks whether comment flooding is occurring. |
0 | 812 |
* |
813 |
* Won't run, if current user can manage options, so to not block |
|
814 |
* administrators. |
|
815 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
* @since 4.7.0 |
5 | 817 |
* |
818 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 819 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
* @param bool $is_flood Is a comment flooding occurring? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
821 |
* @param string $ip Comment author's IP address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
* @param string $email Comment author's email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
* @param string $date MySQL time string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
* @param bool $avoid_die When true, a disallowed comment will result in the function |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* 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
|
826 |
* Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* @return bool Whether comment flooding is occurring. |
0 | 828 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
function wp_check_comment_flood( $is_flood, $ip, $email, $date, $avoid_die = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
|
0 | 831 |
global $wpdb; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
// Another callback has declared a flood. Trust it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
if ( true === $is_flood ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
return $is_flood; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
// don't throttle admins or moderators |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
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
|
840 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
} |
0 | 842 |
$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
|
843 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
if ( is_user_logged_in() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
$user = get_current_user_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
$check_column = '`user_id`'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
$user = $ip; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
$check_column = '`comment_author_IP`'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
$sql = $wpdb->prepare( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
"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
|
854 |
$hour_ago, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
$user, |
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 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
$lasttime = $wpdb->get_var( $sql ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
if ( $lasttime ) { |
0 | 860 |
$time_lastcomment = mysql2date('U', $lasttime, false); |
861 |
$time_newcomment = mysql2date('U', $date, false); |
|
5 | 862 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* Filters the comment flood status. |
5 | 864 |
* |
865 |
* @since 2.1.0 |
|
866 |
* |
|
867 |
* @param bool $bool Whether a comment flood is occurring. Default false. |
|
868 |
* @param int $time_lastcomment Timestamp of when the last comment was posted. |
|
869 |
* @param int $time_newcomment Timestamp of when the new comment was posted. |
|
870 |
*/ |
|
871 |
$flood_die = apply_filters( 'comment_flood_filter', false, $time_lastcomment, $time_newcomment ); |
|
0 | 872 |
if ( $flood_die ) { |
5 | 873 |
/** |
874 |
* Fires before the comment flood message is triggered. |
|
875 |
* |
|
876 |
* @since 1.5.0 |
|
877 |
* |
|
878 |
* @param int $time_lastcomment Timestamp of when the last comment was posted. |
|
879 |
* @param int $time_newcomment Timestamp of when the new comment was posted. |
|
880 |
*/ |
|
881 |
do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
if ( true === $avoid_die ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
if ( wp_doing_ajax() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
die( __('You are posting comments too quickly. Slow down.') ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
wp_die( __( 'You are posting comments too quickly. Slow down.' ), 429 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
} |
0 | 891 |
} |
892 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
return false; |
0 | 895 |
} |
896 |
||
897 |
/** |
|
898 |
* Separates an array of comments into an array keyed by comment_type. |
|
899 |
* |
|
900 |
* @since 2.7.0 |
|
901 |
* |
|
902 |
* @param array $comments Array of comments |
|
903 |
* @return array Array of comments keyed by comment_type. |
|
904 |
*/ |
|
905 |
function separate_comments(&$comments) { |
|
906 |
$comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array()); |
|
907 |
$count = count($comments); |
|
908 |
for ( $i = 0; $i < $count; $i++ ) { |
|
909 |
$type = $comments[$i]->comment_type; |
|
910 |
if ( empty($type) ) |
|
911 |
$type = 'comment'; |
|
912 |
$comments_by_type[$type][] = &$comments[$i]; |
|
913 |
if ( 'trackback' == $type || 'pingback' == $type ) |
|
914 |
$comments_by_type['pings'][] = &$comments[$i]; |
|
915 |
} |
|
916 |
||
917 |
return $comments_by_type; |
|
918 |
} |
|
919 |
||
920 |
/** |
|
921 |
* Calculate the total number of comment pages. |
|
922 |
* |
|
923 |
* @since 2.7.0 |
|
5 | 924 |
* |
0 | 925 |
* @uses Walker_Comment |
926 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
* @global WP_Query $wp_query |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
* @param array $comments Optional array of WP_Comment objects. Defaults to $wp_query->comments |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
* @param int $per_page Optional comments per page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
* @param bool $threaded Optional control over flat or threaded comments. |
0 | 932 |
* @return int Number of comment pages. |
933 |
*/ |
|
934 |
function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) { |
|
935 |
global $wp_query; |
|
936 |
||
937 |
if ( null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages) ) |
|
938 |
return $wp_query->max_num_comment_pages; |
|
939 |
||
5 | 940 |
if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) |
0 | 941 |
$comments = $wp_query->comments; |
942 |
||
943 |
if ( empty($comments) ) |
|
944 |
return 0; |
|
945 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
if ( ! get_option( 'page_comments' ) ) { |
0 | 947 |
return 1; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
} |
0 | 949 |
|
950 |
if ( !isset($per_page) ) |
|
951 |
$per_page = (int) get_query_var('comments_per_page'); |
|
952 |
if ( 0 === $per_page ) |
|
953 |
$per_page = (int) get_option('comments_per_page'); |
|
954 |
if ( 0 === $per_page ) |
|
955 |
return 1; |
|
956 |
||
957 |
if ( !isset($threaded) ) |
|
958 |
$threaded = get_option('thread_comments'); |
|
959 |
||
960 |
if ( $threaded ) { |
|
961 |
$walker = new Walker_Comment; |
|
962 |
$count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page ); |
|
963 |
} else { |
|
964 |
$count = ceil( count( $comments ) / $per_page ); |
|
965 |
} |
|
966 |
||
967 |
return $count; |
|
968 |
} |
|
969 |
||
970 |
/** |
|
971 |
* Calculate what page number a comment will appear on for comment paging. |
|
972 |
* |
|
973 |
* @since 2.7.0 |
|
974 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
* @param int $comment_ID Comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
* Array of optional arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
* @type string $type Limit paginated comments to those matching a given type. Accepts 'comment', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
* 'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
* Default is 'all'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
* @type int $per_page Per-page count to use when calculating pagination. Defaults to the value of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
* 'comments_per_page' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
* @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
* `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
* } * |
0 | 988 |
* @return int|null Comment page number or null on error. |
989 |
*/ |
|
990 |
function get_page_of_comment( $comment_ID, $args = array() ) { |
|
991 |
global $wpdb; |
|
992 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
$page = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
|
0 | 995 |
if ( !$comment = get_comment( $comment_ID ) ) |
996 |
return; |
|
997 |
||
998 |
$defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); |
|
999 |
$args = wp_parse_args( $args, $defaults ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
$original_args = $args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
// 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
|
1003 |
if ( get_option( 'page_comments' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
if ( '' === $args['per_page'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
$args['per_page'] = get_query_var( 'comments_per_page' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
if ( '' === $args['per_page'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
$args['per_page'] = get_option( 'comments_per_page' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1010 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
|
0 | 1013 |
if ( empty($args['per_page']) ) { |
1014 |
$args['per_page'] = 0; |
|
1015 |
$args['page'] = 0; |
|
1016 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
if ( $args['per_page'] < 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
$page = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
if ( null === $page ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1023 |
if ( '' === $args['max_depth'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
if ( get_option('thread_comments') ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
$args['max_depth'] = get_option('thread_comments_depth'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
else |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
$args['max_depth'] = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
// Find this comment's top level parent if threading is enabled |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
return get_page_of_comment( $comment->comment_parent, $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
$comment_args = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
'type' => $args['type'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
'post_id' => $comment->comment_post_ID, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
'fields' => 'ids', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
'count' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
'status' => 'approve', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
'parent' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
'date_query' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
'column' => "$wpdb->comments.comment_date_gmt", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
'before' => $comment->comment_date_gmt, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
$comment_query = new WP_Comment_Query(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
$older_comment_count = $comment_query->query( $comment_args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
// No older comments? Then it's page #1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
if ( 0 == $older_comment_count ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
$page = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
// Divide comments older than this one by comments per page to get this comment's page number |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
$page = ceil( ( $older_comment_count + 1 ) / $args['per_page'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
} |
0 | 1060 |
} |
1061 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
* Filters the calculated page on which a comment appears. |
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 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
* @since 4.7.0 Introduced the `$comment_ID` parameter. |
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 |
* @param int $page Comment page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
* 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
|
1071 |
* 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
|
1072 |
* see `$original_args`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
* @type string $type Type of comments to count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
* @type int $page Calculated current page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
* @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
|
1077 |
* @type int $max_depth Maximum comment threading depth allowed. |
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 |
* @param array $original_args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
* 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
|
1081 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
* @type string $type Type of comments to count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1083 |
* @type int $page Current comment page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
* @type int $per_page Number of comments per page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
* @type int $max_depth Maximum comment threading depth allowed. |
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 |
* @param int $comment_ID ID of the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
return apply_filters( 'get_page_of_comment', (int) $page, $args, $original_args, $comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
|
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 |
* 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
|
1094 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
* @return array Maximum character length for the comment form fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
function wp_get_comment_fields_max_lengths() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
$lengths = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
'comment_author' => 245, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
'comment_author_email' => 100, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
'comment_author_url' => 200, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
'comment_content' => 65525, |
0 | 1109 |
); |
1110 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
if ( $wpdb->is_mysql ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
foreach ( $lengths as $column => $length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
$col_length = $wpdb->get_col_length( $wpdb->comments, $column ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
$max_length = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
// No point if we can't get the DB column lengths |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
if ( is_wp_error( $col_length ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1119 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
if ( ! is_array( $col_length ) && (int) $col_length > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
$max_length = (int) $col_length; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
} elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && intval( $col_length['length'] ) > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
$max_length = (int) $col_length['length']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
if ( ! empty( $col_length['type'] ) && 'byte' === $col_length['type'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
$max_length = $max_length - 10; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
if ( $max_length > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
$lengths[ $column ] = $max_length; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1133 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1134 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1135 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
* Filters the lengths for the comment form fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
* @param array $lengths Associative array `'field_name' => 'maximum length'`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
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
|
1145 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
|
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 |
* 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
|
1149 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
* @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
|
1153 |
* @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
|
1154 |
* otherwise true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
function wp_check_comment_data_max_lengths( $comment_data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
$max_lengths = wp_get_comment_fields_max_lengths(); |
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 |
if ( isset( $comment_data['comment_author'] ) && mb_strlen( $comment_data['comment_author'], '8bit' ) > $max_lengths['comment_author'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
return new WP_Error( 'comment_author_column_length', __( '<strong>ERROR</strong>: your name is too long.' ), 200 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
if ( isset( $comment_data['comment_author_email'] ) && strlen( $comment_data['comment_author_email'] ) > $max_lengths['comment_author_email'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
return new WP_Error( 'comment_author_email_column_length', __( '<strong>ERROR</strong>: your email address is too long.' ), 200 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
if ( isset( $comment_data['comment_author_url'] ) && strlen( $comment_data['comment_author_url'] ) > $max_lengths['comment_author_url'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
return new WP_Error( 'comment_author_url_column_length', __( '<strong>ERROR</strong>: your url is too long.' ), 200 ); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
if ( isset( $comment_data['comment_content'] ) && mb_strlen( $comment_data['comment_content'], '8bit' ) > $max_lengths['comment_content'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
return new WP_Error( 'comment_content_column_length', __( '<strong>ERROR</strong>: your comment is too long.' ), 200 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
} |
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 |
return true; |
0 | 1176 |
} |
1177 |
||
1178 |
/** |
|
1179 |
* Does comment contain blacklisted characters or words. |
|
1180 |
* |
|
1181 |
* @since 1.5.0 |
|
1182 |
* |
|
1183 |
* @param string $author The author of the comment |
|
1184 |
* @param string $email The email of the comment |
|
1185 |
* @param string $url The url used in the comment |
|
1186 |
* @param string $comment The comment content |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
* @param string $user_ip The comment author's IP address |
0 | 1188 |
* @param string $user_agent The author's browser user agent |
1189 |
* @return bool True if comment contains blacklisted content, false if comment does not |
|
1190 |
*/ |
|
1191 |
function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) { |
|
5 | 1192 |
/** |
1193 |
* Fires before the comment is tested for blacklisted characters or words. |
|
1194 |
* |
|
1195 |
* @since 1.5.0 |
|
1196 |
* |
|
1197 |
* @param string $author Comment author. |
|
1198 |
* @param string $email Comment author's email. |
|
1199 |
* @param string $url Comment author's URL. |
|
1200 |
* @param string $comment Comment content. |
|
1201 |
* @param string $user_ip Comment author's IP address. |
|
1202 |
* @param string $user_agent Comment author's browser user agent. |
|
1203 |
*/ |
|
1204 |
do_action( 'wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent ); |
|
0 | 1205 |
|
1206 |
$mod_keys = trim( get_option('blacklist_keys') ); |
|
1207 |
if ( '' == $mod_keys ) |
|
1208 |
return false; // If moderation keys are empty |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
// Ensure HTML tags are not being used to bypass the blacklist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
$comment_without_html = wp_strip_all_tags( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
|
0 | 1213 |
$words = explode("\n", $mod_keys ); |
1214 |
||
1215 |
foreach ( (array) $words as $word ) { |
|
1216 |
$word = trim($word); |
|
1217 |
||
1218 |
// Skip empty lines |
|
1219 |
if ( empty($word) ) { continue; } |
|
1220 |
||
1221 |
// Do some escaping magic so that '#' chars in the |
|
1222 |
// spam words don't break things: |
|
1223 |
$word = preg_quote($word, '#'); |
|
1224 |
||
1225 |
$pattern = "#$word#i"; |
|
1226 |
if ( |
|
1227 |
preg_match($pattern, $author) |
|
1228 |
|| preg_match($pattern, $email) |
|
1229 |
|| preg_match($pattern, $url) |
|
1230 |
|| preg_match($pattern, $comment) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
|| preg_match($pattern, $comment_without_html) |
0 | 1232 |
|| preg_match($pattern, $user_ip) |
1233 |
|| preg_match($pattern, $user_agent) |
|
1234 |
) |
|
1235 |
return true; |
|
1236 |
} |
|
1237 |
return false; |
|
1238 |
} |
|
1239 |
||
1240 |
/** |
|
1241 |
* Retrieve total comments for blog or single post. |
|
1242 |
* |
|
1243 |
* The properties of the returned object contain the 'moderated', 'approved', |
|
1244 |
* and spam comments for either the entire blog or single post. Those properties |
|
1245 |
* contain the amount of comments that match the status. The 'total_comments' |
|
1246 |
* property contains the integer of total comments. |
|
1247 |
* |
|
1248 |
* The comment stats are cached and then retrieved, if they already exist in the |
|
1249 |
* cache. |
|
1250 |
* |
|
1251 |
* @since 2.5.0 |
|
1252 |
* |
|
1253 |
* @param int $post_id Optional. Post ID. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
* @return object|array Comment stats. |
0 | 1255 |
*/ |
1256 |
function wp_count_comments( $post_id = 0 ) { |
|
1257 |
$post_id = (int) $post_id; |
|
1258 |
||
5 | 1259 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
* Filters the comments count for a given post. |
5 | 1261 |
* |
1262 |
* @since 2.7.0 |
|
1263 |
* |
|
1264 |
* @param array $count An empty array. |
|
1265 |
* @param int $post_id The post ID. |
|
1266 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
$filtered = apply_filters( 'wp_count_comments', array(), $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
if ( ! empty( $filtered ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
return $filtered; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1272 |
$count = wp_cache_get( "comments-{$post_id}", 'counts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1273 |
if ( false !== $count ) { |
0 | 1274 |
return $count; |
1275 |
} |
|
1276 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
$stats = get_comment_count( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
$stats['moderated'] = $stats['awaiting_moderation']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
unset( $stats['awaiting_moderation'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
$stats_object = (object) $stats; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
wp_cache_set( "comments-{$post_id}", $stats_object, 'counts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
return $stats_object; |
0 | 1285 |
} |
1286 |
||
1287 |
/** |
|
1288 |
* Trashes or deletes a comment. |
|
1289 |
* |
|
1290 |
* The comment is moved to trash instead of permanently deleted unless trash is |
|
1291 |
* disabled, item is already in the trash, or $force_delete is true. |
|
1292 |
* |
|
1293 |
* The post comment count will be updated if the comment was approved and has a |
|
1294 |
* post ID available. |
|
1295 |
* |
|
1296 |
* @since 2.0.0 |
|
5 | 1297 |
* |
1298 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 1299 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1300 |
* @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
|
1301 |
* @param bool $force_delete Whether to bypass trash and force deletion. Default is false. |
0 | 1302 |
* @return bool True on success, false on failure. |
1303 |
*/ |
|
1304 |
function wp_delete_comment($comment_id, $force_delete = false) { |
|
1305 |
global $wpdb; |
|
1306 |
if (!$comment = get_comment($comment_id)) |
|
1307 |
return false; |
|
1308 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) ) |
0 | 1310 |
return wp_trash_comment($comment_id); |
1311 |
||
5 | 1312 |
/** |
1313 |
* Fires immediately before a comment is deleted from the database. |
|
1314 |
* |
|
1315 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1317 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
* @param WP_Comment $comment The comment to be deleted. |
5 | 1320 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
do_action( 'delete_comment', $comment->comment_ID, $comment ); |
0 | 1322 |
|
1323 |
// Move children up a level. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
$children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID) ); |
0 | 1325 |
if ( !empty($children) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
$wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment->comment_ID)); |
0 | 1327 |
clean_comment_cache($children); |
1328 |
} |
|
1329 |
||
1330 |
// Delete metadata |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) ); |
0 | 1332 |
foreach ( $meta_ids as $mid ) |
1333 |
delete_metadata_by_mid( 'comment', $mid ); |
|
1334 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) |
0 | 1336 |
return false; |
5 | 1337 |
|
1338 |
/** |
|
1339 |
* Fires immediately after a comment is deleted from the database. |
|
1340 |
* |
|
1341 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1343 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
* @param WP_Comment $comment The deleted comment. |
5 | 1346 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
do_action( 'deleted_comment', $comment->comment_ID, $comment ); |
0 | 1348 |
|
1349 |
$post_id = $comment->comment_post_ID; |
|
1350 |
if ( $post_id && $comment->comment_approved == 1 ) |
|
1351 |
wp_update_comment_count($post_id); |
|
1352 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
clean_comment_cache( $comment->comment_ID ); |
0 | 1354 |
|
5 | 1355 |
/** 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
|
1356 |
do_action( 'wp_set_comment_status', $comment->comment_ID, 'delete' ); |
5 | 1357 |
|
0 | 1358 |
wp_transition_comment_status('delete', $comment->comment_approved, $comment); |
1359 |
return true; |
|
1360 |
} |
|
1361 |
||
1362 |
/** |
|
1363 |
* Moves a comment to the Trash |
|
1364 |
* |
|
1365 |
* If trash is disabled, comment is permanently deleted. |
|
1366 |
* |
|
1367 |
* @since 2.9.0 |
|
1368 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
0 | 1370 |
* @return bool True on success, false on failure. |
1371 |
*/ |
|
1372 |
function wp_trash_comment($comment_id) { |
|
1373 |
if ( !EMPTY_TRASH_DAYS ) |
|
1374 |
return wp_delete_comment($comment_id, true); |
|
1375 |
||
1376 |
if ( !$comment = get_comment($comment_id) ) |
|
1377 |
return false; |
|
1378 |
||
5 | 1379 |
/** |
1380 |
* Fires immediately before a comment is sent to the Trash. |
|
1381 |
* |
|
1382 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1384 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
* @param WP_Comment $comment The comment to be trashed. |
5 | 1387 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
do_action( 'trash_comment', $comment->comment_ID, $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
if ( wp_set_comment_status( $comment, 'trash' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
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
|
1392 |
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
|
1393 |
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
|
1394 |
add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); |
5 | 1395 |
|
1396 |
/** |
|
1397 |
* Fires immediately after a comment is sent to Trash. |
|
1398 |
* |
|
1399 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1401 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
* @param WP_Comment $comment The trashed comment. |
5 | 1404 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
do_action( 'trashed_comment', $comment->comment_ID, $comment ); |
0 | 1406 |
return true; |
1407 |
} |
|
1408 |
||
1409 |
return false; |
|
1410 |
} |
|
1411 |
||
1412 |
/** |
|
1413 |
* Removes a comment from the Trash |
|
1414 |
* |
|
1415 |
* @since 2.9.0 |
|
1416 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
0 | 1418 |
* @return bool True on success, false on failure. |
1419 |
*/ |
|
1420 |
function wp_untrash_comment($comment_id) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
$comment = get_comment( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
if ( ! $comment ) { |
0 | 1423 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
} |
0 | 1425 |
|
5 | 1426 |
/** |
1427 |
* Fires immediately before a comment is restored from the Trash. |
|
1428 |
* |
|
1429 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1430 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1431 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
* @param WP_Comment $comment The comment to be untrashed. |
5 | 1434 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1435 |
do_action( 'untrash_comment', $comment->comment_ID, $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
$status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); |
0 | 1438 |
if ( empty($status) ) |
1439 |
$status = '0'; |
|
1440 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1441 |
if ( wp_set_comment_status( $comment, $status ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
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
|
1443 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
5 | 1444 |
/** |
1445 |
* Fires immediately after a comment is restored from the Trash. |
|
1446 |
* |
|
1447 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1448 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1449 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1451 |
* @param WP_Comment $comment The untrashed comment. |
5 | 1452 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1453 |
do_action( 'untrashed_comment', $comment->comment_ID, $comment ); |
0 | 1454 |
return true; |
1455 |
} |
|
1456 |
||
1457 |
return false; |
|
1458 |
} |
|
1459 |
||
1460 |
/** |
|
1461 |
* Marks a comment as Spam |
|
1462 |
* |
|
1463 |
* @since 2.9.0 |
|
1464 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1465 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
0 | 1466 |
* @return bool True on success, false on failure. |
1467 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
function wp_spam_comment( $comment_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1469 |
$comment = get_comment( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
if ( ! $comment ) { |
0 | 1471 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
} |
0 | 1473 |
|
5 | 1474 |
/** |
1475 |
* Fires immediately before a comment is marked as Spam. |
|
1476 |
* |
|
1477 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1478 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1479 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1480 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
* @param WP_Comment $comment The comment to be marked as spam. |
5 | 1482 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
do_action( 'spam_comment', $comment->comment_ID, $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
if ( wp_set_comment_status( $comment, 'spam' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1486 |
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
|
1487 |
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
|
1488 |
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
|
1489 |
add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); |
5 | 1490 |
/** |
1491 |
* Fires immediately after a comment is marked as Spam. |
|
1492 |
* |
|
1493 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1495 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1496 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1497 |
* @param WP_Comment $comment The comment marked as spam. |
5 | 1498 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
do_action( 'spammed_comment', $comment->comment_ID, $comment ); |
0 | 1500 |
return true; |
1501 |
} |
|
1502 |
||
1503 |
return false; |
|
1504 |
} |
|
1505 |
||
1506 |
/** |
|
1507 |
* Removes a comment from the Spam |
|
1508 |
* |
|
1509 |
* @since 2.9.0 |
|
1510 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1511 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
0 | 1512 |
* @return bool True on success, false on failure. |
1513 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1514 |
function wp_unspam_comment( $comment_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
$comment = get_comment( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
if ( ! $comment ) { |
0 | 1517 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1518 |
} |
0 | 1519 |
|
5 | 1520 |
/** |
1521 |
* Fires immediately before a comment is unmarked as Spam. |
|
1522 |
* |
|
1523 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1525 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1526 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
* @param WP_Comment $comment The comment to be unmarked as spam. |
5 | 1528 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1529 |
do_action( 'unspam_comment', $comment->comment_ID, $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1530 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1531 |
$status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); |
0 | 1532 |
if ( empty($status) ) |
1533 |
$status = '0'; |
|
1534 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1535 |
if ( wp_set_comment_status( $comment, $status ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1536 |
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
|
1537 |
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
5 | 1538 |
/** |
1539 |
* Fires immediately after a comment is unmarked as Spam. |
|
1540 |
* |
|
1541 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1542 |
* @since 4.9.0 Added the `$comment` parameter. |
5 | 1543 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1544 |
* @param int $comment_id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1545 |
* @param WP_Comment $comment The comment unmarked as spam. |
5 | 1546 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1547 |
do_action( 'unspammed_comment', $comment->comment_ID, $comment ); |
0 | 1548 |
return true; |
1549 |
} |
|
1550 |
||
1551 |
return false; |
|
1552 |
} |
|
1553 |
||
1554 |
/** |
|
1555 |
* The status of a comment by ID. |
|
1556 |
* |
|
1557 |
* @since 1.0.0 |
|
1558 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object |
5 | 1560 |
* @return false|string Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure. |
0 | 1561 |
*/ |
1562 |
function wp_get_comment_status($comment_id) { |
|
1563 |
$comment = get_comment($comment_id); |
|
1564 |
if ( !$comment ) |
|
1565 |
return false; |
|
1566 |
||
1567 |
$approved = $comment->comment_approved; |
|
1568 |
||
1569 |
if ( $approved == null ) |
|
1570 |
return false; |
|
1571 |
elseif ( $approved == '1' ) |
|
1572 |
return 'approved'; |
|
1573 |
elseif ( $approved == '0' ) |
|
1574 |
return 'unapproved'; |
|
1575 |
elseif ( $approved == 'spam' ) |
|
1576 |
return 'spam'; |
|
1577 |
elseif ( $approved == 'trash' ) |
|
1578 |
return 'trash'; |
|
1579 |
else |
|
1580 |
return false; |
|
1581 |
} |
|
1582 |
||
1583 |
/** |
|
1584 |
* Call hooks for when a comment status transition occurs. |
|
1585 |
* |
|
1586 |
* Calls hooks for comment status transitions. If the new comment status is not the same |
|
1587 |
* as the previous comment status, then two hooks will be ran, the first is |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
* {@see 'transition_comment_status'} with new status, old status, and comment data. The |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
* next action called is {@see comment_$old_status_to_$new_status'}. It has the |
0 | 1590 |
* comment data. |
1591 |
* |
|
1592 |
* The final action will run whether or not the comment statuses are the same. The |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1593 |
* action is named {@see 'comment_$new_status_$comment->comment_type'}. |
0 | 1594 |
* |
1595 |
* @since 2.7.0 |
|
1596 |
* |
|
1597 |
* @param string $new_status New comment status. |
|
1598 |
* @param string $old_status Previous comment status. |
|
1599 |
* @param object $comment Comment data. |
|
1600 |
*/ |
|
1601 |
function wp_transition_comment_status($new_status, $old_status, $comment) { |
|
5 | 1602 |
/* |
1603 |
* Translate raw statuses to human readable formats for the hooks. |
|
1604 |
* This is not a complete list of comment status, it's only the ones |
|
1605 |
* that need to be renamed |
|
1606 |
*/ |
|
0 | 1607 |
$comment_statuses = array( |
1608 |
0 => 'unapproved', |
|
1609 |
'hold' => 'unapproved', // wp_set_comment_status() uses "hold" |
|
1610 |
1 => 'approved', |
|
1611 |
'approve' => 'approved', // wp_set_comment_status() uses "approve" |
|
1612 |
); |
|
1613 |
if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status]; |
|
1614 |
if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status]; |
|
1615 |
||
1616 |
// Call the hooks |
|
1617 |
if ( $new_status != $old_status ) { |
|
5 | 1618 |
/** |
1619 |
* Fires when the comment status is in transition. |
|
1620 |
* |
|
1621 |
* @since 2.7.0 |
|
1622 |
* |
|
1623 |
* @param int|string $new_status The new comment status. |
|
1624 |
* @param int|string $old_status The old comment status. |
|
1625 |
* @param object $comment The comment data. |
|
1626 |
*/ |
|
1627 |
do_action( 'transition_comment_status', $new_status, $old_status, $comment ); |
|
1628 |
/** |
|
1629 |
* Fires when the comment status is in transition from one specific status to another. |
|
1630 |
* |
|
1631 |
* The dynamic portions of the hook name, `$old_status`, and `$new_status`, |
|
1632 |
* refer to the old and new comment statuses, respectively. |
|
1633 |
* |
|
1634 |
* @since 2.7.0 |
|
1635 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1636 |
* @param WP_Comment $comment Comment object. |
5 | 1637 |
*/ |
1638 |
do_action( "comment_{$old_status}_to_{$new_status}", $comment ); |
|
0 | 1639 |
} |
5 | 1640 |
/** |
1641 |
* Fires when the status of a specific comment type is in transition. |
|
1642 |
* |
|
1643 |
* The dynamic portions of the hook name, `$new_status`, and `$comment->comment_type`, |
|
1644 |
* refer to the new comment status, and the type of comment, respectively. |
|
1645 |
* |
|
1646 |
* Typical comment types include an empty string (standard comment), 'pingback', |
|
1647 |
* or 'trackback'. |
|
1648 |
* |
|
1649 |
* @since 2.7.0 |
|
1650 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
* @param int $comment_ID The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1652 |
* @param WP_Comment $comment Comment object. |
5 | 1653 |
*/ |
1654 |
do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment ); |
|
0 | 1655 |
} |
1656 |
||
1657 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1658 |
* Clear the lastcommentmodified cached value when a comment status is changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1659 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1660 |
* 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
|
1661 |
* 'approved' status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1662 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1663 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1664 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1665 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1666 |
* @param string $new_status The new comment status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1667 |
* @param string $old_status The old comment status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1668 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1669 |
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
|
1670 |
if ( 'approved' === $new_status || 'approved' === $old_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1671 |
foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1672 |
wp_cache_delete( "lastcommentmodified:$timezone", 'timeinfo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1673 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1674 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1675 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1676 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
/** |
0 | 1678 |
* Get current commenter's name, email, and URL. |
1679 |
* |
|
1680 |
* Expects cookies content to already be sanitized. User of this function might |
|
1681 |
* wish to recheck the returned array for validity. |
|
1682 |
* |
|
1683 |
* @see sanitize_comment_cookies() Use to sanitize cookies |
|
1684 |
* |
|
1685 |
* @since 2.0.4 |
|
1686 |
* |
|
1687 |
* @return array Comment author, email, url respectively. |
|
1688 |
*/ |
|
1689 |
function wp_get_current_commenter() { |
|
1690 |
// Cookies should already be sanitized. |
|
1691 |
||
1692 |
$comment_author = ''; |
|
1693 |
if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) |
|
1694 |
$comment_author = $_COOKIE['comment_author_'.COOKIEHASH]; |
|
1695 |
||
1696 |
$comment_author_email = ''; |
|
1697 |
if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) |
|
1698 |
$comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH]; |
|
1699 |
||
1700 |
$comment_author_url = ''; |
|
1701 |
if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) |
|
1702 |
$comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH]; |
|
1703 |
||
5 | 1704 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1705 |
* Filters the current commenter's name, email, and URL. |
5 | 1706 |
* |
1707 |
* @since 3.1.0 |
|
1708 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1709 |
* @param array $comment_author_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
* An array of current commenter variables. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1711 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1712 |
* @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
|
1713 |
* @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
|
1714 |
* @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
|
1715 |
* } |
5 | 1716 |
*/ |
1717 |
return apply_filters( 'wp_get_current_commenter', compact('comment_author', 'comment_author_email', 'comment_author_url') ); |
|
0 | 1718 |
} |
1719 |
||
1720 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1721 |
* Inserts a comment into the database. |
0 | 1722 |
* |
1723 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1724 |
* @since 4.4.0 Introduced `$comment_meta` argument. |
5 | 1725 |
* |
1726 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 1727 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1728 |
* @param array $commentdata { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1729 |
* Array of arguments for inserting a new comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1730 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1731 |
* @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
|
1732 |
* the comment was submitted. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1733 |
* @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
|
1734 |
* @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
|
1735 |
* @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
|
1736 |
* @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
|
1737 |
* @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
|
1738 |
* @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
|
1739 |
* @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
|
1740 |
* manually, `$comment_date_gmt` must also be specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1741 |
* Default is the current time. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
* @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
|
1743 |
* 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
|
1744 |
* @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
|
1745 |
* @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
|
1746 |
* @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
|
1747 |
* Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1748 |
* @type string $comment_type Comment type. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1749 |
* @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
|
1750 |
* new comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1751 |
* @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
|
1752 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1753 |
* @return int|false The new comment's ID on success, false on failure. |
0 | 1754 |
*/ |
5 | 1755 |
function wp_insert_comment( $commentdata ) { |
0 | 1756 |
global $wpdb; |
5 | 1757 |
$data = wp_unslash( $commentdata ); |
1758 |
||
1759 |
$comment_author = ! isset( $data['comment_author'] ) ? '' : $data['comment_author']; |
|
1760 |
$comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email']; |
|
1761 |
$comment_author_url = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url']; |
|
1762 |
$comment_author_IP = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP']; |
|
1763 |
||
1764 |
$comment_date = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date']; |
|
1765 |
$comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt']; |
|
1766 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1767 |
$comment_post_ID = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID']; |
5 | 1768 |
$comment_content = ! isset( $data['comment_content'] ) ? '' : $data['comment_content']; |
1769 |
$comment_karma = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma']; |
|
1770 |
$comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved']; |
|
1771 |
$comment_agent = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent']; |
|
1772 |
$comment_type = ! isset( $data['comment_type'] ) ? '' : $data['comment_type']; |
|
1773 |
$comment_parent = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent']; |
|
1774 |
||
1775 |
$user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id']; |
|
1776 |
||
1777 |
$compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' ); |
|
1778 |
if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) { |
|
1779 |
return false; |
|
1780 |
} |
|
0 | 1781 |
|
1782 |
$id = (int) $wpdb->insert_id; |
|
1783 |
||
5 | 1784 |
if ( $comment_approved == 1 ) { |
1785 |
wp_update_comment_count( $comment_post_ID ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1786 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1787 |
foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1788 |
wp_cache_delete( "lastcommentmodified:$timezone", 'timeinfo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1789 |
} |
5 | 1790 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1791 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1792 |
clean_comment_cache( $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1793 |
|
5 | 1794 |
$comment = get_comment( $id ); |
1795 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1796 |
// If metadata is provided, store it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1797 |
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
|
1798 |
foreach ( $commentdata['comment_meta'] as $meta_key => $meta_value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1799 |
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
|
1800 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1801 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
|
5 | 1803 |
/** |
1804 |
* Fires immediately after a comment is inserted into the database. |
|
1805 |
* |
|
1806 |
* @since 2.8.0 |
|
1807 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1808 |
* @param int $id The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1809 |
* @param WP_Comment $comment Comment object. |
5 | 1810 |
*/ |
1811 |
do_action( 'wp_insert_comment', $id, $comment ); |
|
0 | 1812 |
|
1813 |
return $id; |
|
1814 |
} |
|
1815 |
||
1816 |
/** |
|
1817 |
* Filters and sanitizes comment data. |
|
1818 |
* |
|
1819 |
* Sets the comment data 'filtered' field to true when finished. This can be |
|
1820 |
* checked as to whether the comment should be filtered and to keep from |
|
1821 |
* filtering the same comment more than once. |
|
1822 |
* |
|
1823 |
* @since 2.0.0 |
|
1824 |
* |
|
1825 |
* @param array $commentdata Contains information on the comment. |
|
1826 |
* @return array Parsed comment information. |
|
1827 |
*/ |
|
1828 |
function wp_filter_comment($commentdata) { |
|
5 | 1829 |
if ( isset( $commentdata['user_ID'] ) ) { |
1830 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1831 |
* Filters the comment author's user id before it is set. |
5 | 1832 |
* |
1833 |
* The first time this filter is evaluated, 'user_ID' is checked |
|
1834 |
* (for back-compat), followed by the standard 'user_id' value. |
|
1835 |
* |
|
1836 |
* @since 1.5.0 |
|
1837 |
* |
|
1838 |
* @param int $user_ID The comment author's user ID. |
|
1839 |
*/ |
|
1840 |
$commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] ); |
|
1841 |
} elseif ( isset( $commentdata['user_id'] ) ) { |
|
1842 |
/** This filter is documented in wp-includes/comment.php */ |
|
1843 |
$commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_id'] ); |
|
1844 |
} |
|
1845 |
||
1846 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1847 |
* Filters the comment author's browser user agent before it is set. |
5 | 1848 |
* |
1849 |
* @since 1.5.0 |
|
1850 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1851 |
* @param string $comment_agent The comment author's browser user agent. |
5 | 1852 |
*/ |
1853 |
$commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '' ) ); |
|
1854 |
/** This filter is documented in wp-includes/comment.php */ |
|
1855 |
$commentdata['comment_author'] = apply_filters( 'pre_comment_author_name', $commentdata['comment_author'] ); |
|
1856 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1857 |
* Filters the comment content before it is set. |
5 | 1858 |
* |
1859 |
* @since 1.5.0 |
|
1860 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1861 |
* @param string $comment_content The comment content. |
5 | 1862 |
*/ |
1863 |
$commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] ); |
|
1864 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1865 |
* Filters the comment author's IP address before it is set. |
5 | 1866 |
* |
1867 |
* @since 1.5.0 |
|
1868 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1869 |
* @param string $comment_author_ip The comment author's IP address. |
5 | 1870 |
*/ |
1871 |
$commentdata['comment_author_IP'] = apply_filters( 'pre_comment_user_ip', $commentdata['comment_author_IP'] ); |
|
1872 |
/** This filter is documented in wp-includes/comment.php */ |
|
1873 |
$commentdata['comment_author_url'] = apply_filters( 'pre_comment_author_url', $commentdata['comment_author_url'] ); |
|
1874 |
/** This filter is documented in wp-includes/comment.php */ |
|
1875 |
$commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] ); |
|
0 | 1876 |
$commentdata['filtered'] = true; |
1877 |
return $commentdata; |
|
1878 |
} |
|
1879 |
||
1880 |
/** |
|
5 | 1881 |
* Whether a comment should be blocked because of comment flood. |
0 | 1882 |
* |
1883 |
* @since 2.1.0 |
|
1884 |
* |
|
1885 |
* @param bool $block Whether plugin has already blocked comment. |
|
1886 |
* @param int $time_lastcomment Timestamp for last comment. |
|
1887 |
* @param int $time_newcomment Timestamp for new comment. |
|
1888 |
* @return bool Whether comment should be blocked. |
|
1889 |
*/ |
|
1890 |
function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) { |
|
1891 |
if ( $block ) // a plugin has already blocked... we'll let that decision stand |
|
1892 |
return $block; |
|
1893 |
if ( ($time_newcomment - $time_lastcomment) < 15 ) |
|
1894 |
return true; |
|
1895 |
return false; |
|
1896 |
} |
|
1897 |
||
1898 |
/** |
|
1899 |
* Adds a new comment to the database. |
|
1900 |
* |
|
1901 |
* 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
|
1902 |
* 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
|
1903 |
* and whether comment is approved by WordPress. Also has {@see 'preprocess_comment'} |
0 | 1904 |
* filter for processing the comment data before the function handles it. |
1905 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1906 |
* We use `REMOTE_ADDR` here directly. If you are behind a proxy, you should ensure |
0 | 1907 |
* 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
|
1908 |
* |
5 | 1909 |
* See {@link https://core.trac.wordpress.org/ticket/9235} |
0 | 1910 |
* |
1911 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
* @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1913 |
* @since 4.7.0 The `$avoid_die` parameter was added, allowing the function to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1914 |
* return a WP_Error object instead of dying. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1915 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1916 |
* @see wp_insert_comment() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1917 |
* @global wpdb $wpdb WordPress database abstraction object. |
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 |
* @param array $commentdata { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
* Comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1921 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1922 |
* @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
|
1923 |
* @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
|
1924 |
* @type string $comment_author_url The comment author URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1925 |
* @type string $comment_content The content of the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1926 |
* @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
|
1927 |
* @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
|
1928 |
* Default is `$comment_date` in the GMT timezone. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1929 |
* @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
|
1930 |
* @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
|
1931 |
* @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
|
1932 |
* @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
|
1933 |
* @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
|
1934 |
* in the `$_SERVER` superglobal sent in the original request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
* @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
|
1936 |
* '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
|
1937 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1938 |
* @param bool $avoid_die Should errors be returned as WP_Error objects instead of |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
* executing wp_die()? Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1940 |
* @return int|false|WP_Error The ID of the comment on success, false or WP_Error on failure. |
0 | 1941 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1942 |
function wp_new_comment( $commentdata, $avoid_die = false ) { |
5 | 1943 |
global $wpdb; |
1944 |
||
1945 |
if ( isset( $commentdata['user_ID'] ) ) { |
|
1946 |
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID']; |
|
1947 |
} |
|
1948 |
||
1949 |
$prefiltered_user_id = ( isset( $commentdata['user_id'] ) ) ? (int) $commentdata['user_id'] : 0; |
|
1950 |
||
1951 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1952 |
* Filters a comment's data before it is sanitized and inserted into the database. |
5 | 1953 |
* |
1954 |
* @since 1.5.0 |
|
1955 |
* |
|
1956 |
* @param array $commentdata Comment data. |
|
1957 |
*/ |
|
1958 |
$commentdata = apply_filters( 'preprocess_comment', $commentdata ); |
|
0 | 1959 |
|
1960 |
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID']; |
|
5 | 1961 |
if ( isset( $commentdata['user_ID'] ) && $prefiltered_user_id !== (int) $commentdata['user_ID'] ) { |
0 | 1962 |
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID']; |
5 | 1963 |
} elseif ( isset( $commentdata['user_id'] ) ) { |
0 | 1964 |
$commentdata['user_id'] = (int) $commentdata['user_id']; |
5 | 1965 |
} |
0 | 1966 |
|
1967 |
$commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0; |
|
1968 |
$parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : ''; |
|
1969 |
$commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0; |
|
1970 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1971 |
if ( ! isset( $commentdata['comment_author_IP'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1972 |
$commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1973 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1974 |
$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
|
1975 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1976 |
if ( ! isset( $commentdata['comment_agent'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1977 |
$commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT']: ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1978 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1979 |
$commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 ); |
0 | 1980 |
|
5 | 1981 |
if ( empty( $commentdata['comment_date'] ) ) { |
1982 |
$commentdata['comment_date'] = current_time('mysql'); |
|
1983 |
} |
|
1984 |
||
1985 |
if ( empty( $commentdata['comment_date_gmt'] ) ) { |
|
1986 |
$commentdata['comment_date_gmt'] = current_time( 'mysql', 1 ); |
|
1987 |
} |
|
0 | 1988 |
|
1989 |
$commentdata = wp_filter_comment($commentdata); |
|
1990 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
$commentdata['comment_approved'] = wp_allow_comment( $commentdata, $avoid_die ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
if ( is_wp_error( $commentdata['comment_approved'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
return $commentdata['comment_approved']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1994 |
} |
0 | 1995 |
|
1996 |
$comment_ID = wp_insert_comment($commentdata); |
|
5 | 1997 |
if ( ! $comment_ID ) { |
1998 |
$fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' ); |
|
1999 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2000 |
foreach ( $fields as $field ) { |
5 | 2001 |
if ( isset( $commentdata[ $field ] ) ) { |
2002 |
$commentdata[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, $field, $commentdata[ $field ] ); |
|
2003 |
} |
|
2004 |
} |
|
2005 |
||
2006 |
$commentdata = wp_filter_comment( $commentdata ); |
|
2007 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2008 |
$commentdata['comment_approved'] = wp_allow_comment( $commentdata, $avoid_die ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2009 |
if ( is_wp_error( $commentdata['comment_approved'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2010 |
return $commentdata['comment_approved']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2011 |
} |
5 | 2012 |
|
2013 |
$comment_ID = wp_insert_comment( $commentdata ); |
|
2014 |
if ( ! $comment_ID ) { |
|
2015 |
return false; |
|
2016 |
} |
|
2017 |
} |
|
2018 |
||
2019 |
/** |
|
2020 |
* Fires immediately after a comment is inserted into the database. |
|
2021 |
* |
|
2022 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2023 |
* @since 4.5.0 The `$commentdata` parameter was added. |
5 | 2024 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2025 |
* @param int $comment_ID The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
* @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
|
2027 |
* @param array $commentdata Comment data. |
5 | 2028 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'], $commentdata ); |
0 | 2030 |
|
2031 |
return $comment_ID; |
|
2032 |
} |
|
2033 |
||
2034 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
* Send a comment moderation notification to the comment moderator. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2036 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2037 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2038 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2039 |
* @param int $comment_ID ID of the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2041 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2042 |
function wp_new_comment_notify_moderator( $comment_ID ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2043 |
$comment = get_comment( $comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2044 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2045 |
// Only send notifications for pending comments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2046 |
$maybe_notify = ( '0' == $comment->comment_approved ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2047 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
/** This filter is documented in wp-includes/comment.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2049 |
$maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
if ( ! $maybe_notify ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2054 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2055 |
return wp_notify_moderator( $comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2056 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2057 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2058 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2059 |
* Send a notification of a new comment to the post author. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2060 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2062 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2063 |
* 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
|
2064 |
* 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
|
2065 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2066 |
* @param int $comment_ID Comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2067 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2068 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2069 |
function wp_new_comment_notify_postauthor( $comment_ID ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2070 |
$comment = get_comment( $comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2071 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2072 |
$maybe_notify = get_option( 'comments_notify' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2073 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2074 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2075 |
* 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
|
2076 |
* overriding the site setting. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2077 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2078 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2079 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2080 |
* @param bool $maybe_notify Whether to notify the post author about the new comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2081 |
* @param int $comment_ID The ID of the comment for the notification. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
$maybe_notify = apply_filters( 'notify_post_author', $maybe_notify, $comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2085 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2086 |
* 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
|
2087 |
* 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
|
2088 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2089 |
if ( ! $maybe_notify ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2091 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2092 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
// Only send notifications for approved comments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2094 |
if ( ! isset( $comment->comment_approved ) || '1' != $comment->comment_approved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2095 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2096 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2097 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2098 |
return wp_notify_postauthor( $comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2099 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2100 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2101 |
/** |
0 | 2102 |
* Sets the status of a comment. |
2103 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2104 |
* The {@see 'wp_set_comment_status'} action is called after the comment is handled. |
0 | 2105 |
* If the comment status is not in the list, then false is returned. |
2106 |
* |
|
2107 |
* @since 1.0.0 |
|
2108 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2109 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
* @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
|
2112 |
* @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
* @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false. |
0 | 2114 |
* @return bool|WP_Error True on success, false or WP_Error on failure. |
2115 |
*/ |
|
2116 |
function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) { |
|
2117 |
global $wpdb; |
|
2118 |
||
2119 |
switch ( $comment_status ) { |
|
2120 |
case 'hold': |
|
2121 |
case '0': |
|
2122 |
$status = '0'; |
|
2123 |
break; |
|
2124 |
case 'approve': |
|
2125 |
case '1': |
|
2126 |
$status = '1'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2127 |
add_action( 'wp_set_comment_status', 'wp_new_comment_notify_postauthor' ); |
0 | 2128 |
break; |
2129 |
case 'spam': |
|
2130 |
$status = 'spam'; |
|
2131 |
break; |
|
2132 |
case 'trash': |
|
2133 |
$status = 'trash'; |
|
2134 |
break; |
|
2135 |
default: |
|
2136 |
return false; |
|
2137 |
} |
|
2138 |
||
2139 |
$comment_old = clone get_comment($comment_id); |
|
2140 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2141 |
if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array( 'comment_ID' => $comment_old->comment_ID ) ) ) { |
0 | 2142 |
if ( $wp_error ) |
2143 |
return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error); |
|
2144 |
else |
|
2145 |
return false; |
|
2146 |
} |
|
2147 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2148 |
clean_comment_cache( $comment_old->comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2149 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2150 |
$comment = get_comment( $comment_old->comment_ID ); |
0 | 2151 |
|
5 | 2152 |
/** |
2153 |
* Fires immediately before transitioning a comment's status from one to another |
|
2154 |
* in the database. |
|
2155 |
* |
|
2156 |
* @since 1.5.0 |
|
2157 |
* |
|
2158 |
* @param int $comment_id Comment ID. |
|
2159 |
* @param string|bool $comment_status Current comment status. Possible values include |
|
2160 |
* 'hold', 'approve', 'spam', 'trash', or false. |
|
2161 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2162 |
do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); |
5 | 2163 |
|
0 | 2164 |
wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment); |
2165 |
||
2166 |
wp_update_comment_count($comment->comment_post_ID); |
|
2167 |
||
2168 |
return true; |
|
2169 |
} |
|
2170 |
||
2171 |
/** |
|
2172 |
* Updates an existing comment in the database. |
|
2173 |
* |
|
2174 |
* Filters the comment and makes sure certain fields are valid before updating. |
|
2175 |
* |
|
2176 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
* @since 4.9.0 Add updating comment meta during comment update. |
5 | 2178 |
* |
2179 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 2180 |
* |
2181 |
* @param array $commentarr Contains information on the comment. |
|
2182 |
* @return int Comment was updated if value is 1, or was not updated if value is 0. |
|
2183 |
*/ |
|
2184 |
function wp_update_comment($commentarr) { |
|
2185 |
global $wpdb; |
|
2186 |
||
2187 |
// First, get all of the original fields |
|
2188 |
$comment = get_comment($commentarr['comment_ID'], ARRAY_A); |
|
5 | 2189 |
if ( empty( $comment ) ) { |
0 | 2190 |
return 0; |
5 | 2191 |
} |
2192 |
||
2193 |
// 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
|
2194 |
if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) { |
5 | 2195 |
return 0; |
2196 |
} |
|
0 | 2197 |
|
2198 |
// Escape data pulled from DB. |
|
2199 |
$comment = wp_slash($comment); |
|
2200 |
||
2201 |
$old_status = $comment['comment_approved']; |
|
2202 |
||
2203 |
// Merge old and new fields with new fields overwriting old ones. |
|
2204 |
$commentarr = array_merge($comment, $commentarr); |
|
2205 |
||
2206 |
$commentarr = wp_filter_comment( $commentarr ); |
|
2207 |
||
2208 |
// Now extract the merged array. |
|
5 | 2209 |
$data = wp_unslash( $commentarr ); |
2210 |
||
2211 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2212 |
* Filters the comment content before it is updated in the database. |
5 | 2213 |
* |
2214 |
* @since 1.5.0 |
|
2215 |
* |
|
2216 |
* @param string $comment_content The comment data. |
|
2217 |
*/ |
|
2218 |
$data['comment_content'] = apply_filters( 'comment_save_pre', $data['comment_content'] ); |
|
2219 |
||
2220 |
$data['comment_date_gmt'] = get_gmt_from_date( $data['comment_date'] ); |
|
2221 |
||
2222 |
if ( ! isset( $data['comment_approved'] ) ) { |
|
2223 |
$data['comment_approved'] = 1; |
|
2224 |
} elseif ( 'hold' == $data['comment_approved'] ) { |
|
2225 |
$data['comment_approved'] = 0; |
|
2226 |
} elseif ( 'approve' == $data['comment_approved'] ) { |
|
2227 |
$data['comment_approved'] = 1; |
|
2228 |
} |
|
2229 |
||
2230 |
$comment_ID = $data['comment_ID']; |
|
2231 |
$comment_post_ID = $data['comment_post_ID']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2232 |
|
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 |
* 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
|
2235 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
* 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
|
2237 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
* @since 4.7.0 |
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 |
* @param array $data The new, processed comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
* @param array $comment The old, unslashed comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2242 |
* @param array $commentarr The new, raw comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2243 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
$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
|
2245 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2246 |
$keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id', 'comment_agent', 'comment_author_IP' ); |
5 | 2247 |
$data = wp_array_slice_assoc( $data, $keys ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2248 |
|
0 | 2249 |
$rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); |
2250 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2251 |
// If metadata is provided, store it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2252 |
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
|
2253 |
foreach ( $commentarr['comment_meta'] as $meta_key => $meta_value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2254 |
update_comment_meta( $comment_ID, $meta_key, $meta_value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2255 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2256 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2257 |
|
5 | 2258 |
clean_comment_cache( $comment_ID ); |
2259 |
wp_update_comment_count( $comment_post_ID ); |
|
2260 |
/** |
|
2261 |
* Fires immediately after a comment is updated in the database. |
|
2262 |
* |
|
2263 |
* The hook also fires immediately before comment status transition hooks are fired. |
|
2264 |
* |
|
2265 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2266 |
* @since 4.6.0 Added the `$data` parameter. |
5 | 2267 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2268 |
* @param int $comment_ID The comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2269 |
* @param array $data Comment data. |
5 | 2270 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2271 |
do_action( 'edit_comment', $comment_ID, $data ); |
0 | 2272 |
$comment = get_comment($comment_ID); |
2273 |
wp_transition_comment_status($comment->comment_approved, $old_status, $comment); |
|
2274 |
return $rval; |
|
2275 |
} |
|
2276 |
||
2277 |
/** |
|
2278 |
* Whether to defer comment counting. |
|
2279 |
* |
|
2280 |
* When setting $defer to true, all post comment counts will not be updated |
|
2281 |
* until $defer is set to false. When $defer is set to false, then all |
|
2282 |
* previously deferred updated post comment counts will then be automatically |
|
2283 |
* updated without having to call wp_update_comment_count() after. |
|
2284 |
* |
|
2285 |
* @since 2.5.0 |
|
2286 |
* @staticvar bool $_defer |
|
2287 |
* |
|
2288 |
* @param bool $defer |
|
5 | 2289 |
* @return bool |
0 | 2290 |
*/ |
2291 |
function wp_defer_comment_counting($defer=null) { |
|
2292 |
static $_defer = false; |
|
2293 |
||
2294 |
if ( is_bool($defer) ) { |
|
2295 |
$_defer = $defer; |
|
2296 |
// flush any deferred counts |
|
2297 |
if ( !$defer ) |
|
2298 |
wp_update_comment_count( null, true ); |
|
2299 |
} |
|
2300 |
||
2301 |
return $_defer; |
|
2302 |
} |
|
2303 |
||
2304 |
/** |
|
2305 |
* Updates the comment count for post(s). |
|
2306 |
* |
|
2307 |
* When $do_deferred is false (is by default) and the comments have been set to |
|
2308 |
* be deferred, the post_id will be added to a queue, which will be updated at a |
|
2309 |
* later date and only updated once per post ID. |
|
2310 |
* |
|
2311 |
* If the comments have not be set up to be deferred, then the post will be |
|
2312 |
* updated. When $do_deferred is set to true, then all previous deferred post |
|
2313 |
* IDs will be updated along with the current $post_id. |
|
2314 |
* |
|
2315 |
* @since 2.1.0 |
|
2316 |
* @see wp_update_comment_count_now() For what could cause a false return value |
|
2317 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2318 |
* @staticvar array $_deferred |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2319 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2320 |
* @param int|null $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2321 |
* @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
|
2322 |
* post comment counts. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2323 |
* @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
|
2324 |
* not exist. |
0 | 2325 |
*/ |
2326 |
function wp_update_comment_count($post_id, $do_deferred=false) { |
|
2327 |
static $_deferred = array(); |
|
2328 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2329 |
if ( empty( $post_id ) && ! $do_deferred ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2330 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2331 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2332 |
|
0 | 2333 |
if ( $do_deferred ) { |
2334 |
$_deferred = array_unique($_deferred); |
|
2335 |
foreach ( $_deferred as $i => $_post_id ) { |
|
2336 |
wp_update_comment_count_now($_post_id); |
|
2337 |
unset( $_deferred[$i] ); /** @todo Move this outside of the foreach and reset $_deferred to an array instead */ |
|
2338 |
} |
|
2339 |
} |
|
2340 |
||
2341 |
if ( wp_defer_comment_counting() ) { |
|
2342 |
$_deferred[] = $post_id; |
|
2343 |
return true; |
|
2344 |
} |
|
2345 |
elseif ( $post_id ) { |
|
2346 |
return wp_update_comment_count_now($post_id); |
|
2347 |
} |
|
2348 |
||
2349 |
} |
|
2350 |
||
2351 |
/** |
|
2352 |
* Updates the comment count for the post. |
|
2353 |
* |
|
2354 |
* @since 2.5.0 |
|
5 | 2355 |
* |
2356 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 2357 |
* |
2358 |
* @param int $post_id Post ID |
|
2359 |
* @return bool True on success, false on '0' $post_id or if post with ID does not exist. |
|
2360 |
*/ |
|
2361 |
function wp_update_comment_count_now($post_id) { |
|
2362 |
global $wpdb; |
|
2363 |
$post_id = (int) $post_id; |
|
2364 |
if ( !$post_id ) |
|
2365 |
return false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2366 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2367 |
wp_cache_delete( 'comments-0', 'counts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2368 |
wp_cache_delete( "comments-{$post_id}", 'counts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2369 |
|
0 | 2370 |
if ( !$post = get_post($post_id) ) |
2371 |
return false; |
|
2372 |
||
2373 |
$old = (int) $post->comment_count; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2374 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2375 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2376 |
* 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
|
2377 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2378 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2379 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2380 |
* @param int $new The new comment count. Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2381 |
* @param int $old The old comment count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2382 |
* @param int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2383 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2384 |
$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
|
2385 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2386 |
if ( is_null( $new ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2387 |
$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
|
2388 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2389 |
$new = (int) $new; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2390 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2391 |
|
0 | 2392 |
$wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) ); |
2393 |
||
2394 |
clean_post_cache( $post ); |
|
2395 |
||
5 | 2396 |
/** |
2397 |
* Fires immediately after a post's comment count is updated in the database. |
|
2398 |
* |
|
2399 |
* @since 2.3.0 |
|
2400 |
* |
|
2401 |
* @param int $post_id Post ID. |
|
2402 |
* @param int $new The new comment count. |
|
2403 |
* @param int $old The old comment count. |
|
2404 |
*/ |
|
2405 |
do_action( 'wp_update_comment_count', $post_id, $new, $old ); |
|
2406 |
/** This action is documented in wp-includes/post.php */ |
|
2407 |
do_action( 'edit_post', $post_id, $post ); |
|
0 | 2408 |
|
2409 |
return true; |
|
2410 |
} |
|
2411 |
||
2412 |
// |
|
2413 |
// Ping and trackback functions. |
|
2414 |
// |
|
2415 |
||
2416 |
/** |
|
2417 |
* Finds a pingback server URI based on the given URL. |
|
2418 |
* |
|
2419 |
* Checks the HTML for the rel="pingback" link and x-pingback headers. It does |
|
2420 |
* a check for the x-pingback headers first and returns that, if available. The |
|
2421 |
* check for the rel="pingback" has more overhead than just the header. |
|
2422 |
* |
|
2423 |
* @since 1.5.0 |
|
2424 |
* |
|
2425 |
* @param string $url URL to ping. |
|
2426 |
* @param int $deprecated Not Used. |
|
5 | 2427 |
* @return false|string False on failure, string containing URI on success. |
0 | 2428 |
*/ |
2429 |
function discover_pingback_server_uri( $url, $deprecated = '' ) { |
|
2430 |
if ( !empty( $deprecated ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2431 |
_deprecated_argument( __FUNCTION__, '2.7.0' ); |
0 | 2432 |
|
2433 |
$pingback_str_dquote = 'rel="pingback"'; |
|
2434 |
$pingback_str_squote = 'rel=\'pingback\''; |
|
2435 |
||
2436 |
/** @todo Should use Filter Extension or custom preg_match instead. */ |
|
2437 |
$parsed_url = parse_url($url); |
|
2438 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2439 |
if ( ! isset( $parsed_url['host'] ) ) // Not a URL. This should never happen. |
0 | 2440 |
return false; |
2441 |
||
2442 |
//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
|
2443 |
$uploads_dir = wp_get_upload_dir(); |
0 | 2444 |
if ( 0 === strpos($url, $uploads_dir['baseurl']) ) |
2445 |
return false; |
|
2446 |
||
2447 |
$response = wp_safe_remote_head( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) ); |
|
2448 |
||
2449 |
if ( is_wp_error( $response ) ) |
|
2450 |
return false; |
|
2451 |
||
2452 |
if ( wp_remote_retrieve_header( $response, 'x-pingback' ) ) |
|
2453 |
return wp_remote_retrieve_header( $response, 'x-pingback' ); |
|
2454 |
||
2455 |
// Not an (x)html, sgml, or xml page, no use going further. |
|
2456 |
if ( preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) ) |
|
2457 |
return false; |
|
2458 |
||
2459 |
// Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file) |
|
2460 |
$response = wp_safe_remote_get( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) ); |
|
2461 |
||
2462 |
if ( is_wp_error( $response ) ) |
|
2463 |
return false; |
|
2464 |
||
2465 |
$contents = wp_remote_retrieve_body( $response ); |
|
2466 |
||
2467 |
$pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote); |
|
2468 |
$pingback_link_offset_squote = strpos($contents, $pingback_str_squote); |
|
2469 |
if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) { |
|
2470 |
$quote = ($pingback_link_offset_dquote) ? '"' : '\''; |
|
2471 |
$pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote; |
|
2472 |
$pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset); |
|
2473 |
$pingback_href_start = $pingback_href_pos+6; |
|
2474 |
$pingback_href_end = @strpos($contents, $quote, $pingback_href_start); |
|
2475 |
$pingback_server_url_len = $pingback_href_end - $pingback_href_start; |
|
2476 |
$pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len); |
|
2477 |
||
2478 |
// We may find rel="pingback" but an incomplete pingback URL |
|
2479 |
if ( $pingback_server_url_len > 0 ) { // We got it! |
|
2480 |
return $pingback_server_url; |
|
2481 |
} |
|
2482 |
} |
|
2483 |
||
2484 |
return false; |
|
2485 |
} |
|
2486 |
||
2487 |
/** |
|
2488 |
* Perform all pingbacks, enclosures, trackbacks, and send to pingback services. |
|
2489 |
* |
|
2490 |
* @since 2.1.0 |
|
5 | 2491 |
* |
2492 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 2493 |
*/ |
2494 |
function do_all_pings() { |
|
2495 |
global $wpdb; |
|
2496 |
||
2497 |
// Do pingbacks |
|
2498 |
while ($ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) { |
|
2499 |
delete_metadata_by_mid( 'post', $ping->meta_id ); |
|
2500 |
pingback( $ping->post_content, $ping->ID ); |
|
2501 |
} |
|
2502 |
||
2503 |
// Do Enclosures |
|
2504 |
while ($enclosure = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) { |
|
2505 |
delete_metadata_by_mid( 'post', $enclosure->meta_id ); |
|
2506 |
do_enclose( $enclosure->post_content, $enclosure->ID ); |
|
2507 |
} |
|
2508 |
||
2509 |
// Do Trackbacks |
|
2510 |
$trackbacks = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'"); |
|
2511 |
if ( is_array($trackbacks) ) |
|
2512 |
foreach ( $trackbacks as $trackback ) |
|
2513 |
do_trackbacks($trackback); |
|
2514 |
||
2515 |
//Do Update Services/Generic Pings |
|
2516 |
generic_ping(); |
|
2517 |
} |
|
2518 |
||
2519 |
/** |
|
2520 |
* Perform trackbacks. |
|
2521 |
* |
|
2522 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2523 |
* @since 4.7.0 $post_id can be a WP_Post object. |
5 | 2524 |
* |
2525 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 2526 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2527 |
* @param int|WP_Post $post_id Post object or ID to do trackbacks on. |
0 | 2528 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2529 |
function do_trackbacks( $post_id ) { |
0 | 2530 |
global $wpdb; |
2531 |
$post = get_post( $post_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2532 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2533 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2534 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2535 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2536 |
$to_ping = get_to_ping( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2537 |
$pinged = get_pung( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2538 |
if ( empty( $to_ping ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2539 |
$wpdb->update($wpdb->posts, array( 'to_ping' => '' ), array( 'ID' => $post->ID ) ); |
0 | 2540 |
return; |
2541 |
} |
|
2542 |
||
5 | 2543 |
if ( empty($post->post_excerpt) ) { |
2544 |
/** This filter is documented in wp-includes/post-template.php */ |
|
2545 |
$excerpt = apply_filters( 'the_content', $post->post_content, $post->ID ); |
|
2546 |
} else { |
|
2547 |
/** This filter is documented in wp-includes/post-template.php */ |
|
2548 |
$excerpt = apply_filters( 'the_excerpt', $post->post_excerpt ); |
|
2549 |
} |
|
2550 |
||
0 | 2551 |
$excerpt = str_replace(']]>', ']]>', $excerpt); |
2552 |
$excerpt = wp_html_excerpt($excerpt, 252, '…'); |
|
2553 |
||
2554 |
/** This filter is documented in wp-includes/post-template.php */ |
|
5 | 2555 |
$post_title = apply_filters( 'the_title', $post->post_title, $post->ID ); |
0 | 2556 |
$post_title = strip_tags($post_title); |
2557 |
||
2558 |
if ( $to_ping ) { |
|
2559 |
foreach ( (array) $to_ping as $tb_ping ) { |
|
2560 |
$tb_ping = trim($tb_ping); |
|
2561 |
if ( !in_array($tb_ping, $pinged) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2562 |
trackback( $tb_ping, $post_title, $excerpt, $post->ID ); |
0 | 2563 |
$pinged[] = $tb_ping; |
2564 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2565 |
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2566 |
'')) WHERE ID = %d", $tb_ping, $post->ID ) ); |
0 | 2567 |
} |
2568 |
} |
|
2569 |
} |
|
2570 |
} |
|
2571 |
||
2572 |
/** |
|
2573 |
* Sends pings to all of the ping site services. |
|
2574 |
* |
|
2575 |
* @since 1.2.0 |
|
2576 |
* |
|
5 | 2577 |
* @param int $post_id Post ID. |
0 | 2578 |
* @return int Same as Post ID from parameter |
2579 |
*/ |
|
5 | 2580 |
function generic_ping( $post_id = 0 ) { |
0 | 2581 |
$services = get_option('ping_sites'); |
2582 |
||
2583 |
$services = explode("\n", $services); |
|
2584 |
foreach ( (array) $services as $service ) { |
|
2585 |
$service = trim($service); |
|
2586 |
if ( '' != $service ) |
|
2587 |
weblog_ping($service); |
|
2588 |
} |
|
2589 |
||
2590 |
return $post_id; |
|
2591 |
} |
|
2592 |
||
2593 |
/** |
|
2594 |
* Pings back the links found in a post. |
|
2595 |
* |
|
2596 |
* @since 0.71 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2597 |
* @since 4.7.0 $post_id can be a WP_Post object. |
0 | 2598 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2599 |
* @param string $content Post content to check for links. If empty will retrieve from post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2600 |
* @param int|WP_Post $post_id Post Object or ID. |
0 | 2601 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2602 |
function pingback( $content, $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2603 |
include_once( ABSPATH . WPINC . '/class-IXR.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2604 |
include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' ); |
0 | 2605 |
|
2606 |
// original code by Mort (http://mort.mine.nu:8080) |
|
2607 |
$post_links = array(); |
|
2608 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2609 |
$post = get_post( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2610 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2611 |
return; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2614 |
$pung = get_pung( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2615 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2616 |
if ( empty( $content ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2617 |
$content = $post->post_content; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2618 |
} |
0 | 2619 |
|
2620 |
// Step 1 |
|
2621 |
// Parsing the post, external links (if any) are stored in the $post_links array |
|
2622 |
$post_links_temp = wp_extract_urls( $content ); |
|
2623 |
||
2624 |
// Step 2. |
|
2625 |
// Walking thru the links array |
|
2626 |
// first we get rid of links pointing to sites, not to specific files |
|
2627 |
// Example: |
|
2628 |
// http://dummy-weblog.org |
|
2629 |
// http://dummy-weblog.org/ |
|
2630 |
// http://dummy-weblog.org/post.php |
|
2631 |
// We don't wanna ping first and second types, even if they have a valid <link/> |
|
2632 |
||
2633 |
foreach ( (array) $post_links_temp as $link_test ) : |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2634 |
if ( ! in_array( $link_test, $pung ) && ( url_to_postid( $link_test ) != $post->ID ) // If we haven't pung it already and it isn't a link to itself |
0 | 2635 |
&& !is_local_attachment($link_test) ) : // Also, let's never ping local attachments. |
2636 |
if ( $test = @parse_url($link_test) ) { |
|
2637 |
if ( isset($test['query']) ) |
|
2638 |
$post_links[] = $link_test; |
|
2639 |
elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) ) |
|
2640 |
$post_links[] = $link_test; |
|
2641 |
} |
|
2642 |
endif; |
|
2643 |
endforeach; |
|
2644 |
||
2645 |
$post_links = array_unique( $post_links ); |
|
5 | 2646 |
/** |
2647 |
* Fires just before pinging back links found in a post. |
|
2648 |
* |
|
2649 |
* @since 2.0.0 |
|
2650 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2651 |
* @param array $post_links An array of post links to be checked (passed by reference). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2652 |
* @param array $pung Whether a link has already been pinged (passed by reference). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2653 |
* @param int $post_ID The post ID. |
5 | 2654 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2655 |
do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post->ID ) ); |
0 | 2656 |
|
2657 |
foreach ( (array) $post_links as $pagelinkedto ) { |
|
2658 |
$pingback_server_url = discover_pingback_server_uri( $pagelinkedto ); |
|
2659 |
||
2660 |
if ( $pingback_server_url ) { |
|
2661 |
@ set_time_limit( 60 ); |
|
5 | 2662 |
// Now, the RPC call |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2663 |
$pagelinkedfrom = get_permalink( $post ); |
0 | 2664 |
|
2665 |
// using a timeout of 3 seconds should be enough to cover slow servers |
|
2666 |
$client = new WP_HTTP_IXR_Client($pingback_server_url); |
|
2667 |
$client->timeout = 3; |
|
5 | 2668 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2669 |
* Filters the user agent sent when pinging-back a URL. |
5 | 2670 |
* |
2671 |
* @since 2.9.0 |
|
2672 |
* |
|
2673 |
* @param string $concat_useragent The user agent concatenated with ' -- WordPress/' |
|
2674 |
* and the WordPress version. |
|
2675 |
* @param string $useragent The useragent. |
|
2676 |
* @param string $pingback_server_url The server URL being linked to. |
|
2677 |
* @param string $pagelinkedto URL of page linked to. |
|
2678 |
* @param string $pagelinkedfrom URL of page linked from. |
|
2679 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2680 |
$client->useragent = apply_filters( 'pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo( 'version' ), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom ); |
0 | 2681 |
// when set to true, this outputs debug messages by itself |
2682 |
$client->debug = false; |
|
2683 |
||
2684 |
if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) ) // Already registered |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2685 |
add_ping( $post, $pagelinkedto ); |
0 | 2686 |
} |
2687 |
} |
|
2688 |
} |
|
2689 |
||
2690 |
/** |
|
2691 |
* Check whether blog is public before returning sites. |
|
2692 |
* |
|
2693 |
* @since 2.1.0 |
|
2694 |
* |
|
2695 |
* @param mixed $sites Will return if blog is public, will not return if not public. |
|
2696 |
* @return mixed Empty string if blog is not public, returns $sites, if site is public. |
|
2697 |
*/ |
|
2698 |
function privacy_ping_filter($sites) { |
|
2699 |
if ( '0' != get_option('blog_public') ) |
|
2700 |
return $sites; |
|
2701 |
else |
|
2702 |
return ''; |
|
2703 |
} |
|
2704 |
||
2705 |
/** |
|
2706 |
* Send a Trackback. |
|
2707 |
* |
|
2708 |
* Updates database when sending trackback to prevent duplicates. |
|
2709 |
* |
|
2710 |
* @since 0.71 |
|
5 | 2711 |
* |
2712 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 2713 |
* |
2714 |
* @param string $trackback_url URL to send trackbacks. |
|
2715 |
* @param string $title Title of post. |
|
2716 |
* @param string $excerpt Excerpt of post. |
|
2717 |
* @param int $ID Post ID. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2718 |
* @return int|false|void Database query from update. |
0 | 2719 |
*/ |
2720 |
function trackback($trackback_url, $title, $excerpt, $ID) { |
|
2721 |
global $wpdb; |
|
2722 |
||
2723 |
if ( empty($trackback_url) ) |
|
2724 |
return; |
|
2725 |
||
2726 |
$options = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2727 |
$options['timeout'] = 10; |
0 | 2728 |
$options['body'] = array( |
2729 |
'title' => $title, |
|
2730 |
'url' => get_permalink($ID), |
|
2731 |
'blog_name' => get_option('blogname'), |
|
2732 |
'excerpt' => $excerpt |
|
2733 |
); |
|
2734 |
||
2735 |
$response = wp_safe_remote_post( $trackback_url, $options ); |
|
2736 |
||
2737 |
if ( is_wp_error( $response ) ) |
|
2738 |
return; |
|
2739 |
||
2740 |
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID) ); |
|
2741 |
return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID) ); |
|
2742 |
} |
|
2743 |
||
2744 |
/** |
|
2745 |
* Send a pingback. |
|
2746 |
* |
|
2747 |
* @since 1.2.0 |
|
2748 |
* |
|
2749 |
* @param string $server Host of blog to connect to. |
|
2750 |
* @param string $path Path to send the ping. |
|
2751 |
*/ |
|
2752 |
function weblog_ping($server = '', $path = '') { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2753 |
include_once( ABSPATH . WPINC . '/class-IXR.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2754 |
include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' ); |
0 | 2755 |
|
2756 |
// using a timeout of 3 seconds should be enough to cover slow servers |
|
2757 |
$client = new WP_HTTP_IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path)); |
|
2758 |
$client->timeout = 3; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2759 |
$client->useragent .= ' -- WordPress/' . get_bloginfo( 'version' ); |
0 | 2760 |
|
2761 |
// when set to true, this outputs debug messages by itself |
|
2762 |
$client->debug = false; |
|
2763 |
$home = trailingslashit( home_url() ); |
|
2764 |
if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping |
|
2765 |
$client->query('weblogUpdates.ping', get_option('blogname'), $home); |
|
2766 |
} |
|
2767 |
||
2768 |
/** |
|
2769 |
* Default filter attached to pingback_ping_source_uri to validate the pingback's Source URI |
|
2770 |
* |
|
2771 |
* @since 3.5.1 |
|
2772 |
* @see wp_http_validate_url() |
|
2773 |
* |
|
2774 |
* @param string $source_uri |
|
2775 |
* @return string |
|
2776 |
*/ |
|
2777 |
function pingback_ping_source_uri( $source_uri ) { |
|
2778 |
return (string) wp_http_validate_url( $source_uri ); |
|
2779 |
} |
|
2780 |
||
2781 |
/** |
|
2782 |
* Default filter attached to xmlrpc_pingback_error. |
|
2783 |
* |
|
2784 |
* Returns a generic pingback error code unless the error code is 48, |
|
2785 |
* which reports that the pingback is already registered. |
|
2786 |
* |
|
2787 |
* @since 3.5.1 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2788 |
* @link https://www.hixie.ch/specs/pingback/pingback#TOC3 |
0 | 2789 |
* |
2790 |
* @param IXR_Error $ixr_error |
|
2791 |
* @return IXR_Error |
|
2792 |
*/ |
|
2793 |
function xmlrpc_pingback_error( $ixr_error ) { |
|
2794 |
if ( $ixr_error->code === 48 ) |
|
2795 |
return $ixr_error; |
|
2796 |
return new IXR_Error( 0, '' ); |
|
2797 |
} |
|
2798 |
||
2799 |
// |
|
2800 |
// Cache |
|
2801 |
// |
|
2802 |
||
2803 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2804 |
* Removes a comment from the object cache. |
0 | 2805 |
* |
2806 |
* @since 2.3.0 |
|
2807 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2808 |
* @param int|array $ids Comment ID or an array of comment IDs to remove from cache. |
0 | 2809 |
*/ |
2810 |
function clean_comment_cache($ids) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2811 |
foreach ( (array) $ids as $id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2812 |
wp_cache_delete( $id, 'comment' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2813 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2814 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2815 |
* 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
|
2816 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2817 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2818 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2819 |
* @param int $id Comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2820 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2821 |
do_action( 'clean_comment_cache', $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2822 |
} |
0 | 2823 |
|
2824 |
wp_cache_set( 'last_changed', microtime(), 'comment' ); |
|
2825 |
} |
|
2826 |
||
2827 |
/** |
|
2828 |
* Updates the comment cache of given comments. |
|
2829 |
* |
|
2830 |
* Will add the comments in $comments to the cache. If comment ID already exists |
|
2831 |
* in the comment cache then it will not be updated. The comment is added to the |
|
2832 |
* cache using the comment group with the key using the ID of the comments. |
|
2833 |
* |
|
2834 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2835 |
* @since 4.4.0 Introduced the `$update_meta_cache` parameter. |
0 | 2836 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2837 |
* @param array $comments Array of comment row objects |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2838 |
* @param bool $update_meta_cache Whether to update commentmeta cache. Default true. |
0 | 2839 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2840 |
function update_comment_cache( $comments, $update_meta_cache = true ) { |
0 | 2841 |
foreach ( (array) $comments as $comment ) |
2842 |
wp_cache_add($comment->comment_ID, $comment, 'comment'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2843 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2844 |
if ( $update_meta_cache ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2845 |
// 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
|
2846 |
$comment_ids = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2847 |
foreach ( $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2848 |
$comment_ids[] = $comment->comment_ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2849 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2850 |
update_meta_cache( 'comment', $comment_ids ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2851 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2852 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2853 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2854 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2855 |
* 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
|
2856 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2858 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2859 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2860 |
* @see update_comment_cache() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2861 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2862 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2863 |
* @param array $comment_ids Array of comment IDs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2864 |
* @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
|
2865 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2866 |
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
|
2867 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2868 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2869 |
$non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2870 |
if ( !empty( $non_cached_ids ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2871 |
$fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2872 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2873 |
update_comment_cache( $fresh_comments, $update_meta_cache ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2874 |
} |
0 | 2875 |
} |
2876 |
||
2877 |
// |
|
2878 |
// Internal |
|
2879 |
// |
|
2880 |
||
2881 |
/** |
|
2882 |
* Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts. |
|
2883 |
* |
|
2884 |
* @access private |
|
2885 |
* @since 2.7.0 |
|
2886 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2887 |
* @param WP_Post $posts Post data object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2888 |
* @param WP_Query $query Query object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2889 |
* @return array |
0 | 2890 |
*/ |
2891 |
function _close_comments_for_old_posts( $posts, $query ) { |
|
2892 |
if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) |
|
2893 |
return $posts; |
|
2894 |
||
5 | 2895 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2896 |
* Filters the list of post types to automatically close comments for. |
5 | 2897 |
* |
2898 |
* @since 3.2.0 |
|
2899 |
* |
|
2900 |
* @param array $post_types An array of registered post types. Default array with 'post'. |
|
2901 |
*/ |
|
0 | 2902 |
$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); |
2903 |
if ( ! in_array( $posts[0]->post_type, $post_types ) ) |
|
2904 |
return $posts; |
|
2905 |
||
2906 |
$days_old = (int) get_option( 'close_comments_days_old' ); |
|
2907 |
if ( ! $days_old ) |
|
2908 |
return $posts; |
|
2909 |
||
2910 |
if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { |
|
2911 |
$posts[0]->comment_status = 'closed'; |
|
2912 |
$posts[0]->ping_status = 'closed'; |
|
2913 |
} |
|
2914 |
||
2915 |
return $posts; |
|
2916 |
} |
|
2917 |
||
2918 |
/** |
|
2919 |
* Close comments on an old post. Hooked to comments_open and pings_open. |
|
2920 |
* |
|
2921 |
* @access private |
|
2922 |
* @since 2.7.0 |
|
2923 |
* |
|
2924 |
* @param bool $open Comments open or closed |
|
2925 |
* @param int $post_id Post ID |
|
2926 |
* @return bool $open |
|
2927 |
*/ |
|
2928 |
function _close_comments_for_old_post( $open, $post_id ) { |
|
2929 |
if ( ! $open ) |
|
2930 |
return $open; |
|
2931 |
||
2932 |
if ( !get_option('close_comments_for_old_posts') ) |
|
2933 |
return $open; |
|
2934 |
||
2935 |
$days_old = (int) get_option('close_comments_days_old'); |
|
2936 |
if ( !$days_old ) |
|
2937 |
return $open; |
|
2938 |
||
2939 |
$post = get_post($post_id); |
|
2940 |
||
5 | 2941 |
/** This filter is documented in wp-includes/comment.php */ |
0 | 2942 |
$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); |
2943 |
if ( ! in_array( $post->post_type, $post_types ) ) |
|
2944 |
return $open; |
|
2945 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2946 |
// Undated drafts should not show up as comments closed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2947 |
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
|
2948 |
return $open; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2949 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2950 |
|
0 | 2951 |
if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) |
2952 |
return false; |
|
2953 |
||
2954 |
return $open; |
|
2955 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2956 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2957 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2958 |
* 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
|
2959 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2960 |
* 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
|
2961 |
* expect slashed data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2962 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2963 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2964 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2965 |
* @param array $comment_data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2966 |
* Comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2967 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2968 |
* @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
|
2969 |
* @type string $author The name of the comment author. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2970 |
* @type string $email The comment author email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2971 |
* @type string $url The comment author URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2972 |
* @type string $comment The content of the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2973 |
* @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
|
2974 |
* @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
|
2975 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2976 |
* @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
|
2977 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2978 |
function wp_handle_comment_submission( $comment_data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2979 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2980 |
$comment_post_ID = $comment_parent = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2981 |
$comment_author = $comment_author_email = $comment_author_url = $comment_content = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2982 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2983 |
if ( isset( $comment_data['comment_post_ID'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
$comment_post_ID = (int) $comment_data['comment_post_ID']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2985 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2986 |
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
|
2987 |
$comment_author = trim( strip_tags( $comment_data['author'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2988 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2989 |
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
|
2990 |
$comment_author_email = trim( $comment_data['email'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2991 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2992 |
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
|
2993 |
$comment_author_url = trim( $comment_data['url'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2994 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2995 |
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
|
2996 |
$comment_content = trim( $comment_data['comment'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2997 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2998 |
if ( isset( $comment_data['comment_parent'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2999 |
$comment_parent = absint( $comment_data['comment_parent'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3000 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3001 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3002 |
$post = get_post( $comment_post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3003 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3004 |
if ( empty( $post->comment_status ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3005 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3006 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3007 |
* 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
|
3008 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3009 |
* @since 1.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3010 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3011 |
* @param int $comment_post_ID Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3012 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3013 |
do_action( 'comment_id_not_found', $comment_post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3014 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3015 |
return new WP_Error( 'comment_id_not_found' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3016 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3017 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3019 |
// 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
|
3020 |
$status = get_post_status( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3021 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3022 |
if ( ( 'private' == $status ) && ! current_user_can( 'read_post', $comment_post_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3023 |
return new WP_Error( 'comment_id_not_found' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3024 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3025 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3026 |
$status_obj = get_post_status_object( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3027 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3028 |
if ( ! comments_open( $comment_post_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3029 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3030 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3031 |
* 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
|
3032 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3033 |
* @since 1.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3034 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3035 |
* @param int $comment_post_ID Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3036 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3037 |
do_action( 'comment_closed', $comment_post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3038 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3039 |
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
|
3040 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3041 |
} elseif ( 'trash' == $status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3042 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3043 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3044 |
* 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
|
3045 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3046 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3047 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3048 |
* @param int $comment_post_ID Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3049 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3050 |
do_action( 'comment_on_trash', $comment_post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3051 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3052 |
return new WP_Error( 'comment_on_trash' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3053 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3054 |
} elseif ( ! $status_obj->public && ! $status_obj->private ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3055 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3056 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3057 |
* 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
|
3058 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3059 |
* @since 1.5.1 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3060 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3061 |
* @param int $comment_post_ID Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3062 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3063 |
do_action( 'comment_on_draft', $comment_post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3064 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3065 |
if ( current_user_can( 'read_post', $comment_post_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3066 |
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
|
3067 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3068 |
return new WP_Error( 'comment_on_draft' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3069 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3070 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3071 |
} elseif ( post_password_required( $comment_post_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3072 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3073 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3074 |
* 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
|
3075 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3076 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3077 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3078 |
* @param int $comment_post_ID Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3079 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
do_action( 'comment_on_password_protected', $comment_post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3081 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3082 |
return new WP_Error( 'comment_on_password_protected' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3083 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3084 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3085 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3086 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3087 |
* Fires before a comment is posted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3088 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3089 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3090 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3091 |
* @param int $comment_post_ID Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3092 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3093 |
do_action( 'pre_comment_on_post', $comment_post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3094 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3095 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3096 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3097 |
// If the user is logged in |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3098 |
$user = wp_get_current_user(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3099 |
if ( $user->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3100 |
if ( empty( $user->display_name ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3101 |
$user->display_name=$user->user_login; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3102 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
$comment_author = $user->display_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3104 |
$comment_author_email = $user->user_email; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3105 |
$comment_author_url = $user->user_url; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3106 |
$user_ID = $user->ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3107 |
if ( current_user_can( 'unfiltered_html' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3108 |
if ( ! isset( $comment_data['_wp_unfiltered_html_comment'] ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3109 |
|| ! wp_verify_nonce( $comment_data['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3110 |
) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3111 |
kses_remove_filters(); // start with a clean slate |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3112 |
kses_init_filters(); // set up the filters |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3113 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3114 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3115 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3116 |
if ( get_option( 'comment_registration' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3117 |
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
|
3118 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3120 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
$comment_type = ''; |
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 |
if ( get_option( 'require_name_email' ) && ! $user->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3124 |
if ( '' == $comment_author_email || '' == $comment_author ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3125 |
return new WP_Error( 'require_name_email', __( '<strong>ERROR</strong>: please fill the required fields (name, email).' ), 200 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3126 |
} elseif ( ! is_email( $comment_author_email ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
return new WP_Error( 'require_valid_email', __( '<strong>ERROR</strong>: please enter a valid email address.' ), 200 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3128 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3129 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3130 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3131 |
if ( '' == $comment_content ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3132 |
return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3133 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3134 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3135 |
$commentdata = compact( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3136 |
'comment_post_ID', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3137 |
'comment_author', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3138 |
'comment_author_email', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3139 |
'comment_author_url', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3140 |
'comment_content', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
'comment_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
'comment_parent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
'user_ID' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3144 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3145 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3146 |
$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
|
3147 |
if ( is_wp_error( $check_max_lengths ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3148 |
return $check_max_lengths; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3149 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3150 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3151 |
$comment_id = wp_new_comment( wp_slash( $commentdata ), true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3152 |
if ( is_wp_error( $comment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3153 |
return $comment_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3154 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3155 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3156 |
if ( ! $comment_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3157 |
return new WP_Error( 'comment_save_error', __( '<strong>ERROR</strong>: The comment could not be saved. Please try again later.' ), 500 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3158 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3159 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3160 |
return get_comment( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3161 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3162 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3163 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3164 |
* Registers the personal data exporter for comments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3165 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3166 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3167 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3168 |
* @param array $exporters An array of personal data exporters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3169 |
* @return array $exporters An array of personal data exporters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3170 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3171 |
function wp_register_comment_personal_data_exporter( $exporters ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3172 |
$exporters['wordpress-comments'] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3173 |
'exporter_friendly_name' => __( 'WordPress Comments' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3174 |
'callback' => 'wp_comments_personal_data_exporter', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3175 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3176 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3177 |
return $exporters; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3178 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3179 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3180 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3181 |
* 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
|
3182 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3183 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3184 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3185 |
* @param string $email_address The comment author email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3186 |
* @param int $page Comment page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3187 |
* @return array $return An array of personal data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3188 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3189 |
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
|
3190 |
// 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
|
3191 |
$number = 500; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3192 |
$page = (int) $page; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3193 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
$data_to_export = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3195 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3196 |
$comments = get_comments( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3198 |
'author_email' => $email_address, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3199 |
'number' => $number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3200 |
'paged' => $page, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3201 |
'order_by' => 'comment_ID', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3202 |
'order' => 'ASC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3203 |
'update_comment_meta_cache' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3204 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3205 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3206 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3207 |
$comment_prop_to_export = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3208 |
'comment_author' => __( 'Comment Author' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3209 |
'comment_author_email' => __( 'Comment Author Email' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3210 |
'comment_author_url' => __( 'Comment Author URL' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3211 |
'comment_author_IP' => __( 'Comment Author IP' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3212 |
'comment_agent' => __( 'Comment Author User Agent' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3213 |
'comment_date' => __( 'Comment Date' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3214 |
'comment_content' => __( 'Comment Content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3215 |
'comment_link' => __( 'Comment URL' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3216 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3217 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3218 |
foreach ( (array) $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3219 |
$comment_data_to_export = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3220 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3221 |
foreach ( $comment_prop_to_export as $key => $name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3222 |
$value = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3223 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3224 |
switch ( $key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3225 |
case 'comment_author': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3226 |
case 'comment_author_email': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3227 |
case 'comment_author_url': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3228 |
case 'comment_author_IP': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3229 |
case 'comment_agent': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3230 |
case 'comment_date': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3231 |
$value = $comment->{$key}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3232 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3233 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3234 |
case 'comment_content': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3235 |
$value = get_comment_text( $comment->comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3236 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3237 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3238 |
case 'comment_link': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3239 |
$value = get_comment_link( $comment->comment_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3240 |
$value = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3241 |
'<a href="%s" target="_blank" rel="noreferrer noopener">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3242 |
esc_url( $value ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3243 |
esc_html( $value ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3244 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3245 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3246 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3247 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3248 |
if ( ! empty( $value ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3249 |
$comment_data_to_export[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3250 |
'name' => $name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3251 |
'value' => $value, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3252 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3253 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3254 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3255 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3256 |
$data_to_export[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3257 |
'group_id' => 'comments', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3258 |
'group_label' => __( 'Comments' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3259 |
'item_id' => "comment-{$comment->comment_ID}", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3260 |
'data' => $comment_data_to_export, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3261 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3262 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3263 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3264 |
$done = count( $comments ) < $number; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3265 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3266 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3267 |
'data' => $data_to_export, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3268 |
'done' => $done, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3269 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3270 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3271 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3272 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3273 |
* Registers the personal data eraser for comments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3274 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3275 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3276 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3277 |
* @param array $erasers An array of personal data erasers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3278 |
* @return array $erasers An array of personal data erasers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3279 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3280 |
function wp_register_comment_personal_data_eraser( $erasers ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3281 |
$erasers['wordpress-comments'] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3282 |
'eraser_friendly_name' => __( 'WordPress Comments' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3283 |
'callback' => 'wp_comments_personal_data_eraser', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3284 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3285 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3286 |
return $erasers; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3287 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3288 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3289 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3290 |
* 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
|
3291 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3292 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3293 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3294 |
* @param string $email_address The comment author email address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3295 |
* @param int $page Comment page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3296 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3297 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3298 |
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
|
3299 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3300 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3301 |
if ( empty( $email_address ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3302 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3303 |
'items_removed' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3304 |
'items_retained' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3305 |
'messages' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3306 |
'done' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3307 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3308 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3309 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3310 |
// 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
|
3311 |
$number = 500; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3312 |
$page = (int) $page; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3313 |
$items_removed = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3314 |
$items_retained = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3315 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3316 |
$comments = get_comments( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3317 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3318 |
'author_email' => $email_address, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3319 |
'number' => $number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3320 |
'paged' => $page, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3321 |
'order_by' => 'comment_ID', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3322 |
'order' => 'ASC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3323 |
'include_unapproved' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3324 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3325 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3326 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3327 |
/* 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
|
3328 |
$anon_author = __( 'Anonymous' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3329 |
$messages = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3330 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3331 |
foreach ( (array) $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3332 |
$anonymized_comment = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3333 |
$anonymized_comment['comment_agent'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3334 |
$anonymized_comment['comment_author'] = $anon_author; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3335 |
$anonymized_comment['comment_author_email'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3336 |
$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
|
3337 |
$anonymized_comment['comment_author_url'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3338 |
$anonymized_comment['user_id'] = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3339 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3340 |
$comment_id = (int) $comment->comment_ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3341 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3342 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3343 |
* Filters whether to anonymize the comment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3344 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3345 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3346 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3347 |
* @param bool|string Whether to apply the comment anonymization (bool). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3348 |
* Custom prevention message (string). Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3349 |
* @param WP_Comment $comment WP_Comment object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3350 |
* @param array $anonymized_comment Anonymized comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3351 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3352 |
$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
|
3353 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3354 |
if ( true !== $anon_message ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3355 |
if ( $anon_message && is_string( $anon_message ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3356 |
$messages[] = esc_html( $anon_message ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3357 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3358 |
/* translators: %d: Comment ID */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3359 |
$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
|
3360 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3361 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3362 |
$items_retained = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3363 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3364 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3365 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3366 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3367 |
$args = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3368 |
'comment_ID' => $comment_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3369 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3370 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3371 |
$updated = $wpdb->update( $wpdb->comments, $anonymized_comment, $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3372 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3373 |
if ( $updated ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3374 |
$items_removed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3375 |
clean_comment_cache( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
$items_retained = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3381 |
$done = count( $comments ) < $number; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3382 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3383 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3384 |
'items_removed' => $items_removed, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3385 |
'items_retained' => $items_retained, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3386 |
'messages' => $messages, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3387 |
'done' => $done, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3388 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3389 |
} |