• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress a2z

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Akismet_CLI::stats() – Fetches stats from the Akismet API.

You appear to be a bot. Output may be restricted

Description

Fetches stats from the Akismet API.

OPTIONS

[<interval>] : The time period for which to retrieve stats. — default: all options: – days – months – all — [–format=<format>] : Allows overriding the output of the command when listing connections. — default: table options: – table – json – csv – yaml – count — [–summary] : When set, will display a summary of the stats.

EXAMPLES

wp akismet stats wp akismet stats all wp akismet stats days wp akismet stats months wp akismet stats all –summary

Usage

Akismet_CLI::stats( $args, $assoc_args );

Parameters

$args
( mixed ) required –
$assoc_args
( mixed ) required –

Returns

void

Source

File name: akismet/class.akismet-cli.php
Lines:

1 to 55 of 55
  public function stats( $args, $assoc_args ) {
    $api_key = Akismet::get_api_key();
 
    if ( empty( $api_key ) ) {
      WP_CLI::error( __( 'API key must be set to fetch stats.', 'akismet' ) );
    }
 
    switch ( $args[0] ) {
      case 'days':
        $interval = '60-days';
        break;
      case 'months':
        $interval = '6-months';
        break;
      default:
        $interval = 'all';
        break;
    }
 
    $response = Akismet::http_post(
      Akismet::build_query( array(
        'blog' => get_option( 'home' ),
        'key'  => $api_key,
        'from' => $interval,
      ) ),
      'get-stats'
    );
 
    if ( empty( $response[1] ) ) {
      WP_CLI::error( __( 'Currently unable to fetch stats. Please try again.', 'akismet' ) );
    }
 
    $response_body = json_decode( $response[1], true );
    
    if ( is_null( $response_body ) ) {
      WP_CLI::error( __( 'Stats response could not be decoded.', 'akismet' ) );
    }
 
    if ( isset( $assoc_args['summary'] ) ) {
      $keys = array(
        'spam',
        'ham',
        'missed_spam',
        'false_positives',
        'accuracy',
        'time_saved',
      );
 
      WP_CLI\Utils\format_items( $assoc_args['format'], array( $response_body ), $keys );
    }
    else {
      $stats = $response_body['breakdown'];
      WP_CLI\Utils\format_items( $assoc_args['format'], $stats, array_keys( end( $stats ) ) );
    }
  }
 

 View on GitHub View on Trac

Published: 19th December 2019 | Last updated: 19th December 2019

Primary Sidebar

Information

Function name: Akismet_CLI::stats
Class ref: Akismet_CLI
Plugin ref: Akismet
Version: 5.0.1
Sourcefile: class.akismet-cli.php
File ref: class.akismet-cli.php
Deprecated?: No
API Letters: A,C,S

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 6.1.1. PHP: 8.0.27
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wp-a2z.org
© Copyright WordPress a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites