wp doctor

Identifies problems in WordPress using a series of tests.

The doctor package makes it easy to run a series of customizable checks to diagnose weaknesses in WordPress operation.

With this package you can save a lot of time by quickly identifying weaknesses of your WordPress installations, encoding diagnostic procedures as a series of checks to be run with WP-CLI. The wp doctor package ships with dozens of checks out of the box (see below) and allows you to create your own doctor.yml file to create a template of checks.

Each check contains a Name, Status ("success", "warning" or "error"), and a Message describing what is wrong. For example, the cron-count check helps quickly ensure that WP is not overwhelmed with cron tasks:

$ wp doctor check cron-count
+------------+---------+--------------------------------------------------------------------+
| name       | status  | message                                                            |
+------------+---------+--------------------------------------------------------------------+
| cron-count | success | Total number of cron jobs is within normal operating expectations. |
+------------+---------+--------------------------------------------------------------------+

Need to pass results to another system? Use the flags --format=json or --format=csv to display checks in the appropriate format.

The package can be extended. Create your own doctor.yml file to define additional checks that you consider necessary for your system:

plugin-w3-total-cache:
  check: Plugin_Status
  options:
	name: w3-total-cache
	status: uninstalled

Then run this file using the parameter --config=<file>:

$ wp doctor check --fields=name,status --all --config=doctor.yml
+-----------------------+--------+
| name                  | status |
+-----------------------+--------+
| plugin-w3-total-cache | error  |
+-----------------------+--------+

See example of using this package to locate large autoloaded options.

Package installation

This command package needs to be installed separately (it isn't included in the base WP-CLI installation).

Use the command wp package install to install the command package. After successful installation, the wp doctor command will appear in the list of available commands.

wp package install not_wp_cli/doctor-command

Installing this package requires the latest stable version of WP-CLI; it can be updated with the command wp cli update.

List of Commands Description
wp doctor check Run a series of WordPress checks to identify potential issues on your site.
wp doctor list A list of all checks that can be run.

Source code of commands


wp doctor check

Run a series of WordPress checks to identify potential issues on your site.

A check is a routine run against some scope of WordPress that reports a 'status' and a 'message'. The status can be 'success', 'warning', or 'error'. The message is a human-readable explanation of the status. If any of the checks fail, then the command will exit with the code 1.

Parameters

You can specify Global Parameters and the following:

[{checks}...]

The name of the check to run. What checks exist can be viewed with the command wp doctor list. The list of available checks as of April 2020 is:

  • autoload-options-size — Warns when autoloaded options size exceeds threshold of 900 kb.
  • constant-savequeries-falsy — Confirms expected state of the SAVEQUERIES constant.
  • constant-wp-debug-falsy — Confirms expected state of the WP_DEBUG constant.
  • core-update — Errors when new WordPress minor release is available; warns for major release.
  • core-verify-checksums — Verifies WordPress files against published checksums; errors on failure.
  • cron-count — Errors when there's an excess of 50 total cron jobs registered.
  • cron-duplicates — Errors when there's an excess of 10 duplicate cron jobs registered.
  • file-eval — Checks files on the filesystem for regex pattern eval\(.*base64_decode\(.*.
  • option-blog-public — Confirms the expected value of the 'blog_public' option.
  • plugin-active-count — Warns when there are greater than 80 plugins activated.
  • plugin-deactivated — Warns when greater than 40% of plugins are deactivated.
  • plugin-update — Warns when there are plugin updates available.
  • theme-update — Warns when there are theme updates available.
  • cache-flush — Detects the number of occurrences of the wp_cache_flush() function.
  • php-in-upload — Warns when a PHP file is present in the Uploads folder.
  • language-update — Warns when there are language updates available.
[--all]
Run all registered checks.
[--spotlight]
Focus on warnings and errors; ignore any successful checks.
[--config={file}]
Use checks registered in a specific configuration file.
[--fields={fields}]
Limit the output to specific fields. Default is name,status,message.
[--format={format}]

Render results in a particular format.
Default: table
May be:

  • table
  • json
  • csv
  • yaml
  • count

Usage

wp doctor check 

Examples

# Verify WordPress core is up to date.
$ wp doctor check core-update
+-------------+---------+-----------------------------------------------------------+
| name        | status  | message                                                   |
+-------------+---------+-----------------------------------------------------------+
| core-update | warning | A new major version of WordPress is available for update. |
+-------------+---------+-----------------------------------------------------------+
# Verify the site is public as expected.
$ wp doctor check option-blog-public
+--------------------+--------+--------------------------------------------+
| name               | status | message                                    |
+--------------------+--------+--------------------------------------------+
| option-blog-public | error  | Site is private but expected to be public. |
+--------------------+--------+--------------------------------------------+
# Run the autoload-options-size check
$ wp doctor check autoload-options-size
+-----------------------+---------+------------------------------------------------------------+
| name                  | status  | message                                                    |
+-----------------------+---------+------------------------------------------------------------+
| autoload-options-size | warning | Autoloaded options size (2.62mb) exceeds threshold (900kb) |
+-----------------------+---------+------------------------------------------------------------+

wp doctor list

A list of all checks that can be run.

Parameters

You can specify Global Parameters and the following:

[--config={file}]
Use checks registered in a specific configuration file.
[--fields={fields}]
Limit the output to specific fields. Defaults to name,description.
[--format={format}]

Render output in a specific format.
Default: table
May be:

  • table
  • json
  • csv
  • count

Usage

wp doctor list 

Examples

$ wp doctor list
+----------------------------+--------------------------------------------------------------------------------+
| name                       | description                                                                    |
+----------------------------+--------------------------------------------------------------------------------+
| autoload-options-size      | Warns when autoloaded options size exceeds threshold of 900 kb.                |
| constant-savequeries-falsy | Confirms expected state of the SAVEQUERIES constant.                           |
| constant-wp-debug-falsy    | Confirms expected state of the WP_DEBUG constant.                              |
| core-update                | Errors when new WordPress minor release is available; warns for major release. |
| core-verify-checksums      | Verifies WordPress files against published checksums; errors on failure.       |
| cron-count                 | Errors when there's an excess of 50 total cron jobs registered.                |
| cron-duplicates            | Errors when there's an excess of 10 duplicate cron jobs registered.            |
| file-eval                  | Checks files on the filesystem for regex pattern `eval\(.*base64_decode\(.*`.  |
| option-blog-public         | Confirms the expected value of the 'blog_public' option.                       |
| plugin-active-count        | Warns when there are greater than 80 plugins activated.                        |
| plugin-deactivated         | Warns when greater than 40% of plugins are deactivated.                        |
| plugin-update              | Warns when there are plugin updates available.                                 |
| theme-update               | Warns when there are theme updates available.                                  |
| cache-flush                | Detects the number of occurrences of the `wp_cache_flush()` function.          |
| php-in-upload              | Warns when a PHP file is present in the Uploads folder.                        |
| language-update            | Warns when there are language updates available.                               |
+----------------------------+--------------------------------------------------------------------------------+