Skip to content
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

Reader mode: Generate styles for color palette, gradient presets, and font sizes from the theme support features of the primary theme #6042

Merged
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8d19c25
Retrieve editor color palette and generate style rules
pierlon Apr 5, 2021
f1140dd
Remove indentation
pierlon Apr 5, 2021
2d6386a
Add comment on deriving text color from editor color
pierlon Apr 5, 2021
a500206
Add fallback Cover block colors when serving a Reader theme
westonruter Apr 8, 2021
c342a03
Add color palette styles from primary theme to reader theme
westonruter Apr 18, 2021
5e0836d
Ensure non-default text color will override the relative luminance de…
westonruter Apr 18, 2021
4c19e3a
Print color palette styles after wp_print_styles
westonruter Apr 20, 2021
64594fc
Capture primary theme support features for gradient presets and font …
westonruter Apr 20, 2021
f317988
Add editor-gradient-presets from active theme
westonruter Apr 20, 2021
1d82c5e
Add support for editor-font-sizes
westonruter Apr 20, 2021
2d55d6b
Add primary theme support features in case referenced
westonruter Apr 20, 2021
68e766d
Fix adding theme support feature styles to legacy Reader template
westonruter Apr 20, 2021
6970bbd
Move code into ReaderThemeSupportFeatures service
westonruter Apr 20, 2021
3c4d183
Use constants for feature strings
westonruter Apr 20, 2021
e27bb4b
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/5229-…
westonruter Apr 21, 2021
004fbbb
Add test for is_enabled with supplied options
westonruter Apr 21, 2021
99257a6
Verify options are set before accessing
westonruter Apr 21, 2021
d57a849
Split up print_theme_support_styles into multiple methods
westonruter Apr 21, 2021
5fbb5a9
Limit printing theme support styles to AMP pages
westonruter Apr 21, 2021
a9ec26e
Limit overriding theme support to when theme is overridden by Reader …
westonruter Apr 21, 2021
95e1193
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/5229-…
westonruter Apr 21, 2021
6e6eb6b
Limit printing theme support styles to when serving AMP page in Reade…
westonruter Apr 21, 2021
c964cdf
Ensure PRIMARY_THEME_SUPPORT is array
westonruter Apr 21, 2021
ff7c546
Defer options migration until admin_init action so settings are regis…
westonruter Apr 21, 2021
0ef7666
Store only the required theme support props
westonruter Apr 22, 2021
a4d23a8
Eliminate setting the theme support features from the primary theme
westonruter Apr 22, 2021
b62a8c8
Defer updating cached primary_theme_support until cron if theme overr…
westonruter Apr 22, 2021
4201418
Update cached primary_theme_support when updating a theme
westonruter Apr 22, 2021
733f71c
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/5229-…
westonruter Apr 22, 2021
1ba4a36
Add testing code coverage for is_enabled
westonruter Apr 22, 2021
acf39f3
Add stubs for testing ReaderThemeSupportFeatures
westonruter Apr 22, 2021
5e2487e
Add some tests for ReaderThemeSupportFeatures
westonruter Apr 22, 2021
aafa228
Add tests for handle_theme_update and update_cached_theme_support
westonruter Apr 23, 2021
8462653
Add remaining tests for ReaderThemeSupportFeatures
westonruter Apr 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'plugin_registry' => \AmpProject\AmpWP\PluginRegistry::class,
'plugin_suppression' => \AmpProject\AmpWP\PluginSuppression::class,
'reader_theme_loader' => \AmpProject\AmpWP\ReaderThemeLoader::class,
'reader_theme_support_features' => \AmpProject\AmpWP\ReaderThemeSupportFeatures::class,
'rest.options_controller' => \AmpProject\AmpWP\OptionsRESTController::class,
'rest.validation_counts_controller' => \AmpProject\AmpWP\Validation\ValidationCountsRestController::class,
'server_timing' => \AmpProject\AmpWP\Instrumentation\ServerTiming::class,
Expand Down
5 changes: 3 additions & 2 deletions includes/amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ function () {
$old_version = isset( $options[ Option::VERSION ] ) ? $options[ Option::VERSION ] : '0.0';

if ( AMP__VERSION !== $old_version && is_admin() && current_user_can( 'manage_options' ) ) {
// This waits to happen until the very end of init to ensure that amp theme support and amp post type support have all been added.
// This waits to happen until the very end of admin_init to ensure that amp theme support and amp post type
// support have all been added, and that the settings have been registered.
add_action(
'init',
'admin_init',
static function () use ( $old_version ) {
/**
* Triggers when after amp_init when the plugin version has updated.
Expand Down
2 changes: 2 additions & 0 deletions src/AmpWpPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ final class AmpWpPlugin extends ServiceBasedPlugin {
'plugin_registry' => PluginRegistry::class,
'plugin_suppression' => PluginSuppression::class,
'reader_theme_loader' => ReaderThemeLoader::class,
'reader_theme_support_features' => ReaderThemeSupportFeatures::class,
'rest.options_controller' => OptionsRESTController::class,
'rest.validation_counts_controller' => Validation\ValidationCountsRestController::class,
'server_timing' => Instrumentation\ServerTiming::class,
Expand Down Expand Up @@ -193,6 +194,7 @@ protected function get_shared_instances() {
DevTools\CallbackReflection::class,
DevTools\FileReflection::class,
ReaderThemeLoader::class,
ReaderThemeSupportFeatures::class,
BackgroundTask\BackgroundTaskDeactivator::class,
PairedRouting::class,
Injector::class,
Expand Down
10 changes: 10 additions & 0 deletions src/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ interface Option {
*/
const READER_THEME = 'reader_theme';

/**
* Theme support features from the primary theme.
*
* When using a Reader theme, the theme support features from the primary theme are stored in this option so that
* they will be available when the Reader theme is active.
*
* @var string
*/
const PRIMARY_THEME_SUPPORT = 'primary_theme_support';

/**
* The key of the option storing whether the setup wizard has been completed.
*
Expand Down
18 changes: 15 additions & 3 deletions src/ReaderThemeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,34 @@ public function __construct( PairedRouting $paired_routing ) {
/**
* Is Reader mode with a Reader theme selected.
*
* @param array $options Options to check. If omitted, the currently-saved options are used.
* @return bool Whether new Reader mode.
*/
public function is_enabled() {
public function is_enabled( $options = null ) {
// If the theme was overridden then we know it is enabled. We can't check get_template() at this point because
// it will be identical to $reader_theme.
if ( $this->is_theme_overridden() ) {
return true;
}

if ( null === $options ) {
$options = AMP_Options_Manager::get_options();
}

// If Reader mode is not enabled, then a Reader theme is definitely not going to be served.
if ( AMP_Theme_Support::READER_MODE_SLUG !== AMP_Options_Manager::get_option( Option::THEME_SUPPORT ) ) {
if (
! isset( $options[ Option::THEME_SUPPORT ] )
||
AMP_Theme_Support::READER_MODE_SLUG !== $options[ Option::THEME_SUPPORT ]
) {
return false;
}

// If the Legacy Reader mode is active, then a Reader theme is not going to be served.
$reader_theme = AMP_Options_Manager::get_option( Option::READER_THEME );
if ( ! isset( $options[ Option::READER_THEME ] ) ) {
return false;
}
$reader_theme = $options[ Option::READER_THEME ];
if ( ReaderThemes::DEFAULT_READER_THEME === $reader_theme ) {
return false;
}
Expand Down
Loading