From ca7f529219f6e47e58957a1a350ccac3acbbd974 Mon Sep 17 00:00:00 2001 From: Derrick Tennant Date: Thu, 8 Nov 2018 12:35:20 -0500 Subject: [PATCH 01/40] Performance fixes This adds a few tweaks to amp_admin_get_preview_permalink: * Allows query caching for plugins like Advanced Post Cache to cache the query * Removes pagination support to remove `SQL_CALC_FOUND_ROWS` from the query. --- includes/admin/functions.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/includes/admin/functions.php b/includes/admin/functions.php index eebef8554f2..5c9ed82939e 100644 --- a/includes/admin/functions.php +++ b/includes/admin/functions.php @@ -68,11 +68,13 @@ function amp_admin_get_preview_permalink() { } $post_ids = get_posts( array( - 'post_status' => 'publish', - 'post_password' => '', - 'post_type' => $supported_post_types, - 'posts_per_page' => 1, - 'fields' => 'ids', + 'no_found_rows' => true, + 'suppress_filters' => false, + 'post_status' => 'publish', + 'post_password' => '', + 'post_type' => $supported_post_types, + 'posts_per_page' => 1, + 'fields' => 'ids', // @todo This should eventually do a meta_query to make sure there are none that have AMP_Post_Meta_Box::STATUS_POST_META_KEY = DISABLED_STATUS. ) ); From 62ca70c85ba56948b40fd63a55e7d38d15a68cc2 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 12 Nov 2018 06:21:04 -0600 Subject: [PATCH 02/40] Begin to address issue where a @font-face can be removed Sometimes this appears in $parsed_selector['tags'], and the logic look for the presence of the tag on the page. This would apply well if it were an HTML tag like div, but @font-face wouldn't appear as an element in an HTML document. So add a conditional to check if the tag is in the 'allowed_at_rules'. Still, this might not be the best solution. Also, it looks like @font-face should appear at the top of the stylesheet. --- includes/sanitizers/class-amp-style-sanitizer.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 81df4c0a899..56665035518 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -2063,6 +2063,8 @@ private function finalize_stylesheet_set( $stylesheet_set ) { empty( $parsed_selector['tags'] ) || 0 === count( array_diff( $parsed_selector['tags'], $this->get_used_tag_names() ) ) + || + 0 === count( array_diff( $parsed_selector['tags'], $stylesheet_set['cdata_spec']['css_spec']['allowed_at_rules'] ) ) ) ) ); From 4fb548aa8883a9fd80c7849fb74e51cf5edb8366 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 15 Nov 2018 22:26:25 -0800 Subject: [PATCH 03/40] Fix object-fit:cover style of Twenty Nineteen featured image --- .../class-amp-core-theme-sanitizer.php | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/includes/sanitizers/class-amp-core-theme-sanitizer.php b/includes/sanitizers/class-amp-core-theme-sanitizer.php index 1221d04e637..524e54009fc 100644 --- a/includes/sanitizers/class-amp-core-theme-sanitizer.php +++ b/includes/sanitizers/class-amp-core-theme-sanitizer.php @@ -53,16 +53,17 @@ class AMP_Core_Theme_Sanitizer extends AMP_Base_Sanitizer { protected static $theme_features = array( // Twenty Nineteen. 'twentynineteen' => array( - 'dequeue_scripts' => array( + 'dequeue_scripts' => array( 'twentynineteen-skip-link-focus-fix', // This is part of AMP. See . 'twentynineteen-priority-menu', 'twentynineteen-touch-navigation', // @todo There could be an AMP implementation of this, similar to what is implemented on ampproject.org. ), - 'remove_actions' => array( + 'remove_actions' => array( 'wp_print_footer_scripts' => array( 'twentynineteen_skip_link_focus_fix', // See . ), ), + 'add_twentynineteen_masthead_styles' => array(), ), // Twenty Seventeen. @@ -526,6 +527,51 @@ protected static function get_twentyseventeen_navigation_outer_height() { return 72; } + /** + * Add required styles for featured image header in Twenty Nineteen. + * + * The following is necessary because the styles in the theme apply to the featured img, + * and the CSS parser will then convert the selectors to amp-img. Nevertheless, object-fit + * does not apply on amp-img and it needs to apply on an actual img. + * + * @link https://github.com/WordPress/wordpress-develop/blob/5.0/src/wp-content/themes/twentynineteen/style.css#L2276-L2299 + * @since 1.0 + */ + public static function add_twentynineteen_masthead_styles() { + add_action( 'wp_enqueue_scripts', function() { + ?> + + ', '' ), '', ob_get_clean() ); + wp_add_inline_style( get_template() . '-style', $styles ); + }, 11 ); + } + /** * Add required styles for video and image headers. * From 322be16bd78d4c36261d2df83cf4902c4d96995c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 15 Nov 2018 22:29:39 -0800 Subject: [PATCH 04/40] Fix remaining gutenberg_get_jed_locale_data() usage missed in c5b505ad9 --- tests/validation/test-class-amp-validation-manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/validation/test-class-amp-validation-manager.php b/tests/validation/test-class-amp-validation-manager.php index 671e6fa13f5..4164400aafd 100644 --- a/tests/validation/test-class-amp-validation-manager.php +++ b/tests/validation/test-class-amp-validation-manager.php @@ -1282,7 +1282,7 @@ public function test_print_plugin_notice() { * @covers AMP_Validation_Manager::enqueue_block_validation() */ public function test_enqueue_block_validation() { - if ( ! function_exists( 'gutenberg_get_jed_locale_data' ) ) { + if ( ! function_exists( 'wp_get_jed_locale_data' ) && ! function_exists( 'gutenberg_get_jed_locale_data' ) ) { $this->markTestSkipped( 'Gutenberg not available.' ); } From 9d9527287da594acd89dffbf511852dba898de8b Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 16 Nov 2018 07:56:28 -0800 Subject: [PATCH 05/40] Add missing ob_start() call --- includes/sanitizers/class-amp-core-theme-sanitizer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/sanitizers/class-amp-core-theme-sanitizer.php b/includes/sanitizers/class-amp-core-theme-sanitizer.php index 524e54009fc..a7010a27f3a 100644 --- a/includes/sanitizers/class-amp-core-theme-sanitizer.php +++ b/includes/sanitizers/class-amp-core-theme-sanitizer.php @@ -539,6 +539,7 @@ protected static function get_twentyseventeen_navigation_outer_height() { */ public static function add_twentynineteen_masthead_styles() { add_action( 'wp_enqueue_scripts', function() { + ob_start(); ?> + ', '' ), '', ob_get_clean() ); + wp_add_inline_style( get_template() . '-style', $styles ); + }, 11 ); + } } From d7de7d17bd769d55e5adf95e0b6b2723c0d4932b Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 19 Nov 2018 21:30:00 -0600 Subject: [PATCH 09/40] Remove the sizes attribute from thumbnail images in Twenty Nineteen The AMP runtime sets an inline style on an based on the sizes attribute if it's present. For example, . Removing the 'sizes' attribute isn't ideal, but it looks like it's not possible to override that inline style. This is only a workaround until the issue is addressed in the amphtml repo. --- .../class-amp-core-theme-sanitizer.php | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/includes/sanitizers/class-amp-core-theme-sanitizer.php b/includes/sanitizers/class-amp-core-theme-sanitizer.php index 6126c907427..2e22faf4882 100644 --- a/includes/sanitizers/class-amp-core-theme-sanitizer.php +++ b/includes/sanitizers/class-amp-core-theme-sanitizer.php @@ -53,18 +53,20 @@ class AMP_Core_Theme_Sanitizer extends AMP_Base_Sanitizer { protected static $theme_features = array( // Twenty Nineteen. 'twentynineteen' => array( - 'dequeue_scripts' => array( + 'dequeue_scripts' => array( 'twentynineteen-skip-link-focus-fix', // This is part of AMP. See . 'twentynineteen-priority-menu', 'twentynineteen-touch-navigation', // @todo There could be an AMP implementation of this, similar to what is implemented on ampproject.org. ), - 'remove_actions' => array( + 'remove_actions' => array( 'wp_print_footer_scripts' => array( 'twentynineteen_skip_link_focus_fix', // See . ), ), - 'add_twentynineteen_masthead_styles' => array(), - 'add_twentynineteen_image_styles' => array(), + 'add_twentynineteen_masthead_styles' => array(), + 'add_twentynineteen_image_styles' => array(), + 'remove_twentynineteen_thumbnail_image_sizes' => array(), + ), // Twenty Seventeen. @@ -342,6 +344,26 @@ public static function set_twentyseventeen_quotes_icon() { } ); } + /** + * Remove the sizes attribute from thumbnail images in Twenty Nineteen. + * + * The AMP runtime sets an inline style on an based on the sizes attribute if it's present. + * For example, . + * Removing the 'sizes' attribute isn't ideal, but it looks like it's not possible to override that inline style. + * + * @todo: remove when this is resolved: https://github.com/ampproject/amphtml/issues/17053 + * @since 1.0 + */ + public static function remove_twentynineteen_thumbnail_image_sizes() { + add_filter( 'wp_get_attachment_image_attributes', function( $attr ) { + if ( isset( $attr['class'] ) && false !== strpos( $attr['class'], 'attachment-post-thumbnail' ) ) { + unset( $attr['sizes'] ); + } + + return $attr; + }, 11 ); + } + /** * Add filter to adjust the attachment image attributes to ensure attachment pages have a consistent rendering. * From 1afa46b39520b0281b8a9910c6e3d796e7fb893a Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 19 Nov 2018 22:41:34 -0600 Subject: [PATCH 10/40] Fall back to the normal gallery shortcode markup for 'thumbnail' size. If the 'gallery' shortcode has a 'size' attribute of 'thumbnail', prevent outputting an . That will often get thumbnail images around 150 x 150, while the usually has a width of 600 and a height of 480. That often means very low-resolution images. So fall back to the normal 'gallery' shortcode callback, gallery_shortcode(). --- includes/embeds/class-amp-gallery-embed.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/embeds/class-amp-gallery-embed.php b/includes/embeds/class-amp-gallery-embed.php index a2c94ff3b7d..d2a2964d901 100644 --- a/includes/embeds/class-amp-gallery-embed.php +++ b/includes/embeds/class-amp-gallery-embed.php @@ -160,6 +160,15 @@ public function maybe_override_gallery( $html, $attributes ) { } return $html; + } elseif ( isset( $attributes['size'] ) && 'thumbnail' === $attributes['size'] ) { + /* + * If the 'gallery' shortcode has a 'size' attribute of 'thumbnail', prevent outputting an . + * That will often get thumbnail images around 150 x 150, + * while the usually has a width of 600 and a height of 480. + * That often means very low-resolution images. + * So fall back to the normal 'gallery' shortcode callback, gallery_shortcode(). + */ + return ''; } return $this->shortcode( $attributes ); } From c9e0f03b34b423df011e108d5d8c390bcc2630ea Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 20 Nov 2018 00:44:13 -0600 Subject: [PATCH 11/40] Prevent horizontall-compressed images in Gallery block There's a style rule that prevents these from compressing. img { object-fit: cover; } This selector seems to be changed to amp-img in style sanitization, but it doesn't have the same effect as when applied to img So copy the style rule verbatim into a stylesheet. This is in AMP_Gallery_Embed_Handler, as it's too late to enqueue_style, 'wp_print_styles' has already run by the time that sanitizer runs. --- assets/css/amp-gallery-block.css | 9 +++++++++ includes/embeds/class-amp-gallery-embed.php | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 assets/css/amp-gallery-block.css diff --git a/assets/css/amp-gallery-block.css b/assets/css/amp-gallery-block.css new file mode 100644 index 00000000000..2dadf8dc1a4 --- /dev/null +++ b/assets/css/amp-gallery-block.css @@ -0,0 +1,9 @@ +/** + * For the AMP implementation of the Gallery block. + * This rule is copied exactly from block-library/style.css, but the selector here has amp-img >. + * The image sanitizer normally converts the from that original stylesheet , + * but that doesn't have the same effect as applying it to the . + */ +.wp-block-gallery.is-cropped .blocks-gallery-item amp-img > img { + object-fit: cover; +} diff --git a/includes/embeds/class-amp-gallery-embed.php b/includes/embeds/class-amp-gallery-embed.php index d2a2964d901..1f7682101ae 100644 --- a/includes/embeds/class-amp-gallery-embed.php +++ b/includes/embeds/class-amp-gallery-embed.php @@ -17,6 +17,7 @@ class AMP_Gallery_Embed_Handler extends AMP_Base_Embed_Handler { */ public function register_embed() { add_filter( 'post_gallery', array( $this, 'maybe_override_gallery' ), 10, 2 ); + add_filter( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); } /** @@ -233,4 +234,21 @@ public function render( $args ) { implode( PHP_EOL, $images ) ); } + + /** + * Enqueues the Gallery block styling. + * + * It would be better to enqueue this in AMP_Gallery_Block_Sanitizer, + * but by the time that runs, it's too late to call wp_enqueue_style(). + * + * @return void + */ + public function enqueue_styles() { + wp_enqueue_style( + 'amp-gallery-block', + amp_get_asset_url( 'css/amp-gallery-block.css' ), + array(), + AMP__VERSION + ); + } } From 35c738640c24d7eecbee13b212d6eb7a1ef2ba25 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 20 Nov 2018 05:50:36 -0600 Subject: [PATCH 12/40] Remove the Byte Order Mark, as it can prevent styles from applying In the Essence Pro theme, the ionicons CSS file has a "\ufeff" character. For some reason, this blocks the style rule from applying on the AMP endpoint, though it doesn't affect the non-AMP endpoint. --- includes/sanitizers/class-amp-style-sanitizer.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 56665035518..64691863623 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -1838,6 +1838,9 @@ private function finalize_styles() { $css .= implode( '', $stylesheet_sets['custom']['final_stylesheets'] ); $css .= $stylesheet_sets['custom']['source_map_comment']; + // Remove the Byte Order Mark if it exists, as it can prevent styles from rendering. + $css = preg_replace('/\x{FEFF}/u', '', $css ); + /* * Let the style[amp-custom] be populated with the concatenated CSS. * !important: Updating the contents of this style element by setting textContent is not From dd212e554fea6f2ab3fd357e53838c36c104ace1 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 20 Nov 2018 06:16:43 -0600 Subject: [PATCH 13/40] Update changelog with PRs merged since 1.0-RC2 See the PRs: https://github.com/Automattic/amp-wp/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aclosed+merged%3A2018-11-05T03%3A17%3A43..2018-11-21T03%3A17%3A43Z+milestone%3Av1.0+ --- readme.md | 9 +++++++++ readme.txt | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/readme.md b/readme.md index a4df05d524d..4051e09581c 100644 --- a/readme.md +++ b/readme.md @@ -75,6 +75,7 @@ To learn how to use the new features in this release, please see the wiki pages - **Add support for allowing a site subset to be native AMP.** See [#1235](https://github.com/Automattic/amp-wp/pull/1235). Props westonruter. - Add an admin pointer for updated AMP settings screen for version 1.0. See [#1271](https://github.com/Automattic/amp-wp/pull/1271), [#1254](https://github.com/Automattic/amp-wp/issues/1254). Props kienstra. - Add support for three core themes (Twenty Fifteen, Twenty Sixteen, Twenty Seventeen) so that they can be used out of the box with AMP theme support added without needing to create a child theme. See [#1074](https://github.com/Automattic/amp-wp/pull/1074). Props westonruter, DavidCramer, kienstra. +- Add AMP support for Twenty Nineteen. See [#1587](https://github.com/Automattic/amp-wp/pull/1587), [#1619](https://github.com/Automattic/amp-wp/pull/1619). Props westonruter. - Add AMP menu item to admin bar on frontend with indication of AMP validation status; accessing an AMP URL that has unaccepted validation errors will redirect to the non-AMP page and cause the AMP admin bar item to indicate the failure, along with a link to access the validation results. See [#1199](https://github.com/Automattic/amp-wp/pull/1199). Props westonruter. - Add dynamic handling of validation errors. See [#1093](https://github.com/Automattic/amp-wp/pull/1093), [#1063](https://github.com/Automattic/amp-wp/pull/1063), [#1087](https://github.com/Automattic/amp-wp/issues/1087). Props westonruter. - Add AMP validation of blocks. See [#1019](https://github.com/Automattic/amp-wp/pull/1019). Props westonruter. @@ -147,18 +148,24 @@ To learn how to use the new features in this release, please see the wiki pages - Improve validation and presentation of analytics form. See [#1299](https://github.com/Automattic/amp-wp/pull/1299), [#1133](https://github.com/Automattic/amp-wp/issues/1133), [#1296](https://github.com/Automattic/amp-wp/pull/1296). Props westonruter, AdelDima. - Prevent validation of auto-drafts, including when merely accessing New Post screen. See [#1301](https://github.com/Automattic/amp-wp/pull/1301). Props westonruter. - Fix inability to move link element due to assigned parent. See [#1322](https://github.com/Automattic/amp-wp/issues/1322). Props westonruter. +- Gutenberg: Remove 'type' from attributes where 'source' is set. See [#1622](https://github.com/Automattic/amp-wp/pull/1622). Props miina. +- Gutenberg: Fix displaying validation warning and usage of PHP function. See [#1612](https://github.com/Automattic/amp-wp/pull/1612). Props miina. - Fix stretched images in Twenty Seventeen them and Gutenberg. See [#1321](https://github.com/Automattic/amp-wp/issues/1321), [#1281](https://github.com/Automattic/amp-wp/issues/1281), [#1237](https://github.com/Automattic/amp-wp/issues/1237). Props hellofromtonya. - Fix image dimension extractor so it does not disregard duplicate images. See [#1314](https://github.com/Automattic/amp-wp/issues/1314). Props lukas9393. +- Short-circuit polldaddy shortcode when no poll or survey supplied. See [#1621](#https://github.com/Automattic/amp-wp/pull/1621). Props westonruter. - Remove redundant version from composer.json and add PHP version requirement. See [#1333](https://github.com/Automattic/amp-wp/issues/1333), [#1328](https://github.com/Automattic/amp-wp/issues/1328), [#1334](https://github.com/Automattic/amp-wp/issues/1334), [#1332](https://github.com/Automattic/amp-wp/issues/1332). Props swissspidy. +- Add warning when AMP plugin is installed in incorrect directory. See [#1593](https://github.com/Automattic/amp-wp/pull/1593). Props westonruter. - Store validation errors in order of occurrence in document. See [#1335](https://github.com/Automattic/amp-wp/issues/1335). Props westonruter. - Add .editorconfig file. See [#1336](https://github.com/Automattic/amp-wp/issues/1336), [#51](https://github.com/Automattic/amp-wp/issues/51). Props swissspidy. - Update i18n to make use of updated WP-CLI command. See [#1329](https://github.com/Automattic/amp-wp/issues/1329), [#1327](https://github.com/Automattic/amp-wp/issues/1327), [#1341](https://github.com/Automattic/amp-wp/issues/1341), [#1345](https://github.com/Automattic/amp-wp/issues/1345), [#1393](https://github.com/Automattic/amp-wp/issues/1393). Props swissspidy, felixarntz, westonruter. - Use all eligible post types when `all_templates_supported` is selected. See [#1338](https://github.com/Automattic/amp-wp/issues/1338), [#1302](https://github.com/Automattic/amp-wp/issues/1302), [#1344](https://github.com/Automattic/amp-wp/issues/1344). Props hellofromtonya, westonruter. +- Do not show fallback source as active theme if no validation errors. See [#1592](https://github.com/Automattic/amp-wp/pull/1592). Props westonruter. - Respect default AMP enabled status when creating a new post in Gutenberg. See [#1339](https://github.com/Automattic/amp-wp/issues/1339). Props hellofromtonya. - Fix incorrect attribution of theme as source for content validation errors. See [#1467](https://github.com/Automattic/amp-wp/pull/1467). Props westonruter. - Fix conversion of video to amp-video. See [#1477](https://github.com/Automattic/amp-wp/pull/1477). Props westonruter. - Add new icon, text, and style to splash notice. See [#1470](https://github.com/Automattic/amp-wp/pull/1470). Props jacobschweitzer. - Normalize 'ver' query param in script/style validation errors to prevent recurrence after accepted. See [#1346](https://github.com/Automattic/amp-wp/issues/1346). Props westonruter. +- Add bing-amp.com to the list of AMP Cache hosts. See [#1447](https://github.com/Automattic/amp-wp/pull/1447). Props westonruter. - Add missing tabindex attribute to lightbox images. See [#1350](https://github.com/Automattic/amp-wp/issues/1350). Props amedina. - Detect ineffectual post-processor response cache due to high MISS rates and auto-disable. See [#1325](https://github.com/Automattic/amp-wp/issues/1325), [#1239](https://github.com/Automattic/amp-wp/issues/1239). Props hellofromtonya, westonruter. - Update the validator spec version to 720 and AMP v1534879991178; add support for reference points. See [#1315](https://github.com/Automattic/amp-wp/issues/1315), [#1386](https://github.com/Automattic/amp-wp/issues/1386), [#1330](https://github.com/Automattic/amp-wp/issues/1330). Props westonruter. @@ -172,6 +179,7 @@ To learn how to use the new features in this release, please see the wiki pages - Fix handling responses to form submissions from an AMP Cache. See [#1382](https://github.com/Automattic/amp-wp/issues/1382), [#1356](https://github.com/Automattic/amp-wp/issues/1356). - Replace Gutenberg's deprecated isCleanNewPost selector. See [#1387](https://github.com/Automattic/amp-wp/issues/1387). Props miina. - Updates php-css-parser to include fix for parsing calc() with negative values. See [#1392](https://github.com/Automattic/amp-wp/issues/1392). Props westonruter. +- Update AMP spec to 757 (v1811091519050). See [#1588](https://github.com/Automattic/amp-wp/pull/1588). Props westonruter, kienstra. - Add embed support for Twitter timelines via new amp-twitter attributes. See [#1396](https://github.com/Automattic/amp-wp/issues/1396). Props felixarntz. - Fix tooltip position. See [#1472](https://github.com/Automattic/amp-wp/pull/1472). Props jacobschweitzer. - Add error type filters on validation error and invalid URL screens. See [#1373](https://github.com/Automattic/amp-wp/issues/1373). Props kienstra. @@ -186,6 +194,7 @@ To learn how to use the new features in this release, please see the wiki pages - Improve access to AMP admin screens for users who are not administrators. [#1437](https://github.com/Automattic/amp-wp/pull/1437). Props westonruter. - Display a welcome notice on the main 'AMP Settings' page. See [#1442](https://github.com/Automattic/amp-wp/pull/1442). Props kienstra. - Fix URL protocol validation and parsing attribute values with multiple URLs. See [#1411](https://github.com/Automattic/amp-wp/pull/1411), [#1410](https://github.com/Automattic/amp-wp/issues/1410). Props westonruter. +- Prevent a notice from appearing in the Compatibility Tool meta box. See [#1605](https://github.com/Automattic/amp-wp/pull/1605). Props kienstra. - Restore ability to customize 'amp' query var when theme support added. [#1455](https://github.com/Automattic/amp-wp/pull/1455). Props westonruter. - Add slug constants for theme support and post type support. [#1456](https://github.com/Automattic/amp-wp/pull/1456). Props westonruter. - Fix ability to add AMP support for custom post types. See [#1441](https://github.com/Automattic/amp-wp/pull/1441). Props westonruter. diff --git a/readme.txt b/readme.txt index df6a51b3e38..d6657df1ecd 100644 --- a/readme.txt +++ b/readme.txt @@ -59,6 +59,7 @@ To learn how to use the new features in this release, please see the wiki pages - **Add support for allowing a site subset to be native AMP.** See [#1235](https://github.com/Automattic/amp-wp/pull/1235). Props westonruter. - Add an admin pointer for updated AMP settings screen for version 1.0. See [#1271](https://github.com/Automattic/amp-wp/pull/1271), [#1254](https://github.com/Automattic/amp-wp/issues/1254). Props kienstra. - Add support for three core themes (Twenty Fifteen, Twenty Sixteen, Twenty Seventeen) so that they can be used out of the box with AMP theme support added without needing to create a child theme. See [#1074](https://github.com/Automattic/amp-wp/pull/1074). Props westonruter, DavidCramer, kienstra. +- Add AMP support for Twenty Nineteen. See [#1587](https://github.com/Automattic/amp-wp/pull/1587), [#1619](https://github.com/Automattic/amp-wp/pull/1619). Props westonruter. - Add AMP menu item to admin bar on frontend with indication of AMP validation status; accessing an AMP URL that has unaccepted validation errors will redirect to the non-AMP page and cause the AMP admin bar item to indicate the failure, along with a link to access the validation results. See [#1199](https://github.com/Automattic/amp-wp/pull/1199). Props westonruter. - Add dynamic handling of validation errors. See [#1093](https://github.com/Automattic/amp-wp/pull/1093), [#1063](https://github.com/Automattic/amp-wp/pull/1063), [#1087](https://github.com/Automattic/amp-wp/issues/1087). Props westonruter. - Add AMP validation of blocks. See [#1019](https://github.com/Automattic/amp-wp/pull/1019). Props westonruter. @@ -131,18 +132,24 @@ To learn how to use the new features in this release, please see the wiki pages - Improve validation and presentation of analytics form. See [#1299](https://github.com/Automattic/amp-wp/pull/1299), [#1133](https://github.com/Automattic/amp-wp/issues/1133), [#1296](https://github.com/Automattic/amp-wp/pull/1296). Props westonruter, AdelDima. - Prevent validation of auto-drafts, including when merely accessing New Post screen. See [#1301](https://github.com/Automattic/amp-wp/pull/1301). Props westonruter. - Fix inability to move link element due to assigned parent. See [#1322](https://github.com/Automattic/amp-wp/issues/1322). Props westonruter. +- Gutenberg: Remove 'type' from attributes where 'source' is set. See [#1622](https://github.com/Automattic/amp-wp/pull/1622). Props miina. +- Gutenberg: Fix displaying validation warning and usage of PHP function. See [#1612](https://github.com/Automattic/amp-wp/pull/1612). Props miina. - Fix stretched images in Twenty Seventeen them and Gutenberg. See [#1321](https://github.com/Automattic/amp-wp/issues/1321), [#1281](https://github.com/Automattic/amp-wp/issues/1281), [#1237](https://github.com/Automattic/amp-wp/issues/1237). Props hellofromtonya. - Fix image dimension extractor so it does not disregard duplicate images. See [#1314](https://github.com/Automattic/amp-wp/issues/1314). Props lukas9393. +- Short-circuit polldaddy shortcode when no poll or survey supplied. See [#1621](#https://github.com/Automattic/amp-wp/pull/1621). Props westonruter. - Remove redundant version from composer.json and add PHP version requirement. See [#1333](https://github.com/Automattic/amp-wp/issues/1333), [#1328](https://github.com/Automattic/amp-wp/issues/1328), [#1334](https://github.com/Automattic/amp-wp/issues/1334), [#1332](https://github.com/Automattic/amp-wp/issues/1332). Props swissspidy. +- Add warning when AMP plugin is installed in incorrect directory. See [#1593](https://github.com/Automattic/amp-wp/pull/1593). Props westonruter. - Store validation errors in order of occurrence in document. See [#1335](https://github.com/Automattic/amp-wp/issues/1335). Props westonruter. - Add .editorconfig file. See [#1336](https://github.com/Automattic/amp-wp/issues/1336), [#51](https://github.com/Automattic/amp-wp/issues/51). Props swissspidy. - Update i18n to make use of updated WP-CLI command. See [#1329](https://github.com/Automattic/amp-wp/issues/1329), [#1327](https://github.com/Automattic/amp-wp/issues/1327), [#1341](https://github.com/Automattic/amp-wp/issues/1341), [#1345](https://github.com/Automattic/amp-wp/issues/1345), [#1393](https://github.com/Automattic/amp-wp/issues/1393). Props swissspidy, felixarntz, westonruter. - Use all eligible post types when `all_templates_supported` is selected. See [#1338](https://github.com/Automattic/amp-wp/issues/1338), [#1302](https://github.com/Automattic/amp-wp/issues/1302), [#1344](https://github.com/Automattic/amp-wp/issues/1344). Props hellofromtonya, westonruter. +- Do not show fallback source as active theme if no validation errors. See [#1592](https://github.com/Automattic/amp-wp/pull/1592). Props westonruter. - Respect default AMP enabled status when creating a new post in Gutenberg. See [#1339](https://github.com/Automattic/amp-wp/issues/1339). Props hellofromtonya. - Fix incorrect attribution of theme as source for content validation errors. See [#1467](https://github.com/Automattic/amp-wp/pull/1467). Props westonruter. - Fix conversion of video to amp-video. See [#1477](https://github.com/Automattic/amp-wp/pull/1477). Props westonruter. - Add new icon, text, and style to splash notice. See [#1470](https://github.com/Automattic/amp-wp/pull/1470). Props jacobschweitzer. - Normalize 'ver' query param in script/style validation errors to prevent recurrence after accepted. See [#1346](https://github.com/Automattic/amp-wp/issues/1346). Props westonruter. +- Add bing-amp.com to the list of AMP Cache hosts. See [#1447](https://github.com/Automattic/amp-wp/pull/1447). Props westonruter. - Add missing tabindex attribute to lightbox images. See [#1350](https://github.com/Automattic/amp-wp/issues/1350). Props amedina. - Detect ineffectual post-processor response cache due to high MISS rates and auto-disable. See [#1325](https://github.com/Automattic/amp-wp/issues/1325), [#1239](https://github.com/Automattic/amp-wp/issues/1239). Props hellofromtonya, westonruter. - Update the validator spec version to 720 and AMP v1534879991178; add support for reference points. See [#1315](https://github.com/Automattic/amp-wp/issues/1315), [#1386](https://github.com/Automattic/amp-wp/issues/1386), [#1330](https://github.com/Automattic/amp-wp/issues/1330). Props westonruter. @@ -156,6 +163,7 @@ To learn how to use the new features in this release, please see the wiki pages - Fix handling responses to form submissions from an AMP Cache. See [#1382](https://github.com/Automattic/amp-wp/issues/1382), [#1356](https://github.com/Automattic/amp-wp/issues/1356). - Replace Gutenberg's deprecated isCleanNewPost selector. See [#1387](https://github.com/Automattic/amp-wp/issues/1387). Props miina. - Updates php-css-parser to include fix for parsing calc() with negative values. See [#1392](https://github.com/Automattic/amp-wp/issues/1392). Props westonruter. +- Update AMP spec to 757 (v1811091519050). See [#1588](https://github.com/Automattic/amp-wp/pull/1588). Props westonruter, kienstra. - Add embed support for Twitter timelines via new amp-twitter attributes. See [#1396](https://github.com/Automattic/amp-wp/issues/1396). Props felixarntz. - Fix tooltip position. See [#1472](https://github.com/Automattic/amp-wp/pull/1472). Props jacobschweitzer. - Add error type filters on validation error and invalid URL screens. See [#1373](https://github.com/Automattic/amp-wp/issues/1373). Props kienstra. @@ -170,6 +178,7 @@ To learn how to use the new features in this release, please see the wiki pages - Improve access to AMP admin screens for users who are not administrators. [#1437](https://github.com/Automattic/amp-wp/pull/1437). Props westonruter. - Display a welcome notice on the main 'AMP Settings' page. See [#1442](https://github.com/Automattic/amp-wp/pull/1442). Props kienstra. - Fix URL protocol validation and parsing attribute values with multiple URLs. See [#1411](https://github.com/Automattic/amp-wp/pull/1411), [#1410](https://github.com/Automattic/amp-wp/issues/1410). Props westonruter. +- Prevent a notice from appearing in the Compatibility Tool meta box. See [#1605](https://github.com/Automattic/amp-wp/pull/1605). Props kienstra. - Restore ability to customize 'amp' query var when theme support added. [#1455](https://github.com/Automattic/amp-wp/pull/1455). Props westonruter. - Add slug constants for theme support and post type support. [#1456](https://github.com/Automattic/amp-wp/pull/1456). Props westonruter. - Fix ability to add AMP support for custom post types. See [#1441](https://github.com/Automattic/amp-wp/pull/1441). Props westonruter. From b4bed88b592fd6f79e90e68859690caa8dc28649 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 20 Nov 2018 06:18:21 -0600 Subject: [PATCH 14/40] Bump the plugin version to 1.0-RC3 in amp.php In preparation for the 1.0-RC3 release. Following the update of the changelog. --- amp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/amp.php b/amp.php index 4adaa6cafba..ab5320ec415 100644 --- a/amp.php +++ b/amp.php @@ -5,7 +5,7 @@ * Plugin URI: https://github.com/automattic/amp-wp * Author: WordPress.com VIP, XWP, Google, and contributors * Author URI: https://github.com/Automattic/amp-wp/graphs/contributors - * Version: 1.0-RC2 + * Version: 1.0-RC3 * Text Domain: amp * Domain Path: /languages/ * License: GPLv2 or later @@ -66,7 +66,7 @@ function _amp_print_composer_install_admin_notice() { define( 'AMP__FILE__', __FILE__ ); define( 'AMP__DIR__', dirname( __FILE__ ) ); -define( 'AMP__VERSION', '1.0-RC2' ); +define( 'AMP__VERSION', '1.0-RC3' ); /** * Print admin notice if plugin installed with incorrect slug (which impacts WordPress's auto-update system). From 05c852df306d7ac297a3e55df350fbb814808edc Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 20 Nov 2018 06:27:11 -0600 Subject: [PATCH 15/40] Correct a typo in a link, and move an entry higher There was a typo that caused the link not to render Also, move up the 'Update AMP spec to 757' line. --- readme.md | 4 ++-- readme.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 4051e09581c..01c6a0dfcf9 100644 --- a/readme.md +++ b/readme.md @@ -152,7 +152,7 @@ To learn how to use the new features in this release, please see the wiki pages - Gutenberg: Fix displaying validation warning and usage of PHP function. See [#1612](https://github.com/Automattic/amp-wp/pull/1612). Props miina. - Fix stretched images in Twenty Seventeen them and Gutenberg. See [#1321](https://github.com/Automattic/amp-wp/issues/1321), [#1281](https://github.com/Automattic/amp-wp/issues/1281), [#1237](https://github.com/Automattic/amp-wp/issues/1237). Props hellofromtonya. - Fix image dimension extractor so it does not disregard duplicate images. See [#1314](https://github.com/Automattic/amp-wp/issues/1314). Props lukas9393. -- Short-circuit polldaddy shortcode when no poll or survey supplied. See [#1621](#https://github.com/Automattic/amp-wp/pull/1621). Props westonruter. +- Short-circuit polldaddy shortcode when no poll or survey supplied. See [#1621](https://github.com/Automattic/amp-wp/pull/1621). Props westonruter. - Remove redundant version from composer.json and add PHP version requirement. See [#1333](https://github.com/Automattic/amp-wp/issues/1333), [#1328](https://github.com/Automattic/amp-wp/issues/1328), [#1334](https://github.com/Automattic/amp-wp/issues/1334), [#1332](https://github.com/Automattic/amp-wp/issues/1332). Props swissspidy. - Add warning when AMP plugin is installed in incorrect directory. See [#1593](https://github.com/Automattic/amp-wp/pull/1593). Props westonruter. - Store validation errors in order of occurrence in document. See [#1335](https://github.com/Automattic/amp-wp/issues/1335). Props westonruter. @@ -167,6 +167,7 @@ To learn how to use the new features in this release, please see the wiki pages - Normalize 'ver' query param in script/style validation errors to prevent recurrence after accepted. See [#1346](https://github.com/Automattic/amp-wp/issues/1346). Props westonruter. - Add bing-amp.com to the list of AMP Cache hosts. See [#1447](https://github.com/Automattic/amp-wp/pull/1447). Props westonruter. - Add missing tabindex attribute to lightbox images. See [#1350](https://github.com/Automattic/amp-wp/issues/1350). Props amedina. +- Update AMP spec to 757 (v1811091519050). See [#1588](https://github.com/Automattic/amp-wp/pull/1588). Props westonruter, kienstra. - Detect ineffectual post-processor response cache due to high MISS rates and auto-disable. See [#1325](https://github.com/Automattic/amp-wp/issues/1325), [#1239](https://github.com/Automattic/amp-wp/issues/1239). Props hellofromtonya, westonruter. - Update the validator spec version to 720 and AMP v1534879991178; add support for reference points. See [#1315](https://github.com/Automattic/amp-wp/issues/1315), [#1386](https://github.com/Automattic/amp-wp/issues/1386), [#1330](https://github.com/Automattic/amp-wp/issues/1330). Props westonruter. - Update spec from revision 720 to 734. See [#1475](https://github.com/Automattic/amp-wp/pull/1475). Props kienstra. @@ -179,7 +180,6 @@ To learn how to use the new features in this release, please see the wiki pages - Fix handling responses to form submissions from an AMP Cache. See [#1382](https://github.com/Automattic/amp-wp/issues/1382), [#1356](https://github.com/Automattic/amp-wp/issues/1356). - Replace Gutenberg's deprecated isCleanNewPost selector. See [#1387](https://github.com/Automattic/amp-wp/issues/1387). Props miina. - Updates php-css-parser to include fix for parsing calc() with negative values. See [#1392](https://github.com/Automattic/amp-wp/issues/1392). Props westonruter. -- Update AMP spec to 757 (v1811091519050). See [#1588](https://github.com/Automattic/amp-wp/pull/1588). Props westonruter, kienstra. - Add embed support for Twitter timelines via new amp-twitter attributes. See [#1396](https://github.com/Automattic/amp-wp/issues/1396). Props felixarntz. - Fix tooltip position. See [#1472](https://github.com/Automattic/amp-wp/pull/1472). Props jacobschweitzer. - Add error type filters on validation error and invalid URL screens. See [#1373](https://github.com/Automattic/amp-wp/issues/1373). Props kienstra. diff --git a/readme.txt b/readme.txt index d6657df1ecd..a38d7786e80 100644 --- a/readme.txt +++ b/readme.txt @@ -136,7 +136,7 @@ To learn how to use the new features in this release, please see the wiki pages - Gutenberg: Fix displaying validation warning and usage of PHP function. See [#1612](https://github.com/Automattic/amp-wp/pull/1612). Props miina. - Fix stretched images in Twenty Seventeen them and Gutenberg. See [#1321](https://github.com/Automattic/amp-wp/issues/1321), [#1281](https://github.com/Automattic/amp-wp/issues/1281), [#1237](https://github.com/Automattic/amp-wp/issues/1237). Props hellofromtonya. - Fix image dimension extractor so it does not disregard duplicate images. See [#1314](https://github.com/Automattic/amp-wp/issues/1314). Props lukas9393. -- Short-circuit polldaddy shortcode when no poll or survey supplied. See [#1621](#https://github.com/Automattic/amp-wp/pull/1621). Props westonruter. +- Short-circuit polldaddy shortcode when no poll or survey supplied. See [#1621](https://github.com/Automattic/amp-wp/pull/1621). Props westonruter. - Remove redundant version from composer.json and add PHP version requirement. See [#1333](https://github.com/Automattic/amp-wp/issues/1333), [#1328](https://github.com/Automattic/amp-wp/issues/1328), [#1334](https://github.com/Automattic/amp-wp/issues/1334), [#1332](https://github.com/Automattic/amp-wp/issues/1332). Props swissspidy. - Add warning when AMP plugin is installed in incorrect directory. See [#1593](https://github.com/Automattic/amp-wp/pull/1593). Props westonruter. - Store validation errors in order of occurrence in document. See [#1335](https://github.com/Automattic/amp-wp/issues/1335). Props westonruter. @@ -151,6 +151,7 @@ To learn how to use the new features in this release, please see the wiki pages - Normalize 'ver' query param in script/style validation errors to prevent recurrence after accepted. See [#1346](https://github.com/Automattic/amp-wp/issues/1346). Props westonruter. - Add bing-amp.com to the list of AMP Cache hosts. See [#1447](https://github.com/Automattic/amp-wp/pull/1447). Props westonruter. - Add missing tabindex attribute to lightbox images. See [#1350](https://github.com/Automattic/amp-wp/issues/1350). Props amedina. +- Update AMP spec to 757 (v1811091519050). See [#1588](https://github.com/Automattic/amp-wp/pull/1588). Props westonruter, kienstra. - Detect ineffectual post-processor response cache due to high MISS rates and auto-disable. See [#1325](https://github.com/Automattic/amp-wp/issues/1325), [#1239](https://github.com/Automattic/amp-wp/issues/1239). Props hellofromtonya, westonruter. - Update the validator spec version to 720 and AMP v1534879991178; add support for reference points. See [#1315](https://github.com/Automattic/amp-wp/issues/1315), [#1386](https://github.com/Automattic/amp-wp/issues/1386), [#1330](https://github.com/Automattic/amp-wp/issues/1330). Props westonruter. - Update spec from revision 720 to 734. See [#1475](https://github.com/Automattic/amp-wp/pull/1475). Props kienstra. @@ -163,7 +164,6 @@ To learn how to use the new features in this release, please see the wiki pages - Fix handling responses to form submissions from an AMP Cache. See [#1382](https://github.com/Automattic/amp-wp/issues/1382), [#1356](https://github.com/Automattic/amp-wp/issues/1356). - Replace Gutenberg's deprecated isCleanNewPost selector. See [#1387](https://github.com/Automattic/amp-wp/issues/1387). Props miina. - Updates php-css-parser to include fix for parsing calc() with negative values. See [#1392](https://github.com/Automattic/amp-wp/issues/1392). Props westonruter. -- Update AMP spec to 757 (v1811091519050). See [#1588](https://github.com/Automattic/amp-wp/pull/1588). Props westonruter, kienstra. - Add embed support for Twitter timelines via new amp-twitter attributes. See [#1396](https://github.com/Automattic/amp-wp/issues/1396). Props felixarntz. - Fix tooltip position. See [#1472](https://github.com/Automattic/amp-wp/pull/1472). Props jacobschweitzer. - Add error type filters on validation error and invalid URL screens. See [#1373](https://github.com/Automattic/amp-wp/issues/1373). Props kienstra. From fea603d1bf180dd7cd5e2150ffa06ae2e80bb4df Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 20 Nov 2018 07:09:13 -0600 Subject: [PATCH 16/40] Correct a phpcs issue by adding a space between ( and ' --- includes/sanitizers/class-amp-style-sanitizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 64691863623..ce0e46b4f5a 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -1839,7 +1839,7 @@ private function finalize_styles() { $css .= $stylesheet_sets['custom']['source_map_comment']; // Remove the Byte Order Mark if it exists, as it can prevent styles from rendering. - $css = preg_replace('/\x{FEFF}/u', '', $css ); + $css = preg_replace( '/\x{FEFF}/u', '', $css ); /* * Let the style[amp-custom] be populated with the concatenated CSS. From 0a0b134b6bc74fd27f4e8a924878c9637ca3877d Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 20 Nov 2018 09:35:57 -0600 Subject: [PATCH 17/40] Bump 'Tested up to' version to 5.0 As Weston has mentioned, there's no need to have any more specificity than this, like 5.0-beta5 --- readme.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index a4df05d524d..7abb0e180f0 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ Enable Accelerated Mobile Pages (AMP) on your WordPress site. **Contributors:** [batmoo](https://profiles.wordpress.org/batmoo), [joen](https://profiles.wordpress.org/joen), [automattic](https://profiles.wordpress.org/automattic), [potatomaster](https://profiles.wordpress.org/potatomaster), [albertomedina](https://profiles.wordpress.org/albertomedina), [google](https://profiles.wordpress.org/google), [xwp](https://profiles.wordpress.org/xwp), [westonruter](https://profiles.wordpress.org/westonruter) **Tags:** [amp](https://wordpress.org/plugins/tags/amp), [mobile](https://wordpress.org/plugins/tags/mobile) **Requires at least:** 4.7 -**Tested up to:** 4.9 +**Tested up to:** 5.0 **Stable tag:** 0.7.2 **License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) **Requires PHP:** 5.3.6 diff --git a/readme.txt b/readme.txt index df6a51b3e38..b1b572d0677 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: batmoo, joen, automattic, potatomaster, albertomedina, google, xwp, westonruter Tags: amp, mobile Requires at least: 4.7 -Tested up to: 4.9 +Tested up to: 5.0 Stable tag: 0.7.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html From 443bd9b5b44682c6916e6da73d0c59fbe4dbc565 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 20 Nov 2018 12:03:11 -0600 Subject: [PATCH 18/40] Update includes/embeds/class-amp-gallery-embed.php Apply Weston's suggestion to change add_filter() to add_action() Co-Authored-By: kienstra --- includes/embeds/class-amp-gallery-embed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/embeds/class-amp-gallery-embed.php b/includes/embeds/class-amp-gallery-embed.php index 1f7682101ae..4965f8d4b79 100644 --- a/includes/embeds/class-amp-gallery-embed.php +++ b/includes/embeds/class-amp-gallery-embed.php @@ -17,7 +17,7 @@ class AMP_Gallery_Embed_Handler extends AMP_Base_Embed_Handler { */ public function register_embed() { add_filter( 'post_gallery', array( $this, 'maybe_override_gallery' ), 10, 2 ); - add_filter( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); } /** From 6b7d305ced47864ecf0c898338889e4857da7cc3 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 20 Nov 2018 13:12:59 -0600 Subject: [PATCH 19/40] Move the enqueued stylesheet into a callback for 'wp_print_styles' As Weston mentioned, it's not necessary to enqueue a stylesheet that only has one rule. So output it in a callback for 'wp_print_styles' --- assets/css/amp-gallery-block.css | 9 ------- includes/embeds/class-amp-gallery-embed.php | 26 ++++++++++++--------- 2 files changed, 15 insertions(+), 20 deletions(-) delete mode 100644 assets/css/amp-gallery-block.css diff --git a/assets/css/amp-gallery-block.css b/assets/css/amp-gallery-block.css deleted file mode 100644 index 2dadf8dc1a4..00000000000 --- a/assets/css/amp-gallery-block.css +++ /dev/null @@ -1,9 +0,0 @@ -/** - * For the AMP implementation of the Gallery block. - * This rule is copied exactly from block-library/style.css, but the selector here has amp-img >. - * The image sanitizer normally converts the from that original stylesheet , - * but that doesn't have the same effect as applying it to the . - */ -.wp-block-gallery.is-cropped .blocks-gallery-item amp-img > img { - object-fit: cover; -} diff --git a/includes/embeds/class-amp-gallery-embed.php b/includes/embeds/class-amp-gallery-embed.php index 4965f8d4b79..c2c481a8d06 100644 --- a/includes/embeds/class-amp-gallery-embed.php +++ b/includes/embeds/class-amp-gallery-embed.php @@ -17,7 +17,7 @@ class AMP_Gallery_Embed_Handler extends AMP_Base_Embed_Handler { */ public function register_embed() { add_filter( 'post_gallery', array( $this, 'maybe_override_gallery' ), 10, 2 ); - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); + add_action( 'wp_print_styles', array( $this, 'print_styles' ) ); } /** @@ -236,19 +236,23 @@ public function render( $args ) { } /** - * Enqueues the Gallery block styling. + * Prints the Gallery block styling. * - * It would be better to enqueue this in AMP_Gallery_Block_Sanitizer, - * but by the time that runs, it's too late to call wp_enqueue_style(). + * It would be better to print this in AMP_Gallery_Block_Sanitizer, + * but by the time that runs, it's too late. + * This rule is copied exactly from block-library/style.css, but the selector here has amp-img >. + * The image sanitizer normally converts the from that original stylesheet , + * but that doesn't have the same effect as applying it to the . * * @return void */ - public function enqueue_styles() { - wp_enqueue_style( - 'amp-gallery-block', - amp_get_asset_url( 'css/amp-gallery-block.css' ), - array(), - AMP__VERSION - ); + public function print_styles() { + ?> + + Date: Tue, 20 Nov 2018 11:29:59 -0800 Subject: [PATCH 20/40] Strip BOM before parsing --- includes/sanitizers/class-amp-style-sanitizer.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index ce0e46b4f5a..dc6eae69379 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -1046,6 +1046,9 @@ private function prepare_stylesheet( $stylesheet_string, $options = array() ) { $options ); + // Strip the dreaded UTF-8 byte order mark (BOM, \uFEFF). This should ideally get handled by PHP-CSS-Parser . + $stylesheet_string = preg_replace( '/^\xEF\xBB\xBF/', '', $stylesheet_string ); + $stylesheet = array(); $parsed_stylesheet = $this->parse_stylesheet( $stylesheet_string, $options ); $validation_results = $parsed_stylesheet['validation_results']; @@ -1838,9 +1841,6 @@ private function finalize_styles() { $css .= implode( '', $stylesheet_sets['custom']['final_stylesheets'] ); $css .= $stylesheet_sets['custom']['source_map_comment']; - // Remove the Byte Order Mark if it exists, as it can prevent styles from rendering. - $css = preg_replace( '/\x{FEFF}/u', '', $css ); - /* * Let the style[amp-custom] be populated with the concatenated CSS. * !important: Updating the contents of this style element by setting textContent is not @@ -2066,8 +2066,6 @@ private function finalize_stylesheet_set( $stylesheet_set ) { empty( $parsed_selector['tags'] ) || 0 === count( array_diff( $parsed_selector['tags'], $this->get_used_tag_names() ) ) - || - 0 === count( array_diff( $parsed_selector['tags'], $stylesheet_set['cdata_spec']['css_spec']['allowed_at_rules'] ) ) ) ) ); From 89f3b4a1e378560031c9aab255e1bbd105df8d9e Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 25 Oct 2018 20:37:22 +0200 Subject: [PATCH 21/40] Update regex for tag selectors See #1513. --- includes/sanitizers/class-amp-style-sanitizer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 118acd80636..9dc37b91327 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -1984,11 +1984,11 @@ private function ampify_ruleset_selectors( $ruleset ) { $edited_selectors = array( $selector ); foreach ( $this->selector_mappings as $html_selector => $amp_selectors ) { // Note: The $selector_mappings array contains ~6 items. - $html_pattern = '/(?<=^|[^a-z0-9_-])' . preg_quote( $html_selector, '/' ) . '(?=$|[^a-z0-9_-])/i'; + $html_pattern = '/(?<=^|\s|>)' . preg_quote( $html_selector, '/' ) . '(?=$|[^a-z0-9_-])/i'; foreach ( $edited_selectors as &$edited_selector ) { // Note: The $edited_selectors array contains only item in the normal case. $original_selector = $edited_selector; $amp_selector = array_shift( $amp_selectors ); - $amp_tag_pattern = '/(?<=^|[^a-z0-9_-])' . preg_quote( $amp_selector, '/' ) . '(?=$|[^a-z0-9_-])/i'; + $amp_tag_pattern = '/(?<=^|\s|>)' . preg_quote( $amp_selector, '/' ) . '(?=$|[^a-z0-9_-])/i'; preg_match( $amp_tag_pattern, $edited_selector, $matches ); if ( ! empty( $matches ) && $amp_selector === $matches[0] ) { continue; From 43628e4280561d95507bf82c4859656511614de2 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 25 Oct 2018 21:30:53 +0200 Subject: [PATCH 22/40] Only change second regex --- includes/sanitizers/class-amp-style-sanitizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 9dc37b91327..d3a9f3781dd 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -1984,7 +1984,7 @@ private function ampify_ruleset_selectors( $ruleset ) { $edited_selectors = array( $selector ); foreach ( $this->selector_mappings as $html_selector => $amp_selectors ) { // Note: The $selector_mappings array contains ~6 items. - $html_pattern = '/(?<=^|\s|>)' . preg_quote( $html_selector, '/' ) . '(?=$|[^a-z0-9_-])/i'; + $html_pattern = '/(?<=^|[^a-z0-9_-])' . preg_quote( $html_selector, '/' ) . '(?=$|[^a-z0-9_-])/i'; foreach ( $edited_selectors as &$edited_selector ) { // Note: The $edited_selectors array contains only item in the normal case. $original_selector = $edited_selector; $amp_selector = array_shift( $amp_selectors ); From bb188ea953247e33c480f0ae0de1de20ba7a2cc1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 20 Nov 2018 14:43:35 -0800 Subject: [PATCH 23/40] Fix pattern match element type in selector --- includes/sanitizers/class-amp-style-sanitizer.php | 8 ++++++-- tests/test-amp-style-sanitizer.php | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index d3a9f3781dd..8442b827b5e 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -1982,13 +1982,17 @@ private function ampify_ruleset_selectors( $ruleset ) { continue; } + // An element (type) either starts a selector or is preceded by combinator or opening paren. + $before_type_selector_pattern = '(?<=^|\(|\s|>|\+|~)'; + $after_type_selector_pattern = '(?=$|[^a-zA-Z0-9_-])'; + $edited_selectors = array( $selector ); foreach ( $this->selector_mappings as $html_selector => $amp_selectors ) { // Note: The $selector_mappings array contains ~6 items. - $html_pattern = '/(?<=^|[^a-z0-9_-])' . preg_quote( $html_selector, '/' ) . '(?=$|[^a-z0-9_-])/i'; + $html_pattern = '/' . $before_type_selector_pattern . preg_quote( $html_selector, '/' ) . $after_type_selector_pattern . '/i'; foreach ( $edited_selectors as &$edited_selector ) { // Note: The $edited_selectors array contains only item in the normal case. $original_selector = $edited_selector; $amp_selector = array_shift( $amp_selectors ); - $amp_tag_pattern = '/(?<=^|\s|>)' . preg_quote( $amp_selector, '/' ) . '(?=$|[^a-z0-9_-])/i'; + $amp_tag_pattern = '/' . $before_type_selector_pattern . preg_quote( $amp_selector, '/' ) . $after_type_selector_pattern . '/i'; preg_match( $amp_tag_pattern, $edited_selector, $matches ); if ( ! empty( $matches ) && $amp_selector === $matches[0] ) { continue; diff --git a/tests/test-amp-style-sanitizer.php b/tests/test-amp-style-sanitizer.php index 66bddb41e0b..df2ffe4e841 100644 --- a/tests/test-amp-style-sanitizer.php +++ b/tests/test-amp-style-sanitizer.php @@ -502,6 +502,11 @@ public function get_amp_selector_data() { 'span {color:red;} @keyframes foo { from: { opacity:0; } 50% {opacity:0.5} 75%,80% { opacity:0.6 } to { opacity:1 } }', '@keyframes foo{from:{opacity:0}50%{opacity:.5}75%,80%{opacity:.6}to{opacity:1}}', ), + 'type_class_names' => array( + '', + '.audio{color:purple;} .video{color:blue;} .iframe{color:black;} img.img{color:purple;} .form{color:green;}', + '.audio{color:purple}.video{color:blue}.iframe{color:black}amp-img.img{color:purple}.form{color:green}', + ), ); } From 81e02f44c20ecf474e830c5f77654cb0e296fac0 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 20 Nov 2018 15:09:22 -0800 Subject: [PATCH 24/40] Accoiunt for closing brace in selector mapping; add missing form=>amp-form map --- includes/sanitizers/class-amp-form-sanitizer.php | 11 +++++++++++ includes/sanitizers/class-amp-style-sanitizer.php | 4 ++-- tests/test-amp-style-sanitizer.php | 6 +++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/includes/sanitizers/class-amp-form-sanitizer.php b/includes/sanitizers/class-amp-form-sanitizer.php index 750bd88f85a..03babed13c5 100644 --- a/includes/sanitizers/class-amp-form-sanitizer.php +++ b/includes/sanitizers/class-amp-form-sanitizer.php @@ -24,6 +24,17 @@ class AMP_Form_Sanitizer extends AMP_Base_Sanitizer { */ public static $tag = 'form'; + /** + * Get mapping of HTML selectors to the AMP component selectors which they may be converted into. + * + * @return array Mapping. + */ + public function get_selector_conversion_mapping() { + return array( + 'form' => array( 'amp-form' ), + ); + } + /** * Sanitize the
elements from the HTML contained in this instance's DOMDocument. * diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 8442b827b5e..0ddb48b372a 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -1982,8 +1982,8 @@ private function ampify_ruleset_selectors( $ruleset ) { continue; } - // An element (type) either starts a selector or is preceded by combinator or opening paren. - $before_type_selector_pattern = '(?<=^|\(|\s|>|\+|~)'; + // An element (type) either starts a selector or is preceded by combinator, comma, opening paren, or closing brace. + $before_type_selector_pattern = '(?<=^|\(|\s|>|\+|~|,|})'; $after_type_selector_pattern = '(?=$|[^a-zA-Z0-9_-])'; $edited_selectors = array( $selector ); diff --git a/tests/test-amp-style-sanitizer.php b/tests/test-amp-style-sanitizer.php index df2ffe4e841..8105e3abc28 100644 --- a/tests/test-amp-style-sanitizer.php +++ b/tests/test-amp-style-sanitizer.php @@ -503,9 +503,9 @@ public function get_amp_selector_data() { '@keyframes foo{from:{opacity:0}50%{opacity:.5}75%,80%{opacity:.6}to{opacity:1}}', ), 'type_class_names' => array( - '', - '.audio{color:purple;} .video{color:blue;} .iframe{color:black;} img.img{color:purple;} .form{color:green;}', - '.audio{color:purple}.video{color:blue}.iframe{color:black}amp-img.img{color:purple}.form{color:green}', + '