X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f..fc24d733700d6d2bd886ffa9188df5c78069b018:/wp-content/plugins/akismet/class.akismet-admin.php diff --git a/wp-content/plugins/akismet/class.akismet-admin.php b/wp-content/plugins/akismet/class.akismet-admin.php index a1c712e0..840b3674 100644 --- a/wp-content/plugins/akismet/class.akismet-admin.php +++ b/wp-content/plugins/akismet/class.akismet-admin.php @@ -37,6 +37,7 @@ class Akismet_Admin { add_action( 'wp_ajax_akismet_recheck_queue', array( 'Akismet_Admin', 'recheck_queue' ) ); add_action( 'wp_ajax_comment_author_deurl', array( 'Akismet_Admin', 'remove_comment_author_url' ) ); add_action( 'wp_ajax_comment_author_reurl', array( 'Akismet_Admin', 'add_comment_author_url' ) ); + add_action( 'jetpack_auto_activate_akismet', array( 'Akismet_Admin', 'connect_jetpack_user' ) ); add_filter( 'plugin_action_links', array( 'Akismet_Admin', 'plugin_action_links' ), 10, 2 ); add_filter( 'comment_row_actions', array( 'Akismet_Admin', 'comment_row_action' ), 10, 2 ); @@ -324,8 +325,12 @@ class Akismet_Admin { } public static function check_for_spam_button( $comment_status ) { - if ( 'approved' == $comment_status ) + // The "Check for Spam" button should only appear when the page might be showing + // a comment with comment_approved=0, which means an un-trashed, un-spammed, + // not-yet-moderated comment. + if ( 'all' != $comment_status && 'moderated' != $comment_status ) { return; + } if ( function_exists('plugins_url') ) $link = add_query_arg( array( 'action' => 'akismet_recheck_queue' ), admin_url( 'admin.php' ) ); @@ -649,13 +654,12 @@ class Akismet_Admin { return $stat_totals; } - public static function verify_wpcom_key( $api_key, $user_id, $token = '' ) { - $akismet_account = Akismet::http_post( Akismet::build_query( array( + public static function verify_wpcom_key( $api_key, $user_id, $extra = array() ) { + $akismet_account = Akismet::http_post( Akismet::build_query( array_merge( array( 'user_id' => $user_id, 'api_key' => $api_key, - 'token' => $token, 'get_account_type' => 'true' - ) ), 'verify-wpcom-key' ); + ), $extra ) ), 'verify-wpcom-key' ); if ( ! empty( $akismet_account[1] ) ) $akismet_account = json_decode( $akismet_account[1] ); @@ -664,6 +668,22 @@ class Akismet_Admin { return $akismet_account; } + + public static function connect_jetpack_user() { + + if ( $jetpack_user = self::get_jetpack_user() ) { + if ( isset( $jetpack_user['user_id'] ) && isset( $jetpack_user['api_key'] ) ) { + $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'], array( 'action' => 'connect_jetpack_user' ) ); + + if ( is_object( $akismet_user ) ) { + self::save_key( $akismet_user->api_key ); + return in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) ); + } + } + } + + return false; + } public static function display_alert() { Akismet::view( 'notice', array( @@ -719,7 +739,7 @@ class Akismet_Admin { $akismet_user = false; if ( isset( $_GET['token'] ) && preg_match('/^(\d+)-[0-9a-f]{20}$/', $_GET['token'] ) ) - $akismet_user = self::verify_wpcom_key( '', '', $_GET['token'] ); + $akismet_user = self::verify_wpcom_key( '', '', array( 'token' => $_GET['token'] ) ); elseif ( $jetpack_user = self::get_jetpack_user() ) $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'] ); @@ -793,7 +813,10 @@ class Akismet_Admin { global $hook_suffix; if ( in_array( $hook_suffix, array( 'jetpack_page_akismet-key-config', 'settings_page_akismet-key-config', 'edit-comments.php' ) ) && (int) get_option( 'akismet_alert_code' ) > 0 ) { - self::display_alert(); + Akismet::verify_key( Akismet::get_api_key() ); //verify that the key is still in alert state + + if ( get_option( 'akismet_alert_code' ) > 0 ) + self::display_alert(); } elseif ( $hook_suffix == 'plugins.php' && !Akismet::get_api_key() ) { self::display_api_key_warning();