wp-cli/config-command

生成和读取 wp-config.php 文件。

安装数量: 6,030,128

依赖项: 12

建议者: 0

安全性: 0

星级: 38

关注者: 11

分支: 36

开放问题: 16

语言:Gherkin

类型:wp-cli-package

v2.3.6 2024-08-05 13:34 UTC

README

生成和读取 wp-config.php 文件。

Testing

快速链接: 使用 | 安装 | 贡献 | 支持

使用

此包实现了以下命令

wp config

生成和读取 wp-config.php 文件。

wp config

示例

# Create standard wp-config.php file.
$ wp config create --dbname=testing --dbuser=wp --dbpass=securepswd --locale=ro_RO
Success: Generated 'wp-config.php' file.

# List constants and variables defined in wp-config.php file.
$ wp config list
+------------------+------------------------------------------------------------------+----------+
| key              | value                                                            | type     |
+------------------+------------------------------------------------------------------+----------+
| table_prefix     | wp_                                                              | variable |
| DB_NAME          | wp_cli_test                                                      | constant |
| DB_USER          | root                                                             | constant |
| DB_PASSWORD      | root                                                             | constant |
| AUTH_KEY         | r6+@shP1yO&$)1gdu.hl[/j;7Zrvmt~o;#WxSsa0mlQOi24j2cR,7i+QM/#7S:o^ | constant |
| SECURE_AUTH_KEY  | iO-z!_m--YH$Tx2tf/&V,YW*13Z_HiRLqi)d?$o-tMdY+82pK$`T.NYW~iTLW;xp | constant |
+------------------+------------------------------------------------------------------+----------+

# Get wp-config.php file path.
$ wp config path
/home/person/htdocs/project/wp-config.php

# Get the table_prefix as defined in wp-config.php file.
$ wp config get table_prefix
wp_

# Set the WP_DEBUG constant to true.
$ wp config set WP_DEBUG true --raw
Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'true'.

# Delete the COOKIE_DOMAIN constant from the wp-config.php file.
$ wp config delete COOKIE_DOMAIN
Success: Deleted the constant 'COOKIE_DOMAIN' from the 'wp-config.php' file.

# Launch system editor to edit wp-config.php file.
$ wp config edit

# Check whether the DB_PASSWORD constant exists in the wp-config.php file.
$ wp config has DB_PASSWORD
$ echo $?
0

# Assert if MULTISITE is true.
$ wp config is-true MULTISITE
$ echo $?
0

# Get new salts for your wp-config.php file.
$ wp config shuffle-salts
Success: Shuffled the salt keys.

wp config edit

启动系统编辑器以编辑 wp-config.php 文件。

wp config edit [--config-file=<path>]

选项

[--config-file=<path>]
	Specify the file path to the config file to be edited. Defaults to the root of the
	WordPress installation and the filename "wp-config.php".

示例

# Launch system editor to edit wp-config.php file
$ wp config edit

# Edit wp-config.php file in a specific editor
$ EDITOR=vim wp config edit

wp config delete

从 wp-config.php 文件中删除特定的常量或变量。

wp config delete <name> [--type=<type>] [--config-file=<path>]

选项

<name>
	Name of the wp-config.php constant or variable.

[--type=<type>]
	Type of the config value to delete. Defaults to 'all'.
	---
	default: all
	options:
	  - constant
	  - variable
	  - all
	---

[--config-file=<path>]
	Specify the file path to the config file to be modified. Defaults to the root of the
	WordPress installation and the filename "wp-config.php".

示例

# Delete the COOKIE_DOMAIN constant from the wp-config.php file.
$ wp config delete COOKIE_DOMAIN
Success: Deleted the constant 'COOKIE_DOMAIN' from the 'wp-config.php' file.

wp config create

生成 wp-config.php 文件。

wp config create --dbname=<dbname> --dbuser=<dbuser> [--dbpass=<dbpass>] [--dbhost=<dbhost>] [--dbprefix=<dbprefix>] [--dbcharset=<dbcharset>] [--dbcollate=<dbcollate>] [--locale=<locale>] [--extra-php] [--skip-salts] [--skip-check] [--force] [--config-file=<path>] [--insecure]

创建一个新的 wp-config.php 文件,包含数据库常量,并验证数据库常量是否正确。

选项

--dbname=<dbname>
	Set the database name.

--dbuser=<dbuser>
	Set the database user.

[--dbpass=<dbpass>]
	Set the database user password.

[--dbhost=<dbhost>]
	Set the database host.
	---
	default: localhost
	---

[--dbprefix=<dbprefix>]
	Set the database table prefix.
	---
	default: wp_
	---

[--dbcharset=<dbcharset>]
	Set the database charset.
	---
	default: utf8
	---

[--dbcollate=<dbcollate>]
	Set the database collation.
	---
	default:
	---

[--locale=<locale>]
	Set the WPLANG constant. Defaults to $wp_local_package variable.

[--extra-php]
	If set, the command copies additional PHP code into wp-config.php from STDIN.

[--skip-salts]
	If set, keys and salts won't be generated, but should instead be passed via `--extra-php`.

[--skip-check]
	If set, the database connection is not checked.

[--force]
	Overwrites existing files, if present.

[--config-file=<path>]
	Specify the file path to the config file to be created. Defaults to the root of the
	WordPress installation and the filename "wp-config.php".

[--insecure]
	Retry API download without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.

示例

# Standard wp-config.php file
$ wp config create --dbname=testing --dbuser=wp --dbpass=securepswd --locale=ro_RO
Success: Generated 'wp-config.php' file.

# Enable WP_DEBUG and WP_DEBUG_LOG
$ wp config create --dbname=testing --dbuser=wp --dbpass=securepswd --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
PHP
Success: Generated 'wp-config.php' file.

# Avoid disclosing password to bash history by reading from password.txt
# Using --prompt=dbpass will prompt for the 'dbpass' argument
$ wp config create --dbname=testing --dbuser=wp --prompt=dbpass < password.txt
Success: Generated 'wp-config.php' file.

wp config get

获取 wp-config.php 文件中定义的特定常量或变量的值。

wp config get <name> [--type=<type>] [--format=<format>] [--config-file=<path>]

选项

<name>
	Name of the wp-config.php constant or variable.

[--type=<type>]
	Type of config value to retrieve. Defaults to 'all'.
	---
	default: all
	options:
	  - constant
	  - variable
	  - all
	---

[--format=<format>]
	Get value in a particular format.
	Dotenv is limited to non-object values.
	---
	default: var_export
	options:
	  - var_export
	  - json
	  - yaml
	  - dotenv
	---

[--config-file=<path>]
	Specify the file path to the config file to be read. Defaults to the root of the
	WordPress installation and the filename "wp-config.php".

示例

# Get the table_prefix as defined in wp-config.php file.
$ wp config get table_prefix
wp_

wp config has

检查 wp-config.php 文件中是否存在特定的常量或变量。

wp config has <name> [--type=<type>] [--config-file=<path>]

选项

<name>
	Name of the wp-config.php constant or variable.

[--type=<type>]
	Type of the config value to set. Defaults to 'all'.
	---
	default: all
	options:
	  - constant
	  - variable
	  - all
	---

[--config-file=<path>]
	Specify the file path to the config file to be checked. Defaults to the root of the
	WordPress installation and the filename "wp-config.php".

示例

# Check whether the DB_PASSWORD constant exists in the wp-config.php file.
$ wp config has DB_PASSWORD

wp config is-true

确定特定定义的常量或变量的值是否为真。

wp config is-true <name> [--type=<type>] [--config-file=<path>]

此确定是通过通过 boolval() 评估检索到的值来完成的。

选项

<name>
	Name of the wp-config.php constant or variable.

[--type=<type>]
	Type of config value to retrieve. Defaults to 'all'.
	---
	default: all
	options:
	  - constant
	  - variable
	  - all
	---

[--config-file=<path>]
	Specify the file path to the config file to be read. Defaults to the root of the
	WordPress installation and the filename "wp-config.php".

示例

# Assert if MULTISITE is true
$ wp config is-true MULTISITE
$ echo $?
0

wp config list

列出 wp-config.php 文件中定义的变量、常量和文件包含。

wp config list [<filter>...] [--fields=<fields>] [--format=<format>] [--strict] [--config-file=<path>]

选项

[<filter>...]
	Name or partial name to filter the list by.

[--fields=<fields>]
	Limit the output to specific fields. Defaults to all fields.

[--format=<format>]
	Render output in a particular format.
	Dotenv is limited to non-object values.
	---
	default: table
	options:
	  - table
	  - csv
	  - json
	  - yaml
	  - dotenv
	---

[--strict]
	Enforce strict matching when a filter is provided.

[--config-file=<path>]
	Specify the file path to the config file to be read. Defaults to the root of the
	WordPress installation and the filename "wp-config.php".

示例

# List constants and variables defined in wp-config.php file.
$ wp config list
+------------------+------------------------------------------------------------------+----------+
| key              | value                                                            | type     |
+------------------+------------------------------------------------------------------+----------+
| table_prefix     | wp_                                                              | variable |
| DB_NAME          | wp_cli_test                                                      | constant |
| DB_USER          | root                                                             | constant |
| DB_PASSWORD      | root                                                             | constant |
| AUTH_KEY         | r6+@shP1yO&$)1gdu.hl[/j;7Zrvmt~o;#WxSsa0mlQOi24j2cR,7i+QM/#7S:o^ | constant |
| SECURE_AUTH_KEY  | iO-z!_m--YH$Tx2tf/&V,YW*13Z_HiRLqi)d?$o-tMdY+82pK$`T.NYW~iTLW;xp | constant |
+------------------+------------------------------------------------------------------+----------+

# List only database user and password from wp-config.php file.
$ wp config list DB_USER DB_PASSWORD --strict
+------------------+-------+----------+
| key              | value | type     |
+------------------+-------+----------+
| DB_USER          | root  | constant |
| DB_PASSWORD      | root  | constant |
+------------------+-------+----------+

# List all salts from wp-config.php file.
$ wp config list _SALT
+------------------+------------------------------------------------------------------+----------+
| key              | value                                                            | type     |
+------------------+------------------------------------------------------------------+----------+
| AUTH_SALT        | n:]Xditk+_7>Qi=>BmtZHiH-6/Ecrvl(V5ceeGP:{>?;BT^=[B3-0>,~F5z$(+Q$ | constant |
| SECURE_AUTH_SALT | ?Z/p|XhDw3w}?c.z%|+BAr|(Iv*H%%U+Du&kKR y?cJOYyRVRBeB[2zF-`(>+LCC | constant |
| LOGGED_IN_SALT   | +$@(1{b~Z~s}Cs>8Y]6[m6~TnoCDpE>O%e75u}&6kUH!>q:7uM4lxbB6[1pa_X,q | constant |
| NONCE_SALT       | _x+F li|QL?0OSQns1_JZ{|Ix3Jleox-71km/gifnyz8kmo=w-;@AE8W,(fP<N}2 | constant |
+------------------+------------------------------------------------------------------+----------+

wp config path

获取 wp-config.php 文件的路径。

wp config path 

示例

# Get wp-config.php file path
$ wp config path
/home/person/htdocs/project/wp-config.php

wp config set

设置 wp-config.php 文件中定义的特定常量或变量的值。

wp config set <name> <value> [--add] [--raw] [--anchor=<anchor>] [--placement=<placement>] [--separator=<separator>] [--type=<type>] [--config-file=<path>]

选项

<name>
	Name of the wp-config.php constant or variable.

<value>
	Value to set the wp-config.php constant or variable to.

[--add]
	Add the value if it doesn't exist yet.
	This is the default behavior, override with --no-add.

[--raw]
	Place the value into the wp-config.php file as is, instead of as a quoted string.

[--anchor=<anchor>]
	Anchor string where additions of new values are anchored around.
	Defaults to "/* That's all, stop editing!".
	The special case "EOF" string uses the end of the file as the anchor.

[--placement=<placement>]
	Where to place the new values in relation to the anchor string.
	---
	default: 'before'
	options:
	  - before
	  - after
	---

[--separator=<separator>]
	Separator string to put between an added value and its anchor string.
	The following escape sequences will be recognized and properly interpreted: '\n' => newline, '\r' => carriage return, '\t' => tab.
	Defaults to a single EOL ("\n" on *nix and "\r\n" on Windows).

[--type=<type>]
	Type of the config value to set. Defaults to 'all'.
	---
	default: all
	options:
	  - constant
	  - variable
	  - all
	---

[--config-file=<path>]
	Specify the file path to the config file to be modified. Defaults to the root of the
	WordPress installation and the filename "wp-config.php".

示例

# Set the WP_DEBUG constant to true.
$ wp config set WP_DEBUG true --raw
Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'true'.

wp config shuffle-salts

刷新 wp-config.php 文件中定义的盐值。

wp config shuffle-salts [<keys>...] [--force] [--config-file=<path>] [--insecure]

选项

[<keys>...]
	One ore more keys to shuffle. If none are provided, this falls back to the default WordPress Core salt keys.

[--force]
	If an unknown key is requested to be shuffled, add it instead of throwing a warning.

[--config-file=<path>]
	Specify the file path to the config file to be modified. Defaults to the root of the
	WordPress installation and the filename "wp-config.php".

[--insecure]
	Retry API download without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.

示例

# Get new salts for your wp-config.php file
$ wp config shuffle-salts
Success: Shuffled the salt keys.

# Add a cache key salt to the wp-config.php file
$ wp config shuffle-salts WP_CACHE_KEY_SALT --force
Success: Shuffled the salt keys.

安装

此包包含在 WP-CLI 本身中,无需额外安装。

要安装此包的最新版本,覆盖 WP-CLI 中包含的版本,请运行

wp package install [email protected]:wp-cli/config-command.git

贡献

我们感谢您主动为这个项目做出贡献。

贡献不仅限于代码。我们鼓励您以最适合您能力的方式做出贡献,例如编写教程、在当地聚会中演示、帮助其他用户解决支持问题或修订我们的文档。

要了解更多信息,请查看 WP-CLI 贡献指南。此包遵循那些政策和指南。

报告错误

你认为你发现了一个错误?我们很高兴你能帮助我们修复它。

在创建新问题之前,你应该搜索现有问题,看看是否已经存在对该错误的解决方案,或者它是否已经在更新的版本中修复。

在你进行了一些搜索并发现没有开放或已修复的问题与你的错误相关之后,请创建一个新问题。尽可能详细地说明,如果可能的话,提供重现错误的清晰步骤。有关更多指导,请查看我们的错误报告文档

创建 pull request

想要贡献一个新功能?请首先打开一个新问题,讨论该功能是否适合该项目。

一旦您决定投入时间来跟进您的拉取请求,请按照我们创建拉取请求的指南进行操作,以确保这是一次愉快的体验。有关在本地处理此包的详细信息,请参阅"设置"。

支持

GitHub问题不是用于一般支持问题的,但您还可以尝试其他途径:https://wp-cli.org/#support

此README.md是通过使用wp scaffold package-readme文档)从项目的代码库动态生成的。要提出更改建议,请提交针对代码库相应部分的拉取请求。