-
Notifications
You must be signed in to change notification settings - Fork 4
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix token decoding during wp-env
startup.
#220
Changes from all commits
5d2bb79
2fbe164
b49bf7b
e7a978d
d510e8c
e2413f7
5aa83c4
3d7cd22
8ea7c06
957d915
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
use RemoteDataBlocks\WpdbStorage\DataSourceCrud; | ||
use function wp_get_environment_type; | ||
use function wp_is_development_mode; | ||
use function add_settings_error; | ||
|
||
defined( 'ABSPATH' ) || exit(); | ||
|
||
|
@@ -154,19 +155,36 @@ public static function encrypt_option( array $new_value, string|array|bool $old_ | |
} | ||
} | ||
|
||
public static function decrypt_option( string $value ): array|null { | ||
public static function decrypt_option( string $value ): array { | ||
$decryptor = new \RemoteDataBlocks\WpdbStorage\DataEncryption(); | ||
$is_error = false; | ||
|
||
try { | ||
$decrypted = $decryptor->decrypt( $value ); | ||
return json_decode( $decrypted, true ); | ||
|
||
if ( false === $decrypted ) { | ||
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. This fixes the original stack trace in the issue description.
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. From testing, I think the reason this fails is that Because the values are initially encrypted with the site's real |
||
$is_error = true; | ||
} | ||
} catch ( \Exception $e ) { | ||
$is_error = true; | ||
} | ||
|
||
if ( $is_error ) { | ||
self::show_decryption_error(); | ||
return []; | ||
} else { | ||
return json_decode( $decrypted, true ); | ||
} | ||
} | ||
|
||
private static function show_decryption_error(): void { | ||
// Check that we have add_settings_error() available. This can be unavailable during wp-env startup. | ||
if ( is_admin() ) { | ||
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. Even after the fixes above, I was getting this stack trace for using the
The root cause is a bit harder to determine. I think WP_CLI is doing something strange with load order, as We can get around this error by ensuring |
||
add_settings_error( | ||
'remote_data_blocks_settings', | ||
'decryption_error', | ||
__( 'Error decrypting remote-data-blocks settings.', 'remote-data-blocks' ) | ||
); | ||
return null; | ||
} | ||
} | ||
} |
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.
decrypt_option()
was also changed to return an empty array[]
instead ofnull
on error. Returningnull
causes a runtime type failure in the parent call toget_config()
, which expects to return anarray
.