1 |
commit: d6d1dfaa04642908ab488292ffd21fac36460c56 |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jan 2 03:26:55 2019 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jan 2 03:26:55 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/blogs-gentoo.git/commit/?id=d6d1dfaa |
7 |
|
8 |
Update akismet 4.1 |
9 |
|
10 |
Signed-off-by: Anthony G. Basile <blueness <AT> gentoo.org> |
11 |
|
12 |
plugins/akismet/akismet.php | 4 +- |
13 |
plugins/akismet/class.akismet-admin.php | 63 +++++++++++++++++++- |
14 |
plugins/akismet/class.akismet-cli.php | 94 +++++++++++++++++++++++++++++ |
15 |
plugins/akismet/class.akismet-rest-api.php | 95 ++++++++++++++++++++++++++++++ |
16 |
plugins/akismet/class.akismet.php | 1 - |
17 |
plugins/akismet/readme.txt | 11 +++- |
18 |
6 files changed, 262 insertions(+), 6 deletions(-) |
19 |
|
20 |
diff --git a/plugins/akismet/akismet.php b/plugins/akismet/akismet.php |
21 |
index d4f2135..800dd72 100644 |
22 |
--- a/plugins/akismet/akismet.php |
23 |
+++ b/plugins/akismet/akismet.php |
24 |
@@ -6,7 +6,7 @@ |
25 |
Plugin Name: Akismet Anti-Spam |
26 |
Plugin URI: https://akismet.com/ |
27 |
Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key. |
28 |
-Version: 4.0.8 |
29 |
+Version: 4.1 |
30 |
Author: Automattic |
31 |
Author URI: https://automattic.com/wordpress-plugins/ |
32 |
License: GPLv2 or later |
33 |
@@ -37,7 +37,7 @@ if ( !function_exists( 'add_action' ) ) { |
34 |
exit; |
35 |
} |
36 |
|
37 |
-define( 'AKISMET_VERSION', '4.0.8' ); |
38 |
+define( 'AKISMET_VERSION', '4.1' ); |
39 |
define( 'AKISMET__MINIMUM_WP_VERSION', '4.0' ); |
40 |
define( 'AKISMET__PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
41 |
define( 'AKISMET_DELETE_LIMIT', 100000 ); |
42 |
|
43 |
diff --git a/plugins/akismet/class.akismet-admin.php b/plugins/akismet/class.akismet-admin.php |
44 |
index 1e80617..07a4d19 100644 |
45 |
--- a/plugins/akismet/class.akismet-admin.php |
46 |
+++ b/plugins/akismet/class.akismet-admin.php |
47 |
@@ -74,6 +74,9 @@ class Akismet_Admin { |
48 |
add_filter( 'akismet_comment_form_privacy_notice_url_display', array( 'Akismet_Admin', 'jetpack_comment_form_privacy_notice_url' ) ); |
49 |
add_filter( 'akismet_comment_form_privacy_notice_url_hide', array( 'Akismet_Admin', 'jetpack_comment_form_privacy_notice_url' ) ); |
50 |
} |
51 |
+ |
52 |
+ // priority=1 because we need ours to run before core's comment anonymizer runs, and that's registered at priority=10 |
53 |
+ add_filter( 'wp_privacy_personal_data_erasers', array( 'Akismet_Admin', 'register_personal_data_eraser' ), 1 ); |
54 |
} |
55 |
|
56 |
public static function admin_init() { |
57 |
@@ -1049,7 +1052,7 @@ class Akismet_Admin { |
58 |
$message .= ' '; |
59 |
|
60 |
if ( $spam_count === 0 ) { |
61 |
- $message .= __( 'No comments were caught as spam.' ); |
62 |
+ $message .= __( 'No comments were caught as spam.', 'akismet' ); |
63 |
} |
64 |
else { |
65 |
$message .= sprintf( _n( '%s comment was caught as spam.', '%s comments were caught as spam.', $spam_count, 'akismet' ), number_format( $spam_count ) ); |
66 |
@@ -1180,4 +1183,62 @@ class Akismet_Admin { |
67 |
public static function jetpack_comment_form_privacy_notice_url( $url ) { |
68 |
return str_replace( 'options-general.php', 'admin.php', $url ); |
69 |
} |
70 |
+ |
71 |
+ public static function register_personal_data_eraser( $erasers ) { |
72 |
+ $erasers['akismet'] = array( |
73 |
+ 'eraser_friendly_name' => __( 'Akismet', 'akismet' ), |
74 |
+ 'callback' => array( 'Akismet_Admin', 'erase_personal_data' ), |
75 |
+ ); |
76 |
+ |
77 |
+ return $erasers; |
78 |
+ } |
79 |
+ |
80 |
+ /** |
81 |
+ * When a user requests that their personal data be removed, Akismet has a duty to discard |
82 |
+ * any personal data we store outside of the comment itself. Right now, that is limited |
83 |
+ * to the copy of the comment we store in the akismet_as_submitted commentmeta. |
84 |
+ * |
85 |
+ * FWIW, this information would be automatically deleted after 15 days. |
86 |
+ * |
87 |
+ * @param $email_address string The email address of the user who has requested erasure. |
88 |
+ * @param $page int This function can (and will) be called multiple times to prevent timeouts, |
89 |
+ * so this argument is used for pagination. |
90 |
+ * @return array |
91 |
+ * @see https://developer.wordpress.org/plugins/privacy/adding-the-personal-data-eraser-to-your-plugin/ |
92 |
+ */ |
93 |
+ public static function erase_personal_data( $email_address, $page = 1 ) { |
94 |
+ $items_removed = false; |
95 |
+ |
96 |
+ $number = 50; |
97 |
+ $page = (int) $page; |
98 |
+ |
99 |
+ $comments = get_comments( |
100 |
+ array( |
101 |
+ 'author_email' => $email_address, |
102 |
+ 'number' => $number, |
103 |
+ 'paged' => $page, |
104 |
+ 'order_by' => 'comment_ID', |
105 |
+ 'order' => 'ASC', |
106 |
+ ) |
107 |
+ ); |
108 |
+ |
109 |
+ foreach ( (array) $comments as $comment ) { |
110 |
+ $comment_as_submitted = get_comment_meta( $comment->comment_ID, 'akismet_as_submitted', true ); |
111 |
+ |
112 |
+ if ( $comment_as_submitted ) { |
113 |
+ delete_comment_meta( $comment->comment_ID, 'akismet_as_submitted' ); |
114 |
+ $items_removed = true; |
115 |
+ } |
116 |
+ } |
117 |
+ |
118 |
+ // Tell core if we have more comments to work on still |
119 |
+ $done = count( $comments ) < $number; |
120 |
+ |
121 |
+ return array( |
122 |
+ 'items_removed' => $items_removed, |
123 |
+ 'items_retained' => false, // always false in this example |
124 |
+ 'messages' => array(), // no messages in this example |
125 |
+ 'done' => $done, |
126 |
+ ); |
127 |
+ } |
128 |
} |
129 |
|
130 |
diff --git a/plugins/akismet/class.akismet-cli.php b/plugins/akismet/class.akismet-cli.php |
131 |
index b0b4836..9cbe7a9 100644 |
132 |
--- a/plugins/akismet/class.akismet-cli.php |
133 |
+++ b/plugins/akismet/class.akismet-cli.php |
134 |
@@ -88,4 +88,98 @@ class Akismet_CLI extends WP_CLI_Command { |
135 |
WP_CLI::line( sprintf( _n( "%d comment could not be checked.", "%d comments could not be checked.", $total_counts['error'], 'akismet' ), number_format( $total_counts['error'] ) ) ); |
136 |
} |
137 |
} |
138 |
+ |
139 |
+ /** |
140 |
+ * Fetches stats from the Akismet API. |
141 |
+ * |
142 |
+ * ## OPTIONS |
143 |
+ * |
144 |
+ * [<interval>] |
145 |
+ * : The time period for which to retrieve stats. |
146 |
+ * --- |
147 |
+ * default: all |
148 |
+ * options: |
149 |
+ * - days |
150 |
+ * - months |
151 |
+ * - all |
152 |
+ * --- |
153 |
+ * |
154 |
+ * [--format=<format>] |
155 |
+ * : Allows overriding the output of the command when listing connections. |
156 |
+ * --- |
157 |
+ * default: table |
158 |
+ * options: |
159 |
+ * - table |
160 |
+ * - json |
161 |
+ * - csv |
162 |
+ * - yaml |
163 |
+ * - count |
164 |
+ * --- |
165 |
+ * |
166 |
+ * [--summary] |
167 |
+ * : When set, will display a summary of the stats. |
168 |
+ * |
169 |
+ * ## EXAMPLES |
170 |
+ * |
171 |
+ * wp akismet stats |
172 |
+ * wp akismet stats all |
173 |
+ * wp akismet stats days |
174 |
+ * wp akismet stats months |
175 |
+ * wp akismet stats all --summary |
176 |
+ */ |
177 |
+ public function stats( $args, $assoc_args ) { |
178 |
+ $api_key = Akismet::get_api_key(); |
179 |
+ |
180 |
+ if ( empty( $api_key ) ) { |
181 |
+ WP_CLI::error( __( 'API key must be set to fetch stats.', 'akismet' ) ); |
182 |
+ } |
183 |
+ |
184 |
+ switch ( $args[0] ) { |
185 |
+ case 'days': |
186 |
+ $interval = '60-days'; |
187 |
+ break; |
188 |
+ case 'months': |
189 |
+ $interval = '6-months'; |
190 |
+ break; |
191 |
+ default: |
192 |
+ $interval = 'all'; |
193 |
+ break; |
194 |
+ } |
195 |
+ |
196 |
+ $response = Akismet::http_post( |
197 |
+ Akismet::build_query( array( |
198 |
+ 'blog' => get_option( 'home' ), |
199 |
+ 'key' => $api_key, |
200 |
+ 'from' => $interval, |
201 |
+ ) ), |
202 |
+ 'get-stats' |
203 |
+ ); |
204 |
+ |
205 |
+ if ( empty( $response[1] ) ) { |
206 |
+ WP_CLI::error( __( 'Currently unable to fetch stats. Please try again.', 'akismet' ) ); |
207 |
+ } |
208 |
+ |
209 |
+ $response_body = json_decode( $response[1], true ); |
210 |
+ |
211 |
+ if ( is_null( $response_body ) ) { |
212 |
+ WP_CLI::error( __( 'Stats response could not be decoded.', 'akismet' ) ); |
213 |
+ } |
214 |
+ |
215 |
+ if ( isset( $assoc_args['summary'] ) ) { |
216 |
+ $keys = array( |
217 |
+ 'spam', |
218 |
+ 'ham', |
219 |
+ 'missed_spam', |
220 |
+ 'false_positives', |
221 |
+ 'accuracy', |
222 |
+ 'time_saved', |
223 |
+ ); |
224 |
+ |
225 |
+ WP_CLI\Utils\format_items( $assoc_args['format'], array( $response_body ), $keys ); |
226 |
+ } |
227 |
+ else { |
228 |
+ $stats = $response_body['breakdown']; |
229 |
+ WP_CLI\Utils\format_items( $assoc_args['format'], $stats, array_keys( end( $stats ) ) ); |
230 |
+ } |
231 |
+ } |
232 |
} |
233 |
\ No newline at end of file |
234 |
|
235 |
diff --git a/plugins/akismet/class.akismet-rest-api.php b/plugins/akismet/class.akismet-rest-api.php |
236 |
index f97b710..bf71998 100644 |
237 |
--- a/plugins/akismet/class.akismet-rest-api.php |
238 |
+++ b/plugins/akismet/class.akismet-rest-api.php |
239 |
@@ -87,6 +87,48 @@ class Akismet_REST_API { |
240 |
'callback' => array( 'Akismet_REST_API', 'get_stats' ), |
241 |
) |
242 |
) ); |
243 |
+ |
244 |
+ register_rest_route( 'akismet/v1', '/alert', array( |
245 |
+ array( |
246 |
+ 'methods' => WP_REST_Server::READABLE, |
247 |
+ 'permission_callback' => array( 'Akismet_REST_API', 'remote_call_permission_callback' ), |
248 |
+ 'callback' => array( 'Akismet_REST_API', 'get_alert' ), |
249 |
+ 'args' => array( |
250 |
+ 'key' => array( |
251 |
+ 'required' => false, |
252 |
+ 'type' => 'string', |
253 |
+ 'sanitize_callback' => array( 'Akismet_REST_API', 'sanitize_key' ), |
254 |
+ 'description' => __( 'A 12-character Akismet API key. Available at akismet.com/get/', 'akismet' ), |
255 |
+ ), |
256 |
+ ), |
257 |
+ ), |
258 |
+ array( |
259 |
+ 'methods' => WP_REST_Server::EDITABLE, |
260 |
+ 'permission_callback' => array( 'Akismet_REST_API', 'remote_call_permission_callback' ), |
261 |
+ 'callback' => array( 'Akismet_REST_API', 'set_alert' ), |
262 |
+ 'args' => array( |
263 |
+ 'key' => array( |
264 |
+ 'required' => false, |
265 |
+ 'type' => 'string', |
266 |
+ 'sanitize_callback' => array( 'Akismet_REST_API', 'sanitize_key' ), |
267 |
+ 'description' => __( 'A 12-character Akismet API key. Available at akismet.com/get/', 'akismet' ), |
268 |
+ ), |
269 |
+ ), |
270 |
+ ), |
271 |
+ array( |
272 |
+ 'methods' => WP_REST_Server::DELETABLE, |
273 |
+ 'permission_callback' => array( 'Akismet_REST_API', 'remote_call_permission_callback' ), |
274 |
+ 'callback' => array( 'Akismet_REST_API', 'delete_alert' ), |
275 |
+ 'args' => array( |
276 |
+ 'key' => array( |
277 |
+ 'required' => false, |
278 |
+ 'type' => 'string', |
279 |
+ 'sanitize_callback' => array( 'Akismet_REST_API', 'sanitize_key' ), |
280 |
+ 'description' => __( 'A 12-character Akismet API key. Available at akismet.com/get/', 'akismet' ), |
281 |
+ ), |
282 |
+ ), |
283 |
+ ) |
284 |
+ ) ); |
285 |
} |
286 |
|
287 |
/** |
288 |
@@ -231,6 +273,50 @@ class Akismet_REST_API { |
289 |
return rest_ensure_response( $stat_totals ); |
290 |
} |
291 |
|
292 |
+ /** |
293 |
+ * Get the current alert code and message. Alert codes are used to notify the site owner |
294 |
+ * if there's a problem, like a connection issue between their site and the Akismet API, |
295 |
+ * invalid requests being sent, etc. |
296 |
+ * |
297 |
+ * @param WP_REST_Request $request |
298 |
+ * @return WP_Error|WP_REST_Response |
299 |
+ */ |
300 |
+ public static function get_alert( $request ) { |
301 |
+ return rest_ensure_response( array( |
302 |
+ 'code' => get_option( 'akismet_alert_code' ), |
303 |
+ 'message' => get_option( 'akismet_alert_msg' ), |
304 |
+ ) ); |
305 |
+ } |
306 |
+ |
307 |
+ /** |
308 |
+ * Update the current alert code and message by triggering a call to the Akismet server. |
309 |
+ * |
310 |
+ * @param WP_REST_Request $request |
311 |
+ * @return WP_Error|WP_REST_Response |
312 |
+ */ |
313 |
+ public static function set_alert( $request ) { |
314 |
+ delete_option( 'akismet_alert_code' ); |
315 |
+ delete_option( 'akismet_alert_msg' ); |
316 |
+ |
317 |
+ // Make a request so the most recent alert code and message are retrieved. |
318 |
+ Akismet::verify_key( Akismet::get_api_key() ); |
319 |
+ |
320 |
+ return self::get_alert( $request ); |
321 |
+ } |
322 |
+ |
323 |
+ /** |
324 |
+ * Clear the current alert code and message. |
325 |
+ * |
326 |
+ * @param WP_REST_Request $request |
327 |
+ * @return WP_Error|WP_REST_Response |
328 |
+ */ |
329 |
+ public static function delete_alert( $request ) { |
330 |
+ delete_option( 'akismet_alert_code' ); |
331 |
+ delete_option( 'akismet_alert_msg' ); |
332 |
+ |
333 |
+ return self::get_alert( $request ); |
334 |
+ } |
335 |
+ |
336 |
private static function key_is_valid( $key ) { |
337 |
$response = Akismet::http_post( |
338 |
Akismet::build_query( |
339 |
@@ -253,6 +339,15 @@ class Akismet_REST_API { |
340 |
return current_user_can( 'manage_options' ); |
341 |
} |
342 |
|
343 |
+ /** |
344 |
+ * For calls that Akismet.com makes to the site to clear outdated alert codes, use the API key for authorization. |
345 |
+ */ |
346 |
+ public static function remote_call_permission_callback( $request ) { |
347 |
+ $local_key = Akismet::get_api_key(); |
348 |
+ |
349 |
+ return $local_key && ( strtolower( $request->get_param( 'key' ) ) === strtolower( $local_key ) ); |
350 |
+ } |
351 |
+ |
352 |
public static function sanitize_interval( $interval, $request, $param ) { |
353 |
$interval = trim( $interval ); |
354 |
|
355 |
|
356 |
diff --git a/plugins/akismet/class.akismet.php b/plugins/akismet/class.akismet.php |
357 |
index 3a1307f..9b70d9e 100644 |
358 |
--- a/plugins/akismet/class.akismet.php |
359 |
+++ b/plugins/akismet/class.akismet.php |
360 |
@@ -762,7 +762,6 @@ class Akismet { |
361 |
|| strtotime( $comment->comment_date_gmt ) < strtotime( "-15 days" ) // Comment is too old. |
362 |
|| $comment->comment_approved !== "0" // Comment is no longer in the Pending queue |
363 |
) { |
364 |
- echo "Deleting"; |
365 |
delete_comment_meta( $comment_id, 'akismet_error' ); |
366 |
delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' ); |
367 |
continue; |
368 |
|
369 |
diff --git a/plugins/akismet/readme.txt b/plugins/akismet/readme.txt |
370 |
index 4853f6f..9473fb9 100644 |
371 |
--- a/plugins/akismet/readme.txt |
372 |
+++ b/plugins/akismet/readme.txt |
373 |
@@ -2,8 +2,8 @@ |
374 |
Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, eoigal, cfinke, automattic, jgs, procifer, stephdau |
375 |
Tags: akismet, comments, spam, antispam, anti-spam, anti spam, comment moderation, comment spam, contact form spam, spam comments |
376 |
Requires at least: 4.0 |
377 |
-Tested up to: 4.9.6 |
378 |
-Stable tag: 4.0.8 |
379 |
+Tested up to: 5.0 |
380 |
+Stable tag: 4.1 |
381 |
License: GPLv2 or later |
382 |
|
383 |
Akismet checks your comments and contact form submissions against our global database of spam to protect you and your site from malicious content. |
384 |
@@ -30,6 +30,13 @@ Upload the Akismet plugin to your blog, Activate it, then enter your [Akismet.co |
385 |
|
386 |
== Changelog == |
387 |
|
388 |
+= 4.1 = |
389 |
+*Release Date - 12 November 2018* |
390 |
+ |
391 |
+* Added a WP-CLI method for retrieving stats. |
392 |
+* Hooked into the new "Personal Data Eraser" functionality from WordPress 4.9.6. |
393 |
+* Added functionality to clear outdated alerts from Akismet.com. |
394 |
+ |
395 |
= 4.0.8 = |
396 |
*Release Date - 19 June 2018* |