diff --git a/assets/src/components/reader-themes-context-provider/index.js b/assets/src/components/reader-themes-context-provider/index.js index 8b8e8df5865..38cfb5c48d7 100644 --- a/assets/src/components/reader-themes-context-provider/index.js +++ b/assets/src/components/reader-themes-context-provider/index.js @@ -9,7 +9,7 @@ import { __ } from '@wordpress/i18n'; * External dependencies */ import PropTypes from 'prop-types'; -import { READER_THEME_AVAILABLE, LEGACY_THEME_SLUG } from 'amp-settings'; +import { USING_FALLBACK_READER_THEME, LEGACY_THEME_SLUG } from 'amp-settings'; /** * Internal dependencies @@ -92,7 +92,7 @@ export function ReaderThemesContextProvider( { wpAjaxUrl, children, currentTheme if ( selectedTheme.availability === 'non-installable' || originalSelectedTheme.availability === 'active' || - ! READER_THEME_AVAILABLE + USING_FALLBACK_READER_THEME ) { updateOptions( { reader_theme: LEGACY_THEME_SLUG } ); setThemeWasOverridden( true ); diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index f7295e25e1b..0f22f3c697a 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -520,7 +520,9 @@ public static function reader_theme_fallback_notice() { return; } - if ( amp_is_legacy() && ReaderThemes::DEFAULT_READER_THEME !== self::get_option( Option::READER_THEME ) && current_user_can( 'manage_options' ) ) { + $reader_themes = new ReaderThemes(); + + if ( $reader_themes->using_fallback_theme() ) { $selected_theme = self::get_option( Option::READER_THEME ); $error_message = sprintf( /* translators: 1: slug of the Reader theme, 2: the URL for the reader theme selection UI */ diff --git a/src/Admin/OnboardingWizardSubmenuPage.php b/src/Admin/OnboardingWizardSubmenuPage.php index 96357d46445..0fe6f37e60f 100644 --- a/src/Admin/OnboardingWizardSubmenuPage.php +++ b/src/Admin/OnboardingWizardSubmenuPage.php @@ -213,7 +213,6 @@ public function enqueue_assets( $hook_suffix ) { wp_styles()->add_data( self::ASSET_HANDLE, 'rtl', 'replace' ); $theme = wp_get_theme(); - $reader_theme = AMP_Options_Manager::get_option( Option::READER_THEME ); $is_reader_theme = $this->reader_themes->theme_data_exists( get_stylesheet() ); $exit_link = menu_page_url( AMP_Options_Manager::OPTION_NAME, false ); @@ -240,7 +239,7 @@ public function enqueue_assets( $hook_suffix ) { 'screenshot' => $theme->get_screenshot() ?: null, 'url' => $theme->get( 'ThemeURI' ), ], - 'READER_THEME_AVAILABLE' => $this->reader_themes->theme_data_exists( $reader_theme ), + 'USING_FALLBACK_READER_THEME' => $this->reader_themes->using_fallback_theme(), 'FINISH_LINK' => $exit_link, 'OPTIONS_REST_PATH' => '/amp/v1/options', 'READER_THEMES_REST_PATH' => '/amp/v1/reader-themes', diff --git a/src/Admin/OptionsMenu.php b/src/Admin/OptionsMenu.php index 7ee801b6f09..e534a199df8 100644 --- a/src/Admin/OptionsMenu.php +++ b/src/Admin/OptionsMenu.php @@ -195,29 +195,28 @@ public function enqueue_assets( $hook_suffix ) { wp_styles()->add_data( self::ASSET_HANDLE, 'rtl', 'replace' ); $theme = wp_get_theme(); - $reader_theme = AMP_Options_Manager::get_option( Option::READER_THEME ); $is_reader_theme = $this->reader_themes->theme_data_exists( get_stylesheet() ); $js_data = [ - 'CURRENT_THEME' => [ + 'CURRENT_THEME' => [ 'name' => $theme->get( 'Name' ), 'description' => $theme->get( 'Description' ), 'is_reader_theme' => $is_reader_theme, 'screenshot' => $theme->get_screenshot() ?: null, 'url' => $theme->get( 'ThemeURI' ), ], - 'OPTIONS_REST_PATH' => '/amp/v1/options', - 'READER_THEMES_REST_PATH' => '/amp/v1/reader-themes', - 'IS_CORE_THEME' => in_array( + 'OPTIONS_REST_PATH' => '/amp/v1/options', + 'READER_THEMES_REST_PATH' => '/amp/v1/reader-themes', + 'IS_CORE_THEME' => in_array( get_stylesheet(), AMP_Core_Theme_Sanitizer::get_supported_themes(), true ), - 'LEGACY_THEME_SLUG' => ReaderThemes::DEFAULT_READER_THEME, - 'READER_THEME_AVAILABLE' => $this->reader_themes->theme_data_exists( $reader_theme ), - 'THEME_SUPPORT_ARGS' => AMP_Theme_Support::get_theme_support_args(), - 'THEME_SUPPORTS_READER_MODE' => AMP_Theme_Support::supports_reader_mode(), - 'UPDATES_NONCE' => wp_create_nonce( 'updates' ), + 'LEGACY_THEME_SLUG' => ReaderThemes::DEFAULT_READER_THEME, + 'USING_FALLBACK_READER_THEME' => $this->reader_themes->using_fallback_theme(), + 'THEME_SUPPORT_ARGS' => AMP_Theme_Support::get_theme_support_args(), + 'THEME_SUPPORTS_READER_MODE' => AMP_Theme_Support::supports_reader_mode(), + 'UPDATES_NONCE' => wp_create_nonce( 'updates' ), ]; wp_add_inline_script( diff --git a/src/Admin/ReaderThemes.php b/src/Admin/ReaderThemes.php index 3ba440f6ac6..96b9cdb1afe 100644 --- a/src/Admin/ReaderThemes.php +++ b/src/Admin/ReaderThemes.php @@ -346,6 +346,12 @@ public function theme_data_exists( $theme_slug ) { return in_array( $theme_slug, wp_list_pluck( $this->get_themes(), 'slug' ), true ); } + public function using_fallback_theme() { + return amp_is_legacy() + && self::DEFAULT_READER_THEME !== AMP_Options_Manager::get_option( Option::READER_THEME ) + && current_user_can( 'manage_options' ); + } + /** * Provides details for the legacy theme included with the plugin. *