Plugin Directory

Changeset 2580537


Ignore:
Timestamp:
08/09/2021 08:10:43 PM (5 years ago)
Author:
procifer
Message:

Akismet 4.1.11a1: Added support for Akismet API usage notifications on Akismet settings and edit-comments admin pages.

Location:
akismet/trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • akismet/trunk/.htaccess

    r1413166 r2580537  
    2424
    2525# Akismet images
    26 <FilesMatch "^logo-full-2x\.png$">
     26<FilesMatch "^logo-(a|full)-2x\.png$">
    2727    <IfModule !mod_authz_core.c>
    2828        Allow from all
  • akismet/trunk/_inc/akismet.css

    r2309873 r2580537  
    661661    padding-bottom: 1.5rem;
    662662}
     663
     664div.error.akismet-usage-limit-alert {
     665    padding: 25px 45px 25px 15px;
     666    display: flex;
     667    align-items: center;
     668}
     669
     670#akismet-plugin-container .akismet-usage-limit-alert {
     671    margin: 0 auto 0.625rem auto;
     672    box-sizing: border-box;
     673    box-shadow: 0 0 0 1px rgba(200, 215, 225, 0.5), 0 1px 2px #e9eff3;
     674    border: none;
     675    border-left: 4px solid #d63638;
     676}
     677
     678.akismet-usage-limit-alert .akismet-usage-limit-logo {
     679    width: 38px;
     680    min-width: 38px;
     681    height: 38px;
     682    border-radius: 20px;
     683    margin-right: 18px;
     684    background: black;
     685    position: relative;
     686}
     687
     688.akismet-usage-limit-alert .akismet-usage-limit-logo img {
     689    position: absolute;
     690    width: 22px;
     691    left: 8px;
     692    top: 10px;
     693}
     694
     695.akismet-usage-limit-alert .akismet-usage-limit-text {
     696    flex-grow: 1;
     697    margin-right: 18px;
     698}
     699
     700.akismet-usage-limit-alert h3 {
     701    margin: 0;
     702}
     703
     704.akismet-usage-limit-alert .akismet-usage-limit-cta {
     705    text-align: right;
     706}
     707
     708@media (max-width: 550px) {
     709    div.error.akismet-usage-limit-alert {
     710        display: block;
     711    }
     712
     713    .akismet-usage-limit-alert .akismet-usage-limit-logo,
     714    .akismet-usage-limit-alert .akismet-usage-limit-text {
     715        margin-bottom: 15px;
     716    }
     717
     718    .akismet-usage-limit-alert .akismet-usage-limit-cta {
     719        text-align: left;
     720    }
     721}
  • akismet/trunk/akismet.php

    r2559612 r2580537  
    77Plugin URI: https://akismet.com/
    88Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key.
    9 Version: 4.1.10
     9Version: 4.1.11a1
    1010Author: Automattic
    1111Author URI: https://automattic.com/wordpress-plugins/
     
    3838}
    3939
    40 define( 'AKISMET_VERSION', '4.1.10' );
     40define( 'AKISMET_VERSION', '4.1.11a1' );
    4141define( 'AKISMET__MINIMUM_WP_VERSION', '4.0' );
    4242define( 'AKISMET__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
  • akismet/trunk/class.akismet-admin.php

    r2402753 r2580537  
    889889    }
    890890
     891    public static function get_usage_limit_alert_data() {
     892        return array(
     893            'type'         => 'usage-limit',
     894            'code'         => (int) get_option( 'akismet_alert_code' ),
     895            'msg'          => get_option( 'akismet_alert_msg' ),
     896            'api_calls'    => get_option( 'akismet_alert_api_calls' ),
     897            'usage_limit'  => get_option( 'akismet_alert_usage_limit' ),
     898            'upgrade_plan' => get_option( 'akismet_alert_upgrade_plan' ),
     899            'upgrade_url'  => get_option( 'akismet_alert_upgrade_url' ),
     900        );
     901    }
     902
     903    public static function display_usage_limit_alert() {
     904        Akismet::view( 'notice', self::get_usage_limit_alert_data() );
     905    }
     906
    891907    public static function display_spam_check_warning() {
    892908        Akismet::fix_scheduled_recheck();
     
    10201036        if ( !isset( self::$notices['status'] ) && in_array( $akismet_user->status, array( 'cancelled', 'suspended', 'missing', 'no-sub' ) ) ) {
    10211037            $notices[] = array( 'type' => $akismet_user->status );
     1038        }
     1039
     1040        $alert_code = get_option( 'akismet_alert_code' );
     1041        if ( preg_match( '/^105\d\d$/', $alert_code ) ) {
     1042            $notices[] = self::get_usage_limit_alert_data();
    10221043        }
    10231044
     
    10411062        $notices[] = array( 'type' => 'limit-reached', 'level' => 'yellow' );
    10421063        $notices[] = array( 'type' => 'limit-reached', 'level' => 'red' );
     1064        $notices[] = array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_plan' => 'Enterprise', 'upgrade_url' => 'https://akismet.com/account/' );
    10431065        */
    10441066       
     
    10571079        if ( in_array( $hook_suffix, array( 'edit-comments.php' ) ) && (int) get_option( 'akismet_alert_code' ) > 0 ) {
    10581080            Akismet::verify_key( Akismet::get_api_key() ); //verify that the key is still in alert state
    1059            
    1060             if ( get_option( 'akismet_alert_code' ) > 0 )
     1081       
     1082            $alert_code = get_option( 'akismet_alert_code' );
     1083            if ( preg_match( '/^105\d\d$/', $alert_code ) ) {
     1084                self::display_usage_limit_alert();
     1085            }
     1086            elseif ( $alert_code > 0 ) {
    10611087                self::display_alert();
     1088            }
    10621089        }
    10631090        elseif ( ( 'plugins.php' === $hook_suffix || 'edit-comments.php' === $hook_suffix ) && ! Akismet::get_api_key() ) {
  • akismet/trunk/class.akismet.php

    r2531878 r2580537  
    55    const API_PORT = 80;
    66    const MAX_DELAY_BEFORE_MODERATION_EMAIL = 86400; // One day in seconds
     7
     8    const LIMIT_NOTICE_FIRST_MONTH_OVER_LIMIT        = 10501;
     9    const LIMIT_NOTICE_SECOND_MONTH_OVER_LIMIT       = 10502;
     10    const LIMIT_NOTICE_THIRD_MONTH_APPROACHING_LIMIT = 10504;
     11    const LIMIT_NOTICE_THIRD_MONTH_OVER_LIMIT        = 10508;
     12    const LIMIT_NOTICE_FOUR_PLUS_MONTHS_OVER_LIMIT   = 10516;
    713
    814    private static $last_comment = '';
     
    12551261    // given a response from an API call like check_key_status(), update the alert code options if an alert is present.
    12561262    public static function update_alert( $response ) {
    1257         $code = $msg = null;
    1258         if ( isset( $response[0]['x-akismet-alert-code'] ) ) {
    1259             $code = $response[0]['x-akismet-alert-code'];
    1260             $msg  = $response[0]['x-akismet-alert-msg'];
    1261         }
    1262 
    1263         // only call update_option() if the value has changed
    1264         if ( $code != get_option( 'akismet_alert_code' ) ) {
    1265             if ( ! $code ) {
    1266                 delete_option( 'akismet_alert_code' );
    1267                 delete_option( 'akismet_alert_msg' );
    1268             }
    1269             else {
    1270                 update_option( 'akismet_alert_code', $code );
    1271                 update_option( 'akismet_alert_msg', $msg );
     1263        $alert_option_prefix = 'akismet_alert_';
     1264        $alert_header_prefix = 'x-akismet-alert-';
     1265        $alert_header_names  = array(
     1266            'code',
     1267            'msg',
     1268            'api-calls',
     1269            'usage-limit',
     1270            'upgrade-plan',
     1271            'upgrade-url',
     1272        );
     1273
     1274        foreach( $alert_header_names as $alert_header_name ) {
     1275            $value = null;
     1276            if ( isset( $response[0][$alert_header_prefix . $alert_header_name] ) ) {
     1277                $value = $response[0][$alert_header_prefix . $alert_header_name];
     1278            }
     1279
     1280            $option_name = $alert_option_prefix . str_replace( '-', '_', $alert_header_name );
     1281            if ( $value != get_option( $option_name ) ) {
     1282                if ( ! $value ) {
     1283                    delete_option( $option_name );
     1284                }
     1285                else {
     1286                    update_option( $option_name, $value );
     1287                }
    12721288            }
    12731289        }
  • akismet/trunk/readme.txt

    r2559612 r2580537  
    3030
    3131== Changelog ==
     32
     33= 4.1.11 =
     34*Release Date - TBD*
     35
     36* Added support for Akismet API usage notifications on Akismet settings and edit-comments admin pages.
    3237
    3338= 4.1.10 =
  • akismet/trunk/views/notice.php

    r2519525 r2580537  
    140140    <?php endif; ?>
    141141</div>
     142<?php elseif ( $type == 'usage-limit' ) :?>
     143<div class="error akismet-usage-limit-alert">
     144    <div class="akismet-usage-limit-logo">
     145        <img src="<?php echo esc_url( plugins_url( '../_inc/img/logo-a-2x.png', __FILE__ ) ); ?>" alt="Akismet" />
     146    </div>
     147    <div class="akismet-usage-limit-text">
     148        <h3>
     149        <?php
     150        switch ( $code ) {
     151            case Akismet::LIMIT_NOTICE_FIRST_MONTH_OVER_LIMIT:
     152            case Akismet::LIMIT_NOTICE_SECOND_MONTH_OVER_LIMIT:
     153                esc_html_e( 'Your Akismet account usage is over the plan limit', 'akismet' );
     154                break;
     155            case Akismet::LIMIT_NOTICE_THIRD_MONTH_APPROACHING_LIMIT:
     156                esc_html_e( 'Your Akismet account usage is approaching the plan limit', 'akismet' );
     157                break;
     158            case Akismet::LIMIT_NOTICE_THIRD_MONTH_OVER_LIMIT:
     159            case Akismet::LIMIT_NOTICE_FOUR_PLUS_MONTHS_OVER_LIMIT:
     160                esc_html_e( 'Your account has been restricted', 'akismet' );
     161                break;
     162            default:
     163        }
     164        ?>
     165        </h3>
     166        <p>
     167        <?php
     168        switch ( $code ) {
     169            case Akismet::LIMIT_NOTICE_FIRST_MONTH_OVER_LIMIT:
     170                printf(
     171                    __( 'Since %s, your account made %s API calls, compared to your plan limit of %s. <a href="%s" target="_blank">Learn more</a> about usage limits.', 'akismet' ),
     172                    esc_html( gmdate( 'F' ) . ' 1' ),
     173                    number_format( $api_calls ),
     174                    number_format( $usage_limit ),
     175                    'https://docs.akismet.com/akismet-api-usage-limits/'
     176                );
     177                break;
     178            case Akismet::LIMIT_NOTICE_SECOND_MONTH_OVER_LIMIT:
     179                esc_html_e( 'Your Akismet usage has been over the plan limit for two consecutive months. Next month, we will restrict your account after you reach the limit. Please consider upgrading your plan.', 'akismet' );
     180                break;
     181            case Akismet::LIMIT_NOTICE_THIRD_MONTH_APPROACHING_LIMIT:
     182                esc_html_e( 'Your Akismet usage is nearing the plan limit for the third consecutive month. We will restrict your account after you reach the limit. Upgrade your plan so Akismet can continue blocking spam.', 'akismet' );
     183                break;
     184            case Akismet::LIMIT_NOTICE_THIRD_MONTH_OVER_LIMIT:
     185            case Akismet::LIMIT_NOTICE_FOUR_PLUS_MONTHS_OVER_LIMIT:
     186                esc_html_e( 'Your Akismet usage has been over the plan limit for three consecutive months. We have restricted your account for the rest of the month. Upgrade your plan so Akismet can continue blocking spam.', 'akismet' );
     187                break;
     188            default:
     189        }
     190        ?>
     191        </p>
     192    </div>
     193    <div class="akismet-usage-limit-cta">
     194        <?php printf( __( '<a href="%1$s" class="button" target="_blank">Upgrade to %2$s</a>', 'akismet' ), esc_attr( $upgrade_url ), esc_html( $upgrade_plan ) ); ?>
     195    </div>
     196</div>
    142197<?php endif;?>
Note: See TracChangeset for help on using the changeset viewer.