Glue for Yoast SEO & AMP - Version 0.4.0

Version Description

  • Bugfixes:

    • Removed page from post-type list to avoid unwanted canonical link.
  • Enhancements:

    • Removed canonical feature because it is being handled by the AMP plugin.
    • Removed sanitizations which are already being done by the AMP plugin.
    • Added a check for Monster Insights analytics implementation and disables our implementation if present.
    • Added class selector implementation for AMP 0.4.x compatibility.
Download this release

Release Info

Developer jipmoors
Plugin Icon 128x128 Glue for Yoast SEO & AMP
Version 0.4.0
Comparing to
See all releases

Code changes from version 0.3.3 to 0.4.0

classes/class-backend.php CHANGED
@@ -28,6 +28,23 @@ if ( ! class_exists( 'YoastSEO_AMP_Backend', false ) ) {
28
 
29
  // Register AMP admin page as a Yoast SEO admin page
30
  add_filter( 'wpseo_admin_pages', array( $this, 'add_admin_pages' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
32
 
33
  /**
28
 
29
  // Register AMP admin page as a Yoast SEO admin page
30
  add_filter( 'wpseo_admin_pages', array( $this, 'add_admin_pages' ) );
31
+
32
+ add_filter( 'wpseo_amp_supported_post_types', array( $this, 'remove_page_post_type' ) );
33
+ }
34
+
35
+ /**
36
+ * Filters out page post-type if not enabled in the AMP plugin.
37
+ *
38
+ * @param array $post_types Post types enabled for AMP support.
39
+ *
40
+ * @return array
41
+ */
42
+ public function remove_page_post_type( $post_types ) {
43
+ if ( ! post_type_supports( 'page', AMP_QUERY_VAR ) ) {
44
+ unset( $post_types[ 'page' ] );
45
+ }
46
+
47
+ return $post_types;
48
  }
49
 
50
  /**
classes/class-frontend.php CHANGED
@@ -74,7 +74,15 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
74
  * @return array
75
  */
76
  public function analytics( $analytics ) {
77
- if ( isset( $this->options['analytics-extra'] ) && ! empty( $this->options['analytics-extra'] ) ) {
 
 
 
 
 
 
 
 
78
  return $analytics;
79
  }
80
 
@@ -116,6 +124,11 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
116
  continue;
117
  }
118
 
 
 
 
 
 
119
  if ( $this->options[ 'post_types-' . $post_type_name . '-amp' ] === 'on' ) {
120
  add_post_type_support( $post_type_name, AMP_QUERY_VAR );
121
  continue;
@@ -146,7 +159,6 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
146
  * @return array
147
  */
148
  public function fix_amp_post_data( $data ) {
149
- $data['canonical_url'] = $this->front->canonical( false );
150
  if ( ! empty( $this->options['amp_site_icon'] ) ) {
151
  $data['site_icon_url'] = $this->options['amp_site_icon'];
152
  }
@@ -162,7 +174,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
162
  /**
163
  * Fix the AMP metadata for a post
164
  *
165
- * @param array $metadata
166
  * @param WP_Post $post
167
  *
168
  * @return array
@@ -189,27 +201,28 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
189
  * Add additional CSS to the AMP output
190
  */
191
  public function additional_css() {
192
-
193
  require 'views/additional-css.php';
194
 
 
 
195
  $css_builder = new YoastSEO_AMP_CSS_Builder();
196
- $css_builder->add_option( 'header-color', 'nav.amp-wp-title-bar', 'background' );
197
- $css_builder->add_option( 'headings-color', '.amp-wp-title, h2, h3, h4', 'color' );
198
- $css_builder->add_option( 'text-color', '.amp-wp-content', 'color' );
199
 
200
- $css_builder->add_option( 'blockquote-bg-color', '.amp-wp-content blockquote', 'background-color' );
201
- $css_builder->add_option( 'blockquote-border-color', '.amp-wp-content blockquote', 'border-color' );
202
- $css_builder->add_option( 'blockquote-text-color', '.amp-wp-content blockquote', 'color' );
203
 
204
- $css_builder->add_option( 'link-color', 'a, a:active, a:visited', 'color' );
205
- $css_builder->add_option( 'link-color-hover', 'a:hover, a:focus', 'color' );
206
 
207
- $css_builder->add_option( 'meta-color', '.amp-wp-meta li, .amp-wp-meta li a', 'color' );
208
 
209
  echo $css_builder->build();
210
 
211
  if ( ! empty( $this->options['extra-css'] ) ) {
212
- $safe_text = strip_tags($this->options['extra-css']);
213
  $safe_text = wp_check_invalid_utf8( $safe_text );
214
  $safe_text = _wp_specialchars( $safe_text, ENT_NOQUOTES );
215
  echo $safe_text;
@@ -263,8 +276,8 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
263
  /**
264
  * Builds an image object array from an image URL
265
  *
266
- * @param string $image_url
267
- * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width
268
  * and height values in pixels (in that order). Default 'full'.
269
  *
270
  * @return array|false
@@ -292,8 +305,8 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
292
  /**
293
  * Retrieve the Schema.org image for the post
294
  *
295
- * @param WP_Post $post
296
- * @param array|null $image The currently set post image
297
  *
298
  * @return array
299
  */
@@ -335,5 +348,42 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
335
 
336
  return $type;
337
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
  }
339
  }
74
  * @return array
75
  */
76
  public function analytics( $analytics ) {
77
+ // If Monster Insights is outputting analytics, don't do anything.
78
+ if ( ! empty( $analytics['monsterinsights-googleanalytics'] ) ) {
79
+ // Clear analytics-extra options because Monster Insights is taking care of everything.
80
+ $this->options['analytics-extra'] = '';
81
+
82
+ return $analytics;
83
+ }
84
+
85
+ if ( ! empty( $this->options['analytics-extra'] ) ) {
86
  return $analytics;
87
  }
88
 
124
  continue;
125
  }
126
 
127
+ // If AMP page support is not present, don't allow enabling it here.
128
+ if ( 'page' === $post_type_name && ! post_type_supports( 'page', AMP_QUERY_VAR ) ) {
129
+ continue;
130
+ }
131
+
132
  if ( $this->options[ 'post_types-' . $post_type_name . '-amp' ] === 'on' ) {
133
  add_post_type_support( $post_type_name, AMP_QUERY_VAR );
134
  continue;
159
  * @return array
160
  */
161
  public function fix_amp_post_data( $data ) {
 
162
  if ( ! empty( $this->options['amp_site_icon'] ) ) {
163
  $data['site_icon_url'] = $this->options['amp_site_icon'];
164
  }
174
  /**
175
  * Fix the AMP metadata for a post
176
  *
177
+ * @param array $metadata
178
  * @param WP_Post $post
179
  *
180
  * @return array
201
  * Add additional CSS to the AMP output
202
  */
203
  public function additional_css() {
 
204
  require 'views/additional-css.php';
205
 
206
+ $selectors = $this->get_class_selectors();
207
+
208
  $css_builder = new YoastSEO_AMP_CSS_Builder();
209
+ $css_builder->add_option( 'header-color', $selectors[ 'header-color' ], 'background' );
210
+ $css_builder->add_option( 'headings-color', $selectors[ 'headings-color' ], 'color' );
211
+ $css_builder->add_option( 'text-color', $selectors[ 'text-color' ], 'color' );
212
 
213
+ $css_builder->add_option( 'blockquote-bg-color', $selectors[ 'blockquote-bg-color' ], 'background-color' );
214
+ $css_builder->add_option( 'blockquote-border-color', $selectors[ 'blockquote-border-color' ], 'border-color' );
215
+ $css_builder->add_option( 'blockquote-text-color', $selectors[ 'blockquote-text-color' ], 'color' );
216
 
217
+ $css_builder->add_option( 'link-color', $selectors[ 'link-color' ], 'color' );
218
+ $css_builder->add_option( 'link-color-hover', $selectors[ 'link-color-hover' ], 'color' );
219
 
220
+ $css_builder->add_option( 'meta-color', $selectors[ 'meta-color' ], 'color' );
221
 
222
  echo $css_builder->build();
223
 
224
  if ( ! empty( $this->options['extra-css'] ) ) {
225
+ $safe_text = strip_tags( $this->options['extra-css'] );
226
  $safe_text = wp_check_invalid_utf8( $safe_text );
227
  $safe_text = _wp_specialchars( $safe_text, ENT_NOQUOTES );
228
  echo $safe_text;
276
  /**
277
  * Builds an image object array from an image URL
278
  *
279
+ * @param string $image_url Image URL to build URL for.
280
+ * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width
281
  * and height values in pixels (in that order). Default 'full'.
282
  *
283
  * @return array|false
305
  /**
306
  * Retrieve the Schema.org image for the post
307
  *
308
+ * @param WP_Post $post Post to retrieve the data for.
309
+ * @param array|null $image The currently set post image.
310
  *
311
  * @return array
312
  */
348
 
349
  return $type;
350
  }
351
+
352
+ /**
353
+ * Gets version dependent class names
354
+ *
355
+ * @return array
356
+ */
357
+ private function get_class_selectors() {
358
+ $selectors = array(
359
+ 'header-color' => 'nav.amp-wp-title-bar',
360
+ 'headings-color' => '.amp-wp-title, h2, h3, h4',
361
+ 'text-color' => '.amp-wp-content',
362
+
363
+ 'blockquote-bg-color' => '.amp-wp-content blockquote',
364
+ 'blockquote-border-color' => '.amp-wp-content blockquote',
365
+ 'blockquote-text-color' => '.amp-wp-content blockquote',
366
+
367
+ 'link-color' => 'a, a:active, a:visited',
368
+ 'link-color-hover' => 'a:hover, a:focus',
369
+
370
+ 'meta-color' => '.amp-wp-meta li, .amp-wp-meta li a',
371
+ );
372
+
373
+ // CSS classnames have been changed in version 0.4.0.
374
+ if ( version_compare( AMP__VERSION, '0.4.0', '>=' ) ) {
375
+ $selectors_v4 = array(
376
+ 'header-color' => 'header.amp-wp-header, html',
377
+ 'text-color' => 'div.amp-wp-article',
378
+ 'blockquote-bg-color' => '.amp-wp-article-content blockquote',
379
+ 'blockquote-border-color' => '.amp-wp-article-content blockquote',
380
+ 'blockquote-text-color' => '.amp-wp-article-content blockquote',
381
+ 'meta-color' => '.amp-wp-meta, .amp-wp-meta a',
382
+ );
383
+ $selectors = array_merge( $selectors, $selectors_v4 );
384
+ }
385
+
386
+ return $selectors;
387
+ }
388
  }
389
  }
classes/class-sanitizer.php CHANGED
@@ -20,9 +20,7 @@ class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
20
  * The actual sanitization function
21
  */
22
  public function sanitize() {
23
- $blacklisted_tags = $this->get_blacklisted_tags();
24
  $body = $this->get_body_node();
25
- $this->strip_tags( $body, $blacklisted_tags );
26
  $this->strip_attributes_recursive( $body );
27
  }
28
 
@@ -46,9 +44,6 @@ class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
46
  case 'a':
47
  $this->sanitize_a_attribute( $node, $attribute );
48
  break;
49
- case 'img':
50
- $this->sanitize_img_attribute( $node, $attribute );
51
- break;
52
  case 'pre':
53
  $this->sanitize_pre_attribute( $node, $attribute );
54
  break;
@@ -151,27 +146,4 @@ class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
151
  }
152
  }
153
 
154
- /**
155
- * Sanitize img tag attributes
156
- *
157
- * @param DOMNode $node
158
- * @param object $attribute
159
- */
160
- private function sanitize_img_attribute( $node, $attribute ) {
161
- $attribute_name = strtolower( $attribute->name );
162
-
163
- if ( 'rel' === $attribute_name ) {
164
- $node->removeAttribute( $attribute_name );
165
- }
166
- }
167
-
168
- /**
169
- * Makes sure the following tags are removed
170
- */
171
- private function get_blacklisted_tags() {
172
- return array(
173
- 'embed',
174
- );
175
- }
176
-
177
  }
20
  * The actual sanitization function
21
  */
22
  public function sanitize() {
 
23
  $body = $this->get_body_node();
 
24
  $this->strip_attributes_recursive( $body );
25
  }
26
 
44
  case 'a':
45
  $this->sanitize_a_attribute( $node, $attribute );
46
  break;
 
 
 
47
  case 'pre':
48
  $this->sanitize_pre_attribute( $node, $attribute );
49
  break;
146
  }
147
  }
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  }
classes/views/admin-page.php CHANGED
@@ -26,6 +26,10 @@ $yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' );
26
  <?php
27
 
28
  $post_types = apply_filters( 'wpseo_sitemaps_supported_post_types', get_post_types( array( 'public' => true ), 'objects' ) );
 
 
 
 
29
  if ( is_array( $post_types ) && $post_types !== array() ) {
30
  foreach ( $post_types as $pt ) {
31
  $yform->toggle_switch(
@@ -38,12 +42,15 @@ $yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' );
38
  );
39
  }
40
  }
41
- ?>
42
 
43
- <br>
44
- <strong><?php echo esc_html( __( 'Please note:', 'wordpress-seo' ) ); ?></strong>
45
- <?php echo esc_html( __( 'Currently pages are not supported by the AMP plugin.', 'wordpress-seo' ) ); ?>
46
- <?php echo esc_html( __( 'We still show this option to be able to provide functionality when the AMP plugin implements support for them.', 'wordpress-seo' ) ); ?>
 
 
 
 
47
  </p>
48
  </div>
49
 
26
  <?php
27
 
28
  $post_types = apply_filters( 'wpseo_sitemaps_supported_post_types', get_post_types( array( 'public' => true ), 'objects' ) );
29
+
30
+ // Allow specific AMP post type overrides, especially needed for Page support.
31
+ $post_types = apply_filters( 'wpseo_amp_supported_post_types', $post_types );
32
+
33
  if ( is_array( $post_types ) && $post_types !== array() ) {
34
  foreach ( $post_types as $pt ) {
35
  $yform->toggle_switch(
42
  );
43
  }
44
  }
 
45
 
46
+ if ( ! post_type_supports( 'page', AMP_QUERY_VAR ) ):
47
+ ?>
48
+ <br>
49
+ <strong><?php echo esc_html( __( 'Please note:', 'wordpress-seo' ) ); ?></strong>
50
+ <?php echo esc_html( __( 'Currently pages are not supported by the AMP plugin.', 'wordpress-seo' ) ); ?>
51
+ <?php
52
+ endif;
53
+ ?>
54
  </p>
55
  </div>
56
 
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Glue for Yoast SEO & AMP ===
2
  Contributors: joostdevalk
3
  Tags: AMP, SEO
4
- Requires at least: 4.2
5
- Tested up to: 4.6
6
- Stable tag: 0.3.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -34,10 +34,20 @@ To change your AMP page design, go to SEO -> AMP, and look at the design tab.
34
 
35
  == Changelog ==
36
 
 
 
 
 
 
 
 
 
 
 
37
  = 0.3.3 =
38
  * Bugfixes:
39
- * Fixes bug where AMP was only activated for the first post type in the list
40
- * Made sure that the function is not declared multiple times
41
 
42
  = 0.3.2 =
43
  * Bugfixes:
1
  === Glue for Yoast SEO & AMP ===
2
  Contributors: joostdevalk
3
  Tags: AMP, SEO
4
+ Requires at least: 4.6
5
+ Tested up to: 4.7.3
6
+ Stable tag: 0.4.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
34
 
35
  == Changelog ==
36
 
37
+ = 0.4.0 =
38
+ * Bugfixes:
39
+ * Removed page from post-type list to avoid unwanted canonical link.
40
+
41
+ * Enhancements:
42
+ * Removed canonical feature because it is being handled by the AMP plugin.
43
+ * Removed sanitizations which are already being done by the AMP plugin.
44
+ * Added a check for Monster Insights analytics implementation and disables our implementation if present.
45
+ * Added class selector implementation for AMP 0.4.x compatibility.
46
+
47
  = 0.3.3 =
48
  * Bugfixes:
49
+ * Fixes bug where AMP was only activated for the first post type in the list.
50
+ * Made sure that the function is not declared multiple times.
51
 
52
  = 0.3.2 =
53
  * Bugfixes:
yoastseo-amp.php CHANGED
@@ -9,7 +9,7 @@
9
  * Plugin Name: Glue for Yoast SEO & AMP
10
  * Plugin URI: https://wordpress.org/plugins/glue-for-yoast-seo-amp/
11
  * Description: Makes sure the default WordPress AMP plugin uses the proper Yoast SEO metadata
12
- * Version: 0.3.3
13
  * Author: Joost de Valk
14
  * Author URI: https://yoast.com
15
  */
9
  * Plugin Name: Glue for Yoast SEO & AMP
10
  * Plugin URI: https://wordpress.org/plugins/glue-for-yoast-seo-amp/
11
  * Description: Makes sure the default WordPress AMP plugin uses the proper Yoast SEO metadata
12
+ * Version: 0.4.0
13
  * Author: Joost de Valk
14
  * Author URI: https://yoast.com
15
  */