我写了一个命令wp-cli
调用wp nurse
. 它是根据wp doctor
命令,但用于运行WordPress站点运行状况检查。使用浏览器中的工具,当前所有16个测试都通过。但是,当从wp
, 只有13项测试成功。
ichabod:~ uplime% wp nurse check --all
+----------------------+-------------+--------------------------------------------------------+
| name | status | message |
+----------------------+-------------+--------------------------------------------------------+
| wordpress_version | good | Your version of WordPress (5.3) is up to date |
| plugin_version | good | Your plugins are all up to date |
| theme_version | good | Your themes are all up to date |
| php_version | good | Your version of PHP (7.3.12) is up to date |
| sql_server | good | SQL server is up to date |
| php_extensions | good | Required and recommended modules are installed |
| utf8mb4_support | good | UTF8MB4 is supported |
| https_status | good | Your website is using an active HTTPS connection. |
| ssl_support | good | Your site can communicate securely with other services |
| scheduled_events | good | Scheduled events are running |
| http_requests | good | HTTP requests seem to be working as expected |
| debug_enabled | good | Your site is not set to output debug information |
| rest_availability | recommended | The REST API encountered an unexpected result |
| dotorg_communication | good | Can communicate with WordPress.org |
| background_updates | critical | Background updates are not working as expected |
| loopback_requests | recommended | Your site could not complete a loopback request |
+----------------------+-------------+--------------------------------------------------------+
Error: Only 13/16 tests passed
深入研究这些测试的代码,看起来它们由于没有经过身份验证而失败了(
rest_availability
,
background_updates
, 和
loopback_requests
). 例如
background_updates
看起来要呼叫
GET /wp-admin/site-health.php?health-check-test-wp_version_check=1
, 这失败了,因为从技术上讲,我没有登录仪表板。除了创建临时管理员并使用该管理员登录(这听起来像是一个糟糕的解决方法),还有什么方法可以临时使用WordPress进行身份验证,以便这些测试能够通过?
最合适的回答,由SO网友:leymannx 整理而成
默认情况下,WP-CLI以未经身份验证(注销)的用户身份执行每个命令。要以任何现有WordPress用户的身份执行命令,可以使用全局--user
参数,该参数接受用户ID、登录名或电子邮件地址。
$ wp nurse check --all --user=1
运行时将列出所有其他全局参数
$ wp --help
或
$ wp COMMAND --help
.
GLOBAL PARAMETERS
--user=<id|login|email>
Set the WordPress user.