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?

Share Improve this question edited Dec 10, 2019 at 9:47 norman.lol 3,2313 gold badges30 silver badges35 bronze badges asked Dec 9, 2019 at 22:49 Lucky The RabbitLucky The Rabbit 631 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 8

By 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