-
Notifications
You must be signed in to change notification settings - Fork 385
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 sanitizer to fixup issues with core themes #1074
Conversation
'twentyseventeen' => array( | ||
'force_svg_support' => array(), | ||
'force_fixed_background_support' => array(), | ||
// @todo Header video probably needs special support in the plugin generally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1078
'force_svg_support' => array(), | ||
'force_fixed_background_support' => array(), | ||
// @todo Header video probably needs special support in the plugin generally. | ||
// @todo Header image is not styled properly. Needs layout=responsive and other things? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1094 (comment)
This PR adds |
Related #1094. |
We still would like testing (configure AMP in Customizer) and document what's clearly a problem. |
includes/class-amp-theme-support.php
Outdated
$atts['layout'] = 'fill'; | ||
unset( $atts['width'] ); | ||
|
||
$place_holder = AMP_HTML_Utils::build_tag( 'img', $atts ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
img
or amp-img
? I think this should be creating an amp-img
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry, it was, I removed it for testing something, but forgot to revert 601c005
@DavidCramer in regards to the header image then, it's going to need to be part of the sanitizer here to add a rule with selector such as |
@westonruter yes, I expected as much. however, not all headers for all core themes work that way, so I have made it part of the twentyseventeen core sanitiser here dc9e628#diff-5d05e505f93786061c2078486784c46dR97 |
@westonruter Feel free to review the header video and image for this, I think it works well now. |
Implement support for mobile nav menus.
… actions * Dequeue core themes' scripts for navigation, skip-link-focus-fix, keyboard-image-navigation. * Remove actions that output unneeded scripts. * Dequeue comments-reply unconditionally.
Also move the get_theme_config method to be closer to logically-related $theme_features class var
…her validation error is accepted
I believe we've done all that can be done here. I'm really happy with the result. Let's get this to testing. |
Thanks, Reviewing Now Hi @westonruter, |
There was a problem hiding this 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. There are some comments below about approach, but I think it's ready to merge if you're happy with them.
includes/class-amp-theme-support.php
Outdated
}; | ||
|
||
if ( ! has_header_video() ) { | ||
return self::output_header_image( $atts ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of these helper functions to simplify conditionally_output_header()
includes/class-amp-theme-support.php
Outdated
* | ||
* This is JS-driven in Core themes like Twenty Sixteen and Twenty Seventeen. | ||
* So in order for the header video to display, | ||
* this replaces the markup of the header image. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a blocker, but maybe this 3-line DocBlock description could be removed. It looks to be the same as in conditionally_output_header()
.
includes/class-amp-theme-support.php
Outdated
* | ||
* This is JS-driven in Core themes like Twenty Sixteen and Twenty Seventeen. | ||
* So in order for the header video to display, | ||
* this replaces the markup of the header image. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the suggestion above, maybe these 3 lines could be removed.
includes/class-amp-theme-support.php
Outdated
* @return string $html Filtered markup. | ||
*/ | ||
public static function output_header_image( $atts ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a blocker, but this might be cleaner as:
public static function output_header_image( $atts ) {
return AMP_HTML_Utils::build_tag( 'amp-img', $atts );
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm going to just remove the method entirely. There's no need for it.
'twentyseventeen-global', // There are somethings not yet implemented in AMP. See todos below. | ||
'jquery-scrollto', // Implemented via add_smooth_scrolling(). | ||
'twentyseventeen-navigation', // Handled by add_nav_menu_styles, add_nav_menu_toggle, add_nav_sub_menu_buttons. | ||
'twentyseventeen-skip-link-focus-fix', // Only needed by IE11 and when admin bar is present. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great how these comments describe the scripts.
@@ -0,0 +1,943 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great to eventually go back and add tests for this class, and other new methods.
*/ | ||
protected static $theme_features = array( | ||
// Twenty Seventeen. | ||
'twentyseventeen' => array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great idea to pass an array of arguments to each of the methods, depending on the theme.
* @link https://github.com/WordPress/wordpress-develop/blob/f4580c122b7d0d2d66d22f806c6fe6e11023c6f0/src/wp-content/themes/twentyseventeen/assets/js/global.js#L105-L108 | ||
*/ | ||
public static function set_twentyseventeen_quotes_icon() { | ||
add_filter( 'the_content', function ( $content ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't relevant now, but maybe a method would be better than an anonymous function here, to enable unit testing.
* and the CSS parser will then convert the selectors to amp-img and amp-video respectively. | ||
* Nevertheless, object-fit does not apply on amp-img and it needs to apply on an actual img. | ||
*/ | ||
add_action( 'wp_enqueue_scripts', function() use ( $args ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the comment above, how about passing a method, instead of an anonymous function? This might help with unit testing, but this isn't a blocker now.
</style> | ||
<?php | ||
$styles = str_replace( array( '<style>', '</style>' ), '', ob_get_clean() ); | ||
wp_add_inline_style( get_template() . '-style', $styles ); |
There was a problem hiding this comment.
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 passes the contents of the buffer to wp_add_inline_style()
/* Attempt to emulate https://github.com/WordPress/wordpress-develop/blob/5e9a39baa7d4368f7d3c36dcbcd53db6317677c9/src/wp-content/themes/twentyfifteen/js/functions.js#L108-L149 */ | ||
#sidebar { | ||
position: sticky; | ||
top: -9vh; | ||
max-height: 109vh; | ||
overflow-y: auto; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per @schlessera in #4744, this can be improved to better emulate the non-AMP version.
accept_validation_errors
to do partial checks.Twenty Seventeen+Sixteen: Try to implement belowEntryMetaClass().Try to figure out a way to implement onResizeARIA() (may be impossible due to lack of trusted actions in AMP).Initial Themes to Check
Previous core themes would be good to test as well, but they could be looked at in a separate PR.
👉 Commits pushed up to this PR (in the
core-themes
branch) will be automatically deployed to https://core-themes-ampconfdemo.pantheonsite.io/AMP can be disabled on this environment for a given URL to see what it looks like normally by adding a
?amp_disabled
query param, for example: https://core-themes-ampconfdemo.pantheonsite.io/?amp_disabledFixes #1060
Fixes #1036
Fixes #1078