-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add amp option
wp cli command to manage plugin options
#7430
Conversation
amp option
wp cli command to manage amp settingsamp option
wp cli command to manage plugin options
Plugin builds for 68bc2ac are ready 🛎️!
|
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.
Just pulling in this previous PR review: #7368 (review)
Co-authored-by: Weston Ruter <westonruter@google.com>
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.
Code looks good! Just a few more bits of feedback.
Co-authored-by: Weston Ruter <westonruter@google.com>
8e82e22
to
0afc408
Compare
* Remove .babelrc, .eslintrc files and add *.feature file extension
… options to be managed by amp option command
… guard in update subcommand
// Update type for some options. | ||
if ( Option::SANDBOXING_LEVEL === $option_name ) { | ||
$option_value = (int) $option_value; | ||
} |
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.
Why was this specific cast needed? Is it because it is a string and the following logic requires it to be an int:
Lines 123 to 129 in c28b8f1
if ( | |
isset( $new_options[ Option::SANDBOXING_LEVEL ] ) | |
&& | |
in_array( $new_options[ Option::SANDBOXING_LEVEL ], self::LEVELS, true ) | |
) { | |
$options[ Option::SANDBOXING_LEVEL ] = $new_options[ Option::SANDBOXING_LEVEL ]; | |
} |
It seems like the Sandboxing
service should be doing that cast to int as well, since it is already doing so for bool:
Lines 120 to 122 in c28b8f1
if ( isset( $new_options[ Option::SANDBOXING_ENABLED ] ) ) { | |
$options[ Option::SANDBOXING_ENABLED ] = (bool) $new_options[ Option::SANDBOXING_ENABLED ]; | |
} |
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.
I believe when we update options using REST API then it first validates the options(and return any validation failures) through provided schema. In the case of '0' and '1'
and 'true' and 'false'
with schema type as boolean, it runs it through the rest_sanitize_boolean
first hence type cast is not required but in the case of enums it fails:
Line 56 in c28b8f1
const LEVELS = [ 1, 2, 3 ]; |
Lines 68 to 72 in c28b8f1
Option::SANDBOXING_LEVEL => [ | |
'type' => 'int', | |
'enum' => self::LEVELS, | |
'default' => 1, | |
], |
In other words, it doesn't reach here:
$options = apply_filters( 'amp_options_updating', $options, $new_options ); |
It seems like the Sandboxing service should be doing that cast to int as well since it is already doing so for bool:
Type cast here is done by REST schema's rest_sanitize_boolean
IMO.
Summary
Fixes #5783
Previously #7368
Checklist