AMP for WordPress - Version 0.4.1

Version Description

(2016-10-10 =

  • Fix: Don't fire the_content for featured image output
  • Fix: Don't show comment link when disabled and no comments on post (h/t neotrope)
  • Fix: strip !important from inline styles (h/t compointdesigner and enriccardonagmailcom)
Download this release

Release Info

Developer batmoo
Plugin Icon 128x128 AMP for WordPress
Version 0.4.1
Comparing to
See all releases

Code changes from version 0.4 to 0.4.1

amp.php CHANGED
@@ -5,7 +5,7 @@
5
  * Plugin URI: https://github.com/automattic/amp-wp
6
  * Author: Automattic
7
  * Author URI: https://automattic.com
8
- * Version: 0.4
9
  * Text Domain: amp
10
  * Domain Path: /languages/
11
  * License: GPLv2 or later
@@ -13,7 +13,7 @@
13
 
14
  define( 'AMP__FILE__', __FILE__ );
15
  define( 'AMP__DIR__', dirname( __FILE__ ) );
16
- define( 'AMP__VERSION', '0.4' );
17
 
18
  require_once( AMP__DIR__ . '/back-compat/back-compat.php' );
19
  require_once( AMP__DIR__ . '/includes/amp-helper-functions.php' );
5
  * Plugin URI: https://github.com/automattic/amp-wp
6
  * Author: Automattic
7
  * Author URI: https://automattic.com
8
+ * Version: 0.4.1
9
  * Text Domain: amp
10
  * Domain Path: /languages/
11
  * License: GPLv2 or later
13
 
14
  define( 'AMP__FILE__', __FILE__ );
15
  define( 'AMP__DIR__', dirname( __FILE__ ) );
16
+ define( 'AMP__VERSION', '0.4.1' );
17
 
18
  require_once( AMP__DIR__ . '/back-compat/back-compat.php' );
19
  require_once( AMP__DIR__ . '/includes/amp-helper-functions.php' );
includes/class-amp-content.php CHANGED
@@ -82,10 +82,28 @@ class AMP_Content {
82
  }
83
 
84
  private function sanitize( $content ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  $dom = AMP_DOM_Utils::get_dom_from_content( $content );
86
 
87
- foreach ( $this->sanitizer_classes as $sanitizer_class => $args ) {
88
- $sanitizer = new $sanitizer_class( $dom, array_merge( $this->args, $args ) );
 
 
 
 
 
89
 
90
  if ( ! is_subclass_of( $sanitizer, 'AMP_Base_Sanitizer' ) ) {
91
  _doing_it_wrong( __METHOD__, sprintf( __( 'Sanitizer (%s) must extend `AMP_Base_Sanitizer`', 'amp' ), esc_html( $sanitizer_class ) ), '0.1' );
@@ -93,10 +111,13 @@ class AMP_Content {
93
  }
94
 
95
  $sanitizer->sanitize();
96
- $this->add_scripts( $sanitizer->get_scripts() );
97
- $this->add_styles( $sanitizer->get_styles() );
 
98
  }
99
 
100
- return AMP_DOM_Utils::get_content_from_dom( $dom );
 
 
101
  }
102
  }
82
  }
83
 
84
  private function sanitize( $content ) {
85
+ list( $sanitized_content, $scripts, $styles ) = AMP_Content_Sanitizer::sanitize( $content, $this->sanitizer_classes, $this->args );
86
+
87
+ $this->add_scripts( $scripts );
88
+ $this->add_styles( $styles );
89
+
90
+ return $sanitized_content;
91
+ }
92
+ }
93
+
94
+ class AMP_Content_Sanitizer {
95
+ public static function sanitize( $content, $sanitizer_classes, $args = array() ) {
96
+ $scripts = array();
97
+ $styles = array();
98
  $dom = AMP_DOM_Utils::get_dom_from_content( $content );
99
 
100
+ foreach ( $sanitizer_classes as $sanitizer_class => $args ) {
101
+ if ( ! class_exists( $sanitizer_class ) ) {
102
+ _doing_it_wrong( __METHOD__, sprintf( __( 'Sanitizer (%s) class does not exist', 'amp' ), esc_html( $sanitizer_class ) ), '0.4.1' );
103
+ continue;
104
+ }
105
+
106
+ $sanitizer = new $sanitizer_class( $dom, array_merge( $args, $args ) );
107
 
108
  if ( ! is_subclass_of( $sanitizer, 'AMP_Base_Sanitizer' ) ) {
109
  _doing_it_wrong( __METHOD__, sprintf( __( 'Sanitizer (%s) must extend `AMP_Base_Sanitizer`', 'amp' ), esc_html( $sanitizer_class ) ), '0.1' );
111
  }
112
 
113
  $sanitizer->sanitize();
114
+
115
+ $scripts = array_merge( $scripts, $sanitizer->get_scripts() );
116
+ $styles = array_merge( $styles, $sanitizer->get_styles() );
117
  }
118
 
119
+ $sanitized_content = AMP_DOM_Utils::get_content_from_dom( $dom );
120
+
121
+ return array( $sanitized_content, $scripts, $styles );
122
  }
123
  }
includes/class-amp-post-template.php CHANGED
@@ -196,8 +196,16 @@ class AMP_Post_Template {
196
  return;
197
  }
198
 
 
 
 
 
 
 
 
 
199
  $comments_link_url = get_comments_link( $this->ID );
200
- $comments_link_text = comments_open( $this->ID )
201
  ? __( 'Leave a Comment', 'amp' )
202
  : __( 'View Comments', 'amp' );
203
 
@@ -259,21 +267,16 @@ class AMP_Post_Template {
259
 
260
  $featured_image = get_post( $featured_id );
261
 
262
- remove_filter( 'the_content', 'wpautop' ); // We don't want our image wrapped in a <p>
263
- $featured_amp_content = new AMP_Content(
264
  $featured_html,
265
- array(),
266
  array(
267
- 'AMP_Img_Sanitizer' => array(),
268
- ),
269
- array(
270
- 'content_max_width' => $this->get( 'content_max_width' ),
271
  )
272
  );
273
- add_filter( 'the_content', 'wpautop' );
274
 
275
  $this->add_data_by_key( 'featured_image', array(
276
- 'amp_html' => $featured_amp_content->get_amp_content(),
277
  'caption' => $featured_image->post_excerpt,
278
  ) );
279
  }
196
  return;
197
  }
198
 
199
+ $comments_open = comments_open( $this->ID );
200
+
201
+ // Don't show link if close and no comments
202
+ if ( ! $comments_open
203
+ && ! $this->post->comment_count ) {
204
+ return;
205
+ }
206
+
207
  $comments_link_url = get_comments_link( $this->ID );
208
+ $comments_link_text = $comments_open
209
  ? __( 'Leave a Comment', 'amp' )
210
  : __( 'View Comments', 'amp' );
211
 
267
 
268
  $featured_image = get_post( $featured_id );
269
 
270
+ list( $sanitized_html ) = AMP_Content_Sanitizer::sanitize(
 
271
  $featured_html,
272
+ array( 'AMP_Img_Sanitizer' => array() ),
273
  array(
274
+ 'content_max_width' => $this->get( 'content_max_width' )
 
 
 
275
  )
276
  );
 
277
 
278
  $this->add_data_by_key( 'featured_image', array(
279
+ 'amp_html' => $sanitized_html,
280
  'caption' => $featured_image->post_excerpt,
281
  ) );
282
  }
includes/sanitizers/class-amp-style-sanitizer.php CHANGED
@@ -93,6 +93,11 @@ class AMP_Style_Sanitizer extends AMP_Base_Sanitizer {
93
  $property = 'max-width';
94
  }
95
 
 
 
 
 
 
96
  return array( $property, $value );
97
  }
98
 
93
  $property = 'max-width';
94
  }
95
 
96
+ // !important is not allowed
97
+ if ( false !== strpos( $value, 'important' ) ) {
98
+ $value = preg_replace( '/\s*\!\s*important$/', '', $value );
99
+ }
100
+
101
  return array( $property, $value );
102
  }
103
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: batmoo, joen, automattic, potatomaster
3
  Tags: amp, mobile
4
  Requires at least: 4.4
5
  Tested up to: 4.6
6
- Stable tag: 0.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -53,9 +53,16 @@ A wise green Yoda once said, "Patience you must have, my young padawan." We're w
53
 
54
  == Changelog ==
55
 
 
 
 
 
 
 
56
  = 0.4 (2016-10-06) =
57
 
58
  - New template: spiffy, shiny, and has the fresh theme smell (props allancole and the Automattic Theme Team).
 
59
  - AMP Customizer: Pick your colours and make the template your own (props DrewAPicture and 10up)
60
  - Fix: support for inline styles (props coreymckrill).
61
  - Fix: no more fatal errors when tags not supported by post type (props david-binda)
3
  Tags: amp, mobile
4
  Requires at least: 4.4
5
  Tested up to: 4.6
6
+ Stable tag: 0.4.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
53
 
54
  == Changelog ==
55
 
56
+ = 0.4.1 (2016-10-10 =
57
+
58
+ - Fix: Don't fire the_content for featured image output
59
+ - Fix: Don't show comment link when disabled and no comments on post (h/t neotrope)
60
+ - Fix: strip `!important` from inline styles (h/t compointdesigner and enriccardonagmailcom)
61
+
62
  = 0.4 (2016-10-06) =
63
 
64
  - New template: spiffy, shiny, and has the fresh theme smell (props allancole and the Automattic Theme Team).
65
+ - *Warning*: The template update has potential breaking changes. Please see https://wordpress.org/support/topic/v0-4-whats-new-and-possible-breaking-changes/
66
  - AMP Customizer: Pick your colours and make the template your own (props DrewAPicture and 10up)
67
  - Fix: support for inline styles (props coreymckrill).
68
  - Fix: no more fatal errors when tags not supported by post type (props david-binda)