admin管理员组文章数量:1405510
I've written a command for wp-cli
called wp nurse
. It is styled after the wp doctor
command, except is meant to run the WordPress Site Health checks. Using the in-browser tool, all 16 tests currently pass. However, when calling it from wp
, only 13 of the tests are succeeding.
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 |
| 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
Digging through the code for these tests, it looks like they're failing due to not being authenticated (rest_availability
, background_updates
, and loopback_requests
). For example, background_updates
looks to call out to GET /wp-admin/site-health.php?health-check-test-wp_version_check=1
, which fails, since I'm not technically signed into the dashboard. Short of creating a temporary administrator, and signing in with that (which sounds like a bad workaround), is there any way to authenticate with WordPress temporarily, so that these tests can pass?
I've written a command for wp-cli
called wp nurse
. It is styled after the wp doctor
command, except is meant to run the WordPress Site Health checks. Using the in-browser tool, all 16 tests currently pass. However, when calling it from wp
, only 13 of the tests are succeeding.
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 |
| 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
Digging through the code for these tests, it looks like they're failing due to not being authenticated (rest_availability
, background_updates
, and loopback_requests
). For example, background_updates
looks to call out to GET /wp-admin/site-health.php?health-check-test-wp_version_check=1
, which fails, since I'm not technically signed into the dashboard. Short of creating a temporary administrator, and signing in with that (which sounds like a bad workaround), is there any way to authenticate with WordPress temporarily, so that these tests can pass?
1 Answer
Reset to default 8By default WP-CLI executes every command as unauthenticated (logged-out) user. To execute a command as any existing WordPress user you can use the global --user
parameter, which accepts an user ID, login, or email address.
$ wp nurse check --all --user=1
You'll get all other global parameters listed when running $ wp --help
or $ wp COMMAND --help
.
GLOBAL PARAMETERS --user=<id|login|email> Set the WordPress user.
本文标签: wp cliHow can I run a WPCLI command as authenticated user
版权声明:本文标题:wp cli - How can I run a WP-CLI command as authenticated user? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744922180a2632362.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论