add_action( 'akismet_scheduled_delete', array( 'Akismet', 'delete_old_comments_meta' ) );
add_action( 'akismet_schedule_cron_recheck', array( 'Akismet', 'cron_recheck' ) );
+ /**
+ * To disable the Akismet comment nonce, add a filter for the 'akismet_comment_nonce' tag
+ * and return any string value that is not 'true' or '' (empty string).
+ *
+ * Don't return boolean false, because that implies that the 'akismet_comment_nonce' option
+ * has not been set and that Akismet should just choose the default behavior for that
+ * situation.
+ */
$akismet_comment_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
if ( $akismet_comment_nonce_option == 'true' || $akismet_comment_nonce_option == '' )
// Run this early in the pingback call, before doing a remote fetch of the source uri
add_action( 'xmlrpc_call', array( 'Akismet', 'pre_check_pingback' ) );
-
- if ( '3.0.5' == $GLOBALS['wp_version'] ) {
- remove_filter( 'comment_text', 'wp_kses_data' );
- if ( is_admin() )
- add_filter( 'comment_text', 'wp_kses_post' );
- }
+
+ // Jetpack compatibility
+ add_filter( 'jetpack_options_whitelist', array( 'Akismet', 'add_to_jetpack_options_whitelist' ) );
+ add_action( 'update_option_wordpress_api_key', array( 'Akismet', 'updated_option' ), 10, 2 );
}
public static function get_api_key() {
return $response[1];
}
+ /**
+ * Add the akismet option to the Jetpack options management whitelist.
+ *
+ * @param array $options The list of whitelisted option names.
+ * @return array The updated whitelist
+ */
+ public static function add_to_jetpack_options_whitelist( $options ) {
+ $options[] = 'wordpress_api_key';
+ return $options;
+ }
+
+ /**
+ * When the akismet option is updated, run the registration call.
+ *
+ * This should only be run when the option is updated from the Jetpack/WP.com
+ * API call, and only if the new key is different than the old key.
+ *
+ * @param mixed $old_value The old option value.
+ * @param mixed $value The new option value.
+ */
+ public static function updated_option( $old_value, $value ) {
+ // Not an API call
+ if ( ! class_exists( 'WPCOM_JSON_API_Update_Option_Endpoint' ) ) {
+ return;
+ }
+ // Only run the registration if the old key is different.
+ if ( $old_value !== $value ) {
+ self::verify_key( $value );
+ }
+ }
+
public static function auto_check_comment( $commentdata ) {
self::$last_comment_result = null;
if ( !empty( $comment['user_ID'] ) )
$comment['user_role'] = Akismet::get_user_roles( $comment['user_ID'] );
+ /** See filter documentation in init_hooks(). */
$akismet_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
$comment['akismet_comment_nonce'] = 'inactive';
if ( $akismet_nonce_option == 'true' || $akismet_nonce_option == '' ) {
$comment["POST_{$key}"] = $value;
}
- $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
-
foreach ( $_SERVER as $key => $value ) {
- if ( !in_array( $key, $ignore ) && is_string($value) )
- $comment["$key"] = $value;
- else
- $comment["$key"] = '';
+ if ( ! is_string( $value ) ) {
+ continue;
+ }
+
+ if ( preg_match( "/^HTTP_COOKIE/", $key ) ) {
+ continue;
+ }
+
+ // Send any potentially useful $_SERVER vars, but avoid sending junk we don't need.
+ if ( preg_match( "/^(HTTP_|REMOTE_ADDR|REQUEST_URI|DOCUMENT_URI)/", $key ) ) {
+ $comment[ "$key" ] = $value;
+ }
}
$post = get_post( $comment['comment_post_ID'] );
elseif ( self::$last_comment['akismet_result'] == 'false' ) {
update_comment_meta( $comment->comment_ID, 'akismet_result', 'false' );
self::update_comment_history( $comment->comment_ID, '', 'check-ham' );
- if ( $comment->comment_approved == 'spam' ) {
+ // Status could be spam or trash, depending on the WP version and whether this change applies:
+ // https://core.trac.wordpress.org/changeset/34726
+ if ( $comment->comment_approved == 'spam' || $comment->comment_approved == 'trash' ) {
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) )
self::update_comment_history( $comment->comment_ID, '', 'wp-blacklisted' );
else
( isset( $_POST['spam'] ) && (int) $_POST['spam'] == 1 ) ||
( isset( $_POST['unspam'] ) && (int) $_POST['unspam'] == 1 ) ||
( isset( $_POST['comment_status'] ) && in_array( $_POST['comment_status'], array( 'spam', 'unspam' ) ) ) ||
- ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'spam', 'unspam' ) ) ) ||
- ( isset( $_POST['action'] ) && in_array( $_POST['action'], array( 'editedcomment' ) ) )
+ ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'spam', 'unspam', 'spamcomment', 'unspamcomment', ) ) ) ||
+ ( isset( $_POST['action'] ) && in_array( $_POST['action'], array( 'editedcomment' ) ) ) ||
+ ( isset( $_GET['for'] ) && ( 'jetpack' == $_GET['for'] ) ) // Moderation via WP.com notifications/WP app/etc.
) {
if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || !$old_status ) ) {
return self::submit_spam_comment( $comment->comment_ID );
$comment1 = (array) $comment1;
$comment2 = (array) $comment2;
- return (
+ $comments_match = (
isset( $comment1['comment_post_ID'], $comment2['comment_post_ID'] )
&& intval( $comment1['comment_post_ID'] ) == intval( $comment2['comment_post_ID'] )
&& (
// The comment author length max is 255 characters, limited by the TINYTEXT column type.
- substr( $comment1['comment_author'], 0, 255 ) == substr( $comment2['comment_author'], 0, 255 )
- || substr( stripslashes( $comment1['comment_author'] ), 0, 255 ) == substr( $comment2['comment_author'], 0, 255 )
- || substr( $comment1['comment_author'], 0, 255 ) == substr( stripslashes( $comment2['comment_author'] ), 0, 255 )
+ // If the comment author includes multibyte characters right around the 255-byte mark, they
+ // may be stripped when the author is saved in the DB, so a 300+ char author may turn into
+ // a 253-char author when it's saved, not 255 exactly. The longest possible character is
+ // theoretically 6 bytes, so we'll only look at the first 248 bytes to be safe.
+ substr( $comment1['comment_author'], 0, 248 ) == substr( $comment2['comment_author'], 0, 248 )
+ || substr( stripslashes( $comment1['comment_author'] ), 0, 248 ) == substr( $comment2['comment_author'], 0, 248 )
+ || substr( $comment1['comment_author'], 0, 248 ) == substr( stripslashes( $comment2['comment_author'] ), 0, 248 )
+ // Certain long comment author names will be truncated to nothing, depending on their encoding.
+ || ( ! $comment1['comment_author'] && strlen( $comment2['comment_author'] ) > 248 )
+ || ( ! $comment2['comment_author'] && strlen( $comment1['comment_author'] ) > 248 )
)
&& (
// The email max length is 100 characters, limited by the VARCHAR(100) column type.
- substr( $comment1['comment_author_email'], 0, 100 ) == substr( $comment2['comment_author_email'], 0, 100 )
- || substr( stripslashes( $comment1['comment_author_email'] ), 0, 100 ) == substr( $comment2['comment_author_email'], 0, 100 )
- || substr( $comment1['comment_author_email'], 0, 100 ) == substr( stripslashes( $comment2['comment_author_email'] ), 0, 100 )
+ // Same argument as above for only looking at the first 93 characters.
+ substr( $comment1['comment_author_email'], 0, 93 ) == substr( $comment2['comment_author_email'], 0, 93 )
+ || substr( stripslashes( $comment1['comment_author_email'] ), 0, 93 ) == substr( $comment2['comment_author_email'], 0, 93 )
+ || substr( $comment1['comment_author_email'], 0, 93 ) == substr( stripslashes( $comment2['comment_author_email'] ), 0, 93 )
// Very long emails can be truncated and then stripped if the [0:100] substring isn't a valid address.
|| ( ! $comment1['comment_author_email'] && strlen( $comment2['comment_author_email'] ) > 100 )
|| ( ! $comment2['comment_author_email'] && strlen( $comment1['comment_author_email'] ) > 100 )
)
);
+
+ return $comments_match;
}
// Does the supplied comment match the details of the one most recently stored in self::$last_comment?
// filter handler used to return a spam result to pre_comment_approved
public static function last_comment_status( $approved, $comment ) {
+ if ( is_null( self::$last_comment_result ) ) {
+ // We didn't have reason to store the result of the last check.
+ return $approved;
+ }
+
// Only do this if it's the correct comment
- if ( is_null(self::$last_comment_result) || ! self::matches_last_comment( $comment ) ) {
+ if ( ! self::matches_last_comment( $comment ) ) {
self::log( "comment_is_spam mismatched comment, returning unaltered $approved" );
return $approved;
}
public static function load_form_js() {
// WP < 3.3 can't enqueue a script this late in the game and still have it appear in the footer.
// Once we drop support for everything pre-3.3, this can change back to a single enqueue call.
- wp_register_script( 'akismet-form', AKISMET__PLUGIN_URL . '_inc/form.js', array(), AKISMET_VERSION, true );
+ wp_register_script( 'akismet-form', plugin_dir_url( __FILE__ ) . '_inc/form.js', array(), AKISMET_VERSION, true );
add_action( 'wp_footer', array( 'Akismet', 'print_form_js' ) );
add_action( 'admin_footer', array( 'Akismet', 'print_form_js' ) );
}
if ( version_compare( $GLOBALS['wp_version'], AKISMET__MINIMUM_WP_VERSION, '<' ) ) {
load_plugin_textdomain( 'akismet' );
- $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', 'http://wordpress.org/extend/plugins/akismet/download/');
+ $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/');
Akismet::bail_on_activation( $message );
}
/**
* Log debugging info to the error log.
*
- * Enabled when WP_DEBUG_LOG is enabled, but can be disabled via the akismet_debug_log filter.
+ * Enabled when WP_DEBUG_LOG is enabled (and WP_DEBUG, since according to
+ * core, "WP_DEBUG_DISPLAY and WP_DEBUG_LOG perform no function unless
+ * WP_DEBUG is true), but can be disabled via the akismet_debug_log filter.
*
* @param mixed $akismet_debug The data to log.
*/
public static function log( $akismet_debug ) {
- if ( apply_filters( 'akismet_debug_log', defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) ) {
+ if ( apply_filters( 'akismet_debug_log', defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) ) {
error_log( print_r( compact( 'akismet_debug' ), true ) );
}
}
return $meta_value;
}
-}
\ No newline at end of file
+}