首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何作为经过身份验证的用户运行WP-CLI命令?

如何作为经过身份验证的用户运行WP-CLI命令?
EN

WordPress Development用户
提问于 2019-12-09 22:49:52
回答 1查看 1.2K关注 0票数 4

我为wp-cli编写了一个名为wp nurse的命令。它以wp doctor命令为样式,但用于运行WordPress站点健康检查的除外。使用浏览器中的工具,所有16个测试目前都通过了.然而,当从wp调用它时,只有13个测试成功。

代码语言:javascript
复制
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_availabilitybackground_updatesloopback_requests)。例如,background_updates希望调用GET /wp-admin/site-health.php?health-check-test-wp_version_check=1,这是失败的,因为技术上我没有被登录到仪表板中。除了创建临时管理员并使用该管理员登录(这听起来是一个糟糕的解决方法)之外,是否有任何方法可以暂时使用WordPress进行身份验证,以便这些测试能够通过?

EN

回答 1

WordPress Development用户

回答已采纳

发布于 2019-12-10 09:22:42

默认情况下,WP-CLI以未经身份验证(注销)用户的身份执行每个命令。要以任何现有WordPress用户的身份执行命令,可以使用全局--user参数,该参数接受用户ID、登录或电子邮件地址。

代码语言:javascript
复制
$ wp nurse check --all --user=1

在运行$ wp --help$ wp COMMAND --help时,您将得到所有其他全局参数。

全局参数- user =设置WordPress用户。

票数 5
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/354247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档