AMP for WordPress - Version 0.7.2

Version Description

(2018-06-27) =

  • Prevent plugins from outputting custom scripts in classic templates via wp_print_scripts action. See #1225, #1227. Props westonruter.
  • Display Schema.org image data for 'attachment' post type. See #1157, #1176. Props kienstra.
  • Output alt attribute in legacy templating gravatar image. See #1179. Props kienstra.

See 0.7.2 milestone.

Download this release

Release Info

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

Code changes from version 0.7.1 to 0.7.2

amp.php CHANGED
@@ -5,7 +5,7 @@
5
  * Plugin URI: https://github.com/automattic/amp-wp
6
  * Author: WordPress.com VIP, XWP, Google, and contributors
7
  * Author URI: https://github.com/Automattic/amp-wp/graphs/contributors
8
- * Version: 0.7.1
9
  * Text Domain: amp
10
  * Domain Path: /languages/
11
  * License: GPLv2 or later
@@ -32,7 +32,7 @@ if ( version_compare( phpversion(), '5.3', '<' ) ) {
32
 
33
  define( 'AMP__FILE__', __FILE__ );
34
  define( 'AMP__DIR__', dirname( __FILE__ ) );
35
- define( 'AMP__VERSION', '0.7.1' );
36
 
37
  require_once AMP__DIR__ . '/includes/class-amp-autoloader.php';
38
  AMP_Autoloader::register();
5
  * Plugin URI: https://github.com/automattic/amp-wp
6
  * Author: WordPress.com VIP, XWP, Google, and contributors
7
  * Author URI: https://github.com/Automattic/amp-wp/graphs/contributors
8
+ * Version: 0.7.2
9
  * Text Domain: amp
10
  * Domain Path: /languages/
11
  * License: GPLv2 or later
32
 
33
  define( 'AMP__FILE__', __FILE__ );
34
  define( 'AMP__DIR__', dirname( __FILE__ ) );
35
+ define( 'AMP__VERSION', '0.7.2' );
36
 
37
  require_once AMP__DIR__ . '/includes/class-amp-autoloader.php';
38
  AMP_Autoloader::register();
includes/amp-helper-functions.php CHANGED
@@ -270,6 +270,53 @@ function amp_register_default_scripts( $wp_scripts ) {
270
  }
271
  }
272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  /**
274
  * Add AMP script attributes to enqueued scripts.
275
  *
@@ -524,6 +571,8 @@ function amp_get_post_image_metadata( $post = null ) {
524
 
525
  if ( has_post_thumbnail( $post->ID ) ) {
526
  $post_image_id = get_post_thumbnail_id( $post->ID );
 
 
527
  } else {
528
  $attached_image_ids = get_posts(
529
  array(
270
  }
271
  }
272
 
273
+ /**
274
+ * Generate HTML for AMP scripts that have not yet been printed.
275
+ *
276
+ * This is adapted from `wp_scripts()->do_items()`, but it runs only the bare minimum required to output
277
+ * the missing scripts, without allowing other filters to apply which may cause an invalid AMP response.
278
+ * The HTML for the scripts is returned instead of being printed.
279
+ *
280
+ * @since 0.7.2
281
+ * @see WP_Scripts::do_items()
282
+ * @see AMP_Base_Embed_Handler::get_scripts()
283
+ * @see AMP_Base_Sanitizer::get_scripts()
284
+ *
285
+ * @param array $scripts Script handles mapped to URLs or true.
286
+ * @return string HTML for scripts tags that have not yet been done.
287
+ */
288
+ function amp_render_scripts( $scripts ) {
289
+ $script_tags = '';
290
+
291
+ /*
292
+ * Make sure the src is up to date. This allows for embed handlers to override the
293
+ * default extension version by defining a different URL.
294
+ */
295
+ foreach ( $scripts as $handle => $src ) {
296
+ if ( is_string( $src ) && wp_script_is( $handle, 'registered' ) ) {
297
+ wp_scripts()->registered[ $handle ]->src = $src;
298
+ }
299
+ }
300
+
301
+ foreach ( array_diff( array_keys( $scripts ), wp_scripts()->done ) as $handle ) {
302
+ if ( ! wp_script_is( $handle, 'registered' ) ) {
303
+ continue;
304
+ }
305
+
306
+ $script_dep = wp_scripts()->registered[ $handle ];
307
+ $script_tags .= amp_filter_script_loader_tag(
308
+ sprintf(
309
+ "<script type='text/javascript' src='%s'></script>\n", // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
310
+ esc_url( $script_dep->src )
311
+ ),
312
+ $handle
313
+ );
314
+
315
+ wp_scripts()->done[] = $handle;
316
+ }
317
+ return $script_tags;
318
+ }
319
+
320
  /**
321
  * Add AMP script attributes to enqueued scripts.
322
  *
571
 
572
  if ( has_post_thumbnail( $post->ID ) ) {
573
  $post_image_id = get_post_thumbnail_id( $post->ID );
574
+ } elseif ( ( 'attachment' === $post->post_type ) && wp_attachment_is( 'image', $post ) ) {
575
+ $post_image_id = $post->ID;
576
  } else {
577
  $attached_image_ids = get_posts(
578
  array(
includes/amp-post-template-actions.php CHANGED
@@ -51,22 +51,13 @@ function amp_post_template_add_canonical( $amp_template ) {
51
  * @param AMP_Post_Template $amp_template Template.
52
  */
53
  function amp_post_template_add_scripts( $amp_template ) {
54
-
55
- // Just in case the runtime has been overridden by amp_post_template_data filter.
56
- wp_scripts()->registered['amp-runtime']->src = $amp_template->get( 'amp_runtime_script' );
57
-
58
- // Make sure any filtered extension script URLs get updated in registered scripts before printing.
59
- $scripts = $amp_template->get( 'amp_component_scripts', array() );
60
- foreach ( $scripts as $handle => $value ) {
61
- if ( is_string( $value ) && wp_script_is( $handle, 'registered' ) ) {
62
- wp_scripts()->registered[ $handle ]->src = $value;
63
- }
64
- }
65
-
66
- wp_print_scripts( array_merge(
67
- array( 'amp-runtime' ),
68
- array_keys( $scripts )
69
- ) );
70
  }
71
 
72
  /**
51
  * @param AMP_Post_Template $amp_template Template.
52
  */
53
  function amp_post_template_add_scripts( $amp_template ) {
54
+ echo amp_render_scripts( array_merge(
55
+ array(
56
+ // Just in case the runtime has been overridden by amp_post_template_data filter.
57
+ 'amp-runtime' => $amp_template->get( 'amp_runtime_script' ),
58
+ ),
59
+ $amp_template->get( 'amp_component_scripts', array() )
60
+ ) ); // WPCS: xss ok.
 
 
 
 
 
 
 
 
 
61
  }
62
 
63
  /**
includes/class-amp-theme-support.php CHANGED
@@ -1133,32 +1133,8 @@ class AMP_Theme_Support {
1133
  );
1134
  }
1135
 
1136
- // Allow for embed handlers to override the default extension version by defining a different URL.
1137
- foreach ( $amp_scripts as $handle => $value ) {
1138
- if ( is_string( $value ) && wp_script_is( $handle, 'registered' ) ) {
1139
- wp_scripts()->registered[ $handle ]->src = $value;
1140
- }
1141
- }
1142
-
1143
- /*
1144
- * Inject additional AMP component scripts which have been discovered by the sanitizers into the head.
1145
- * This is adapted from wp_scripts()->do_items(), but it runs only the bare minimum required to output
1146
- * the missing scripts, without allowing other filters to apply which may cause an invalid AMP response.
1147
- */
1148
- $script_tags = '';
1149
- foreach ( array_diff( array_keys( $amp_scripts ), wp_scripts()->done ) as $handle ) {
1150
- if ( ! wp_script_is( $handle, 'registered' ) ) {
1151
- continue;
1152
- }
1153
- $script_dep = wp_scripts()->registered[ $handle ];
1154
- $script_tags .= amp_filter_script_loader_tag(
1155
- sprintf(
1156
- "<script type='text/javascript' src='%s'></script>\n", // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
1157
- esc_url( $script_dep->src )
1158
- ),
1159
- $handle
1160
- );
1161
- }
1162
  if ( ! empty( $script_tags ) ) {
1163
  $response = preg_replace(
1164
  '#(?=</head>)#',
1133
  );
1134
  }
1135
 
1136
+ // Inject additional AMP component scripts which have been discovered by the sanitizers into the head.
1137
+ $script_tags = amp_render_scripts( $amp_scripts );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1138
  if ( ! empty( $script_tags ) ) {
1139
  $response = preg_replace(
1140
  '#(?=</head>)#',
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: batmoo, joen, automattic, potatomaster, albertomedina, google, xwp
3
  Tags: amp, mobile
4
  Requires at least: 4.7
5
  Tested up to: 4.9
6
- Stable tag: 0.7.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.3
@@ -44,6 +44,14 @@ Follow along with or [contribute](https://github.com/Automattic/amp-wp/blob/deve
44
 
45
  == Changelog ==
46
 
 
 
 
 
 
 
 
 
47
  = 0.7.1 (2018-05-23) =
48
 
49
  - Limit showing AMP validation warnings to when `amp` theme support is present. See [#1132](https://github.com/Automattic/amp-wp/pull/1132). Props westonruter.
3
  Tags: amp, mobile
4
  Requires at least: 4.7
5
  Tested up to: 4.9
6
+ Stable tag: 0.7.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.3
44
 
45
  == Changelog ==
46
 
47
+ = 0.7.2 (2018-06-27) =
48
+
49
+ - Prevent plugins from outputting custom scripts in classic templates via `wp_print_scripts` action. See [#1225](https://github.com/Automattic/amp-wp/issues/1225), [#1227](https://github.com/Automattic/amp-wp/pull/1227). Props westonruter.
50
+ - Display Schema.org image data for 'attachment' post type. See [#1157](https://github.com/Automattic/amp-wp/issues/1157), [#1176](https://github.com/Automattic/amp-wp/pull/1176). Props kienstra.
51
+ - Output `alt` attribute in legacy templating gravatar image. See [#1179](https://github.com/Automattic/amp-wp/pull/1179). Props kienstra.
52
+
53
+ See [0.7.2 milestone](https://github.com/Automattic/amp-wp/milestone/9?closed=1).
54
+
55
  = 0.7.1 (2018-05-23) =
56
 
57
  - Limit showing AMP validation warnings to when `amp` theme support is present. See [#1132](https://github.com/Automattic/amp-wp/pull/1132). Props westonruter.
templates/meta-author.php CHANGED
@@ -2,7 +2,7 @@
2
  <?php if ( $post_author ) : ?>
3
  <div class="amp-wp-meta amp-wp-byline">
4
  <?php if ( function_exists( 'get_avatar_url' ) ) : ?>
5
- <amp-img src="<?php echo esc_url( get_avatar_url( $post_author->user_email, array( 'size' => 24 ) ) ); ?>" width="24" height="24" layout="fixed"></amp-img>
6
  <?php endif; ?>
7
  <span class="amp-wp-author author vcard"><?php echo esc_html( $post_author->display_name ); ?></span>
8
  </div>
2
  <?php if ( $post_author ) : ?>
3
  <div class="amp-wp-meta amp-wp-byline">
4
  <?php if ( function_exists( 'get_avatar_url' ) ) : ?>
5
+ <amp-img src="<?php echo esc_url( get_avatar_url( $post_author->user_email, array( 'size' => 24 ) ) ); ?>" alt="<?php echo esc_attr( $post_author->display_name ); ?>" width="24" height="24" layout="fixed"></amp-img>
6
  <?php endif; ?>
7
  <span class="amp-wp-author author vcard"><?php echo esc_html( $post_author->display_name ); ?></span>
8
  </div>