AMP for WordPress - Version 1.2.2

Version Description

Download this release

Release Info

Developer westonruter
Plugin Icon 128x128 AMP for WordPress
Version 1.2.2
Comparing to
See all releases

Code changes from version 1.2.1 to 1.2.2

amp.php CHANGED
@@ -5,7 +5,7 @@
5
  * Plugin URI: https://amp-wp.org
6
  * Author: AMP Project Contributors
7
  * Author URI: https://github.com/ampproject/amp-wp/graphs/contributors
8
- * Version: 1.2.1
9
  * Text Domain: amp
10
  * Domain Path: /languages/
11
  * License: GPLv2 or later
@@ -15,7 +15,7 @@
15
 
16
  define( 'AMP__FILE__', __FILE__ );
17
  define( 'AMP__DIR__', dirname( __FILE__ ) );
18
- define( 'AMP__VERSION', '1.2.1' );
19
 
20
  /**
21
  * Errors encountered while loading the plugin.
5
  * Plugin URI: https://amp-wp.org
6
  * Author: AMP Project Contributors
7
  * Author URI: https://github.com/ampproject/amp-wp/graphs/contributors
8
+ * Version: 1.2.2
9
  * Text Domain: amp
10
  * Domain Path: /languages/
11
  * License: GPLv2 or later
15
 
16
  define( 'AMP__FILE__', __FILE__ );
17
  define( 'AMP__DIR__', dirname( __FILE__ ) );
18
+ define( 'AMP__VERSION', '1.2.2' );
19
 
20
  /**
21
  * Errors encountered while loading the plugin.
assets/js/amp-block-validation.js CHANGED
@@ -2,4 +2,4 @@
2
  /* translators: %s: number of issues */
3
  Object(l._n)("There is %s issue from AMP validation which needs review.","There are %s issues from AMP validation which need review.",s,"amp"),s);var b=u.filter(function(e){return e.clientId}),m=b.length;if("amp_story"!==c().type)if(m>0?e+=" "+Object(l.sprintf)(
4
  /* translators: %s: number of block errors. */
5
- Object(l._n)("%s issue is directly due to content here.","%s issues are directly due to content here.",m,"amp"),m):1===u.length?e+=" "+Object(l.__)("The issue is not directly due to content here.","amp"):e+=" "+Object(l.__)("The issues are not directly due to content here.","amp"),e+=" ",n()){var f=b.filter(function(e){return 0===e.status||2===e.status}),p=u.filter(function(e){return 0===e.status||2===e.status});e+=0===f.length+p.length?Object(l.__)("However, your site is configured to automatically accept sanitization of the offending markup.","amp"):Object(l._n)("Your site is configured to automatically accept sanitization errors, but this error could be from when auto-acceptance was not selected, or from manually rejecting an error.","Your site is configured to automatically accept sanitization errors, but these errors could be from when auto-acceptance was not selected, or from manually rejecting an error.",u.length,"amp")}else e+=Object(l.__)("Non-accepted validation errors prevent AMP from being served, and the user will be redirected to the non-AMP version.","amp");var d={id:"amp-errors-notice"},O=o();O&&(d.actions=[{label:Object(l.__)("Review issues","amp"),url:O}]),a(e,d)},m=r(13),f=r(0),p=(r(5),function(e){var t=e.message,r=e.code,n=e.node_name,o=e.parent_name;return t?Object(f.createElement)(f.Fragment,null,t):"invalid_element"===r&&n?Object(f.createElement)(f.Fragment,null,Object(l.__)("Invalid element: ","amp"),Object(f.createElement)("code",null,n)):"invalid_attribute"===r&&n?Object(f.createElement)(f.Fragment,null,Object(l.__)("Invalid attribute: ","amp"),Object(f.createElement)("code",null,o?Object(l.sprintf)("%s[%s]",o,n):n)):Object(f.createElement)(f.Fragment,null,Object(l.__)("Error code: ","amp"),Object(f.createElement)("code",null,r||Object(l.__)("unknown","amp")))}),d=r(2),O=r(15),h=(r(45),Object(i.withSelect)(function(e,t){var r=t.clientId,n=(0,e("amp/block-validation").getBlockValidationErrors)(r);return{blockValidationErrors:n.length?n:void 0}})),g=Object(O.createHigherOrderComponent)(function(e){return h(function(t){var r=t.blockValidationErrors,n=t.onReplace;if(!r)return Object(f.createElement)(e,t);var o=r.length,a=[{label:Object(l.__)("Remove Element","amp"),onClick:function(){return n([])}}];return Object(f.createElement)(f.Fragment,null,Object(f.createElement)(d.Notice,{status:"warning",isDismissible:!1,actions:a},Object(f.createElement)("details",{className:"amp-block-validation-errors"},Object(f.createElement)("summary",{className:"amp-block-validation-errors__summary"},Object(l.sprintf)(Object(l._n)("There is %s issue from AMP validation.","There are %s issues from AMP validation.",o,"amp"),o)),Object(f.createElement)("ul",{className:"amp-block-validation-errors__list"},r.map(function(e,t){return Object(f.createElement)("li",{key:t},Object(f.createElement)(p,e))})))),Object(f.createElement)(e,t))})},"withValidationErrorNotice"),j=r(11),v=r.n(j),y=r(34),_=r.n(y);function E(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function x(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?E(r,!0).forEach(function(t){v()(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):E(r).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function w(e,t){return{type:"ADD_VALIDATION_ERROR",error:e,clientId:t}}function P(){return{type:"RESET_VALIDATION_ERRORS"}}function k(e){return{type:"UPDATE_REVIEW_LINK",url:e}}function S(e){return e.errors}function A(e,t){return e.errors.filter(function(e){return e.clientId===t})}function T(e){return e.reviewLink}function L(e){return Boolean(e.isSanitizationAutoAccepted)}function D(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}Object(i.registerStore)("amp/block-validation",{reducer:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,t=arguments.length>1?arguments[1]:void 0,r=t.type,n=t.url,o=t.error,a=t.clientId;switch(r){case"ADD_VALIDATION_ERROR":var i=e?e.errors:[],c=x({},o,{clientId:a});return x({},e,{errors:[].concat(_()(i),[c])});case"RESET_VALIDATION_ERRORS":return x({},e,{errors:[]});case"UPDATE_REVIEW_LINK":return x({},e,{reviewLink:n});default:return e}},selectors:o,actions:n,initialState:function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?D(r,!0).forEach(function(t){v()(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):D(r).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({},window.ampBlockValidation,{errors:[],reviewLink:void 0})}),r(27);var I=Object(i.select)("core/editor").isEditedPostDirty;Object(i.subscribe)(function(){var e,t;I()||(Object(m.e)()?function(){var e=Object(i.select)("core/block-editor"),t=e.getBlockCount,r=e.getClientIdsWithDescendants,n=e.getBlock,o=Object(i.select)("core/editor").getCurrentPost,a=Object(i.dispatch)("amp/block-validation"),l=a.resetValidationErrors,m=a.addValidationError,f=a.updateReviewLink;if(0!==t()){var p=o(),d=p.amp_validity||{};if(d.results&&d.review_link){var O=d.results.filter(function(e){return 3!==e.term_status}).map(function(e){return e.error});if(!Object(c.isEqual)(O,s))if(s=O,l(),0!==O.length){f(d.review_link);var h=r(),g=!0,j=!1,v=void 0;try{for(var y,_=O[Symbol.iterator]();!(g=(y=_.next()).done);g=!0){var E=y.value;if(!E.sources){m(E);break}var x=void 0,w=!0,P=!1,k=void 0;try{for(var S,A=E.sources[Symbol.iterator]();!(w=(S=A.next()).done);w=!0){var T=S.value;if(T.block_name&&void 0!==T.block_content_index&&p.id===T.post_id){var L=h[T.block_content_index];if(L){var D=n(L);D&&D.name===T.block_name&&(x=L)}}}}catch(e){P=!0,k=e}finally{try{w||null==A.return||A.return()}finally{if(P)throw k}}m(E,x)}}catch(e){j=!0,v=e}finally{try{g||null==_.return||_.return()}finally{if(j)throw v}}b()}else u()}}}():(e=Object(i.select)("amp/block-validation").getValidationErrors,t=Object(i.dispatch)("amp/block-validation").resetValidationErrors,e().length>0&&(t(),u(),s=[])))}),Object(a.addFilter)("editor.BlockEdit","amp/add-notice",g,99)}]);
2
  /* translators: %s: number of issues */
3
  Object(l._n)("There is %s issue from AMP validation which needs review.","There are %s issues from AMP validation which need review.",s,"amp"),s);var b=u.filter(function(e){return e.clientId}),m=b.length;if("amp_story"!==c().type)if(m>0?e+=" "+Object(l.sprintf)(
4
  /* translators: %s: number of block errors. */
5
+ Object(l._n)("%s issue is directly due to content here.","%s issues are directly due to content here.",m,"amp"),m):1===u.length?e+=" "+Object(l.__)("The issue is not directly due to content here.","amp"):e+=" "+Object(l.__)("The issues are not directly due to content here.","amp"),e+=" ",n()){var f=b.filter(function(e){return 0===e.status||2===e.status}),p=u.filter(function(e){return 0===e.status||2===e.status});e+=0===f.length+p.length?Object(l.__)("However, your site is configured to automatically accept sanitization of the offending markup.","amp"):Object(l._n)("Your site is configured to automatically accept sanitization errors, but this error could be from when auto-acceptance was not selected, or from manually rejecting an error.","Your site is configured to automatically accept sanitization errors, but these errors could be from when auto-acceptance was not selected, or from manually rejecting an error.",u.length,"amp")}else e+=Object(l.__)("Non-accepted validation errors prevent AMP from being served, and the user will be redirected to the non-AMP version.","amp");var d={id:"amp-errors-notice"},O=o();O&&(d.actions=[{label:Object(l.__)("Review issues","amp"),url:O}]),a(e,d)},m=r(13),f=r(0),p=(r(5),function(e){var t=e.message,r=e.code,n=e.node_name,o=e.parent_name;return t?Object(f.createElement)(f.Fragment,null,t):"invalid_element"===r&&n?Object(f.createElement)(f.Fragment,null,Object(l.__)("Invalid element: ","amp"),Object(f.createElement)("code",null,n)):"invalid_attribute"===r&&n?Object(f.createElement)(f.Fragment,null,Object(l.__)("Invalid attribute: ","amp"),Object(f.createElement)("code",null,o?Object(l.sprintf)("%s[%s]",o,n):n)):Object(f.createElement)(f.Fragment,null,Object(l.__)("Error code: ","amp"),Object(f.createElement)("code",null,r||Object(l.__)("unknown","amp")))}),d=r(2),O=r(15),h=(r(45),Object(i.withSelect)(function(e,t){var r=t.clientId,n=(0,e("amp/block-validation").getBlockValidationErrors)(r);return{blockValidationErrors:n.length?n:void 0}})),g=Object(O.createHigherOrderComponent)(function(e){return h(function(t){var r=t.blockValidationErrors,n=t.onReplace;if(!r)return Object(f.createElement)(e,t);var o=r.length,a=[{label:Object(l.__)("Remove Element","amp"),onClick:function(){return n([])}}];return Object(f.createElement)(f.Fragment,null,Object(f.createElement)(d.Notice,{status:"warning",isDismissible:!1,actions:a},Object(f.createElement)("details",{className:"amp-block-validation-errors"},Object(f.createElement)("summary",{className:"amp-block-validation-errors__summary"},Object(l.sprintf)(Object(l._n)("There is %s issue from AMP validation.","There are %s issues from AMP validation.",o,"amp"),o)),Object(f.createElement)("ul",{className:"amp-block-validation-errors__list"},r.map(function(e,t){return Object(f.createElement)("li",{key:t},Object(f.createElement)(p,e))})))),Object(f.createElement)(e,t))})},"withValidationErrorNotice"),j=r(11),v=r.n(j),y=r(34),_=r.n(y);function E(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function x(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?E(r,!0).forEach(function(t){v()(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):E(r).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function w(e,t){return{type:"ADD_VALIDATION_ERROR",error:e,clientId:t}}function P(){return{type:"RESET_VALIDATION_ERRORS"}}function k(e){return{type:"UPDATE_REVIEW_LINK",url:e}}function S(e){return e.errors}function A(e,t){return e.errors.filter(function(e){return e.clientId===t})}function T(e){return e.reviewLink}function L(e){return Boolean(e.isSanitizationAutoAccepted)}function D(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}Object(i.registerStore)("amp/block-validation",{reducer:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,t=arguments.length>1?arguments[1]:void 0,r=t.type,n=t.url,o=t.error,a=t.clientId;switch(r){case"ADD_VALIDATION_ERROR":var i=e?e.errors:[],c=x({},o,{clientId:a});return x({},e,{errors:[].concat(_()(i),[c])});case"RESET_VALIDATION_ERRORS":return x({},e,{errors:[]});case"UPDATE_REVIEW_LINK":return x({},e,{reviewLink:n});default:return e}},selectors:o,actions:n,initialState:function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?D(r,!0).forEach(function(t){v()(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):D(r).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({},window.ampBlockValidation,{errors:[],reviewLink:void 0})}),r(27);var I=Object(i.select)("core/editor").isEditedPostDirty;Object(i.subscribe)(function(){try{I()||(Object(m.e)()?function(){var e=Object(i.select)("core/block-editor"),t=e.getBlockCount,r=e.getClientIdsWithDescendants,n=e.getBlock,o=Object(i.select)("core/editor").getCurrentPost,a=Object(i.dispatch)("amp/block-validation"),l=a.resetValidationErrors,m=a.addValidationError,f=a.updateReviewLink;if(0!==t()){var p=o(),d=p.amp_validity||{};if(d.results&&d.review_link){var O=d.results.filter(function(e){return 3!==e.term_status}).map(function(e){return e.error});if(!Object(c.isEqual)(O,s))if(s=O,l(),0!==O.length){f(d.review_link);var h=r(),g=!0,j=!1,v=void 0;try{for(var y,_=O[Symbol.iterator]();!(g=(y=_.next()).done);g=!0){var E=y.value;if(!E.sources){m(E);break}var x=void 0,w=!0,P=!1,k=void 0;try{for(var S,A=E.sources[Symbol.iterator]();!(w=(S=A.next()).done);w=!0){var T=S.value;if(T.block_name&&void 0!==T.block_content_index&&p.id===T.post_id){var L=h[T.block_content_index];if(L){var D=n(L);D&&D.name===T.block_name&&(x=L)}}}}catch(e){P=!0,k=e}finally{try{w||null==A.return||A.return()}finally{if(P)throw k}}m(E,x)}}catch(e){j=!0,v=e}finally{try{g||null==_.return||_.return()}finally{if(j)throw v}}b()}else u()}}}():(e=Object(i.select)("amp/block-validation").getValidationErrors,t=Object(i.dispatch)("amp/block-validation").resetValidationErrors,e().length>0&&(t(),u(),s=[])))}catch(e){}var e,t}),Object(a.addFilter)("editor.BlockEdit","amp/add-notice",g,99)}]);
includes/admin/class-amp-story-templates.php CHANGED
@@ -32,20 +32,21 @@ class AMP_Story_Templates {
32
  * Init.
33
  */
34
  public function init() {
35
- // Hide story templates even when the stories feature is not active.
36
  add_filter( 'pre_get_posts', [ $this, 'filter_pre_get_posts' ] );
37
 
 
 
 
 
 
 
38
  if ( ! AMP_Options_Manager::is_stories_experience_enabled() ) {
39
  return;
40
  }
41
 
42
- add_filter( 'rest_wp_block_query', [ $this, 'filter_rest_wp_block_query' ], 10, 2 );
43
  add_action( 'save_post_wp_block', [ $this, 'flag_template_as_modified' ] );
44
 
45
- // Temporary filters for disallowing the users to edit any templates until the feature has been implemented.
46
- add_filter( 'user_has_cap', [ $this, 'filter_user_has_cap' ], 10, 3 );
47
-
48
- $this->register_taxonomy();
49
  $this->maybe_import_story_templates();
50
  }
51
 
@@ -296,44 +297,6 @@ class AMP_Story_Templates {
296
  }
297
  }
298
 
299
- /**
300
- * Filter REST request for reusable blocks to not display templates under Reusable Blocks within other posts.
301
- *
302
- * @param array $args Original args.
303
- * @param WP_REST_Request $request WP REST Request object.
304
- * @return array Args.
305
- */
306
- public function filter_rest_wp_block_query( $args, $request ) {
307
- $headers = $request->get_headers();
308
- if ( ! isset( $headers['referer'][0] ) ) {
309
- return $args;
310
- }
311
-
312
- $parts = wp_parse_url( $headers['referer'][0] );
313
- if ( ! isset( $parts['query'] ) ) {
314
- return $args;
315
- }
316
- parse_str( $parts['query'], $params );
317
- if ( ! isset( $params['post'], $params['action'] ) ) {
318
- return $args;
319
- }
320
-
321
- $edited_post = get_post( absint( $params['post'] ) );
322
- if ( AMP_Story_Post_Type::POST_TYPE_SLUG !== $edited_post->post_type ) {
323
- if ( ! isset( $args['tax_query'] ) ) {
324
- $args['tax_query'] = [];
325
- }
326
- $args['tax_query'][] = [
327
- 'taxonomy' => self::TEMPLATES_TAXONOMY,
328
- 'field' => 'slug',
329
- 'terms' => [ self::TEMPLATES_TERM ],
330
- 'operator' => 'NOT IN',
331
- ];
332
- }
333
-
334
- return $args;
335
- }
336
-
337
  /**
338
  * Flag template as modified when it's being saved.
339
  *
32
  * Init.
33
  */
34
  public function init() {
35
+ // Always hide the story templates.
36
  add_filter( 'pre_get_posts', [ $this, 'filter_pre_get_posts' ] );
37
 
38
+ // Temporary filters for disallowing the users to edit any templates until the feature has been implemented.
39
+ add_filter( 'user_has_cap', [ $this, 'filter_user_has_cap' ], 10, 3 );
40
+
41
+ // We need to register the taxonomy even if AMP Stories is disabled for tax_query.
42
+ $this->register_taxonomy();
43
+
44
  if ( ! AMP_Options_Manager::is_stories_experience_enabled() ) {
45
  return;
46
  }
47
 
 
48
  add_action( 'save_post_wp_block', [ $this, 'flag_template_as_modified' ] );
49
 
 
 
 
 
50
  $this->maybe_import_story_templates();
51
  }
52
 
297
  }
298
  }
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  /**
301
  * Flag template as modified when it's being saved.
302
  *
includes/class-amp-story-post-type.php CHANGED
@@ -954,8 +954,7 @@ class AMP_Story_Post_Type {
954
  * @see /assets/css/amp-stories.css
955
  */
956
  public static function add_custom_stories_styles() {
957
- $post = get_post();
958
- if ( ! $post || self::POST_TYPE_SLUG !== $post->post_type ) {
959
  return;
960
  }
961
 
954
  * @see /assets/css/amp-stories.css
955
  */
956
  public static function add_custom_stories_styles() {
957
+ if ( ! is_singular( self::POST_TYPE_SLUG ) ) {
 
958
  return;
959
  }
960
 
includes/embeds/class-amp-gallery-embed.php CHANGED
@@ -217,12 +217,14 @@ class AMP_Gallery_Embed_Handler extends AMP_Base_Embed_Handler {
217
  foreach ( $args['images'] as $props ) {
218
  $image_atts = [
219
  'src' => $props['url'],
220
- 'srcset' => $props['srcset'],
221
  'width' => $props['width'],
222
  'height' => $props['height'],
223
  'layout' => 'responsive',
224
  'alt' => $props['alt'],
225
  ];
 
 
 
226
 
227
  $this_aspect_ratio = $props['width'] / $props['height'];
228
  if ( $this_aspect_ratio > $max_aspect_ratio ) {
217
  foreach ( $args['images'] as $props ) {
218
  $image_atts = [
219
  'src' => $props['url'],
 
220
  'width' => $props['width'],
221
  'height' => $props['height'],
222
  'layout' => 'responsive',
223
  'alt' => $props['alt'],
224
  ];
225
+ if ( ! empty( $props['srcset'] ) ) {
226
+ $image_atts['srcset'] = $props['srcset'];
227
+ }
228
 
229
  $this_aspect_ratio = $props['width'] / $props['height'];
230
  if ( $this_aspect_ratio > $max_aspect_ratio ) {
includes/embeds/class-amp-twitter-embed.php CHANGED
@@ -229,15 +229,23 @@ class AMP_Twitter_Embed_Handler extends AMP_Base_Embed_Handler {
229
  return;
230
  }
231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  $new_node = AMP_DOM_Utils::create_node(
233
  $dom,
234
  $this->amp_tag,
235
- [
236
- 'width' => $this->DEFAULT_WIDTH,
237
- 'height' => $this->DEFAULT_HEIGHT,
238
- 'layout' => 'responsive',
239
- 'data-tweetid' => $tweet_id,
240
- ]
241
  );
242
 
243
  $this->sanitize_embed_script( $node );
229
  return;
230
  }
231
 
232
+ $attributes = [
233
+ 'width' => $this->DEFAULT_WIDTH,
234
+ 'height' => $this->DEFAULT_HEIGHT,
235
+ 'layout' => 'responsive',
236
+ 'data-tweetid' => $tweet_id,
237
+ ];
238
+
239
+ if ( $node->hasAttributes() ) {
240
+ foreach ( $node->attributes as $attr ) {
241
+ $attributes[ $attr->nodeName ] = $attr->nodeValue;
242
+ }
243
+ }
244
+
245
  $new_node = AMP_DOM_Utils::create_node(
246
  $dom,
247
  $this->amp_tag,
248
+ $attributes
 
 
 
 
 
249
  );
250
 
251
  $this->sanitize_embed_script( $node );
includes/sanitizers/class-amp-iframe-sanitizer.php CHANGED
@@ -132,6 +132,11 @@ class AMP_Iframe_Sanitizer extends AMP_Base_Sanitizer {
132
  if ( $this->args['add_noscript_fallback'] ) {
133
  $node->setAttribute( 'src', $normalized_attributes['src'] );
134
 
 
 
 
 
 
135
  // Preserve original node in noscript for no-JS environments.
136
  $this->append_old_node_noscript( $new_node, $node, $this->dom );
137
  }
@@ -155,7 +160,7 @@ class AMP_Iframe_Sanitizer extends AMP_Base_Sanitizer {
155
  * @type bool $allowfullscreen <iframe> `allowfullscreen` attribute - Convert 'false' to empty string ''
156
  * @type bool $allowtransparency <iframe> `allowtransparency` attribute - Convert 'false' to empty string ''
157
  * }
158
- * @return array Returns HTML attributes; normalizes src, dimensions, frameborder, sandox, allowtransparency and allowfullscreen
159
  */
160
  private function normalize_attributes( $attributes ) {
161
  $out = [];
@@ -189,10 +194,7 @@ class AMP_Iframe_Sanitizer extends AMP_Base_Sanitizer {
189
  break;
190
 
191
  case 'frameborder':
192
- if ( '0' !== $value && '1' !== $value ) {
193
- $value = '0';
194
- }
195
- $out[ $name ] = $value;
196
  break;
197
 
198
  case 'allowfullscreen':
@@ -271,4 +273,34 @@ class AMP_Iframe_Sanitizer extends AMP_Base_Sanitizer {
271
  return $placeholder_node;
272
  }
273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  }
132
  if ( $this->args['add_noscript_fallback'] ) {
133
  $node->setAttribute( 'src', $normalized_attributes['src'] );
134
 
135
+ // AMP is stricter than HTML5 for this attribute, so make sure we use a normalized value.
136
+ if ( $node->hasAttribute( 'frameborder' ) ) {
137
+ $node->setAttribute( 'frameborder', $normalized_attributes['frameborder'] );
138
+ }
139
+
140
  // Preserve original node in noscript for no-JS environments.
141
  $this->append_old_node_noscript( $new_node, $node, $this->dom );
142
  }
160
  * @type bool $allowfullscreen <iframe> `allowfullscreen` attribute - Convert 'false' to empty string ''
161
  * @type bool $allowtransparency <iframe> `allowtransparency` attribute - Convert 'false' to empty string ''
162
  * }
163
+ * @return array Returns HTML attributes; normalizes src, dimensions, frameborder, sandbox, allowtransparency and allowfullscreen
164
  */
165
  private function normalize_attributes( $attributes ) {
166
  $out = [];
194
  break;
195
 
196
  case 'frameborder':
197
+ $out[ $name ] = $this->sanitize_boolean_digit( $value );
 
 
 
198
  break;
199
 
200
  case 'allowfullscreen':
273
  return $placeholder_node;
274
  }
275
 
276
+ /**
277
+ * Sanitizes a boolean character (or string) into a '0' or '1' character.
278
+ *
279
+ * @param string $value A boolean character to sanitize. If a string containing more than a single
280
+ * character is provided, only the first character is taken into account.
281
+ *
282
+ * @return string Returns either '0' or '1'.
283
+ */
284
+ private function sanitize_boolean_digit( $value ) {
285
+
286
+ // Default to false if the value was forgotten.
287
+ if ( empty( $value ) ) {
288
+ return '0';
289
+ }
290
+
291
+ // Default to false if the value has an unexpected type.
292
+ if ( ! is_string( $value ) && ! is_numeric( $value ) ) {
293
+ return '0';
294
+ }
295
+
296
+ // See: https://github.com/ampproject/amp-wp/issues/2335#issuecomment-493209861.
297
+ switch ( substr( (string) $value, 0, 1 ) ) {
298
+ case '1':
299
+ case 'y':
300
+ case 'Y':
301
+ return '1';
302
+ }
303
+
304
+ return '0';
305
+ }
306
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: google, xwp, automattic, westonruter, swissspidy, miinasikk, ryank
3
  Tags: amp, framework, components, performance, mobile, stories
4
  Requires at least: 4.9
5
  Tested up to: 5.2
6
- Stable tag: 1.2.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.4
3
  Tags: amp, framework, components, performance, mobile, stories
4
  Requires at least: 4.9
5
  Tested up to: 5.2
6
+ Stable tag: 1.2.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.4