From 44087d815bf2c8000bd3d9bf197327784a85133f Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Sat, 17 Feb 2018 06:41:41 -0800 Subject: [PATCH] Introduce `config edit` command Launches `wp-config.php` in the system editor --- .github/settings.yml | 4 ++++ README.md | 18 ++++++++++++++++++ composer.json | 1 + src/Config_Command.php | 22 ++++++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/.github/settings.yml b/.github/settings.yml index ee76285bf..710ba592e 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -22,6 +22,10 @@ labels: color: c2e0c6 - name: command:config color: c5def5 + - name: command:config-edit + color: c5def5 + - name: command:config-delete + color: c5def5 - name: command:config-create color: c5def5 - name: command:config-get diff --git a/README.md b/README.md index a2177d07b..d55148384 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,24 @@ wp config +### wp config edit + +Launches system editor to edit the wp-config.php file. + +~~~ +wp config edit +~~~ + +**EXAMPLES** + + # 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 Deletes a specific constant or variable from the wp-config.php file. diff --git a/composer.json b/composer.json index 1f3c6da58..e60ea78a8 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,7 @@ "bundled": true, "commands": [ "config", + "config edit", "config delete", "config create", "config get", diff --git a/src/Config_Command.php b/src/Config_Command.php index 112ef67fb..f518628f9 100644 --- a/src/Config_Command.php +++ b/src/Config_Command.php @@ -162,6 +162,28 @@ public function create( $_, $assoc_args ) { } } + /** + * Launches system editor to edit the wp-config.php file. + * + * ## EXAMPLES + * + * # 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 + */ + public function edit() { + $config_path = $this->get_config_path(); + $contents = file_get_contents( $config_path ); + $r = Utils\launch_editor_for_input( $contents, 'wp-config.php', 'php' ); + if ( $r === false ) { + WP_CLI::warning( 'No changes made to wp-config.php.', 'Aborted' ); + } else { + file_put_contents( $path, $r ); + } + } + /** * Gets the path to wp-config.php file. *