Skip to content

Commit

Permalink
Fix incorrect message shuffling salt in PHP 5.6 (#176)
Browse files Browse the repository at this point in the history
* Fix duplicate warning

* Add feature test for duplicate warning when shuffling salts
  • Loading branch information
ernilambar committed Mar 1, 2024
1 parent 76ffc92 commit 445dfd0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions features/config-shuffle-salts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,17 @@ Feature: Refresh the salts in the wp-config.php file
"""
define( 'NEW_KEY'
"""

@less-than-php-7.0
Scenario: Shuffling salts duplicate warnings on PHP < 7.0
Given a WP install
When I try `wp config shuffle-salts WP_CACHE_KEY_SALT NONCE_SALT`
Then STDERR should contain:
"""
Warning: Could not shuffle the unknown key 'WP_CACHE_KEY_SALT'.
"""
And STDERR should not contain:
"""
Warning: Could not shuffle the unknown key 'WP_CACHE_KEY_SALT'.
Warning: Could not shuffle the unknown key 'WP_CACHE_KEY_SALT'.
"""
3 changes: 2 additions & 1 deletion src/Config_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,12 +894,13 @@ public function shuffle_salts( $args, $assoc_args ) {

try {
foreach ( $keys as $key ) {
$unique_key = self::unique_key();
if ( ! $force && ! in_array( $key, self::DEFAULT_SALT_CONSTANTS, true ) ) {
WP_CLI::warning( "Could not shuffle the unknown key '{$key}'." );
++$skipped;
continue;
}
$secret_keys[ $key ] = trim( self::unique_key() );
$secret_keys[ $key ] = trim( $unique_key );
}
} catch ( Exception $ex ) {
foreach ( $keys as $key ) {
Expand Down

0 comments on commit 445dfd0

Please sign in to comment.