Skip to content
Merged
Show file tree
Hide file tree
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
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,57 @@ Generates and reads the wp-config.php file.
wp config
~~~

**EXAMPLES**

# 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.



Expand Down Expand Up @@ -78,6 +128,7 @@ wp config delete <name> [--type=<type>] [--config-file=<path>]

# 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.



Expand Down Expand Up @@ -437,6 +488,7 @@ wp config set <name> <value> [--add] [--raw] [--anchor=<anchor>] [--placement=<p

# 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'.



Expand Down Expand Up @@ -471,6 +523,7 @@ wp config shuffle-salts [<keys>...] [--force] [--config-file=<path>] [--insecure

# 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.

## Installing

Expand Down
57 changes: 57 additions & 0 deletions src/Config_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,60 @@

/**
* Generates and reads the wp-config.php file.
*
* ## EXAMPLES
*
* # 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.
*
* @package wp-cli
*/
class Config_Command extends WP_CLI_Command {

Expand Down Expand Up @@ -582,6 +636,7 @@ private static function get_wp_config_vars( $wp_config_path = '' ) {
*
* # 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'.
*
* @when before_wp_load
*/
Expand Down Expand Up @@ -685,6 +740,7 @@ public function set( $args, $assoc_args ) {
*
* # 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.
*
* @when before_wp_load
*/
Expand Down Expand Up @@ -815,6 +871,7 @@ public function has( $args, $assoc_args ) {
*
* # 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.
*
* @subcommand shuffle-salts
* @when before_wp_load
Expand Down