-
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
Fix header image filtering and YouTube header video detection #1208
Conversation
* Make sure that any get_header_image_tag filters from theme get applied. Fixes quality issue in Twenty Seventeen. * Fix detection of YouTube short URLs. * Dequeue wp-custom-header instead of deregistering to prevent Query Monitor complaining.
c01fabd
to
4445c18
Compare
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 PR looks good. It's nice how it accommodates URLs like https://youtu.be/v5zg_Yv048s.
Nice "before" and "after" images and markup. I also saw how this PR enables outputting the layout
attribute on the header image.
@@ -369,7 +369,10 @@ public static function add_hooks() { | |||
add_action( 'comment_form', array( __CLASS__, 'amend_comment_form' ), 100 ); | |||
remove_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); | |||
add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'whitelist_layout_in_wp_kses_allowed_html' ), 10 ); | |||
add_filter( 'get_header_image_tag', array( __CLASS__, 'conditionally_output_header' ), 10, 3 ); | |||
add_filter( 'get_header_image_tag', array( __CLASS__, 'amend_header_image_with_video_header' ), PHP_INT_MAX ); |
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 allows all other filters to run first.
@@ -1338,15 +1338,15 @@ public function test_whitelist_layout_in_wp_kses_allowed_html() { | |||
/** | |||
* Test AMP_Theme_Support::conditionally_output_header(). | |||
* | |||
* @see AMP_Theme_Support::conditionally_output_header() | |||
* @see AMP_Theme_Support::amend_header_image_with_video_header() | |||
*/ | |||
public function conditionally_output_header() { |
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 an error I made in a commit, but this method conditionally_output_header()
should have been test_conditionally_output_header()
.
But with the method renamed, this method should probably be test_amend_header_image_with_video_header()
.
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.
Thanks for noting that. Fixed in 97620b9.
$image_header = AMP_HTML_Utils::build_tag( 'amp-img', $atts ); | ||
$youtube_id = null; | ||
if ( isset( $parsed_url['host'] ) && preg_match( '/(^|\.)(youtube\.com|youtu\.be)$/', $parsed_url['host'] ) ) { | ||
if ( 'youtu.be' === $parsed_url['host'] && ! empty( $parsed_url['path'] ) ) { |
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 accounts for URLs like https://youtu.be/v5zg_Yv048s
Amends #1074. See #1078.
get_header_image_tag
filters from theme get applied. Fixes quality issue in Twenty Seventeen. Seetwentyseventeen_header_image_tag()
.wp-custom-header
instead of deregistering to prevent Query Monitor complaining about missing scripts.Before 🚫
Notice the low resolution image:
After ✅
Notice high resolution image: