This commit is contained in:
Hanson.xyz Dev
2026-01-04 17:50:08 -06:00
parent 7e45ce0756
commit acc8ac87a0
4131 changed files with 232562 additions and 250244 deletions
@@ -111,13 +111,22 @@ class Akismet_Admin {
}
public static function admin_menu() {
if ( class_exists( 'Jetpack' ) ) {
if ( self::is_jetpack_active() ) {
add_action( 'jetpack_admin_menu', array( 'Akismet_Admin', 'load_menu' ) );
} else {
self::load_menu();
}
}
/**
* Check if Jetpack is active.
*
* @return bool True if Jetpack class exists, false otherwise.
*/
public static function is_jetpack_active(): bool {
return class_exists( 'Jetpack' );
}
public static function admin_head() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
@@ -131,7 +140,7 @@ class Akismet_Admin {
}
public static function load_menu() {
if ( class_exists( 'Jetpack' ) ) {
if ( self::is_jetpack_active() ) {
$hook = add_submenu_page( 'jetpack', __( 'Akismet Anti-spam', 'akismet' ), __( 'Akismet Anti-spam', 'akismet' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
} else {
$hook = add_options_page( __( 'Akismet Anti-spam', 'akismet' ), __( 'Akismet Anti-spam', 'akismet' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
@@ -234,7 +243,7 @@ class Akismet_Admin {
'<p><strong>' . esc_html__( 'Akismet Setup', 'akismet' ) . '</strong></p>' .
'<p>' . esc_html__( 'You need to enter an API key to activate the Akismet service on your site.', 'akismet' ) . '</p>' .
/* translators: %s: a link to the signup page with the text 'Akismet.com'. */
'<p>' . sprintf( __( 'Sign up for an account on %s to get an API Key.', 'akismet' ), '<a href="https://akismet.com/plugin-signup/" target="_blank">Akismet.com</a>' ) . '</p>',
'<p>' . sprintf( __( 'Sign up for an account on %s to get an API Key.', 'akismet' ), '<a href="https://akismet.com/pricing/?utm_source=akismet_plugin&amp;utm_campaign=plugin_static_link&amp;utm_medium=in_plugin&amp;utm_content=help_signup" target="_blank">Akismet.com</a>' ) . '</p>',
)
);
@@ -306,8 +315,9 @@ class Akismet_Admin {
// Help Sidebar
$current_screen->set_help_sidebar(
'<p><strong>' . esc_html__( 'For more information:', 'akismet' ) . '</strong></p>' .
'<p><a href="https://akismet.com/faq/" target="_blank">' . esc_html__( 'Akismet FAQ', 'akismet' ) . '</a></p>' .
'<p><a href="https://akismet.com/support/" target="_blank">' . esc_html__( 'Akismet Support', 'akismet' ) . '</a></p>'
'<p><a href="https://akismet.com/resources/?utm_source=akismet_plugin&amp;utm_campaign=plugin_static_link&amp;utm_medium=in_plugin&amp;utm_content=help_faq" target="_blank">' . esc_html__( 'Akismet FAQ', 'akismet' ) . '</a></p>' .
'<p><a href="https://akismet.com/support/?utm_source=akismet_plugin&amp;utm_campaign=plugin_static_link&amp;utm_medium=in_plugin&amp;utm_content=help_support" target="_blank">' . esc_html__( 'Akismet Support', 'akismet' ) . '</a></p>'
);
}
@@ -356,14 +366,14 @@ class Akismet_Admin {
$akismet_user = self::get_akismet_user( $api_key );
if ( $akismet_user ) {
if ( in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) ) ) {
if ( in_array( $akismet_user->status, array( Akismet::USER_STATUS_ACTIVE, 'active-dunning' ) ) ) {
update_option( 'wordpress_api_key', $api_key );
}
if ( $akismet_user->status == 'active' ) {
if ( $akismet_user->status == Akismet::USER_STATUS_ACTIVE ) {
self::$notices['status'] = 'new-key-valid';
} elseif ( $akismet_user->status == 'notice' ) {
self::$notices['status'] = $akismet_user;
} elseif ( $akismet_user->status == Akismet::USER_STATUS_NO_SUB ) {
self::$notices['status'] = 'no-sub';
} else {
self::$notices['status'] = $akismet_user->status;
}
@@ -371,7 +381,15 @@ class Akismet_Admin {
self::$notices['status'] = 'new-key-invalid';
}
} elseif ( in_array( $key_status, array( 'invalid', 'failed' ) ) ) {
self::$notices['status'] = 'new-key-' . $key_status;
// When verify-key returns 'invalid', it could be truly invalid OR suspended.
// Check get-subscription to distinguish between these cases.
$akismet_user = self::get_akismet_user( $api_key );
if ( $akismet_user && isset( $akismet_user->status ) && $akismet_user->status === Akismet::USER_STATUS_SUSPENDED ) {
self::$notices['status'] = Akismet::USER_STATUS_SUSPENDED;
} else {
self::$notices['status'] = 'new-key-' . $key_status;
}
}
}
@@ -396,7 +414,7 @@ class Akismet_Admin {
$count,
'akismet'
),
'https://akismet.com/wordpress/',
'https://akismet.com/wordpress/?utm_source=akismet_plugin&amp;utm_campaign=plugin_static_link&amp;utm_medium=in_plugin&amp;utm_content=dashboard_stats',
esc_url( add_query_arg( array( 'page' => 'akismet-admin' ), admin_url( isset( $submenu['edit-comments.php'] ) ? 'edit-comments.php' : 'edit.php' ) ) ),
number_format_i18n( $count )
) . '</p>';
@@ -413,12 +431,12 @@ class Akismet_Admin {
$count,
'akismet'
),
'https://akismet.com/wordpress/',
'https://akismet.com/wordpress/?utm_source=akismet_plugin&amp;utm_campaign=plugin_static_link&amp;utm_medium=in_plugin&amp;utm_content=dashboard_stats',
number_format_i18n( $count )
);
} else {
/* translators: %s: Akismet website URL. */
$intro = sprintf( __( '<a href="%s">Akismet</a> blocks spam from getting to your blog. ', 'akismet' ), 'https://akismet.com/wordpress/' );
$intro = sprintf( __( '<a href="%s">Akismet</a> blocks spam from getting to your blog. ', 'akismet' ), 'https://akismet.com/wordpress/?utm_source=akismet_plugin&amp;utm_campaign=plugin_static_link&amp;utm_medium=in_plugin&amp;utm_content=dashboard_stats' );
}
$link = add_query_arg( array( 'comment_status' => 'spam' ), admin_url( 'edit-comments.php' ) );
@@ -508,7 +526,7 @@ class Akismet_Admin {
return;
}
if ( ! wp_verify_nonce( $_POST['nonce'], 'akismet_check_for_spam' ) ) {
if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'akismet_check_for_spam' ) ) {
wp_send_json(
array(
'error' => __( 'You don&#8217;t have permission to do that.', 'akismet' ),
@@ -959,9 +977,21 @@ class Akismet_Admin {
return add_query_arg( $args, menu_page_url( 'akismet-key-config', false ) );
}
/**
* Get Akismet user subscription information.
*
* @param string $api_key The Akismet API key.
* @return object|false Object with subscription info, or false if key is invalid or has no subscription.
*
* The returned object contains these properties:
* - account_id (int|false): WordPress.com user ID, or false if unavailable.
* - status (string): Account status - 'active', 'active-dunning', 'no-sub', 'cancelled', 'suspended', 'missing', or 'notice'.
* - account_name (string): Subscription plan display name.
* - account_type (string): Account type slug.
* - next_billing_date (int|false): Unix timestamp of next billing date, or false if none.
* - limit_reached (bool): Whether the usage limit has been reached.
*/
public static function get_akismet_user( $api_key ) {
$akismet_user = false;
$request_args = array(
'key' => $api_key,
'blog' => get_option( 'home' ),
@@ -971,9 +1001,14 @@ class Akismet_Admin {
$subscription_verification = Akismet::http_post( Akismet::build_query( $request_args ), 'get-subscription' );
$akismet_user = false;
if ( ! empty( $subscription_verification[1] ) ) {
if ( 'invalid' !== $subscription_verification[1] ) {
$akismet_user = json_decode( $subscription_verification[1] );
$decoded = json_decode( $subscription_verification[1] );
if ( is_object( $decoded ) ) {
$akismet_user = $decoded;
}
}
}
@@ -1040,7 +1075,7 @@ class Akismet_Admin {
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 in_array( $akismet_user->status, array( Akismet::USER_STATUS_ACTIVE, 'active-dunning', Akismet::USER_STATUS_NO_SUB ) );
}
}
}
@@ -1061,15 +1096,16 @@ class Akismet_Admin {
public static function get_usage_limit_alert_data() {
return array(
'type' => 'usage-limit',
'code' => (int) get_option( 'akismet_alert_code' ),
'msg' => get_option( 'akismet_alert_msg' ),
'api_calls' => get_option( 'akismet_alert_api_calls' ),
'usage_limit' => get_option( 'akismet_alert_usage_limit' ),
'upgrade_plan' => get_option( 'akismet_alert_upgrade_plan' ),
'upgrade_url' => get_option( 'akismet_alert_upgrade_url' ),
'upgrade_type' => get_option( 'akismet_alert_upgrade_type' ),
'upgrade_via_support' => get_option( 'akismet_alert_upgrade_via_support' ) === 'true',
'type' => 'usage-limit',
'code' => (int) get_option( 'akismet_alert_code' ),
'msg' => get_option( 'akismet_alert_msg' ),
'api_calls' => get_option( 'akismet_alert_api_calls' ),
'usage_limit' => get_option( 'akismet_alert_usage_limit' ),
'upgrade_plan' => get_option( 'akismet_alert_upgrade_plan' ),
'upgrade_url' => get_option( 'akismet_alert_upgrade_url' ),
'upgrade_type' => get_option( 'akismet_alert_upgrade_type' ),
'upgrade_via_support' => get_option( 'akismet_alert_upgrade_via_support' ) === 'true',
'recommended_plan_name' => get_option( 'akismet_alert_recommended_plan_name' ),
);
}
@@ -1165,11 +1201,11 @@ class Akismet_Admin {
/*
// To see all variants when testing.
$akismet_user->status = 'no-sub';
$akismet_user->status = Akismet::USER_STATUS_NO_SUB;
Akismet::view( 'start', compact( 'akismet_user' ) );
$akismet_user->status = 'cancelled';
$akismet_user->status = Akismet::USER_STATUS_CANCELLED;
Akismet::view( 'start', compact( 'akismet_user' ) );
$akismet_user->status = 'suspended';
$akismet_user->status = Akismet::USER_STATUS_SUSPENDED;
Akismet::view( 'start', compact( 'akismet_user' ) );
$akismet_user->status = 'other';
Akismet::view( 'start', compact( 'akismet_user' ) );
@@ -1208,7 +1244,7 @@ class Akismet_Admin {
$notices = array();
if ( empty( self::$notices ) ) {
if ( ! empty( $stat_totals['all'] ) && isset( $stat_totals['all']->time_saved ) && $akismet_user->status == 'active' && $akismet_user->account_type == 'free-api-key' ) {
if ( ! empty( $stat_totals['all'] ) && isset( $stat_totals['all']->time_saved ) && $akismet_user->status == Akismet::USER_STATUS_ACTIVE && $akismet_user->account_type == 'free-api-key' ) {
$time_saved = false;
@@ -1237,7 +1273,7 @@ class Akismet_Admin {
}
}
if ( ! Akismet::predefined_api_key() && ! isset( self::$notices['status'] ) && in_array( $akismet_user->status, array( 'cancelled', 'suspended', 'missing', 'no-sub' ) ) ) {
if ( ! Akismet::predefined_api_key() && ! isset( self::$notices['status'] ) && in_array( $akismet_user->status, array( Akismet::USER_STATUS_CANCELLED, Akismet::USER_STATUS_SUSPENDED, Akismet::USER_STATUS_MISSING, Akismet::USER_STATUS_NO_SUB ) ) ) {
$notices[] = array( 'type' => $akismet_user->status );
}
@@ -1264,15 +1300,17 @@ class Akismet_Admin {
// $notices[] = array( 'type' => 'missing-functions' );
// $notices[] = array( 'type' => 'servers-be-down' );
// $notices[] = array( 'type' => 'active-dunning' );
// $notices[] = array( 'type' => 'cancelled' );
// $notices[] = array( 'type' => 'suspended' );
// $notices[] = array( 'type' => 'missing' );
// $notices[] = array( 'type' => 'no-sub' );
// $notices[] = array( 'type' => Akismet::USER_STATUS_CANCELLED );
// $notices[] = array( 'type' => Akismet::USER_STATUS_SUSPENDED );
// $notices[] = array( 'type' => Akismet::USER_STATUS_MISSING );
// $notices[] = array( 'type' => Akismet::USER_STATUS_NO_SUB );
// $notices[] = array( 'type' => 'new-key-valid' );
// $notices[] = array( 'type' => 'new-key-invalid' );
// $notices[] = array( 'type' => 'existing-key-invalid' );
// $notices[] = array( 'type' => 'new-key-failed' );
// $notices[] = array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_plan' => 'Enterprise', 'upgrade_url' => 'https://akismet.com/account/', 'code' => 10502 );
// $notices[] = array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_type' => 'qty', 'upgrade_plan' => 'Business', 'upgrade_url' => 'https://akismet.com/account/', 'code' => 10504, 'recommended_plan_name' => 'Akismet Pro (500)' );
// $notices[] = array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_type' => 'qty', 'upgrade_plan' => 'Business', 'upgrade_url' => 'https://akismet.com/pricing/', 'code' => 10508 );
// $notices[] = array( 'type' => 'spam-check', 'link_text' => 'Link text.' );
// $notices[] = array( 'type' => 'spam-check-cron-disabled' );
// $notices[] = array( 'type' => 'alert', 'code' => 123 );
@@ -1294,6 +1332,9 @@ class Akismet_Admin {
// Akismet::view( 'notice', array( 'type' => 'spam-check-cron-disabled' ) );
// Akismet::view( 'notice', array( 'type' => 'spam-check' ) );
// Akismet::view( 'notice', array( 'type' => 'alert', 'code' => 123, 'msg' => 'Message' ) );
// Akismet::view( 'notice', array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_plan' => 'Enterprise', 'upgrade_url' => 'https://akismet.com/account/', 'code' => 10502 ) );
// Akismet::view( 'notice', array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_type' => 'qty', 'upgrade_plan' => 'Business', 'upgrade_url' => 'https://akismet.com/account/', 'code' => 10504, 'recommended_plan_name' => 'Akismet Pro (500)' ) );
// Akismet::view( 'notice', array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_type' => 'qty', 'upgrade_plan' => 'Business', 'upgrade_url' => 'https://akismet.com/pricing/', 'code' => 10508 ) );
if ( in_array( $hook_suffix, array( 'edit-comments.php' ) ) && (int) get_option( 'akismet_alert_code' ) > 0 ) {
Akismet::verify_key( Akismet::get_api_key() ); // verify that the key is still in alert state
@@ -1383,7 +1424,7 @@ class Akismet_Admin {
* @return array|false
*/
private static function get_jetpack_user() {
if ( ! class_exists( 'Jetpack' ) ) {
if ( ! self::is_jetpack_active() ) {
return false;
}