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

Add theme support settings to admin screen; prevent serving dirty AMP #1199

Merged
merged 19 commits into from
Jun 8, 2018

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Jun 6, 2018

  • Add admin settings for picking between disabled, paired, and native theme support. See Add theme support mode selection in AMP general settings page #1196.
  • Prevent making AMP Gutenberg blocks available when AMP is not native.
  • Prevent serving dirty AMP by forcibly sanitizing all validation errors when amp_is_canonical(). See Avoid serving dirty AMP until it is supported by the runtime #1192.
  • Add checkbox for automatically allowing tree shaking. This is not shown when native/canonical because dirty AMP is not allowed.
  • Add checkbox for automatically sanitizing all validation errors (including tree shaking).
  • Make explicitly clear that unaccepted validation errors will block rendering on AMP
  • When validation errors are automatically sanitized, ensure the terms' term_group is updated when re-checking.
  • Update AMP_Options_Manager::get_options() and to return default values.
  • Prevent showing amphtml link in paired mode when it is known that the URL has blocking validation errors.
  • Add link to General settings admin screen in plugin links.
  • Improve UI for distinguishing between validation errors which are rejected but which are also forced to be sanitized (such as in native AMP mode). These are shown as flagged.
  • Fix: Remove menu-toggle in Twenty Fifteen if there is nothing to open.
  • Add an AMP status item to the admin bar to give easy access to the Invalid URL post for any given URL, with an indicator for whether AMP is available, or else to initiate a validation check if no such post exists.

Fixes #1196.
Fixes #1192.

image

image

image

image

… handling

* Add admin settings for picking between disabled, paired, and native theme support. See #1196.
* Add checkbox for automatically allowing tree shaking.
* Add checkbox for automatically sanitizing all validation errors (including tree shaking).
* Make explicitly clear that unaccepted validation errors will block rendering on AMP
* Prevent serving dirty AMP by forcibly sanitizing all validation errors when amp_is_canonical(). See #1192.
* When validation errors are automatically sanitized, ensure the terms' term_group is updated when re-checking.
* Update AMP_Options_Manager::get_options() and to return default values.
@westonruter westonruter added this to the v1.0 milestone Jun 6, 2018
@kienstra kienstra self-assigned this Jun 6, 2018
Copy link
Contributor

@kienstra kienstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Hi @westonruter,
This looks really good, especially the new 'AMP Settings' page. There are a few small points, but no blocker.

if ( 'paired' === $theme_support_option ) {
$args['template_dir'] = './';
}
add_theme_support( 'amp', $args );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice how this can force theme support.

</label>
</dt>
<dd>
<?php esc_html_e( 'Display AMP responses in classic (legacy) post templates in a basic design that does not match your theme\'s templates.', 'amp' ); ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good description of legacy templating.

<p>
<label for="force_sanitization">
<input id="force_sanitization" type="checkbox" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[force_sanitization]' ); ?>" <?php checked( AMP_Options_Manager::get_option( 'force_sanitization' ) ); ?>>
<?php esc_html_e( 'Automatically accept sanitization for any AMP validation error that is encountered.', 'amp' ); ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great how this conditionally displays on selecting "Paired":
conditional-display

<dt>
<input type="radio" id="theme_support_disabled" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[theme_support]' ); ?>" value="disabled" <?php checked( $theme_support, 'disabled' ); ?> <?php disabled( ! $theme_support_mutable ); ?>>
<label for="theme_support_disabled">
<strong><?php esc_html_e( 'Disabled', 'amp' ); ?></strong>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If somebody looked at this really quickly, it might look like AMP is disabled, not just theme support:
classic-templates

Maybe "Disabled" could be "Classic Templates (Disabled)."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great point. Agreed.

And “Paired” doesn't really make sense to users at first look either, nor does “Native”.

Maybe:

  • Classic Templates (Legacy)
  • Active Theme's Templates with Separate URLs (Paired)
  • Active Theme's Templates without Separate URLs (Canonical/Native)

I don't feel great about these these latter two.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed Disabled to Classic in 5bae33e. Needs more iteration.

Copy link
Collaborator

@ThierryA ThierryA Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To look at it from a different angle, perhaps we should consider using an other term than "Theme Support". I understand the reasoning behind it as it is technically defined using add_theme_support() but what this feature really does is controlling the AMP Mode. So perhaps the setting itself should be called "AMP Mode" and then have:

  • Legacy
  • Paired
  • Native

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes perfect sense. 👍

Maybe “Template Mode” would be better since it's clearly related to AMP already.

@@ -43,8 +43,16 @@ public function init() {
if ( function_exists( 'gutenberg_init' ) ) {
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
add_filter( 'wp_kses_allowed_html', array( $this, 'whitelist_block_atts_in_wp_kses_allowed_html' ), 10, 2 );
add_filter( 'the_content', array( $this, 'tally_content_requiring_amp_scripts' ) );
add_action( 'wp_print_footer_scripts', array( $this, 'print_dirty_amp_scripts' ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think the methods tally_content_requiring_amp_scripts() and print_dirty_amp_scripts() could be removed, given that they're not used anymore? Maybe the comment below could link to them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right. It's easy enough to look back in history to find the removal of these methods to resurrect them. 👍

Done in 5bae33e.

@westonruter
Copy link
Member Author

In a5756d9 added Settings link to plugins list table:

image

Copy link
Member

@amedina amedina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are of paramount importance for success on the adoption of the plugin. Great work.

@westonruter
Copy link
Member Author

BTW, the PR regarding URL handling (#1203) is a dependency for the PR regarding the new validation error screen because it ensures that the amp_invalid_url post for a given URL will always be stored with the canonical URL which will then allow for us to reliably add an “AMP Status” item to the admin bar. This is important because if there are unaccepted validation errors on a paired URL then they will get redirected to the non-AMP version and this admin bar item can indicate why. Likewise, we need to omit the amphtml link from the canonical page if there are unaccepted validation errors on the page.

… (and why)

* Indicate the count of validation errors that are blocking AMP from being available.
* Allow passing URL string in addition to amp_invalid_url post to AMP_Invalid_URL_Post_Type::get_invalid_url_validation_errors().
@kienstra kienstra removed their assignment Jun 8, 2018
…ut which are still forcibly sanitized

* Fix PHP 5.3 error
* Remove automatically setting amp_validation_error term_group based on forced status.
* Let preview URL include development=1 flag.
@westonruter westonruter force-pushed the add/admin-theme-support-options branch from 4f44e7c to d890b6c Compare June 8, 2018 07:16
@postphotos
Copy link
Contributor

This is great stuff, @westonruter! 🎂 🎉 I really like the thought you've put into this.

* Update post editor warnings to reflect when validation errors are forcibly sanitized but
not explicitly accepted.
* Allow tree shaking setting to be shown when in native mode.
* Show notice when selecting native mode that sanitization is required.
* Hide the preview button from the amp_invalid_url post if sanitization is required.
…te link

Discontinue automatically-deleting an amp_invalid_url post when all errors are resolved.
@westonruter westonruter changed the title [WIP] Add theme support settings to admin screen; prevent serving dirty AMP Add theme support settings to admin screen; prevent serving dirty AMP Jun 8, 2018
@westonruter
Copy link
Member Author

Now there is an admin bar menu item to link to the AMP version of the page (when available):

image

As well as the AMP validation status (when it is known):

image

If you click on the AMP link and there are validation errors, you'll get redirected back to the canonical URL with the admin bar updated to indicate this:

image

Clicking on the validate link takes you to the Invalid AMP URL edit post screen which lists out all of the errors so you can take action. This validate admin menu item is present even if there are no known validation errors:

image

@westonruter westonruter merged commit 634fbb8 into develop Jun 8, 2018
@westonruter westonruter added this to Ready for review in v1.0 Jun 25, 2018
@westonruter westonruter moved this from Ready for review to Ready for QA in v1.0 Jun 25, 2018
@westonruter westonruter deleted the add/admin-theme-support-options branch July 5, 2018 15:35
@kienstra
Copy link
Contributor

kienstra commented Aug 3, 2018

Moving To "Ready For Merging"

At some point, it'd be appropriate to test this. But as work on the Template Modes is ongoing, I'd propose that we don't need to test this now.

But if you have other ideas, feel free to move this back to "Ready For QA."

@kienstra kienstra moved this from Ready for QA to Ready for Merging in v1.0 Aug 3, 2018
@kienstra kienstra moved this from Ready for Merging to In Production in v1.0 Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v1.0
In Production
Development

Successfully merging this pull request may close these issues.

None yet

5 participants