Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 60 additions & 32 deletions zh-cn/index.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
---
layout: default
title: WordPress 命令行交互界面
title: WP-CLI | WP-CLI
direction: ltr
---

[WP-CLI](https://wp-cli.org/) 是一款用于管理 [WordPress](https://wordpress.org/) 的命令行交互界面,无需浏览器即可完成插件更新,多站点设置等许多操作。

可以通过[以下方式](https://make.wordpress.org/cli/2019/06/27/thanks-to-the-2019-sponsors/)进行持续维护:

<a href="https://automattic.com/"><img src="https://make.wordpress.org/cli/files/2017/04/automattic-1.png" style="width:19%;height:auto;display:inline-block;vertical-align:middle;" alt="" width="160" height="35" class="aligncenter size-full wp-image-347" /></a> <a href="https://www.bluehost.com/"><img class="aligncenter size-full wp-image-335" style="width:19%;height:auto;display:inline-block;vertical-align:middle;" src="https://make.wordpress.org/cli/files/2017/04/bluehost.png" alt="" width="160" height="26" /></a> <a href="https://pantheon.io/"><img class="aligncenter size-full wp-image-333" style="width:19%;height:auto;display:inline-block;vertical-align:middle;" src="https://make.wordpress.org/cli/files/2019/06/pantheon.png" alt="" width="160" height="50" /></a> <a href="https://www.siteground.com/"><img class="aligncenter size-full wp-image-332" style="width:19%;height:auto;display:inline-block;vertical-align:middle;" src="https://make.wordpress.org/cli/files/2019/06/SG_logo.png" alt="" width="160" height="33" /></a> <a href="https://wpengine.com/"><img class="aligncenter size-full wp-image-333" style="width:19%;height:auto;display:inline-block;vertical-align:middle;" src="https://make.wordpress.org/cli/files/2017/04/wpengine.png" alt="" width="160" height="30" /></a>

目前的稳定版本是 [2.4.0](https://make.wordpress.org/cli/2019/11/12/wp-cli-v2-4-0-release-notes/)。如果您想获取最新信息,请在 Twitter 上关注 [@wpcli](https://twitter.com/wpcli) 或者 [订阅邮件通知](https://make.wordpress.org/cli/subscribe/)。请参阅 [产品路线图](https://make.wordpress.org/cli/handbook/roadmap/) 了解未来更新规划。

[![Testing](https://github.com/wp-cli/wp-cli/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/wp-cli/actions/workflows/testing.yml) [![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/wp-cli/wp-cli.svg)](https://isitmaintained.com/project/wp-cli/wp-cli "Average time to resolve an issue") [![Percentage of issues still open](https://isitmaintained.com/badge/open/wp-cli/wp-cli.svg)](https://isitmaintained.com/project/wp-cli/wp-cli "Percentage of issues still open")
[WP-CLI](https://wp-cli.org/) 是一款用于管理 [WordPress](https://wordpress.org/) 的命令行界面,无需浏览器即可完成插件更新、多站点设置等操作。

持续的维护是通过以下方式实现的:

<div style="
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
text-align: center;">
<a href="https://automattic.com/" style="width:49%; margin-bottom: 10px">
<img src="https://make.wordpress.org/cli/files/2017/04/automattic-1.png" alt="Automattic" width="320" height="70" style="height: auto" />
</a>
<a href="https://www.bluehost.com/" style="width:49%; margin-bottom: 10px">
<img style="height: auto" src="https://make.wordpress.org/cli/files/2017/04/bluehost.png" alt="Bluehost" width="320" height="52" />
</a>
<a href="https://pantheon.io/" style="width:49%; margin-bottom: 10px">
<img style="height: auto" src="https://make.wordpress.org/cli/files/2019/06/pantheon.png" alt="Pantheon" width="320" height="100" />
</a>
<a href="https://www.siteground.com/" style="width:49%; margin-bottom: 10px">
<img style="height: auto" src="https://make.wordpress.org/cli/files/2019/06/SG_logo.png" alt="SiteGround" width="320" height="66" />
</a>
<a href="https://wpengine.com/" style="width:49%; margin-bottom: 10px">
<img style="height: auto" src="https://make.wordpress.org/cli/files/2017/04/wpengine.png" alt="WP Engine" width="320" height="60" />
</a>
<a href="https://www.cloudways.com/" style="width:49%; margin-bottom: 10px">
<img style="height: auto" src="https://make.wordpress.org/cli/files/2021/02/Cloudways-Logo-e1612285267691.png" alt="Cloudways" width="320" height="62" />
</a>
</div>

目前的稳定版本是 [2.5.0](https://make.wordpress.org/cli/2021/05/19/wp-cli-v2-5-0-release-notes/)。如果您想获取最新信息,请在 Twitter 上关注 [@wpcli](https://twitter.com/wpcli) 或者 [订阅邮件通知](https://make.wordpress.org/cli/subscribe/)。参阅 [产品路线图](https://make.wordpress.org/cli/handbook/roadmap/) 了解未来版本的更新规划。

[![Testing](https://github.com/wp-cli/automated-tests/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/automated-tests/actions/workflows/testing.yml) [![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/wp-cli/wp-cli.svg)](https://isitmaintained.com/project/wp-cli/wp-cli "Average time to resolve an issue") [![Percentage of issues still open](https://isitmaintained.com/badge/open/wp-cli/wp-cli.svg)](https://isitmaintained.com/project/wp-cli/wp-cli "Percentage of issues still open")

导航链接:[使用](#使用) &#124; [安装](#安装) &#124; [支持](#支持) &#124; [扩展](#扩展) &#124; [贡献](#贡献) &#124; [参考](#参考)

## 使用

WP-CLI 可以为您在 WordPress 后台管理中执行的许多操作提供命令行工具。例如,使用 `wp plugin install --activate`[说明文档](https://developer.wordpress.org/cli/commands/plugin/install/))安装并激活插件
WP-CLI 为您在 WordPress 后台管理中的许多操作提供了一个命令行接口。例如,使用 `wp plugin install --activate`([说明文档](https://developer.wordpress.org/cli/commands/plugin/install/)) 安装并激活一个 WordPress 插件

```bash
$ wp plugin install user-switching --activate
Expand All @@ -41,7 +65,7 @@ Success: 34 transients deleted from the database.

有关如何使用 WP-CLI 的更多内容请阅读《[Quick Start](https://make.wordpress.org/cli/handbook/quick-start/)》。您也可以在 [Shell Friends](https://make.wordpress.org/cli/handbook/shell-friends/) 了解实用的命令行工具。

如果您已经熟悉基本命令,可以到 [WP-CLI Commands](https://developer.wordpress.org/cli/commands/) 了解更多有关主题及插件管理、数据导入与导出和数据库操作的内容
如果已经熟悉基本命令,可以到 [WP-CLI Commands](https://developer.wordpress.org/cli/commands/) 了解更多有关主题及插件管理、数据导入与导出以及数据库操作的内容

## 安装

Expand All @@ -53,13 +77,13 @@ Success: 34 transients deleted from the database.
- PHP 5.6 或更高版本。
- WordPress 3.7 或更高版本,较旧版本在功能上可能会有所减少。

再次检查操作环境,使用 `wget` 或 `curl` 下载 [wp-cli.phar](https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar):
检查好了操作环境,使用 `wget` 或 `curl` 下载 [wp-cli.phar](https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar):

```bash
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
```

接下来,检查 Phar 文件确保其正常运行:
然后,检查 Phar 文件确保其正常运行:

```bash
php wp-cli.phar --info
Expand All @@ -72,42 +96,46 @@ chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
```

如果 WP-CLI 安装成功,使用 `wp --info` 命令,将看到以下输出信息
如果 WP-CLI 安装成功,当您运行 `wp --info` 时,可以看到类似下面的回显

```bash
$ wp --info
OS: Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jan 11 22:59:40 PST 2018; root:xnu-3789.73.8~1/RELEASE_X86_64 x86_64
Shell: /bin/zsh
PHP binary: /usr/local/bin/php
PHP version: 7.0.22
php.ini used: /etc/local/etc/php/7.0/php.ini
WP-CLI root dir: /home/wp-cli/.wp-cli/vendor/wp-cli/wp-cli
WP-CLI vendor dir: /home/wp-cli/.wp-cli/vendor
OS: Linux 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64
Shell: /usr/bin/zsh
PHP binary: /usr/bin/php
PHP version: 8.0.5
php.ini used: /etc/php/8.0/cli/php.ini
MySQL binary: /usr/bin/mysql
MySQL version: mysql Ver 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
SQL modes:
WP-CLI root dir: /home/wp-cli/
WP-CLI vendor dir: /home/wp-cli/vendor
WP_CLI phar path:
WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/
WP-CLI global config: /home/wp-cli/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.4.0
WP-CLI global config:
WP-CLI project config: /home/wp-cli/wp-cli.yml
WP-CLI version: 2.5.0
```

### 更新 WP-CLI
### 更新

如果需要更新 WP-CLI ,可以运行 `wp cli update`([说明文档](https://developer.wordpress.org/cli/commands/cli/update/))或者重复上述安装方法。
您可以用 `wp cli update`([说明文档](https://developer.wordpress.org/cli/commands/cli/update/))更新 WP-CLI,或者重复上述安装方法。

如果 WP-CLI 的所有者是 root 或其他系统管理员,则需要执行 `sudo wp cli update` 操作。
如果 WP-CLI 是由 root 或其他系统用户拥有,则需要执行 `sudo wp cli update` 操作。

如果您想体验最新版本,可以运行 `wp cli update --nightly` 来安装最新的 Nightly Builds 版本(每天更新的版本,不要用到生产环境) WP-CLI 工具。该版本在开发环境中有一定的稳定性,并且始终包含最新和最出色的 WP-CLI 功能。

### Tab 命令行补全

WP-CLI 带有用于 Bash 和 ZSH 的命令行补全脚本。下载 [wp-completion.bash](https://raw.githubusercontent.com/wp-cli/wp-cli/v2.4.0/utils/wp-completion.bash) `~/.bash_profile` 加载它即可。例如:
WP-CLI 带有用于 Bash 和 ZSH 的命令行补全脚本。下载 [wp-completion.bash](https://raw.githubusercontent.com/wp-cli/wp-cli/v2.5.0/utils/wp-completion.bash) 并在 `~/.bash_profile` 中加载即可,例如:

```bash
source /FULL/PATH/TO/wp-completion.bash
```

在此之后不要忘记运行 `source ~/.bash_profile`
然后运行 `source ~/.bash_profile` 使其生效.

对于 ZSH,您可能需要在加载 `bashcompinit` 后加载 `wp-completion.bash`,将以下内容放入您的 `.zshrc`
如果使用 zsh,需要在加载 `bashcompinit` 后载入 `wp-completion.bash`,将下面的内容放入 `.zshrc` 中即可

```bash
autoload bashcompinit
Expand Down Expand Up @@ -196,7 +224,7 @@ WP-CLI 项目维护者: [schlessera](http://github.com/schlessera)。

## 参考

除了 [composer.json](https://wp-cli.org/composer.json) 中定义的库之外,我们还使用了下面项目中的代码或思想
除了 [composer.json](https://wp-cli.org/composer.json) 中定义的库之外,我们还使用了以下项目的代码或想法

* [Drush](https://github.com/drush-ops/drush) 用于很多事情
* [wpshell](https://code.trac.wordpress.org/browser/wpshell) 用于 `wp shell`
Expand Down