wp doctor

Выявляет проблемы в WordPress, с помощью серии тестов.

Пакет doctor позволяет легко запустить серию настраиваемых проверок для диагностики слабых мест в работе WordPress.

Благодаря этому пакету можно хорошо экономить время, быстро выявляя слабые места ваших установок WordPress, кодируя диагностические процедуры в виде серии проверок для запуска с помощью WP-CLI. Пакет wp doctor поставляется с десятками проверок из коробки (см. ниже) и позволяет создать свой файл doctor.yml для создания шаблона проверок.

Каждая проверка содержит Имя, Статус ("success", "warning" или "error") и Сообщение о том что не так. Например, проверка cron-count - позволяет быстро убедиться что WP не переполнен крон задачами:

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

Нужно передать результаты в другую систему? Используйте флаги --format=json или --format=csv для отображения проверок в соотвествующем формате.

Пакет может расширяться. Создайте свой файл doctor.yml для определения дополнительных проверок, которые вы считаете необходимыми для вашей системы:

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

Затем, запустите этот файл используя параметр --config=<file>:

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

Смотрите пример (англ.) использования этого пакета для нахождения объемных авто-загружаемых опций.

Установка пакета

Этот пакет команд нужно устанавливать отдельно (его нет в базовой установке WP-CLI).

Используйте команду wp package install, чтобы установить пакет команды. После успешной установки пакета в списке доступных команд появится команда wp doctor.

wp package install wp-cli/doctor-command

Установка этого пакета требует последнюю стабильную версию WP-CLI, обновится можно командой wp cli update.

Список команд Описание
wp doctor check Запустите серию проверок WordPress, чтобы выявить возможные проблемы на сайте.
wp doctor list Список всех проверок, которые можно запустить.

Исходный код команд


wp doctor check

Запустите серию проверок WordPress, чтобы выявить возможные проблемы на сайте.

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.

Использование

wp doctor check [{checks}...] [--all] [--spotlight] [--config={file}] [--fields={fields}] [--format={format}]

Можно указать Глобальные параметры и следующие:

[{checks}...]

Имя проверки, которую нужно запустить. Какие првоерки существуют можно посмотреть командой wp doctor list. Список возможных проверок на апрель 2020 года:

  • 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.
По умолчанию: table
Может быть:

  • table
  • json
  • csv
  • yaml
  • count

Примеры

# 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

Список всех проверок, которые можно запустить.

Использование

wp doctor list [--config={file}] [--fields={fields}] [--format={format}]

Можно указать Глобальные параметры и следующие:

[--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.
По умолчанию: table
Может быть:

  • table
  • json
  • csv
  • count

Примеры

$ 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.                               |
+----------------------------+--------------------------------------------------------------------------------+