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 );
}
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' ) );
add_comment_meta( $c['comment_ID'], 'akismet_rechecking', true );
- $response = Akismet::http_post( build_query( $c ), 'comment-check' );
+ $response = Akismet::http_post( Akismet::build_query( $c ), 'comment-check' );
+
if ( 'true' == $response[1] ) {
wp_set_comment_status( $c['comment_ID'], 'spam' );
update_comment_meta( $c['comment_ID'], 'akismet_result', 'true' );
}
public static function get_akismet_user( $api_key ) {
- $akismet_user = Akismet::http_post( build_query( array( 'key' => $api_key ) ), 'get-subscription' );
+ $akismet_user = Akismet::http_post( Akismet::build_query( array( 'key' => $api_key ) ), 'get-subscription' );
if ( ! empty( $akismet_user[1] ) )
$akismet_user = json_decode( $akismet_user[1] );
$stat_totals = array();
foreach( array( '6-months', 'all' ) as $interval ) {
- $response = Akismet::http_post( build_query( array( 'blog' => urlencode( get_bloginfo('url') ), 'key' => $api_key, 'from' => $interval ) ), 'get-stats' );
+ $response = Akismet::http_post( Akismet::build_query( array( 'blog' => urlencode( get_bloginfo('url') ), 'key' => $api_key, 'from' => $interval ) ), 'get-stats' );
if ( ! empty( $response[1] ) ) {
$stat_totals[$interval] = json_decode( $response[1] );
return $stat_totals;
}
- public static function verify_wpcom_key( $api_key, $user_id, $token = '' ) {
- $akismet_account = Akismet::http_post( 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] );
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(
public static function display_spam_check_warning() {
Akismet::fix_scheduled_recheck();
-
- $link_text = apply_filters( 'akismet_spam_check_warning_link_text', sprintf( __( 'Please check your <a href="%s">Akismet configuration</a> and contact your web host if problems persist.', 'akismet'), esc_url( self::get_page_url() ) ) );
- if ( self::get_number_spam_waiting() > 0 && wp_next_scheduled('akismet_schedule_cron_recheck') > time() )
+ if ( wp_next_scheduled('akismet_schedule_cron_recheck') > time() && self::get_number_spam_waiting() > 0 ) {
+ $link_text = apply_filters( 'akismet_spam_check_warning_link_text', sprintf( __( 'Please check your <a href="%s">Akismet configuration</a> and contact your web host if problems persist.', 'akismet'), esc_url( self::get_page_url() ) ) );
Akismet::view( 'notice', array( 'type' => 'spam-check', 'link_text' => $link_text ) );
+ }
}
public static function display_invalid_version() {
$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'] );
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();