Skip to content

Commit

Permalink
Ensure AMP legacy theme is being used as a fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
pierlon committed Aug 7, 2020
1 parent 6bb44d7 commit e5e086f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions assets/src/components/reader-themes-context-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 3 additions & 1 deletion includes/options/class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions src/Admin/OnboardingWizardSubmenuPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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',
Expand Down
19 changes: 9 additions & 10 deletions src/Admin/OptionsMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions src/Admin/ReaderThemes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit e5e086f

Please sign in to comment.