New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shuffle-salts
command
#62
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4e489e2
#50 first pass at a shuffle-salts command
CodeProKid bcbae48
#50 simplifying command
CodeProKid 7b2d54b
#50 removing unneeded check
CodeProKid b2a43d9
fixing for older php versions
CodeProKid d23dec6
tests for shuffle-salts command
CodeProKid fcb04a5
modifications from CR feedback
CodeProKid 8d06c9a
fixing issue with salts fetched from API
CodeProKid 2501e8f
updating README with new command
CodeProKid 2b58d25
removing some debug code
CodeProKid 332e594
regenerating readme file
CodeProKid 50e723b
properly adding the new command to the readme
CodeProKid 5e0d6e2
Add missing period to comment
schlessera File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Feature: Refresh the salts in the wp-config.php file | ||
|
||
Scenario: Salts are created properly when none initially exist | ||
Given a WP install | ||
When I try `wp config get AUTH_KEY --type=constant` | ||
Then STDERR should contain: | ||
""" | ||
The constant 'AUTH_KEY' is not defined in the 'wp-config.php' file. | ||
""" | ||
|
||
When I run `wp config shuffle-salts` | ||
Then STDOUT should contain: | ||
""" | ||
Shuffled the salt keys. | ||
""" | ||
And the wp-config.php file should contain: | ||
""" | ||
define( 'AUTH_KEY' | ||
""" | ||
|
||
Scenario: Shuffle the salts | ||
Given a WP install | ||
When I run `wp config shuffle-salts` | ||
Then STDOUT should contain: | ||
""" | ||
Shuffled the salt keys. | ||
""" | ||
And the wp-config.php file should contain: | ||
""" | ||
define( 'AUTH_KEY' | ||
""" | ||
And the wp-config.php file should contain: | ||
""" | ||
define( 'LOGGED_IN_SALT' | ||
""" | ||
|
||
When I run `wp config get AUTH_KEY --type=constant` | ||
Then save STDOUT as {AUTH_KEY_ORIG} | ||
When I run `wp config get LOGGED_IN_SALT --type=constant` | ||
Then save STDOUT as {LOGGED_IN_SALT_ORIG} | ||
|
||
When I run `wp config shuffle-salts` | ||
Then STDOUT should contain: | ||
""" | ||
Shuffled the salt keys. | ||
""" | ||
And the wp-config.php file should not contain: | ||
""" | ||
{AUTH_KEY_ORIG} | ||
""" | ||
And the wp-config.php file should not contain: | ||
""" | ||
{LOGGED_IN_SALT_ORIG} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -619,6 +619,65 @@ public function has( $args, $assoc_args ) { | |
} | ||
} | ||
|
||
/** | ||
* Refreshes the salts defined in the wp-config.php file | ||
* | ||
* ## OPTIONS | ||
* | ||
* ## EXAMPLES | ||
* | ||
* # Get new salts for your wp-config.php file | ||
* $ wp config shuffle-salts | ||
* | ||
* @subcommand shuffle-salts | ||
* @when before_wp_load | ||
*/ | ||
public function shuffle_salts( $args, $assoc_args ) { | ||
|
||
$constant_list = array( | ||
'AUTH_KEY', | ||
'SECURE_AUTH_KEY', | ||
'LOGGED_IN_KEY', | ||
'NONCE_KEY', | ||
'AUTH_SALT', | ||
'SECURE_AUTH_SALT', | ||
'LOGGED_IN_SALT', | ||
'NONCE_SALT' | ||
); | ||
|
||
try { | ||
foreach ( $constant_list as $key ) { | ||
$secret_keys[ $key ] = trim( self::unique_key() ); | ||
} | ||
throw new Exception( 'TEST' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like there's some debugging left-overs here. |
||
} catch ( Exception $ex ) { | ||
|
||
$remote_salts = self::_read( 'https://api.wordpress.org/secret-key/1.1/salt/' ); | ||
$remote_salts = explode( "\n", $remote_salts ); | ||
foreach ( $remote_salts as $k => $salt ) { | ||
if ( ! empty( $salt ) ) { | ||
$key = $constant_list[ $k ]; | ||
$secret_keys[ $key ] = trim( substr( $salt, 28, 64 ) ); | ||
} | ||
} | ||
|
||
} | ||
|
||
$path = $this->get_config_path(); | ||
|
||
try { | ||
$config_transformer = new WPConfigTransformer( $path ); | ||
foreach ( $secret_keys as $constant => $key ) { | ||
$config_transformer->update( 'constant', $constant, (string) $key ); | ||
} | ||
} catch ( Exception $exception ) { | ||
WP_CLI::error( "Could not process the 'wp-config.php' transformation.\nReason: " . $exception->getMessage() ); | ||
} | ||
|
||
WP_CLI::success( 'Shuffled the salt keys.' ); | ||
|
||
} | ||
|
||
/** | ||
* Filters wp-config.php file configurations. | ||
* | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you manually changed the
README.md
file. This should be generated out of the source code docblock instead. The automatic regeneration is not yet included here so yu need to do this manually for now.You can use the following to regenerate the
README.md
file:README.md
file