AMP for WordPress - Version 0.7.1

Version Description

(2018-05-23) =

  • Limit showing AMP validation warnings to when amp theme support is present. See #1132. Props westonruter.
  • Supply the extracted dimensions to images determined to need them; fixes regression from 0.6 this is key for Gutenberg compat. See #1117. Props westonruter.
  • Ensure before/after is amended to filtered comment_reply_link. See #1118. Props westonruter.
  • Force VideoPress to use html5 player for AMP. See #1125. Props yurynix.
  • Soft-deprecate AMP_Base_Sanitizer::get_body_node() instead of hard-deprecating it (with triggered notice). See #1141. Props westonruter.
  • Pass '/' as an argument to home_url(), preventing possible 404. See #1158, #1161. Props kienstra.
  • Deprecate Jetpack helper and some parts of WPCOM helper for Jetpack 6.2. See #1149. Props gravityrail.

See 0.7.1 milestone.

Download this release

Release Info

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

Code changes from version 0.7.0 to 0.7.1

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.0
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.0' );
36
 
37
  require_once AMP__DIR__ . '/includes/class-amp-autoloader.php';
38
  AMP_Autoloader::register();
@@ -110,7 +110,6 @@ function amp_init() {
110
 
111
  add_rewrite_endpoint( amp_get_slug(), EP_PERMALINK );
112
 
113
- AMP_Validation_Utils::init();
114
  AMP_Theme_Support::init();
115
  AMP_Post_Type_Support::add_post_type_support();
116
  add_filter( 'request', 'amp_force_query_var_value' );
@@ -122,7 +121,7 @@ function amp_init() {
122
  // Redirect the old url of amp page to the updated url.
123
  add_filter( 'old_slug_redirect_url', 'amp_redirect_old_slug_to_new_url' );
124
 
125
- if ( class_exists( 'Jetpack' ) && ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
126
  require_once AMP__DIR__ . '/jetpack-helper.php';
127
  }
128
 
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
 
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();
110
 
111
  add_rewrite_endpoint( amp_get_slug(), EP_PERMALINK );
112
 
 
113
  AMP_Theme_Support::init();
114
  AMP_Post_Type_Support::add_post_type_support();
115
  add_filter( 'request', 'amp_force_query_var_value' );
121
  // Redirect the old url of amp page to the updated url.
122
  add_filter( 'old_slug_redirect_url', 'amp_redirect_old_slug_to_new_url' );
123
 
124
+ if ( class_exists( 'Jetpack' ) && ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) && version_compare( JETPACK__VERSION, '6.2-alpha', '<' ) ) {
125
  require_once AMP__DIR__ . '/jetpack-helper.php';
126
  }
127
 
includes/class-amp-theme-support.php CHANGED
@@ -92,6 +92,8 @@ class AMP_Theme_Support {
92
  return;
93
  }
94
 
 
 
95
  self::purge_amp_query_vars();
96
  self::handle_xhr_request();
97
 
@@ -793,7 +795,7 @@ class AMP_Theme_Support {
793
 
794
  // Continue to show default link to wp-login when user is not logged-in.
795
  if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
796
- return $link;
797
  }
798
 
799
  $state_id = self::get_comment_form_state_id( get_the_ID() );
@@ -814,7 +816,7 @@ class AMP_Theme_Support {
814
  esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
815
  $args['reply_text']
816
  );
817
- return $link;
818
  }
819
 
820
  /**
92
  return;
93
  }
94
 
95
+ AMP_Validation_Utils::init();
96
+
97
  self::purge_amp_query_vars();
98
  self::handle_xhr_request();
99
 
795
 
796
  // Continue to show default link to wp-login when user is not logged-in.
797
  if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
798
+ return $args['before'] . $link . $args['after'];
799
  }
800
 
801
  $state_id = self::get_comment_form_state_id( get_the_ID() );
816
  esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
817
  $args['reply_text']
818
  );
819
+ return $args['before'] . $link . $args['after'];
820
  }
821
 
822
  /**
includes/sanitizers/class-amp-base-sanitizer.php CHANGED
@@ -159,11 +159,10 @@ abstract class AMP_Base_Sanitizer {
159
  * Get HTML body as DOMElement from DOMDocument received by the constructor.
160
  *
161
  * @deprecated Just reference $root_element instead.
162
- * @return DOMElement The body or html element.
163
  */
164
  protected function get_body_node() {
165
- _deprecated_function( __METHOD__, 'AMP_Base_Sanitizer::$root_element', '0.7' );
166
- return $this->root_element;
167
  }
168
 
169
  /**
@@ -247,7 +246,7 @@ abstract class AMP_Base_Sanitizer {
247
  */
248
  public function add_or_append_attribute( &$attributes, $key, $value, $separator = ' ' ) {
249
  if ( isset( $attributes[ $key ] ) ) {
250
- $attributes[ $key ] .= $separator . $value;
251
  } else {
252
  $attributes[ $key ] = $value;
253
  }
159
  * Get HTML body as DOMElement from DOMDocument received by the constructor.
160
  *
161
  * @deprecated Just reference $root_element instead.
162
+ * @return DOMElement The body element.
163
  */
164
  protected function get_body_node() {
165
+ return $this->dom->getElementsByTagName( 'body' )->item( 0 );
 
166
  }
167
 
168
  /**
246
  */
247
  public function add_or_append_attribute( &$attributes, $key, $value, $separator = ' ' ) {
248
  if ( isset( $attributes[ $key ] ) ) {
249
+ $attributes[ $key ] = trim( $attributes[ $key ] . $separator . $value );
250
  } else {
251
  $attributes[ $key ] = $value;
252
  }
includes/sanitizers/class-amp-img-sanitizer.php CHANGED
@@ -157,31 +157,48 @@ class AMP_Img_Sanitizer extends AMP_Base_Sanitizer {
157
  if ( ! $node instanceof DOMElement ) {
158
  continue;
159
  }
160
- if (
161
- ! is_numeric( $node->getAttribute( 'width' ) ) &&
162
- ! is_numeric( $node->getAttribute( 'height' ) )
163
- ) {
164
- $height = self::FALLBACK_HEIGHT;
165
- $width = self::FALLBACK_WIDTH;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  $node->setAttribute( 'width', $width );
 
 
 
 
 
 
 
 
 
 
 
167
  $node->setAttribute( 'height', $height );
168
- $class = $node->hasAttribute( 'class' ) ? $node->getAttribute( 'class' ) . ' amp-wp-unknown-size' : 'amp-wp-unknown-size';
169
- $node->setAttribute( 'class', $class );
170
- } elseif (
171
- ! is_numeric( $node->getAttribute( 'height' ) )
172
- ) {
173
- $height = self::FALLBACK_HEIGHT;
174
- $node->setAttribute( 'height', $height );
175
- $class = $node->hasAttribute( 'class' ) ? $node->getAttribute( 'class' ) . ' amp-wp-unknown-size amp-wp-unknown-height' : 'amp-wp-unknown-size amp-wp-unknown-height';
176
- $node->setAttribute( 'class', $class );
177
- } elseif (
178
- ! is_numeric( $node->getAttribute( 'width' ) )
179
- ) {
180
- $width = self::FALLBACK_WIDTH;
181
- $node->setAttribute( 'width', $width );
182
- $class = $node->hasAttribute( 'class' ) ? $node->getAttribute( 'class' ) . ' amp-wp-unknown-size amp-wp-unknown-width' : 'amp-wp-unknown-size amp-wp-unknown-width';
183
- $node->setAttribute( 'class', $class );
184
  }
 
185
  }
186
  }
187
  }
157
  if ( ! $node instanceof DOMElement ) {
158
  continue;
159
  }
160
+ $class = $node->getAttribute( 'class' );
161
+ if ( ! $class ) {
162
+ $class = '';
163
+ }
164
+ if ( ! $dimensions ) {
165
+ $class .= ' amp-wp-unknown-size';
166
+ }
167
+
168
+ $width = isset( $this->args['content_max_width'] ) ? $this->args['content_max_width'] : self::FALLBACK_WIDTH;
169
+ $height = self::FALLBACK_HEIGHT;
170
+ if ( isset( $dimensions['width'] ) ) {
171
+ $width = $dimensions['width'];
172
+ }
173
+ if ( isset( $dimensions['height'] ) ) {
174
+ $height = $dimensions['height'];
175
+ }
176
+
177
+ if ( ! is_numeric( $node->getAttribute( 'width' ) ) ) {
178
+
179
+ // Let width have the right aspect ratio based on the height attribute.
180
+ if ( is_numeric( $node->getAttribute( 'height' ) ) && isset( $dimensions['height'] ) && isset( $dimensions['width'] ) ) {
181
+ $width = ( floatval( $node->getAttribute( 'height' ) ) * $dimensions['width'] ) / $dimensions['height'];
182
+ }
183
+
184
  $node->setAttribute( 'width', $width );
185
+ if ( ! isset( $dimensions['width'] ) ) {
186
+ $class .= ' amp-wp-unknown-width';
187
+ }
188
+ }
189
+ if ( ! is_numeric( $node->getAttribute( 'height' ) ) ) {
190
+
191
+ // Let height have the right aspect ratio based on the width attribute.
192
+ if ( is_numeric( $node->getAttribute( 'width' ) ) && isset( $dimensions['width'] ) && isset( $dimensions['height'] ) ) {
193
+ $height = ( floatval( $node->getAttribute( 'width' ) ) * $dimensions['height'] ) / $dimensions['width'];
194
+ }
195
+
196
  $node->setAttribute( 'height', $height );
197
+ if ( ! isset( $dimensions['height'] ) ) {
198
+ $class .= ' amp-wp-unknown-height';
199
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  }
201
+ $node->setAttribute( 'class', trim( $class ) );
202
  }
203
  }
204
  }
includes/templates/class-amp-post-template.php CHANGED
@@ -113,7 +113,7 @@ class AMP_Post_Template {
113
 
114
  'document_title' => function_exists( 'wp_get_document_title' ) ? wp_get_document_title() : wp_title( '', false ), // Back-compat with 4.3.
115
  'canonical_url' => get_permalink( $this->ID ),
116
- 'home_url' => home_url(),
117
  'blog_name' => get_bloginfo( 'name' ),
118
 
119
  'html_tag_attributes' => array(),
113
 
114
  'document_title' => function_exists( 'wp_get_document_title' ) ? wp_get_document_title() : wp_title( '', false ), // Back-compat with 4.3.
115
  'canonical_url' => get_permalink( $this->ID ),
116
+ 'home_url' => home_url( '/' ),
117
  'blog_name' => get_bloginfo( 'name' ),
118
 
119
  'html_tag_attributes' => array(),
includes/utils/class-amp-validation-utils.php CHANGED
@@ -202,13 +202,10 @@ class AMP_Validation_Utils {
202
  * @return void
203
  */
204
  public static function init() {
205
- if ( current_theme_supports( 'amp' ) ) {
206
- add_action( 'init', array( __CLASS__, 'register_post_type' ) );
207
- add_filter( 'dashboard_glance_items', array( __CLASS__, 'filter_dashboard_glance_items' ) );
208
- add_action( 'rightnow_end', array( __CLASS__, 'print_dashboard_glance_styles' ) );
209
- add_action( 'save_post', array( __CLASS__, 'handle_save_post_prompting_validation' ), 10, 2 );
210
- }
211
-
212
  add_action( 'edit_form_top', array( __CLASS__, 'print_edit_form_validation_status' ), 10, 2 );
213
  add_action( 'all_admin_notices', array( __CLASS__, 'plugin_notice' ) );
214
  add_filter( 'manage_' . self::POST_TYPE_SLUG . '_posts_columns', array( __CLASS__, 'add_post_columns' ) );
@@ -535,64 +532,41 @@ class AMP_Validation_Utils {
535
  return;
536
  }
537
 
538
- $url = null;
539
- $validation_status_post = null;
540
- $validation_errors = array();
541
-
542
- // Incorporate frontend validation status if there is a known URL for the post.
543
- if ( is_post_type_viewable( $post->post_type ) ) {
544
- $url = amp_get_permalink( $post->ID );
545
-
546
- $validation_status_post = self::get_validation_status_post( $url );
547
- if ( $validation_status_post ) {
548
- $data = json_decode( $validation_status_post->post_content, true );
549
- if ( is_array( $data ) ) {
550
- $validation_errors = array_merge( $validation_errors, $data );
551
- }
552
- }
553
  }
554
 
555
- // If no results from URL are available, validate post content outside frontend context.
556
- if ( empty( $validation_errors ) && post_type_supports( $post->post_type, 'editor' ) ) {
557
- self::process_markup( $post->post_content );
558
- $validation_errors = array_merge(
559
- $validation_errors,
560
- self::$validation_errors
561
- );
562
- self::reset_validation_results();
563
 
564
- // Make sure original post is restored after applying shortcodes which could change it.
565
- $GLOBALS['post'] = $post; // WPCS: override ok.
566
- setup_postdata( $post );
567
  }
568
 
569
- if ( empty( $validation_errors ) ) {
 
 
 
570
  return;
571
  }
572
 
573
  echo '<div class="notice notice-warning">';
574
  echo '<p>';
575
  esc_html_e( 'Warning: There is content which fails AMP validation; it will be stripped when served as AMP.', 'amp' );
576
- if ( $validation_status_post || $url ) {
577
- if ( $validation_status_post ) {
578
- echo sprintf(
579
- ' <a href="%s" target="_blank">%s</a>',
580
- esc_url( get_edit_post_link( $validation_status_post ) ),
581
- esc_html__( 'Details', 'amp' )
582
- );
583
- }
584
- if ( $url ) {
585
- if ( $validation_status_post ) {
586
- echo ' | ';
587
- }
588
- echo sprintf(
589
- ' <a href="%s" aria-label="%s" target="_blank">%s</a>',
590
- esc_url( self::get_debug_url( $url ) ),
591
- esc_attr__( 'Validate URL on frontend but without invalid elements/attributes removed', 'amp' ),
592
- esc_html__( 'Debug', 'amp' )
593
- );
594
- }
595
- }
596
  echo '</p>';
597
 
598
  $results = self::summarize_validation_errors( array_unique( $validation_errors, SORT_REGULAR ) );
202
  * @return void
203
  */
204
  public static function init() {
205
+ add_action( 'init', array( __CLASS__, 'register_post_type' ) );
206
+ add_filter( 'dashboard_glance_items', array( __CLASS__, 'filter_dashboard_glance_items' ) );
207
+ add_action( 'rightnow_end', array( __CLASS__, 'print_dashboard_glance_styles' ) );
208
+ add_action( 'save_post', array( __CLASS__, 'handle_save_post_prompting_validation' ), 10, 2 );
 
 
 
209
  add_action( 'edit_form_top', array( __CLASS__, 'print_edit_form_validation_status' ), 10, 2 );
210
  add_action( 'all_admin_notices', array( __CLASS__, 'plugin_notice' ) );
211
  add_filter( 'manage_' . self::POST_TYPE_SLUG . '_posts_columns', array( __CLASS__, 'add_post_columns' ) );
532
  return;
533
  }
534
 
535
+ // Skip if the post type is not viewable on the frontend, since we need a permalink to validate.
536
+ if ( ! is_post_type_viewable( $post->post_type ) ) {
537
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
538
  }
539
 
540
+ $url = amp_get_permalink( $post->ID );
541
+ $validation_status_post = self::get_validation_status_post( $url );
 
 
 
 
 
 
542
 
543
+ // No validation status exists yet, so there is nothing to show.
544
+ if ( ! $validation_status_post ) {
545
+ return;
546
  }
547
 
548
+ $validation_errors = json_decode( $validation_status_post->post_content, true );
549
+
550
+ // No validation errors so abort.
551
+ if ( empty( $validation_errors ) || ! is_array( $validation_errors ) ) {
552
  return;
553
  }
554
 
555
  echo '<div class="notice notice-warning">';
556
  echo '<p>';
557
  esc_html_e( 'Warning: There is content which fails AMP validation; it will be stripped when served as AMP.', 'amp' );
558
+ echo sprintf(
559
+ ' <a href="%s" target="_blank">%s</a>',
560
+ esc_url( get_edit_post_link( $validation_status_post ) ),
561
+ esc_html__( 'Details', 'amp' )
562
+ );
563
+ echo ' | ';
564
+ echo sprintf(
565
+ ' <a href="%s" aria-label="%s" target="_blank">%s</a>',
566
+ esc_url( self::get_debug_url( $url ) ),
567
+ esc_attr__( 'Validate URL on frontend but without invalid elements/attributes removed', 'amp' ),
568
+ esc_html__( 'Debug', 'amp' )
569
+ );
 
 
 
 
 
 
 
 
570
  echo '</p>';
571
 
572
  $results = self::summarize_validation_errors( array_unique( $validation_errors, SORT_REGULAR ) );
jetpack-helper.php CHANGED
@@ -1,21 +1,35 @@
1
  <?php
 
 
 
 
 
 
2
 
3
- // Jetpack bits.
4
-
5
- add_action( 'pre_amp_render_post', 'amp_jetpack_mods' );
6
 
7
  /**
8
  * Disable Jetpack features that are not compatible with AMP.
9
  *
10
- **/
 
11
  function amp_jetpack_mods() {
 
 
 
12
  if ( Jetpack::is_module_active( 'stats' ) ) {
13
  add_action( 'amp_post_template_footer', 'jetpack_amp_add_stats_pixel' );
14
  }
15
  amp_jetpack_disable_sharing();
16
  amp_jetpack_disable_related_posts();
 
17
  }
18
 
 
 
 
 
 
19
  function amp_jetpack_disable_sharing() {
20
  add_filter( 'sharing_show', '__return_false', 100 );
21
  }
@@ -25,7 +39,8 @@ function amp_jetpack_disable_sharing() {
25
  *
26
  * That placeholder is useless since we can't ouput, and don't want to output Related Posts in AMP.
27
  *
28
- **/
 
29
  function amp_jetpack_disable_related_posts() {
30
  if ( class_exists( 'Jetpack_RelatedPosts' ) ) {
31
  $jprp = Jetpack_RelatedPosts::init();
@@ -33,7 +48,12 @@ function amp_jetpack_disable_related_posts() {
33
  }
34
  }
35
 
36
- function jetpack_amp_add_stats_pixel( $amp_template ) {
 
 
 
 
 
37
  if ( ! has_action( 'wp_footer', 'stats_footer' ) ) {
38
  return;
39
  }
@@ -47,25 +67,41 @@ function jetpack_amp_add_stats_pixel( $amp_template ) {
47
  *
48
  * Looks something like:
49
  * https://pixel.wp.com/g.gif?v=ext&j=1%3A3.9.1&blog=1234&post=5678&tz=-4&srv=example.com&host=example.com&ref=&rand=0.4107963021218808
 
 
50
  */
51
  function jetpack_amp_build_stats_pixel_url() {
52
  global $wp_the_query;
53
- if ( function_exists( 'stats_build_view_data' ) ) { // added in https://github.com/Automattic/jetpack/pull/3445
54
  $data = stats_build_view_data();
55
  } else {
56
- $blog = Jetpack_Options::get_option( 'id' );
57
- $tz = get_option( 'gmt_offset' );
58
- $v = 'ext';
59
- $blog_url = AMP_WP_Utils::parse_url( site_url() );
60
- $srv = $blog_url['host'];
61
- $j = sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION );
62
- $post = $wp_the_query->get_queried_object_id();
63
- $data = compact( 'v', 'j', 'blog', 'post', 'tz', 'srv' );
64
  }
65
 
66
- $data['host'] = isset( $_SERVER['HTTP_HOST'] ) ? rawurlencode( $_SERVER['HTTP_HOST'] ) : ''; // input var ok
67
- $data['rand'] = 'RANDOM'; // amp placeholder
68
- $data['ref'] = 'DOCUMENT_REFERRER'; // amp placeholder
69
- $data = array_map( 'rawurlencode' , $data );
70
  return add_query_arg( $data, 'https://pixel.wp.com/g.gif' );
71
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+ /**
3
+ * Jetpack bits.
4
+ *
5
+ * @todo Move this into Jetpack. See https://github.com/Automattic/amp-wp/issues/1021
6
+ * @package AMP
7
+ */
8
 
9
+ add_action( 'template_redirect', 'amp_jetpack_mods', 9 );
 
 
10
 
11
  /**
12
  * Disable Jetpack features that are not compatible with AMP.
13
  *
14
+ * @since 0.2
15
+ */
16
  function amp_jetpack_mods() {
17
+ if ( ! is_amp_endpoint() ) {
18
+ return;
19
+ }
20
  if ( Jetpack::is_module_active( 'stats' ) ) {
21
  add_action( 'amp_post_template_footer', 'jetpack_amp_add_stats_pixel' );
22
  }
23
  amp_jetpack_disable_sharing();
24
  amp_jetpack_disable_related_posts();
25
+ add_filter( 'videopress_shortcode_options', 'amp_videopress_enable_freedom_mode' );
26
  }
27
 
28
+ /**
29
+ * Disable Jetpack sharing.
30
+ *
31
+ * @since 0.3
32
+ */
33
  function amp_jetpack_disable_sharing() {
34
  add_filter( 'sharing_show', '__return_false', 100 );
35
  }
39
  *
40
  * That placeholder is useless since we can't ouput, and don't want to output Related Posts in AMP.
41
  *
42
+ * @since 0.2
43
+ */
44
  function amp_jetpack_disable_related_posts() {
45
  if ( class_exists( 'Jetpack_RelatedPosts' ) ) {
46
  $jprp = Jetpack_RelatedPosts::init();
48
  }
49
  }
50
 
51
+ /**
52
+ * Add Jetpack stats pixel.
53
+ *
54
+ * @since 0.3.2
55
+ */
56
+ function jetpack_amp_add_stats_pixel() {
57
  if ( ! has_action( 'wp_footer', 'stats_footer' ) ) {
58
  return;
59
  }
67
  *
68
  * Looks something like:
69
  * https://pixel.wp.com/g.gif?v=ext&j=1%3A3.9.1&blog=1234&post=5678&tz=-4&srv=example.com&host=example.com&ref=&rand=0.4107963021218808
70
+ *
71
+ * @since 0.3.2
72
  */
73
  function jetpack_amp_build_stats_pixel_url() {
74
  global $wp_the_query;
75
+ if ( function_exists( 'stats_build_view_data' ) ) { // Added in <https://github.com/Automattic/jetpack/pull/3445>.
76
  $data = stats_build_view_data();
77
  } else {
78
+ $blog = Jetpack_Options::get_option( 'id' );
79
+ $tz = get_option( 'gmt_offset' );
80
+ $v = 'ext';
81
+ $blog_url = wp_parse_url( site_url() );
82
+ $srv = $blog_url['host'];
83
+ $j = sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION );
84
+ $post = $wp_the_query->get_queried_object_id();
85
+ $data = compact( 'v', 'j', 'blog', 'post', 'tz', 'srv' );
86
  }
87
 
88
+ $data['host'] = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : ''; // input var ok.
89
+ $data['rand'] = 'RANDOM'; // AMP placeholder.
90
+ $data['ref'] = 'DOCUMENT_REFERRER'; // AMP placeholder.
91
+ $data = array_map( 'rawurlencode', $data );
92
  return add_query_arg( $data, 'https://pixel.wp.com/g.gif' );
93
  }
94
+
95
+ /**
96
+ * Force videopress to use html5 player that would generate <video /> tag
97
+ * that will be later converted to <amp-video />
98
+ *
99
+ * @since 0.7.1
100
+ *
101
+ * @param array $options videopress shortcode options.
102
+ * @return array videopress shortcode options with `freedom` set to true
103
+ */
104
+ function amp_videopress_enable_freedom_mode( $options ) {
105
+ $options['freedom'] = true;
106
+ return $options;
107
+ }
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.0
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,18 @@ Follow along with or [contribute](https://github.com/Automattic/amp-wp/blob/deve
44
 
45
  == Changelog ==
46
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  = 0.7.0 (2018-05-03) =
48
 
49
  - Render an entire site as "Native AMP" if the theme calls `add_theme_support( 'amp' )`. See [#857](https://github.com/Automattic/amp-wp/pull/857), [#852](https://github.com/Automattic/amp-wp/pull/852), [#865](https://github.com/Automattic/amp-wp/pull/865), [#888](https://github.com/Automattic/amp-wp/pull/888). Props westonruter, kaitnyl, ThierryA.
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
 
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.
50
+ - Supply the extracted dimensions to images determined to need them; fixes regression from 0.6 this is key for Gutenberg compat. See [#1117](https://github.com/Automattic/amp-wp/pull/1117). Props westonruter.
51
+ - Ensure before/after is amended to filtered comment_reply_link. See [#1118](https://github.com/Automattic/amp-wp/pull/1118). Props westonruter.
52
+ - Force VideoPress to use html5 player for AMP. See [#1125](https://github.com/Automattic/amp-wp/pull/1125). Props yurynix.
53
+ - Soft-deprecate `AMP_Base_Sanitizer::get_body_node()` instead of hard-deprecating it (with triggered notice). See [#1141](https://github.com/Automattic/amp-wp/pull/1141). Props westonruter.
54
+ - Pass '/' as an argument to home_url(), preventing possible 404. See [#1158](https://github.com/Automattic/amp-wp/issues/1158), [#1161](https://github.com/Automattic/amp-wp/pull/1161). Props kienstra.
55
+ - Deprecate Jetpack helper and some parts of WPCOM helper for Jetpack 6.2. See [#1149](https://github.com/Automattic/amp-wp/pull/1149). Props gravityrail.
56
+
57
+ See [0.7.1 milestone](https://github.com/Automattic/amp-wp/milestone/8?closed=1).
58
+
59
  = 0.7.0 (2018-05-03) =
60
 
61
  - Render an entire site as "Native AMP" if the theme calls `add_theme_support( 'amp' )`. See [#857](https://github.com/Automattic/amp-wp/pull/857), [#852](https://github.com/Automattic/amp-wp/pull/852), [#865](https://github.com/Automattic/amp-wp/pull/865), [#888](https://github.com/Automattic/amp-wp/pull/888). Props westonruter, kaitnyl, ThierryA.
wpcom-helper.php CHANGED
@@ -6,154 +6,9 @@
6
  * @package AMP
7
  */
8
 
9
- add_action( 'pre_amp_render_post', 'jetpack_amp_disable_the_content_filters' );
10
-
11
  // Disable admin menu.
12
  add_filter( 'amp_options_menu_is_enabled', '__return_false', 9999 );
13
 
14
- /**
15
- * Disable the_content filters for Jetpack.
16
- *
17
- * @since 0.3
18
- */
19
- function jetpack_amp_disable_the_content_filters() {
20
- add_filter( 'post_flair_disable', '__return_true', 99 );
21
- add_filter( 'videopress_show_2015_player', '__return_true' );
22
- add_filter( 'protected_embeds_use_form_post', '__return_false' );
23
-
24
- remove_filter( 'the_title', 'widont' );
25
-
26
- remove_filter( 'pre_kses', array( 'Filter_Embedded_HTML_Objects', 'filter' ), 11 );
27
- remove_filter( 'pre_kses', array( 'Filter_Embedded_HTML_Objects', 'maybe_create_links' ), 100 );
28
- }
29
-
30
- add_action( 'amp_post_template_head', 'jetpack_amp_add_og_tags' );
31
-
32
- /**
33
- * Add Open Graph tags.
34
- *
35
- * @since 0.3
36
- */
37
- function jetpack_amp_add_og_tags() {
38
- if ( function_exists( 'jetpack_og_tags' ) ) {
39
- jetpack_og_tags();
40
- }
41
- }
42
-
43
- add_filter( 'amp_post_template_metadata', 'jetpack_amp_post_template_metadata', 10, 2 );
44
-
45
- /**
46
- * Add publisher and image metadata.
47
- *
48
- * @since 0.3
49
- *
50
- * @param array $metadata Metadata array.
51
- * @param WP_Post $post Post.
52
- * @return array Modified metadata array.
53
- */
54
- function jetpack_amp_post_template_metadata( $metadata, $post ) {
55
- if ( isset( $metadata['publisher'] ) && ! isset( $metadata['publisher']['logo'] ) ) {
56
- $metadata = wpcom_amp_add_blavatar_to_metadata( $metadata );
57
- }
58
-
59
- if ( ! isset( $metadata['image'] ) ) {
60
- $metadata = wpcom_amp_add_image_to_metadata( $metadata, $post );
61
- }
62
-
63
- return $metadata;
64
- }
65
-
66
- /**
67
- * Add blavatar to metadata.
68
- *
69
- * @since 0.3
70
- *
71
- * @param array $metadata Metadata.
72
- * @return array Metadata.
73
- */
74
- function wpcom_amp_add_blavatar_to_metadata( $metadata ) {
75
- if ( ! function_exists( 'blavatar_domain' ) ) {
76
- return $metadata;
77
- }
78
-
79
- $size = 60;
80
-
81
- $metadata['publisher']['logo'] = array(
82
- '@type' => 'ImageObject',
83
- 'url' => blavatar_url( blavatar_domain( site_url() ), 'img', $size, staticize_subdomain( 'https://wordpress.com/i/favicons/apple-touch-icon-60x60.png' ) ),
84
- 'width' => $size,
85
- 'height' => $size,
86
- );
87
-
88
- return $metadata;
89
- }
90
-
91
- /**
92
- * Add image to metadata.
93
- *
94
- * @since 0.3.2
95
- *
96
- * @param array $metadata Metadata.
97
- * @param WP_Post $post Post.
98
- * @return array Metadata.
99
- */
100
- function wpcom_amp_add_image_to_metadata( $metadata, $post ) {
101
- if ( ! class_exists( 'Jetpack_PostImages' ) ) {
102
- return wpcom_amp_add_fallback_image_to_metadata( $metadata );
103
- }
104
-
105
- $image = Jetpack_PostImages::get_image( $post->ID, array(
106
- 'fallback_to_avatars' => true,
107
- 'avatar_size' => 200,
108
- // AMP already attempts these.
109
- 'from_thumbnail' => false,
110
- 'from_attachment' => false,
111
- ) );
112
-
113
- if ( empty( $image ) ) {
114
- return wpcom_amp_add_fallback_image_to_metadata( $metadata );
115
- }
116
-
117
- if ( ! isset( $image['src_width'] ) ) {
118
- $dimensions = wpcom_amp_extract_image_dimensions_from_getimagesize( array(
119
- $image['src'] => false,
120
- ) );
121
-
122
- if ( false !== $dimensions[ $image['src'] ] ) {
123
- $image['src_width'] = $dimensions['width'];
124
- $image['src_height'] = $dimensions['height'];
125
- }
126
- }
127
-
128
- $metadata['image'] = array(
129
- '@type' => 'ImageObject',
130
- 'url' => $image['src'],
131
- 'width' => $image['src_width'],
132
- 'height' => $image['src_height'],
133
- );
134
-
135
- return $metadata;
136
- }
137
-
138
- /**
139
- * Add fallback image to metadata.
140
- *
141
- * @since 0.3.2
142
- *
143
- * @param array $metadata Metadata.
144
- * @return array Metadata.
145
- */
146
- function wpcom_amp_add_fallback_image_to_metadata( $metadata ) {
147
- $metadata['image'] = array(
148
- '@type' => 'ImageObject',
149
- 'url' => staticize_subdomain( 'https://wordpress.com/i/blank.jpg' ),
150
- 'width' => 200,
151
- 'height' => 200,
152
- );
153
-
154
- return $metadata;
155
- }
156
-
157
  add_action( 'amp_extract_image_dimensions_batch_callbacks_registered', 'wpcom_amp_extract_image_dimensions_batch_add_custom_callbacks' );
158
 
159
  /**
6
  * @package AMP
7
  */
8
 
 
 
9
  // Disable admin menu.
10
  add_filter( 'amp_options_menu_is_enabled', '__return_false', 9999 );
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  add_action( 'amp_extract_image_dimensions_batch_callbacks_registered', 'wpcom_amp_extract_image_dimensions_batch_add_custom_callbacks' );
13
 
14
  /**