Welcome to WP-CLIWP-CLIWP-CLI is the Command Line Interface for WordPress, used to do administrative and development tasks in a programmatic way. The project page is http://wp-cli.org/https://make.wordpress.org/cli/!
WP-CLI is the official command line tool for interacting with and managing your WordPress sites.
Write a custom check to perform an arbitrary assertion Edit
Because wp doctor checks are built on top of a foundational abstraction, it’s relatively straightforward for you to write your own custom check. The basic requirement is that you create a class extending runcommand\Doctor\Checks\Check that implements a run() method. The run() must set a status and message based on whatever procedural logic As an example, here’s an annotated custom check to assert Akismet is activated with a valid APIAPIAn API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways. key:
<?php
/**
* Ensures Akismet is activated with the appropriate credentials.
*/
class Akismet_Activated extends runcommand\Doctor\Checks\Check {
public function __construct( $options = array() ) {
parent::__construct( $options );
// Every check is to run on 'after_wp_load' by default.
// You could instead use 'before_wp_load' or 'after_wp_config_load'
$this->set_when( 'after_wp_load' );
}
public function run() {
// If the Akismet isn't activated, bail early.
if ( ! class_exists( 'Akismet' ) ) {
$this->set_status( 'error' );
$this->set_message( "Akismet doesn't appear to be activated." );
return;
}
// Verify that the API exists.
$api_key = Akismet::get_api_key();
if ( empty( $api_key ) ) {
$this->set_status( 'error' );
$this->set_message( 'API key is missing.' );
return;
}
// Verify that the API key is valid.
$verification = Akismet::verify_key( $api_key );
if ( 'failed' === $verification ) {
$this->set_status( 'error' );
$this->set_message( 'API key verification failed.' );
return;
}
// Everything looks good, so report a success.
$this->set_status( 'success' );
$this->set_message( 'Akismet is activated with a verified API key.' );
}
}
If the class were placed in an akismet-activated.php file, you could register it with: