Initialize plugin_configured as true if plugin options are not empty#5042
Initialize plugin_configured as true if plugin options are not empty#5042westonruter merged 13 commits intodevelopfrom
Conversation
|
Plugin builds for 19fe024 are ready 🛎️!
|
|
I need to check the failing e2e test. |
includes/amp-helper-functions.php
Outdated
| $options = get_option( AMP_Options_Manager::OPTION_NAME, [] ); | ||
|
|
||
| // Initialize the plugin_configured option, setting it to true if options already exist. | ||
| if ( is_admin() && current_user_can( 'manage_options' ) ) { | ||
| if ( empty( $options ) ) { | ||
| AMP_Options_Manager::update_option( Option::PLUGIN_CONFIGURED, false ); | ||
| } elseif ( ! isset( $options[ Option::PLUGIN_CONFIGURED ] ) ) { | ||
| AMP_Options_Manager::update_option( Option::PLUGIN_CONFIGURED, true ); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I think we can handle this with default values in AMP_Options_Manager::get_options(). I'll make the change.
There was a problem hiding this comment.
Go for it. I'll leave it alone.
There was a problem hiding this comment.
That's what I tried at first but it didn't work, I think because of this: https://github.com/ampproject/amp-wp/blob/develop/includes/amp-helper-functions.php#L145-L160
Once AMP_Options_Manager::update_option( Option::VERSION, AMP__VERSION ); is called, the options will no longer be empty, and that runs way before get_options is called again.
There was a problem hiding this comment.
That's why I was trying to squeeze in the initialization of plugin_configured before that point.
There was a problem hiding this comment.
It seems to be working for me.
If I reset the option to an old value:
echo '{"theme_support":"transitional","supported_post_types":["post"],"analytics":[],"all_templates_supported":false,"supported_templates":["is_singular"],"version":"1.5.5"}' | wp option set amp-options --format=jsonThen:
$ wp eval 'var_dump(AMP_Options_Manager::get_option("plugin_configured"));'
bool(true)
Whereas if I delete the option entirely:
$ wp option delete amp-options
Success: Deleted 'amp-options' option.
Then I get:
$ wp eval 'var_dump(AMP_Options_Manager::get_option("plugin_configured"));'
bool(false)
There was a problem hiding this comment.
Hm, all right, I'll verify when I make the change for the settings page.
|
@johnwatkins0 One more thing: When deleting the The wizard, however, should have its fields empty if |
I think we need to pass some flag in diff --git a/assets/src/components/options-context-provider/index.js b/assets/src/components/options-context-provider/index.js
index 678ab0205..7990d4ef2 100644
--- a/assets/src/components/options-context-provider/index.js
+++ b/assets/src/components/options-context-provider/index.js
@@ -68,7 +68,7 @@ export function OptionsContextProvider( { children, optionsRestEndpoint } ) {
return;
}
- if ( fetchedOptions.plugin_configured === false ) {
+ if ( ! POPULATE_DEFAULT_VALUES && fetchedOptions.plugin_configured === false ) {
fetchedOptions.mobile_redirect = true;
fetchedOptions.reader_theme = null;
fetchedOptions.theme_support = null;
diff --git a/src/Admin/OptionsMenu.php b/src/Admin/OptionsMenu.php
index 828f62b0b..46e614776 100644
--- a/src/Admin/OptionsMenu.php
+++ b/src/Admin/OptionsMenu.php
@@ -241,6 +241,7 @@ class OptionsMenu implements Conditional, Service, Registerable {
],
'OPTIONS_REST_ENDPOINT' => rest_url( 'amp/v1/options' ),
'READER_THEMES_REST_ENDPOINT' => rest_url( 'amp/v1/reader-themes' ),
+ 'POPULATE_DEFAULT_VALUES' => true,
'IS_CORE_THEME' => in_array(
get_stylesheet(),
AMP_Core_Theme_Sanitizer::get_supported_themes(), |
I'm giving this a shot. |
|
@johnwatkins0 there, please check cdc872e. Here's the matrix for how the wizard and settings screen look (as expected):
|
|
(I'll need help with adapting/adding E2E tests.) |
|
@westonruter The code looks right. I'll fix these e2e tests that are now expectedly failing. But -- isn't it supposed to default to Reader mode when options are empty? That's how mine works locally, which differs from your screenshot. |
|
For me, on initial load with empty options, the settings screen has Reader mode selected with the legacy theme selected. |
|
If you have an AMP-compatible theme active, then the default mode should be Standard or Transitional per this logic here: amp-wp/includes/options/class-amp-options-manager.php Lines 96 to 104 in 9f7b74c What theme do you have active? |
|
I see there is also a bug in |
|
Yeah, I was using Twenty Twenty and getting Reader by default. |
|
@johnwatkins0 Please check if 677c20e fixes the issue with the expected default mode. |
Success:
|
|
There's one more bug I found that was missed from #5010: when a child theme of a core theme is active, we should not default to Transitional or Standard because all bets are off as to whether it actually supports AMP. Fixed in f8c8390. We'll only be able to change that once we have the theme scan feature (#4795). |






Summary
Fixes #5020
For the setup wizard, we added a
plugin_configuredoption. When false, certain values are initialized to null in the UI until the user makes decisions about plugin configuration.We need to skip that behavior if the plugin was already configured at some point before
plugin_configuredwas added.With this change, when the plugin options from the database are not empty, we set
plugin_configuredto true. As a result, the UI will reflect previously selected options instead of initializing any fields to null.Test steps
wp option delete amp-optionsChecklist