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-- |
5 | 1 |
<?php |
2 |
||
3 |
class Akismet { |
|
4 |
const API_HOST = 'rest.akismet.com'; |
|
5 |
const API_PORT = 80; |
|
6 |
const MAX_DELAY_BEFORE_MODERATION_EMAIL = 86400; // One day in seconds |
|
7 |
||
8 |
private static $last_comment = ''; |
|
9 |
private static $initiated = false; |
|
10 |
private static $prevent_moderation_email_for_these_comments = array(); |
|
11 |
private static $last_comment_result = null; |
|
12 |
private static $comment_as_submitted_allowed_keys = array( 'blog' => '', 'blog_charset' => '', 'blog_lang' => '', 'blog_ua' => '', 'comment_agent' => '', 'comment_author' => '', 'comment_author_IP' => '', 'comment_author_email' => '', 'comment_author_url' => '', 'comment_content' => '', 'comment_date_gmt' => '', 'comment_tags' => '', 'comment_type' => '', 'guid' => '', 'is_test' => '', 'permalink' => '', 'reporter' => '', 'site_domain' => '', 'submit_referer' => '', 'submit_uri' => '', 'user_ID' => '', 'user_agent' => '', 'user_id' => '', 'user_ip' => '' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
private static $is_rest_api_call = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
|
5 | 15 |
public static function init() { |
16 |
if ( ! self::$initiated ) { |
|
17 |
self::init_hooks(); |
|
18 |
} |
|
19 |
} |
|
20 |
||
21 |
/** |
|
22 |
* Initializes WordPress hooks |
|
23 |
*/ |
|
24 |
private static function init_hooks() { |
|
25 |
self::$initiated = true; |
|
26 |
||
27 |
add_action( 'wp_insert_comment', array( 'Akismet', 'auto_check_update_meta' ), 10, 2 ); |
|
28 |
add_filter( 'preprocess_comment', array( 'Akismet', 'auto_check_comment' ), 1 ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
add_filter( 'rest_pre_insert_comment', array( 'Akismet', 'rest_auto_check_comment' ), 1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
|
5 | 31 |
add_action( 'akismet_scheduled_delete', array( 'Akismet', 'delete_old_comments' ) ); |
32 |
add_action( 'akismet_scheduled_delete', array( 'Akismet', 'delete_old_comments_meta' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
add_action( 'akismet_scheduled_delete', array( 'Akismet', 'delete_orphaned_commentmeta' ) ); |
5 | 34 |
add_action( 'akismet_schedule_cron_recheck', array( 'Akismet', 'cron_recheck' ) ); |
35 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
add_action( 'comment_form', array( 'Akismet', 'add_comment_nonce' ), 1 ); |
5 | 37 |
|
38 |
add_action( 'admin_head-edit-comments.php', array( 'Akismet', 'load_form_js' ) ); |
|
39 |
add_action( 'comment_form', array( 'Akismet', 'load_form_js' ) ); |
|
40 |
add_action( 'comment_form', array( 'Akismet', 'inject_ak_js' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
add_filter( 'script_loader_tag', array( 'Akismet', 'set_form_js_async' ), 10, 3 ); |
5 | 42 |
|
43 |
add_filter( 'comment_moderation_recipients', array( 'Akismet', 'disable_moderation_emails_if_unreachable' ), 1000, 2 ); |
|
44 |
add_filter( 'pre_comment_approved', array( 'Akismet', 'last_comment_status' ), 10, 2 ); |
|
45 |
||
46 |
add_action( 'transition_comment_status', array( 'Akismet', 'transition_comment_status' ), 10, 3 ); |
|
47 |
||
48 |
// Run this early in the pingback call, before doing a remote fetch of the source uri |
|
49 |
add_action( 'xmlrpc_call', array( 'Akismet', 'pre_check_pingback' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
// Jetpack compatibility |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
add_filter( 'jetpack_options_whitelist', array( 'Akismet', 'add_to_jetpack_options_whitelist' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
add_action( 'update_option_wordpress_api_key', array( 'Akismet', 'updated_option' ), 10, 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
add_action( 'add_option_wordpress_api_key', array( 'Akismet', 'added_option' ), 10, 2 ); |
5 | 55 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
add_action( 'comment_form_after', array( 'Akismet', 'display_comment_form_privacy_notice' ) ); |
5 | 57 |
} |
58 |
||
59 |
public static function get_api_key() { |
|
60 |
return apply_filters( 'akismet_get_api_key', defined('WPCOM_API_KEY') ? constant('WPCOM_API_KEY') : get_option('wordpress_api_key') ); |
|
61 |
} |
|
62 |
||
63 |
public static function check_key_status( $key, $ip = null ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
return self::http_post( Akismet::build_query( array( 'key' => $key, 'blog' => get_option( 'home' ) ) ), 'verify-key', $ip ); |
5 | 65 |
} |
66 |
||
67 |
public static function verify_key( $key, $ip = null ) { |
|
68 |
$response = self::check_key_status( $key, $ip ); |
|
69 |
||
70 |
if ( $response[1] != 'valid' && $response[1] != 'invalid' ) |
|
71 |
return 'failed'; |
|
72 |
||
73 |
return $response[1]; |
|
74 |
} |
|
75 |
||
76 |
public static function deactivate_key( $key ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
$response = self::http_post( Akismet::build_query( array( 'key' => $key, 'blog' => get_option( 'home' ) ) ), 'deactivate' ); |
5 | 78 |
|
79 |
if ( $response[1] != 'deactivated' ) |
|
80 |
return 'failed'; |
|
81 |
||
82 |
return $response[1]; |
|
83 |
} |
|
84 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* Add the akismet option to the Jetpack options management whitelist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* @param array $options The list of whitelisted option names. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
* @return array The updated whitelist |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
public static function add_to_jetpack_options_whitelist( $options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
$options[] = 'wordpress_api_key'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
return $options; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
* When the akismet option is updated, run the registration call. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
* This should only be run when the option is updated from the Jetpack/WP.com |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
* API call, and only if the new key is different than the old key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
* @param mixed $old_value The old option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
* @param mixed $value The new option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
public static function updated_option( $old_value, $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
// Not an API call |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
if ( ! class_exists( 'WPCOM_JSON_API_Update_Option_Endpoint' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
// Only run the registration if the old key is different. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
if ( $old_value !== $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
self::verify_key( $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
* Treat the creation of an API key the same as updating the API key to a new value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
* @param mixed $option_name Will always be "wordpress_api_key", until something else hooks in here. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
* @param mixed $value The option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
public static function added_option( $option_name, $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
if ( 'wordpress_api_key' === $option_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
return self::updated_option( '', $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
public static function rest_auto_check_comment( $commentdata ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
self::$is_rest_api_call = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
return self::auto_check_comment( $commentdata ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
|
5 | 134 |
public static function auto_check_comment( $commentdata ) { |
135 |
self::$last_comment_result = null; |
|
136 |
||
137 |
$comment = $commentdata; |
|
138 |
||
139 |
$comment['user_ip'] = self::get_ip_address(); |
|
140 |
$comment['user_agent'] = self::get_user_agent(); |
|
141 |
$comment['referrer'] = self::get_referer(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
$comment['blog'] = get_option( 'home' ); |
5 | 143 |
$comment['blog_lang'] = get_locale(); |
144 |
$comment['blog_charset'] = get_option('blog_charset'); |
|
145 |
$comment['permalink'] = get_permalink( $comment['comment_post_ID'] ); |
|
146 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
if ( ! empty( $comment['user_ID'] ) ) { |
5 | 148 |
$comment['user_role'] = Akismet::get_user_roles( $comment['user_ID'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
} |
5 | 150 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
/** See filter documentation in init_hooks(). */ |
5 | 152 |
$akismet_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) ); |
153 |
$comment['akismet_comment_nonce'] = 'inactive'; |
|
154 |
if ( $akismet_nonce_option == 'true' || $akismet_nonce_option == '' ) { |
|
155 |
$comment['akismet_comment_nonce'] = 'failed'; |
|
156 |
if ( isset( $_POST['akismet_comment_nonce'] ) && wp_verify_nonce( $_POST['akismet_comment_nonce'], 'akismet_comment_nonce_' . $comment['comment_post_ID'] ) ) |
|
157 |
$comment['akismet_comment_nonce'] = 'passed'; |
|
158 |
||
159 |
// comment reply in wp-admin |
|
160 |
if ( isset( $_POST['_ajax_nonce-replyto-comment'] ) && check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ) ) |
|
161 |
$comment['akismet_comment_nonce'] = 'passed'; |
|
162 |
||
163 |
} |
|
164 |
||
165 |
if ( self::is_test_mode() ) |
|
166 |
$comment['is_test'] = 'true'; |
|
167 |
||
168 |
foreach( $_POST as $key => $value ) { |
|
169 |
if ( is_string( $value ) ) |
|
170 |
$comment["POST_{$key}"] = $value; |
|
171 |
} |
|
172 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
foreach ( $_SERVER as $key => $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
if ( ! is_string( $value ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
} |
5 | 177 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
if ( preg_match( "/^HTTP_COOKIE/", $key ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
continue; |
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 |
// Send any potentially useful $_SERVER vars, but avoid sending junk we don't need. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
if ( preg_match( "/^(HTTP_|REMOTE_ADDR|REQUEST_URI|DOCUMENT_URI)/", $key ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
$comment[ "$key" ] = $value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
} |
5 | 186 |
} |
187 |
||
188 |
$post = get_post( $comment['comment_post_ID'] ); |
|
7
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 ( ! is_null( $post ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
// $post can technically be null, although in the past, it's always been an indicator of another plugin interfering. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
$comment[ 'comment_post_modified_gmt' ] = $post->post_modified_gmt; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
} |
5 | 194 |
|
195 |
$response = self::http_post( Akismet::build_query( $comment ), 'comment-check' ); |
|
196 |
||
197 |
do_action( 'akismet_comment_check_response', $response ); |
|
198 |
||
199 |
$commentdata['comment_as_submitted'] = array_intersect_key( $comment, self::$comment_as_submitted_allowed_keys ); |
|
200 |
$commentdata['akismet_result'] = $response[1]; |
|
201 |
||
202 |
if ( isset( $response[0]['x-akismet-pro-tip'] ) ) |
|
203 |
$commentdata['akismet_pro_tip'] = $response[0]['x-akismet-pro-tip']; |
|
204 |
||
205 |
if ( isset( $response[0]['x-akismet-error'] ) ) { |
|
206 |
// An error occurred that we anticipated (like a suspended key) and want the user to act on. |
|
207 |
// Send to moderation. |
|
208 |
self::$last_comment_result = '0'; |
|
209 |
} |
|
210 |
else if ( 'true' == $response[1] ) { |
|
211 |
// akismet_spam_count will be incremented later by comment_is_spam() |
|
212 |
self::$last_comment_result = 'spam'; |
|
213 |
||
214 |
$discard = ( isset( $commentdata['akismet_pro_tip'] ) && $commentdata['akismet_pro_tip'] === 'discard' && self::allow_discard() ); |
|
215 |
||
216 |
do_action( 'akismet_spam_caught', $discard ); |
|
217 |
||
218 |
if ( $discard ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
// The spam is obvious, so we're bailing out early. |
5 | 220 |
// akismet_result_spam() won't be called so bump the counter here |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
if ( $incr = apply_filters( 'akismet_spam_count_incr', 1 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
update_option( 'akismet_spam_count', get_option( 'akismet_spam_count' ) + $incr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
if ( self::$is_rest_api_call ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
return new WP_Error( 'akismet_rest_comment_discarded', __( 'Comment discarded.', 'akismet' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
// Redirect back to the previous page, or failing that, the post permalink, or failing that, the homepage of the blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
$redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : ( $post ? get_permalink( $post ) : home_url() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
wp_safe_redirect( esc_url_raw( $redirect_to ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
die(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
else if ( self::$is_rest_api_call ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
// The way the REST API structures its calls, we can set the comment_approved value right away. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
$commentdata['comment_approved'] = 'spam'; |
5 | 238 |
} |
239 |
} |
|
240 |
||
241 |
// if the response is neither true nor false, hold the comment for moderation and schedule a recheck |
|
242 |
if ( 'true' != $response[1] && 'false' != $response[1] ) { |
|
243 |
if ( !current_user_can('moderate_comments') ) { |
|
244 |
// Comment status should be moderated |
|
245 |
self::$last_comment_result = '0'; |
|
246 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
if ( ! wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
do_action( 'akismet_scheduled_recheck', 'invalid-response-' . $response[1] ); |
5 | 251 |
} |
252 |
||
253 |
self::$prevent_moderation_email_for_these_comments[] = $commentdata; |
|
254 |
} |
|
255 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
// Delete old comments daily |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
if ( ! wp_next_scheduled( 'akismet_scheduled_delete' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
wp_schedule_event( time(), 'daily', 'akismet_scheduled_delete' ); |
5 | 259 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
|
5 | 261 |
self::set_last_comment( $commentdata ); |
262 |
self::fix_scheduled_recheck(); |
|
263 |
||
264 |
return $commentdata; |
|
265 |
} |
|
266 |
||
267 |
public static function get_last_comment() { |
|
268 |
return self::$last_comment; |
|
269 |
} |
|
270 |
||
271 |
public static function set_last_comment( $comment ) { |
|
272 |
if ( is_null( $comment ) ) { |
|
273 |
self::$last_comment = null; |
|
274 |
} |
|
275 |
else { |
|
276 |
// We filter it here so that it matches the filtered comment data that we'll have to compare against later. |
|
277 |
// wp_filter_comment expects comment_author_IP |
|
278 |
self::$last_comment = wp_filter_comment( |
|
279 |
array_merge( |
|
280 |
array( 'comment_author_IP' => self::get_ip_address() ), |
|
281 |
$comment |
|
282 |
) |
|
283 |
); |
|
284 |
} |
|
285 |
} |
|
286 |
||
287 |
// this fires on wp_insert_comment. we can't update comment_meta when auto_check_comment() runs |
|
288 |
// because we don't know the comment ID at that point. |
|
289 |
public static function auto_check_update_meta( $id, $comment ) { |
|
290 |
// wp_insert_comment() might be called in other contexts, so make sure this is the same comment |
|
291 |
// as was checked by auto_check_comment |
|
292 |
if ( is_object( $comment ) && !empty( self::$last_comment ) && is_array( self::$last_comment ) ) { |
|
293 |
if ( self::matches_last_comment( $comment ) ) { |
|
294 |
||
295 |
load_plugin_textdomain( 'akismet' ); |
|
296 |
||
297 |
// normal result: true or false |
|
298 |
if ( self::$last_comment['akismet_result'] == 'true' ) { |
|
299 |
update_comment_meta( $comment->comment_ID, 'akismet_result', 'true' ); |
|
300 |
self::update_comment_history( $comment->comment_ID, '', 'check-spam' ); |
|
301 |
if ( $comment->comment_approved != 'spam' ) |
|
302 |
self::update_comment_history( |
|
303 |
$comment->comment_ID, |
|
304 |
'', |
|
305 |
'status-changed-'.$comment->comment_approved |
|
306 |
); |
|
307 |
} |
|
308 |
elseif ( self::$last_comment['akismet_result'] == 'false' ) { |
|
309 |
update_comment_meta( $comment->comment_ID, 'akismet_result', 'false' ); |
|
310 |
self::update_comment_history( $comment->comment_ID, '', 'check-ham' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
// Status could be spam or trash, depending on the WP version and whether this change applies: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
// https://core.trac.wordpress.org/changeset/34726 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
if ( $comment->comment_approved == 'spam' || $comment->comment_approved == 'trash' ) { |
5 | 314 |
if ( wp_blacklist_check($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent) ) |
315 |
self::update_comment_history( $comment->comment_ID, '', 'wp-blacklisted' ); |
|
316 |
else |
|
317 |
self::update_comment_history( $comment->comment_ID, '', 'status-changed-'.$comment->comment_approved ); |
|
318 |
} |
|
319 |
} // abnormal result: error |
|
320 |
else { |
|
321 |
update_comment_meta( $comment->comment_ID, 'akismet_error', time() ); |
|
322 |
self::update_comment_history( |
|
323 |
$comment->comment_ID, |
|
324 |
'', |
|
325 |
'check-error', |
|
326 |
array( 'response' => substr( self::$last_comment['akismet_result'], 0, 50 ) ) |
|
327 |
); |
|
328 |
} |
|
329 |
||
330 |
// record the complete original data as submitted for checking |
|
331 |
if ( isset( self::$last_comment['comment_as_submitted'] ) ) |
|
332 |
update_comment_meta( $comment->comment_ID, 'akismet_as_submitted', self::$last_comment['comment_as_submitted'] ); |
|
333 |
||
334 |
if ( isset( self::$last_comment['akismet_pro_tip'] ) ) |
|
335 |
update_comment_meta( $comment->comment_ID, 'akismet_pro_tip', self::$last_comment['akismet_pro_tip'] ); |
|
336 |
} |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
public static function delete_old_comments() { |
|
341 |
global $wpdb; |
|
342 |
||
343 |
/** |
|
344 |
* Determines how many comments will be deleted in each batch. |
|
345 |
* |
|
346 |
* @param int The default, as defined by AKISMET_DELETE_LIMIT. |
|
347 |
*/ |
|
348 |
$delete_limit = apply_filters( 'akismet_delete_comment_limit', defined( 'AKISMET_DELETE_LIMIT' ) ? AKISMET_DELETE_LIMIT : 10000 ); |
|
349 |
$delete_limit = max( 1, intval( $delete_limit ) ); |
|
350 |
||
351 |
/** |
|
352 |
* Determines how many days a comment will be left in the Spam queue before being deleted. |
|
353 |
* |
|
354 |
* @param int The default number of days. |
|
355 |
*/ |
|
356 |
$delete_interval = apply_filters( 'akismet_delete_comment_interval', 15 ); |
|
357 |
$delete_interval = max( 1, intval( $delete_interval ) ); |
|
358 |
||
359 |
while ( $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_id FROM {$wpdb->comments} WHERE DATE_SUB(NOW(), INTERVAL %d DAY) > comment_date_gmt AND comment_approved = 'spam' LIMIT %d", $delete_interval, $delete_limit ) ) ) { |
|
360 |
if ( empty( $comment_ids ) ) |
|
361 |
return; |
|
362 |
||
363 |
$wpdb->queries = array(); |
|
364 |
||
365 |
foreach ( $comment_ids as $comment_id ) { |
|
366 |
do_action( 'delete_comment', $comment_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
do_action( 'akismet_batch_delete_count', __FUNCTION__ ); |
5 | 368 |
} |
369 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
// Prepared as strings since comment_id is an unsigned BIGINT, and using %d will constrain the value to the maximum signed BIGINT. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
$format_string = implode( ", ", array_fill( 0, count( $comment_ids ), '%s' ) ); |
5 | 372 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->comments} WHERE comment_id IN ( " . $format_string . " )", $comment_ids ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->commentmeta} WHERE comment_id IN ( " . $format_string . " )", $comment_ids ) ); |
5 | 375 |
|
376 |
clean_comment_cache( $comment_ids ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
do_action( 'akismet_delete_comment_batch', count( $comment_ids ) ); |
5 | 378 |
} |
379 |
||
380 |
if ( apply_filters( 'akismet_optimize_table', ( mt_rand(1, 5000) == 11), $wpdb->comments ) ) // lucky number |
|
381 |
$wpdb->query("OPTIMIZE TABLE {$wpdb->comments}"); |
|
382 |
} |
|
383 |
||
384 |
public static function delete_old_comments_meta() { |
|
385 |
global $wpdb; |
|
386 |
||
387 |
$interval = apply_filters( 'akismet_delete_commentmeta_interval', 15 ); |
|
388 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
# enforce a minimum of 1 day |
5 | 390 |
$interval = absint( $interval ); |
391 |
if ( $interval < 1 ) |
|
392 |
$interval = 1; |
|
393 |
||
394 |
// akismet_as_submitted meta values are large, so expire them |
|
395 |
// after $interval days regardless of the comment status |
|
396 |
while ( $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT m.comment_id FROM {$wpdb->commentmeta} as m INNER JOIN {$wpdb->comments} as c USING(comment_id) WHERE m.meta_key = 'akismet_as_submitted' AND DATE_SUB(NOW(), INTERVAL %d DAY) > c.comment_date_gmt LIMIT 10000", $interval ) ) ) { |
|
397 |
if ( empty( $comment_ids ) ) |
|
398 |
return; |
|
399 |
||
400 |
$wpdb->queries = array(); |
|
401 |
||
402 |
foreach ( $comment_ids as $comment_id ) { |
|
403 |
delete_comment_meta( $comment_id, 'akismet_as_submitted' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
do_action( 'akismet_batch_delete_count', __FUNCTION__ ); |
5 | 405 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
do_action( 'akismet_delete_commentmeta_batch', count( $comment_ids ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
if ( apply_filters( 'akismet_optimize_table', ( mt_rand(1, 5000) == 11), $wpdb->commentmeta ) ) // lucky number |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
$wpdb->query("OPTIMIZE TABLE {$wpdb->commentmeta}"); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
// Clear out comments meta that no longer have corresponding comments in the database |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
public static function delete_orphaned_commentmeta() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
$last_meta_id = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
$start_time = isset( $_SERVER['REQUEST_TIME_FLOAT'] ) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime( true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
$max_exec_time = max( ini_get('max_execution_time') - 5, 3 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
while ( $commentmeta_results = $wpdb->get_results( $wpdb->prepare( "SELECT m.meta_id, m.comment_id, m.meta_key FROM {$wpdb->commentmeta} as m LEFT JOIN {$wpdb->comments} as c USING(comment_id) WHERE c.comment_id IS NULL AND m.meta_id > %d ORDER BY m.meta_id LIMIT 1000", $last_meta_id ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
if ( empty( $commentmeta_results ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
$wpdb->queries = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
$commentmeta_deleted = 0; |
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 |
foreach ( $commentmeta_results as $commentmeta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
if ( 'akismet_' == substr( $commentmeta->meta_key, 0, 8 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
delete_comment_meta( $commentmeta->comment_id, $commentmeta->meta_key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
do_action( 'akismet_batch_delete_count', __FUNCTION__ ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
$commentmeta_deleted++; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
$last_meta_id = $commentmeta->meta_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
do_action( 'akismet_delete_commentmeta_batch', $commentmeta_deleted ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
// If we're getting close to max_execution_time, quit for this round. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
if ( microtime(true) - $start_time > $max_exec_time ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
return; |
5 | 445 |
} |
446 |
||
447 |
if ( apply_filters( 'akismet_optimize_table', ( mt_rand(1, 5000) == 11), $wpdb->commentmeta ) ) // lucky number |
|
448 |
$wpdb->query("OPTIMIZE TABLE {$wpdb->commentmeta}"); |
|
449 |
} |
|
450 |
||
451 |
// how many approved comments does this author have? |
|
452 |
public static function get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url ) { |
|
453 |
global $wpdb; |
|
454 |
||
455 |
if ( !empty( $user_id ) ) |
|
456 |
return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE user_id = %d AND comment_approved = 1", $user_id ) ); |
|
457 |
||
458 |
if ( !empty( $comment_author_email ) ) |
|
459 |
return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_author_email = %s AND comment_author = %s AND comment_author_url = %s AND comment_approved = 1", $comment_author_email, $comment_author, $comment_author_url ) ); |
|
460 |
||
461 |
return 0; |
|
462 |
} |
|
463 |
||
464 |
// get the full comment history for a given comment, as an array in reverse chronological order |
|
465 |
public static function get_comment_history( $comment_id ) { |
|
466 |
$history = get_comment_meta( $comment_id, 'akismet_history', false ); |
|
467 |
usort( $history, array( 'Akismet', '_cmp_time' ) ); |
|
468 |
return $history; |
|
469 |
} |
|
470 |
||
471 |
/** |
|
472 |
* Log an event for a given comment, storing it in comment_meta. |
|
473 |
* |
|
474 |
* @param int $comment_id The ID of the relevant comment. |
|
475 |
* @param string $message The string description of the event. No longer used. |
|
476 |
* @param string $event The event code. |
|
477 |
* @param array $meta Metadata about the history entry. e.g., the user that reported or changed the status of a given comment. |
|
478 |
*/ |
|
479 |
public static function update_comment_history( $comment_id, $message, $event=null, $meta=null ) { |
|
480 |
global $current_user; |
|
481 |
||
482 |
$user = ''; |
|
483 |
||
484 |
$event = array( |
|
485 |
'time' => self::_get_microtime(), |
|
486 |
'event' => $event, |
|
487 |
); |
|
488 |
||
489 |
if ( is_object( $current_user ) && isset( $current_user->user_login ) ) { |
|
490 |
$event['user'] = $current_user->user_login; |
|
491 |
} |
|
492 |
||
493 |
if ( ! empty( $meta ) ) { |
|
494 |
$event['meta'] = $meta; |
|
495 |
} |
|
496 |
||
497 |
// $unique = false so as to allow multiple values per comment |
|
498 |
$r = add_comment_meta( $comment_id, 'akismet_history', $event, false ); |
|
499 |
} |
|
500 |
||
501 |
public static function check_db_comment( $id, $recheck_reason = 'recheck_queue' ) { |
|
502 |
global $wpdb; |
|
503 |
||
504 |
$c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $id ), ARRAY_A ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
if ( ! $c ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
return new WP_Error( 'invalid-comment-id', __( 'Comment not found.', 'akismet' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
} |
5 | 509 |
|
510 |
$c['user_ip'] = $c['comment_author_IP']; |
|
511 |
$c['user_agent'] = $c['comment_agent']; |
|
512 |
$c['referrer'] = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
$c['blog'] = get_option( 'home' ); |
5 | 514 |
$c['blog_lang'] = get_locale(); |
515 |
$c['blog_charset'] = get_option('blog_charset'); |
|
516 |
$c['permalink'] = get_permalink($c['comment_post_ID']); |
|
517 |
$c['recheck_reason'] = $recheck_reason; |
|
518 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
$c['user_role'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
if ( ! empty( $c['user_ID'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
$c['user_role'] = Akismet::get_user_roles( $c['user_ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
|
5 | 524 |
if ( self::is_test_mode() ) |
525 |
$c['is_test'] = 'true'; |
|
526 |
||
527 |
$response = self::http_post( Akismet::build_query( $c ), 'comment-check' ); |
|
528 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
if ( ! empty( $response[1] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
return $response[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
return false; |
5 | 534 |
} |
535 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
public static function recheck_comment( $id, $recheck_reason = 'recheck_queue' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
add_comment_meta( $id, 'akismet_rechecking', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
$api_response = self::check_db_comment( $id, $recheck_reason ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
delete_comment_meta( $id, 'akismet_rechecking' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
if ( is_wp_error( $api_response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
// Invalid comment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
else if ( 'true' === $api_response ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
wp_set_comment_status( $id, 'spam' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
update_comment_meta( $id, 'akismet_result', 'true' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
delete_comment_meta( $id, 'akismet_error' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
delete_comment_meta( $id, 'akismet_delayed_moderation_email' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
Akismet::update_comment_history( $id, '', 'recheck-spam' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
elseif ( 'false' === $api_response ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
update_comment_meta( $id, 'akismet_result', 'false' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
delete_comment_meta( $id, 'akismet_error' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
delete_comment_meta( $id, 'akismet_delayed_moderation_email' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
Akismet::update_comment_history( $id, '', 'recheck-ham' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
// abnormal result: error |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
update_comment_meta( $id, 'akismet_result', 'error' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
Akismet::update_comment_history( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
$id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
'', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
'recheck-error', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
array( 'response' => substr( $api_response, 0, 50 ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
return $api_response; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
} |
5 | 572 |
|
573 |
public static function transition_comment_status( $new_status, $old_status, $comment ) { |
|
574 |
||
575 |
if ( $new_status == $old_status ) |
|
576 |
return; |
|
577 |
||
578 |
# we don't need to record a history item for deleted comments |
|
579 |
if ( $new_status == 'delete' ) |
|
580 |
return; |
|
581 |
||
582 |
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) ) |
|
583 |
return; |
|
584 |
||
585 |
if ( defined('WP_IMPORTING') && WP_IMPORTING == true ) |
|
586 |
return; |
|
587 |
||
588 |
// if this is present, it means the status has been changed by a re-check, not an explicit user action |
|
589 |
if ( get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) ) |
|
590 |
return; |
|
591 |
||
592 |
// Assumption alert: |
|
593 |
// We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status |
|
594 |
// is changed automatically by another plugin. Unfortunately WordPress doesn't provide an unambiguous way to |
|
595 |
// determine why the transition_comment_status action was triggered. And there are several different ways by which |
|
596 |
// to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others. |
|
597 |
// We'll assume that this is an explicit user action if certain POST/GET variables exist. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
if ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
// status=spam: Marking as spam via the REST API or... |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
// status=unspam: I'm not sure. Maybe this used to be used instead of status=approved? Or the UI for removing from spam but not approving has been since removed?... |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
// status=approved: Unspamming via the REST API (Calypso) or... |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
( isset( $_POST['status'] ) && in_array( $_POST['status'], array( 'spam', 'unspam', 'approved', ) ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
// spam=1: Clicking "Spam" underneath a comment in wp-admin and allowing the AJAX request to happen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
|| ( isset( $_POST['spam'] ) && (int) $_POST['spam'] == 1 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
// unspam=1: Clicking "Not Spam" underneath a comment in wp-admin and allowing the AJAX request to happen. Or, clicking "Undo" after marking something as spam. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
|| ( isset( $_POST['unspam'] ) && (int) $_POST['unspam'] == 1 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
// comment_status=spam/unspam: It's unclear where this is happening. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
|| ( isset( $_POST['comment_status'] ) && in_array( $_POST['comment_status'], array( 'spam', 'unspam' ) ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
// action=spam: Choosing "Mark as Spam" from the Bulk Actions dropdown in wp-admin (or the "Spam it" link in notification emails). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
// action=unspam: Choosing "Not Spam" from the Bulk Actions dropdown in wp-admin. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
// action=spamcomment: Following the "Spam" link below a comment in wp-admin (not allowing AJAX request to happen). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
// action=unspamcomment: Following the "Not Spam" link below a comment in wp-admin (not allowing AJAX request to happen). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
|| ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'spam', 'unspam', 'spamcomment', 'unspamcomment', ) ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
// action=editedcomment: Editing a comment via wp-admin (and possibly changing its status). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
|| ( isset( $_POST['action'] ) && in_array( $_POST['action'], array( 'editedcomment' ) ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
// for=jetpack: Moderation via the WordPress app, Calypso, anything powered by the Jetpack connection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
|| ( isset( $_GET['for'] ) && ( 'jetpack' == $_GET['for'] ) && ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
// Certain WordPress.com API requests |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
|| ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
// WordPress.org REST API requests |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
|| ( defined( 'REST_REQUEST' ) && REST_REQUEST ) |
5 | 622 |
) { |
623 |
if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || !$old_status ) ) { |
|
624 |
return self::submit_spam_comment( $comment->comment_ID ); |
|
625 |
} elseif ( $old_status == 'spam' && ( $new_status == 'approved' || $new_status == 'unapproved' ) ) { |
|
626 |
return self::submit_nonspam_comment( $comment->comment_ID ); |
|
627 |
} |
|
628 |
} |
|
629 |
||
630 |
self::update_comment_history( $comment->comment_ID, '', 'status-' . $new_status ); |
|
631 |
} |
|
632 |
||
633 |
public static function submit_spam_comment( $comment_id ) { |
|
634 |
global $wpdb, $current_user, $current_site; |
|
635 |
||
636 |
$comment_id = (int) $comment_id; |
|
637 |
||
638 |
$comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $comment_id ) ); |
|
639 |
||
640 |
if ( !$comment ) // it was deleted |
|
641 |
return; |
|
642 |
||
643 |
if ( 'spam' != $comment->comment_approved ) |
|
644 |
return; |
|
645 |
||
646 |
// use the original version stored in comment_meta if available |
|
647 |
$as_submitted = self::sanitize_comment_as_submitted( get_comment_meta( $comment_id, 'akismet_as_submitted', true ) ); |
|
648 |
||
649 |
if ( $as_submitted && is_array( $as_submitted ) && isset( $as_submitted['comment_content'] ) ) |
|
650 |
$comment = (object) array_merge( (array)$comment, $as_submitted ); |
|
651 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
$comment->blog = get_option( 'home' ); |
5 | 653 |
$comment->blog_lang = get_locale(); |
654 |
$comment->blog_charset = get_option('blog_charset'); |
|
655 |
$comment->permalink = get_permalink($comment->comment_post_ID); |
|
656 |
||
657 |
if ( is_object($current_user) ) |
|
658 |
$comment->reporter = $current_user->user_login; |
|
659 |
||
660 |
if ( is_object($current_site) ) |
|
661 |
$comment->site_domain = $current_site->domain; |
|
662 |
||
663 |
$comment->user_role = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
664 |
if ( ! empty( $comment->user_ID ) ) { |
5 | 665 |
$comment->user_role = Akismet::get_user_roles( $comment->user_ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
} |
5 | 667 |
|
668 |
if ( self::is_test_mode() ) |
|
669 |
$comment->is_test = 'true'; |
|
670 |
||
671 |
$post = get_post( $comment->comment_post_ID ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
if ( ! is_null( $post ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
$comment->comment_post_modified_gmt = $post->post_modified_gmt; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
} |
5 | 676 |
|
677 |
$response = Akismet::http_post( Akismet::build_query( $comment ), 'submit-spam' ); |
|
678 |
if ( $comment->reporter ) { |
|
679 |
self::update_comment_history( $comment_id, '', 'report-spam' ); |
|
680 |
update_comment_meta( $comment_id, 'akismet_user_result', 'true' ); |
|
681 |
update_comment_meta( $comment_id, 'akismet_user', $comment->reporter ); |
|
682 |
} |
|
683 |
||
684 |
do_action('akismet_submit_spam_comment', $comment_id, $response[1]); |
|
685 |
} |
|
686 |
||
687 |
public static function submit_nonspam_comment( $comment_id ) { |
|
688 |
global $wpdb, $current_user, $current_site; |
|
689 |
||
690 |
$comment_id = (int) $comment_id; |
|
691 |
||
692 |
$comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $comment_id ) ); |
|
693 |
if ( !$comment ) // it was deleted |
|
694 |
return; |
|
695 |
||
696 |
// use the original version stored in comment_meta if available |
|
697 |
$as_submitted = self::sanitize_comment_as_submitted( get_comment_meta( $comment_id, 'akismet_as_submitted', true ) ); |
|
698 |
||
699 |
if ( $as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content']) ) |
|
700 |
$comment = (object) array_merge( (array)$comment, $as_submitted ); |
|
701 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
$comment->blog = get_option( 'home' ); |
5 | 703 |
$comment->blog_lang = get_locale(); |
704 |
$comment->blog_charset = get_option('blog_charset'); |
|
705 |
$comment->permalink = get_permalink( $comment->comment_post_ID ); |
|
706 |
$comment->user_role = ''; |
|
707 |
||
708 |
if ( is_object($current_user) ) |
|
709 |
$comment->reporter = $current_user->user_login; |
|
710 |
||
711 |
if ( is_object($current_site) ) |
|
712 |
$comment->site_domain = $current_site->domain; |
|
713 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
if ( ! empty( $comment->user_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
$comment->user_role = Akismet::get_user_roles( $comment->user_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
} |
5 | 717 |
|
718 |
if ( Akismet::is_test_mode() ) |
|
719 |
$comment->is_test = 'true'; |
|
720 |
||
721 |
$post = get_post( $comment->comment_post_ID ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
722 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
if ( ! is_null( $post ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
$comment->comment_post_modified_gmt = $post->post_modified_gmt; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
725 |
} |
5 | 726 |
|
727 |
$response = self::http_post( Akismet::build_query( $comment ), 'submit-ham' ); |
|
728 |
if ( $comment->reporter ) { |
|
729 |
self::update_comment_history( $comment_id, '', 'report-ham' ); |
|
730 |
update_comment_meta( $comment_id, 'akismet_user_result', 'false' ); |
|
731 |
update_comment_meta( $comment_id, 'akismet_user', $comment->reporter ); |
|
732 |
} |
|
733 |
||
734 |
do_action('akismet_submit_nonspam_comment', $comment_id, $response[1]); |
|
735 |
} |
|
736 |
||
737 |
public static function cron_recheck() { |
|
738 |
global $wpdb; |
|
739 |
||
740 |
$api_key = self::get_api_key(); |
|
741 |
||
742 |
$status = self::verify_key( $api_key ); |
|
743 |
if ( get_option( 'akismet_alert_code' ) || $status == 'invalid' ) { |
|
744 |
// since there is currently a problem with the key, reschedule a check for 6 hours hence |
|
745 |
wp_schedule_single_event( time() + 21600, 'akismet_schedule_cron_recheck' ); |
|
746 |
do_action( 'akismet_scheduled_recheck', 'key-problem-' . get_option( 'akismet_alert_code' ) . '-' . $status ); |
|
747 |
return false; |
|
748 |
} |
|
749 |
||
750 |
delete_option('akismet_available_servers'); |
|
751 |
||
752 |
$comment_errors = $wpdb->get_col( "SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error' LIMIT 100" ); |
|
753 |
||
754 |
load_plugin_textdomain( 'akismet' ); |
|
755 |
||
756 |
foreach ( (array) $comment_errors as $comment_id ) { |
|
757 |
// if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck |
|
758 |
$comment = get_comment( $comment_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
if ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
761 |
! $comment // Comment has been deleted |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
|| strtotime( $comment->comment_date_gmt ) < strtotime( "-15 days" ) // Comment is too old. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
|| $comment->comment_approved !== "0" // Comment is no longer in the Pending queue |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
echo "Deleting"; |
5 | 766 |
delete_comment_meta( $comment_id, 'akismet_error' ); |
767 |
delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' ); |
|
768 |
continue; |
|
769 |
} |
|
770 |
||
771 |
add_comment_meta( $comment_id, 'akismet_rechecking', true ); |
|
772 |
$status = self::check_db_comment( $comment_id, 'retry' ); |
|
773 |
||
774 |
$event = ''; |
|
775 |
if ( $status == 'true' ) { |
|
776 |
$event = 'cron-retry-spam'; |
|
777 |
} elseif ( $status == 'false' ) { |
|
778 |
$event = 'cron-retry-ham'; |
|
779 |
} |
|
780 |
||
781 |
// If we got back a legit response then update the comment history |
|
782 |
// other wise just bail now and try again later. No point in |
|
783 |
// re-trying all the comments once we hit one failure. |
|
784 |
if ( !empty( $event ) ) { |
|
785 |
delete_comment_meta( $comment_id, 'akismet_error' ); |
|
786 |
self::update_comment_history( $comment_id, '', $event ); |
|
787 |
update_comment_meta( $comment_id, 'akismet_result', $status ); |
|
788 |
// make sure the comment status is still pending. if it isn't, that means the user has already moved it elsewhere. |
|
789 |
$comment = get_comment( $comment_id ); |
|
790 |
if ( $comment && 'unapproved' == wp_get_comment_status( $comment_id ) ) { |
|
791 |
if ( $status == 'true' ) { |
|
792 |
wp_spam_comment( $comment_id ); |
|
793 |
} elseif ( $status == 'false' ) { |
|
794 |
// comment is good, but it's still in the pending queue. depending on the moderation settings |
|
795 |
// we may need to change it to approved. |
|
796 |
if ( check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type) ) |
|
797 |
wp_set_comment_status( $comment_id, 1 ); |
|
798 |
else if ( get_comment_meta( $comment_id, 'akismet_delayed_moderation_email', true ) ) |
|
799 |
wp_notify_moderator( $comment_id ); |
|
800 |
} |
|
801 |
} |
|
802 |
||
803 |
delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' ); |
|
804 |
} else { |
|
805 |
// If this comment has been pending moderation for longer than MAX_DELAY_BEFORE_MODERATION_EMAIL, |
|
806 |
// send a moderation email now. |
|
807 |
if ( ( intval( gmdate( 'U' ) ) - strtotime( $comment->comment_date_gmt ) ) < self::MAX_DELAY_BEFORE_MODERATION_EMAIL ) { |
|
808 |
delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' ); |
|
809 |
wp_notify_moderator( $comment_id ); |
|
810 |
} |
|
811 |
||
812 |
delete_comment_meta( $comment_id, 'akismet_rechecking' ); |
|
813 |
wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' ); |
|
814 |
do_action( 'akismet_scheduled_recheck', 'check-db-comment-' . $status ); |
|
815 |
return; |
|
816 |
} |
|
817 |
delete_comment_meta( $comment_id, 'akismet_rechecking' ); |
|
818 |
} |
|
819 |
||
820 |
$remaining = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'" ); |
|
821 |
if ( $remaining && !wp_next_scheduled('akismet_schedule_cron_recheck') ) { |
|
822 |
wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' ); |
|
823 |
do_action( 'akismet_scheduled_recheck', 'remaining' ); |
|
824 |
} |
|
825 |
} |
|
826 |
||
827 |
public static function fix_scheduled_recheck() { |
|
828 |
$future_check = wp_next_scheduled( 'akismet_schedule_cron_recheck' ); |
|
829 |
if ( !$future_check ) { |
|
830 |
return; |
|
831 |
} |
|
832 |
||
833 |
if ( get_option( 'akismet_alert_code' ) > 0 ) { |
|
834 |
return; |
|
835 |
} |
|
836 |
||
837 |
$check_range = time() + 1200; |
|
838 |
if ( $future_check > $check_range ) { |
|
839 |
wp_clear_scheduled_hook( 'akismet_schedule_cron_recheck' ); |
|
840 |
wp_schedule_single_event( time() + 300, 'akismet_schedule_cron_recheck' ); |
|
841 |
do_action( 'akismet_scheduled_recheck', 'fix-scheduled-recheck' ); |
|
842 |
} |
|
843 |
} |
|
844 |
||
845 |
public static function add_comment_nonce( $post_id ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
* To disable the Akismet comment nonce, add a filter for the 'akismet_comment_nonce' tag |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
* and return any string value that is not 'true' or '' (empty string). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
* Don't return boolean false, because that implies that the 'akismet_comment_nonce' option |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
* has not been set and that Akismet should just choose the default behavior for that |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
* situation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
$akismet_comment_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
if ( $akismet_comment_nonce_option == 'true' || $akismet_comment_nonce_option == '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
echo '<p style="display: none;">'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
wp_nonce_field( 'akismet_comment_nonce_' . $post_id, 'akismet_comment_nonce', FALSE ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
echo '</p>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
} |
5 | 861 |
} |
862 |
||
863 |
public static function is_test_mode() { |
|
864 |
return defined('AKISMET_TEST_MODE') && AKISMET_TEST_MODE; |
|
865 |
} |
|
866 |
||
867 |
public static function allow_discard() { |
|
868 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
869 |
return false; |
|
870 |
if ( is_user_logged_in() ) |
|
871 |
return false; |
|
872 |
||
873 |
return ( get_option( 'akismet_strictness' ) === '1' ); |
|
874 |
} |
|
875 |
||
876 |
public static function get_ip_address() { |
|
877 |
return isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null; |
|
878 |
} |
|
879 |
||
880 |
/** |
|
881 |
* Do these two comments, without checking the comment_ID, "match"? |
|
882 |
* |
|
883 |
* @param mixed $comment1 A comment object or array. |
|
884 |
* @param mixed $comment2 A comment object or array. |
|
885 |
* @return bool Whether the two comments should be treated as the same comment. |
|
886 |
*/ |
|
887 |
private static function comments_match( $comment1, $comment2 ) { |
|
888 |
$comment1 = (array) $comment1; |
|
889 |
$comment2 = (array) $comment2; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
// Set default values for these strings that we check in order to simplify |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
// the checks and avoid PHP warnings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
if ( ! isset( $comment1['comment_author'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
$comment1['comment_author'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
if ( ! isset( $comment2['comment_author'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
$comment2['comment_author'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
if ( ! isset( $comment1['comment_author_email'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
$comment1['comment_author_email'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
if ( ! isset( $comment2['comment_author_email'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
$comment2['comment_author_email'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
$comments_match = ( |
5 | 910 |
isset( $comment1['comment_post_ID'], $comment2['comment_post_ID'] ) |
911 |
&& intval( $comment1['comment_post_ID'] ) == intval( $comment2['comment_post_ID'] ) |
|
912 |
&& ( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
// The comment author length max is 255 characters, limited by the TINYTEXT column type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
// If the comment author includes multibyte characters right around the 255-byte mark, they |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
// may be stripped when the author is saved in the DB, so a 300+ char author may turn into |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
// a 253-char author when it's saved, not 255 exactly. The longest possible character is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
// theoretically 6 bytes, so we'll only look at the first 248 bytes to be safe. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
substr( $comment1['comment_author'], 0, 248 ) == substr( $comment2['comment_author'], 0, 248 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
|| substr( stripslashes( $comment1['comment_author'] ), 0, 248 ) == substr( $comment2['comment_author'], 0, 248 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
|| substr( $comment1['comment_author'], 0, 248 ) == substr( stripslashes( $comment2['comment_author'] ), 0, 248 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
// Certain long comment author names will be truncated to nothing, depending on their encoding. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
|| ( ! $comment1['comment_author'] && strlen( $comment2['comment_author'] ) > 248 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
|| ( ! $comment2['comment_author'] && strlen( $comment1['comment_author'] ) > 248 ) |
5 | 924 |
) |
925 |
&& ( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
926 |
// The email max length is 100 characters, limited by the VARCHAR(100) column type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
// Same argument as above for only looking at the first 93 characters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
substr( $comment1['comment_author_email'], 0, 93 ) == substr( $comment2['comment_author_email'], 0, 93 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
|| substr( stripslashes( $comment1['comment_author_email'] ), 0, 93 ) == substr( $comment2['comment_author_email'], 0, 93 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
|| substr( $comment1['comment_author_email'], 0, 93 ) == substr( stripslashes( $comment2['comment_author_email'] ), 0, 93 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
// Very long emails can be truncated and then stripped if the [0:100] substring isn't a valid address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
|| ( ! $comment1['comment_author_email'] && strlen( $comment2['comment_author_email'] ) > 100 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
|| ( ! $comment2['comment_author_email'] && strlen( $comment1['comment_author_email'] ) > 100 ) |
5 | 934 |
) |
935 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
return $comments_match; |
5 | 938 |
} |
939 |
||
940 |
// Does the supplied comment match the details of the one most recently stored in self::$last_comment? |
|
941 |
public static function matches_last_comment( $comment ) { |
|
942 |
return self::comments_match( self::$last_comment, $comment ); |
|
943 |
} |
|
944 |
||
945 |
private static function get_user_agent() { |
|
946 |
return isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : null; |
|
947 |
} |
|
948 |
||
949 |
private static function get_referer() { |
|
950 |
return isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : null; |
|
951 |
} |
|
952 |
||
953 |
// return a comma-separated list of role names for the given user |
|
954 |
public static function get_user_roles( $user_id ) { |
|
955 |
$roles = false; |
|
956 |
||
957 |
if ( !class_exists('WP_User') ) |
|
958 |
return false; |
|
959 |
||
960 |
if ( $user_id > 0 ) { |
|
961 |
$comment_user = new WP_User( $user_id ); |
|
962 |
if ( isset( $comment_user->roles ) ) |
|
963 |
$roles = join( ',', $comment_user->roles ); |
|
964 |
} |
|
965 |
||
966 |
if ( is_multisite() && is_super_admin( $user_id ) ) { |
|
967 |
if ( empty( $roles ) ) { |
|
968 |
$roles = 'super_admin'; |
|
969 |
} else { |
|
970 |
$comment_user->roles[] = 'super_admin'; |
|
971 |
$roles = join( ',', $comment_user->roles ); |
|
972 |
} |
|
973 |
} |
|
974 |
||
975 |
return $roles; |
|
976 |
} |
|
977 |
||
978 |
// filter handler used to return a spam result to pre_comment_approved |
|
979 |
public static function last_comment_status( $approved, $comment ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
if ( is_null( self::$last_comment_result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
// We didn't have reason to store the result of the last check. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
return $approved; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
|
5 | 985 |
// Only do this if it's the correct comment |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
if ( ! self::matches_last_comment( $comment ) ) { |
5 | 987 |
self::log( "comment_is_spam mismatched comment, returning unaltered $approved" ); |
988 |
return $approved; |
|
989 |
} |
|
990 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
if ( 'trash' === $approved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
// If the last comment we checked has had its approval set to 'trash', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
// then it failed the comment blacklist check. Let that blacklist override |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
// the spam check, since users have the (valid) expectation that when |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
// they fill out their blacklists, comments that match it will always |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
// end up in the trash. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
return $approved; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
|
5 | 1000 |
// bump the counter here instead of when the filter is added to reduce the possibility of overcounting |
1001 |
if ( $incr = apply_filters('akismet_spam_count_incr', 1) ) |
|
1002 |
update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr ); |
|
1003 |
||
1004 |
return self::$last_comment_result; |
|
1005 |
} |
|
1006 |
||
1007 |
/** |
|
1008 |
* If Akismet is temporarily unreachable, we don't want to "spam" the blogger with |
|
1009 |
* moderation emails for comments that will be automatically cleared or spammed on |
|
1010 |
* the next retry. |
|
1011 |
* |
|
1012 |
* For comments that will be rechecked later, empty the list of email addresses that |
|
1013 |
* the moderation email would be sent to. |
|
1014 |
* |
|
1015 |
* @param array $emails An array of email addresses that the moderation email will be sent to. |
|
1016 |
* @param int $comment_id The ID of the relevant comment. |
|
1017 |
* @return array An array of email addresses that the moderation email will be sent to. |
|
1018 |
*/ |
|
1019 |
public static function disable_moderation_emails_if_unreachable( $emails, $comment_id ) { |
|
1020 |
if ( ! empty( self::$prevent_moderation_email_for_these_comments ) && ! empty( $emails ) ) { |
|
1021 |
$comment = get_comment( $comment_id ); |
|
1022 |
||
1023 |
foreach ( self::$prevent_moderation_email_for_these_comments as $possible_match ) { |
|
1024 |
if ( self::comments_match( $possible_match, $comment ) ) { |
|
1025 |
update_comment_meta( $comment_id, 'akismet_delayed_moderation_email', true ); |
|
1026 |
return array(); |
|
1027 |
} |
|
1028 |
} |
|
1029 |
} |
|
1030 |
||
1031 |
return $emails; |
|
1032 |
} |
|
1033 |
||
1034 |
public static function _cmp_time( $a, $b ) { |
|
1035 |
return $a['time'] > $b['time'] ? -1 : 1; |
|
1036 |
} |
|
1037 |
||
1038 |
public static function _get_microtime() { |
|
1039 |
$mtime = explode( ' ', microtime() ); |
|
1040 |
return $mtime[1] + $mtime[0]; |
|
1041 |
} |
|
1042 |
||
1043 |
/** |
|
1044 |
* Make a POST request to the Akismet API. |
|
1045 |
* |
|
1046 |
* @param string $request The body of the request. |
|
1047 |
* @param string $path The path for the request. |
|
1048 |
* @param string $ip The specific IP address to hit. |
|
1049 |
* @return array A two-member array consisting of the headers and the response body, both empty in the case of a failure. |
|
1050 |
*/ |
|
1051 |
public static function http_post( $request, $path, $ip=null ) { |
|
1052 |
||
1053 |
$akismet_ua = sprintf( 'WordPress/%s | Akismet/%s', $GLOBALS['wp_version'], constant( 'AKISMET_VERSION' ) ); |
|
1054 |
$akismet_ua = apply_filters( 'akismet_ua', $akismet_ua ); |
|
1055 |
||
1056 |
$content_length = strlen( $request ); |
|
1057 |
||
1058 |
$api_key = self::get_api_key(); |
|
1059 |
$host = self::API_HOST; |
|
1060 |
||
1061 |
if ( !empty( $api_key ) ) |
|
1062 |
$host = $api_key.'.'.$host; |
|
1063 |
||
1064 |
$http_host = $host; |
|
1065 |
// use a specific IP if provided |
|
1066 |
// needed by Akismet_Admin::check_server_connectivity() |
|
1067 |
if ( $ip && long2ip( ip2long( $ip ) ) ) { |
|
1068 |
$http_host = $ip; |
|
1069 |
} |
|
1070 |
||
1071 |
$http_args = array( |
|
1072 |
'body' => $request, |
|
1073 |
'headers' => array( |
|
1074 |
'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ), |
|
1075 |
'Host' => $host, |
|
1076 |
'User-Agent' => $akismet_ua, |
|
1077 |
), |
|
1078 |
'httpversion' => '1.0', |
|
1079 |
'timeout' => 15 |
|
1080 |
); |
|
1081 |
||
1082 |
$akismet_url = $http_akismet_url = "http://{$http_host}/1.1/{$path}"; |
|
1083 |
||
1084 |
/** |
|
1085 |
* Try SSL first; if that fails, try without it and don't try it again for a while. |
|
1086 |
*/ |
|
1087 |
||
1088 |
$ssl = $ssl_failed = false; |
|
1089 |
||
1090 |
// Check if SSL requests were disabled fewer than X hours ago. |
|
1091 |
$ssl_disabled = get_option( 'akismet_ssl_disabled' ); |
|
1092 |
||
1093 |
if ( $ssl_disabled && $ssl_disabled < ( time() - 60 * 60 * 24 ) ) { // 24 hours |
|
1094 |
$ssl_disabled = false; |
|
1095 |
delete_option( 'akismet_ssl_disabled' ); |
|
1096 |
} |
|
1097 |
else if ( $ssl_disabled ) { |
|
1098 |
do_action( 'akismet_ssl_disabled' ); |
|
1099 |
} |
|
1100 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
if ( ! $ssl_disabled && ( $ssl = wp_http_supports( array( 'ssl' ) ) ) ) { |
5 | 1102 |
$akismet_url = set_url_scheme( $akismet_url, 'https' ); |
1103 |
||
1104 |
do_action( 'akismet_https_request_pre' ); |
|
1105 |
} |
|
1106 |
||
1107 |
$response = wp_remote_post( $akismet_url, $http_args ); |
|
1108 |
||
1109 |
Akismet::log( compact( 'akismet_url', 'http_args', 'response' ) ); |
|
1110 |
||
1111 |
if ( $ssl && is_wp_error( $response ) ) { |
|
1112 |
do_action( 'akismet_https_request_failure', $response ); |
|
1113 |
||
1114 |
// Intermittent connection problems may cause the first HTTPS |
|
1115 |
// request to fail and subsequent HTTP requests to succeed randomly. |
|
1116 |
// Retry the HTTPS request once before disabling SSL for a time. |
|
1117 |
$response = wp_remote_post( $akismet_url, $http_args ); |
|
1118 |
||
1119 |
Akismet::log( compact( 'akismet_url', 'http_args', 'response' ) ); |
|
1120 |
||
1121 |
if ( is_wp_error( $response ) ) { |
|
1122 |
$ssl_failed = true; |
|
1123 |
||
1124 |
do_action( 'akismet_https_request_failure', $response ); |
|
1125 |
||
1126 |
do_action( 'akismet_http_request_pre' ); |
|
1127 |
||
1128 |
// Try the request again without SSL. |
|
1129 |
$response = wp_remote_post( $http_akismet_url, $http_args ); |
|
1130 |
||
1131 |
Akismet::log( compact( 'http_akismet_url', 'http_args', 'response' ) ); |
|
1132 |
} |
|
1133 |
} |
|
1134 |
||
1135 |
if ( is_wp_error( $response ) ) { |
|
1136 |
do_action( 'akismet_request_failure', $response ); |
|
1137 |
||
1138 |
return array( '', '' ); |
|
1139 |
} |
|
1140 |
||
1141 |
if ( $ssl_failed ) { |
|
1142 |
// The request failed when using SSL but succeeded without it. Disable SSL for future requests. |
|
1143 |
update_option( 'akismet_ssl_disabled', time() ); |
|
1144 |
||
1145 |
do_action( 'akismet_https_disabled' ); |
|
1146 |
} |
|
1147 |
||
1148 |
$simplified_response = array( $response['headers'], $response['body'] ); |
|
1149 |
||
1150 |
self::update_alert( $simplified_response ); |
|
1151 |
||
1152 |
return $simplified_response; |
|
1153 |
} |
|
1154 |
||
1155 |
// given a response from an API call like check_key_status(), update the alert code options if an alert is present. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
public static function update_alert( $response ) { |
5 | 1157 |
$code = $msg = null; |
1158 |
if ( isset( $response[0]['x-akismet-alert-code'] ) ) { |
|
1159 |
$code = $response[0]['x-akismet-alert-code']; |
|
1160 |
$msg = $response[0]['x-akismet-alert-msg']; |
|
1161 |
} |
|
1162 |
||
1163 |
// only call update_option() if the value has changed |
|
1164 |
if ( $code != get_option( 'akismet_alert_code' ) ) { |
|
1165 |
if ( ! $code ) { |
|
1166 |
delete_option( 'akismet_alert_code' ); |
|
1167 |
delete_option( 'akismet_alert_msg' ); |
|
1168 |
} |
|
1169 |
else { |
|
1170 |
update_option( 'akismet_alert_code', $code ); |
|
1171 |
update_option( 'akismet_alert_msg', $msg ); |
|
1172 |
} |
|
1173 |
} |
|
1174 |
} |
|
1175 |
||
1176 |
public static function load_form_js() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
wp_register_script( 'akismet-form', plugin_dir_url( __FILE__ ) . '_inc/form.js', array(), AKISMET_VERSION, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
wp_enqueue_script( 'akismet-form' ); |
5 | 1179 |
} |
1180 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
* Mark form.js as async. Because nothing depends on it, it can run at any time |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
* after it's loaded, and the browser won't have to wait for it to load to continue |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
* parsing the rest of the page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1185 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
public static function set_form_js_async( $tag, $handle, $src ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
if ( 'akismet-form' !== $handle ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
return $tag; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
return preg_replace( '/^<script /i', '<script async="async" ', $tag ); |
5 | 1192 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
|
5 | 1194 |
public static function inject_ak_js( $fields ) { |
1195 |
echo '<p style="display: none;">'; |
|
1196 |
echo '<input type="hidden" id="ak_js" name="ak_js" value="' . mt_rand( 0, 250 ) . '"/>'; |
|
1197 |
echo '</p>'; |
|
1198 |
} |
|
1199 |
||
1200 |
private static function bail_on_activation( $message, $deactivate = true ) { |
|
1201 |
?> |
|
1202 |
<!doctype html> |
|
1203 |
<html> |
|
1204 |
<head> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
<meta charset="<?php bloginfo( 'charset' ); ?>" /> |
5 | 1206 |
<style> |
1207 |
* { |
|
1208 |
text-align: center; |
|
1209 |
margin: 0; |
|
1210 |
padding: 0; |
|
1211 |
font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; |
|
1212 |
} |
|
1213 |
p { |
|
1214 |
margin-top: 1em; |
|
1215 |
font-size: 18px; |
|
1216 |
} |
|
1217 |
</style> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
</head> |
5 | 1219 |
<body> |
1220 |
<p><?php echo esc_html( $message ); ?></p> |
|
1221 |
</body> |
|
1222 |
</html> |
|
1223 |
<?php |
|
1224 |
if ( $deactivate ) { |
|
1225 |
$plugins = get_option( 'active_plugins' ); |
|
1226 |
$akismet = plugin_basename( AKISMET__PLUGIN_DIR . 'akismet.php' ); |
|
1227 |
$update = false; |
|
1228 |
foreach ( $plugins as $i => $plugin ) { |
|
1229 |
if ( $plugin === $akismet ) { |
|
1230 |
$plugins[$i] = false; |
|
1231 |
$update = true; |
|
1232 |
} |
|
1233 |
} |
|
1234 |
||
1235 |
if ( $update ) { |
|
1236 |
update_option( 'active_plugins', array_filter( $plugins ) ); |
|
1237 |
} |
|
1238 |
} |
|
1239 |
exit; |
|
1240 |
} |
|
1241 |
||
1242 |
public static function view( $name, array $args = array() ) { |
|
1243 |
$args = apply_filters( 'akismet_view_arguments', $args, $name ); |
|
1244 |
||
1245 |
foreach ( $args AS $key => $val ) { |
|
1246 |
$$key = $val; |
|
1247 |
} |
|
1248 |
||
1249 |
load_plugin_textdomain( 'akismet' ); |
|
1250 |
||
1251 |
$file = AKISMET__PLUGIN_DIR . 'views/'. $name . '.php'; |
|
1252 |
||
1253 |
include( $file ); |
|
1254 |
} |
|
1255 |
||
1256 |
/** |
|
1257 |
* Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
|
1258 |
* @static |
|
1259 |
*/ |
|
1260 |
public static function plugin_activation() { |
|
1261 |
if ( version_compare( $GLOBALS['wp_version'], AKISMET__MINIMUM_WP_VERSION, '<' ) ) { |
|
1262 |
load_plugin_textdomain( 'akismet' ); |
|
1263 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
$message = '<strong>'.sprintf(esc_html__( 'Akismet %s requires WordPress %s or higher.' , 'akismet'), AKISMET_VERSION, AKISMET__MINIMUM_WP_VERSION ).'</strong> '.sprintf(__('Please <a href="%1$s">upgrade WordPress</a> to a current version, or <a href="%2$s">downgrade to version 2.4 of the Akismet plugin</a>.', 'akismet'), 'https://codex.wordpress.org/Upgrading_WordPress', 'https://wordpress.org/extend/plugins/akismet/download/'); |
5 | 1265 |
|
1266 |
Akismet::bail_on_activation( $message ); |
|
1267 |
} |
|
1268 |
} |
|
1269 |
||
1270 |
/** |
|
1271 |
* Removes all connection options |
|
1272 |
* @static |
|
1273 |
*/ |
|
1274 |
public static function plugin_deactivation( ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1275 |
self::deactivate_key( self::get_api_key() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1276 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
// Remove any scheduled cron jobs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
$akismet_cron_events = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
'akismet_schedule_cron_recheck', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
'akismet_scheduled_delete', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
foreach ( $akismet_cron_events as $akismet_cron_event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
$timestamp = wp_next_scheduled( $akismet_cron_event ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
if ( $timestamp ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
wp_unschedule_event( $timestamp, $akismet_cron_event ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
} |
5 | 1290 |
} |
1291 |
||
1292 |
/** |
|
1293 |
* Essentially a copy of WP's build_query but one that doesn't expect pre-urlencoded values. |
|
1294 |
* |
|
1295 |
* @param array $args An array of key => value pairs |
|
1296 |
* @return string A string ready for use as a URL query string. |
|
1297 |
*/ |
|
1298 |
public static function build_query( $args ) { |
|
1299 |
return _http_build_query( $args, '', '&' ); |
|
1300 |
} |
|
1301 |
||
1302 |
/** |
|
1303 |
* Log debugging info to the error log. |
|
1304 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
* Enabled when WP_DEBUG_LOG is enabled (and WP_DEBUG, since according to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
* core, "WP_DEBUG_DISPLAY and WP_DEBUG_LOG perform no function unless |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
* WP_DEBUG is true), but can be disabled via the akismet_debug_log filter. |
5 | 1308 |
* |
1309 |
* @param mixed $akismet_debug The data to log. |
|
1310 |
*/ |
|
1311 |
public static function log( $akismet_debug ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
if ( apply_filters( 'akismet_debug_log', defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG && defined( 'AKISMET_DEBUG' ) && AKISMET_DEBUG ) ) { |
5 | 1313 |
error_log( print_r( compact( 'akismet_debug' ), true ) ); |
1314 |
} |
|
1315 |
} |
|
1316 |
||
1317 |
public static function pre_check_pingback( $method ) { |
|
1318 |
if ( $method !== 'pingback.ping' ) |
|
1319 |
return; |
|
1320 |
||
1321 |
global $wp_xmlrpc_server; |
|
1322 |
||
1323 |
if ( !is_object( $wp_xmlrpc_server ) ) |
|
1324 |
return false; |
|
1325 |
||
1326 |
// Lame: tightly coupled with the IXR class. |
|
1327 |
$args = $wp_xmlrpc_server->message->params; |
|
1328 |
||
1329 |
if ( !empty( $args[1] ) ) { |
|
1330 |
$post_id = url_to_postid( $args[1] ); |
|
1331 |
||
1332 |
// If this gets through the pre-check, make sure we properly identify the outbound request as a pingback verification |
|
1333 |
Akismet::pingback_forwarded_for( null, $args[0] ); |
|
1334 |
add_filter( 'http_request_args', array( 'Akismet', 'pingback_forwarded_for' ), 10, 2 ); |
|
1335 |
||
1336 |
$comment = array( |
|
1337 |
'comment_author_url' => $args[0], |
|
1338 |
'comment_post_ID' => $post_id, |
|
1339 |
'comment_author' => '', |
|
1340 |
'comment_author_email' => '', |
|
1341 |
'comment_content' => '', |
|
1342 |
'comment_type' => 'pingback', |
|
1343 |
'akismet_pre_check' => '1', |
|
1344 |
'comment_pingback_target' => $args[1], |
|
1345 |
); |
|
1346 |
||
1347 |
$comment = Akismet::auto_check_comment( $comment ); |
|
1348 |
||
1349 |
if ( isset( $comment['akismet_result'] ) && 'true' == $comment['akismet_result'] ) { |
|
1350 |
// Lame: tightly coupled with the IXR classes. Unfortunately the action provides no context and no way to return anything. |
|
1351 |
$wp_xmlrpc_server->error( new IXR_Error( 0, 'Invalid discovery target' ) ); |
|
1352 |
} |
|
1353 |
} |
|
1354 |
} |
|
1355 |
||
1356 |
public static function pingback_forwarded_for( $r, $url ) { |
|
1357 |
static $urls = array(); |
|
1358 |
||
1359 |
// Call this with $r == null to prime the callback to add headers on a specific URL |
|
1360 |
if ( is_null( $r ) && !in_array( $url, $urls ) ) { |
|
1361 |
$urls[] = $url; |
|
1362 |
} |
|
1363 |
||
1364 |
// Add X-Pingback-Forwarded-For header, but only for requests to a specific URL (the apparent pingback source) |
|
1365 |
if ( is_array( $r ) && is_array( $r['headers'] ) && !isset( $r['headers']['X-Pingback-Forwarded-For'] ) && in_array( $url, $urls ) ) { |
|
1366 |
$remote_ip = preg_replace( '/[^a-fx0-9:.,]/i', '', $_SERVER['REMOTE_ADDR'] ); |
|
1367 |
||
1368 |
// Note: this assumes REMOTE_ADDR is correct, and it may not be if a reverse proxy or CDN is in use |
|
1369 |
$r['headers']['X-Pingback-Forwarded-For'] = $remote_ip; |
|
1370 |
||
1371 |
// Also identify the request as a pingback verification in the UA string so it appears in logs |
|
1372 |
$r['user-agent'] .= '; verifying pingback from ' . $remote_ip; |
|
1373 |
} |
|
1374 |
||
1375 |
return $r; |
|
1376 |
} |
|
1377 |
||
1378 |
/** |
|
1379 |
* Ensure that we are loading expected scalar values from akismet_as_submitted commentmeta. |
|
1380 |
* |
|
1381 |
* @param mixed $meta_value |
|
1382 |
* @return mixed |
|
1383 |
*/ |
|
1384 |
private static function sanitize_comment_as_submitted( $meta_value ) { |
|
1385 |
if ( empty( $meta_value ) ) { |
|
1386 |
return $meta_value; |
|
1387 |
} |
|
1388 |
||
1389 |
$meta_value = (array) $meta_value; |
|
1390 |
||
1391 |
foreach ( $meta_value as $key => $value ) { |
|
1392 |
if ( ! isset( self::$comment_as_submitted_allowed_keys[$key] ) || ! is_scalar( $value ) ) { |
|
1393 |
unset( $meta_value[$key] ); |
|
1394 |
} |
|
1395 |
} |
|
1396 |
||
1397 |
return $meta_value; |
|
1398 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
public static function predefined_api_key() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
if ( defined( 'WPCOM_API_KEY' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
return apply_filters( 'akismet_predefined_api_key', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1409 |
* Controls the display of a privacy related notice underneath the comment form using the `akismet_comment_form_privacy_notice` option and filter respectively. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
* Default is top not display the notice, leaving the choice to site admins, or integrators. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
public static function display_comment_form_privacy_notice() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
if ( 'display' !== apply_filters( 'akismet_comment_form_privacy_notice', get_option( 'akismet_comment_form_privacy_notice', 'hide' ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1416 |
echo apply_filters( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
'akismet_comment_form_privacy_notice_markup', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
'<p class="akismet_comment_form_privacy_notice">' . sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
__( 'This site uses Akismet to reduce spam. <a href="%s" target="_blank" rel="nofollow noopener">Learn how your comment data is processed</a>.', 'akismet' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
'https://akismet.com/privacy/' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
) . '</p>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
} |