Skip to content

Commit 445dfd0

Browse files
authored
Fix incorrect message shuffling salt in PHP 5.6 (#176)
* Fix duplicate warning * Add feature test for duplicate warning when shuffling salts
1 parent 76ffc92 commit 445dfd0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

features/config-shuffle-salts.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,17 @@ Feature: Refresh the salts in the wp-config.php file
338338
"""
339339
define( 'NEW_KEY'
340340
"""
341+
342+
@less-than-php-7.0
343+
Scenario: Shuffling salts duplicate warnings on PHP < 7.0
344+
Given a WP install
345+
When I try `wp config shuffle-salts WP_CACHE_KEY_SALT NONCE_SALT`
346+
Then STDERR should contain:
347+
"""
348+
Warning: Could not shuffle the unknown key 'WP_CACHE_KEY_SALT'.
349+
"""
350+
And STDERR should not contain:
351+
"""
352+
Warning: Could not shuffle the unknown key 'WP_CACHE_KEY_SALT'.
353+
Warning: Could not shuffle the unknown key 'WP_CACHE_KEY_SALT'.
354+
"""

src/Config_Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,12 +894,13 @@ public function shuffle_salts( $args, $assoc_args ) {
894894

895895
try {
896896
foreach ( $keys as $key ) {
897+
$unique_key = self::unique_key();
897898
if ( ! $force && ! in_array( $key, self::DEFAULT_SALT_CONSTANTS, true ) ) {
898899
WP_CLI::warning( "Could not shuffle the unknown key '{$key}'." );
899900
++$skipped;
900901
continue;
901902
}
902-
$secret_keys[ $key ] = trim( self::unique_key() );
903+
$secret_keys[ $key ] = trim( $unique_key );
903904
}
904905
} catch ( Exception $ex ) {
905906
foreach ( $keys as $key ) {

0 commit comments

Comments
 (0)