Glue for Yoast SEO & AMP - Version 0.6

Version Description

  • Bugfixes:
    • Fixes a bug where the saved option values weren't reflected in the form fields.
Download this release

Release Info

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

Code changes from version 0.5 to 0.6

.phpcs.xml.dist CHANGED
@@ -14,9 +14,6 @@
14
 
15
  <file>.</file>
16
 
17
- <exclude-pattern>node_modules/*</exclude-pattern>
18
- <exclude-pattern>vendor/*</exclude-pattern>
19
-
20
  <!-- Only check PHP files. -->
21
  <arg name="extensions" value="php"/>
22
 
@@ -26,7 +23,7 @@
26
  <!-- Strip the filepaths down to the relevant bit. -->
27
  <arg name="basepath" value="./"/>
28
 
29
- <!-- Check up to 8 files simultanously. -->
30
  <arg name="parallel" value="8"/>
31
 
32
 
@@ -36,7 +33,15 @@
36
  #############################################################################
37
  -->
38
 
39
- <rule ref="Yoast"/>
 
 
 
 
 
 
 
 
40
 
41
 
42
  <!--
@@ -45,9 +50,6 @@
45
  #############################################################################
46
  -->
47
 
48
- <!-- Set the minimum supported WP version. This is used by several sniffs. -->
49
- <config name="minimum_supported_wp_version" value="4.8"/>
50
-
51
  <!-- Verify that all gettext calls use the correct text domain. -->
52
  <rule ref="WordPress.WP.I18n">
53
  <properties>
@@ -60,30 +62,14 @@
60
  <rule ref="Yoast.Files.FileName">
61
  <properties>
62
  <!-- Don't trigger on the main file as renaming it would deactivate the plugin. -->
63
- <property name="exclude" type="array">
64
  <element value="yoastseo-amp.php"/>
65
  </property>
66
 
67
  <!-- Remove the following prefixes from the names of object structures. -->
68
- <property name="prefixes" type="array">
69
- <element value="yoastseo_amp"/>
70
- <element value="yoast_amp"/>
71
- </property>
72
- </properties>
73
- </rule>
74
-
75
- <!-- Verify that everything in the global namespace is prefixed with a plugin specific prefix. -->
76
- <rule ref="WordPress.NamingConventions.PrefixAllGlobals">
77
- <properties>
78
- <!-- Provide the prefixes to look for. -->
79
- <property name="prefixes" type="array">
80
- <!-- Temporarily allowed until the prefixes are fixed. -->
81
  <element value="yoastseo_amp"/>
82
- <element value="yoast_seo_amp"/>
83
- <element value="wpseo_amp"/>
84
- <!-- These are the new prefixes which all code should comply with in the future. -->
85
  <element value="yoast_amp"/>
86
- <element value="Yoast\WP\AMP"/>
87
  </property>
88
  </properties>
89
  </rule>
@@ -108,6 +94,16 @@
108
  #############################################################################
109
  -->
110
 
 
 
 
 
 
 
 
 
 
 
111
  <!-- The below exclusion has to do with appropriate sanitization and escaping
112
  of CSS and JS data for which no standard functionality exists in WP.
113
  A further review of this is needed and this needs to be tested extensively.
@@ -116,4 +112,9 @@
116
  <rule ref="WordPress.Security.EscapeOutput.OutputNotEscaped">
117
  <exclude-pattern>/classes/frontend\.php$</exclude-pattern>
118
  </rule>
 
 
 
 
 
119
  </ruleset>
14
 
15
  <file>.</file>
16
 
 
 
 
17
  <!-- Only check PHP files. -->
18
  <arg name="extensions" value="php"/>
19
 
23
  <!-- Strip the filepaths down to the relevant bit. -->
24
  <arg name="basepath" value="./"/>
25
 
26
+ <!-- Check up to 8 files simultaneously. -->
27
  <arg name="parallel" value="8"/>
28
 
29
 
33
  #############################################################################
34
  -->
35
 
36
+ <rule ref="Yoast">
37
+ <properties>
38
+ <!-- Provide the plugin specific prefixes for all naming related sniffs. -->
39
+ <property name="prefixes" type="array">
40
+ <element value="Yoast\WP\AMP"/>
41
+ <element value="yoast_amp"/>
42
+ </property>
43
+ </properties>
44
+ </rule>
45
 
46
 
47
  <!--
50
  #############################################################################
51
  -->
52
 
 
 
 
53
  <!-- Verify that all gettext calls use the correct text domain. -->
54
  <rule ref="WordPress.WP.I18n">
55
  <properties>
62
  <rule ref="Yoast.Files.FileName">
63
  <properties>
64
  <!-- Don't trigger on the main file as renaming it would deactivate the plugin. -->
65
+ <property name="excluded_files_strict_check" type="array">
66
  <element value="yoastseo-amp.php"/>
67
  </property>
68
 
69
  <!-- Remove the following prefixes from the names of object structures. -->
70
+ <property name="oo_prefixes" type="array">
 
 
 
 
 
 
 
 
 
 
 
 
71
  <element value="yoastseo_amp"/>
 
 
 
72
  <element value="yoast_amp"/>
 
73
  </property>
74
  </properties>
75
  </rule>
94
  #############################################################################
95
  -->
96
 
97
+ <!-- Until all prefixes are fixed, some exceptions are allowed to the PrefixAllGlobals sniff. -->
98
+ <rule ref="WordPress.NamingConventions.PrefixAllGlobals">
99
+ <properties>
100
+ <property name="prefixes" type="array" extend="true">
101
+ <element value="yoastseo_amp"/>
102
+ <element value="yoast_seo_amp"/>
103
+ </property>
104
+ </properties>
105
+ </rule>
106
+
107
  <!-- The below exclusion has to do with appropriate sanitization and escaping
108
  of CSS and JS data for which no standard functionality exists in WP.
109
  A further review of this is needed and this needs to be tested extensively.
112
  <rule ref="WordPress.Security.EscapeOutput.OutputNotEscaped">
113
  <exclude-pattern>/classes/frontend\.php$</exclude-pattern>
114
  </rule>
115
+ <rule ref="WordPress.WP.AlternativeFunctions.strip_tags_strip_tags">
116
+ <exclude-pattern>/classes/frontend\.php$</exclude-pattern>
117
+ <exclude-pattern>/classes/options\.php$</exclude-pattern>
118
+ </rule>
119
+
120
  </ruleset>
classes/backend.php CHANGED
@@ -28,12 +28,12 @@ if ( ! class_exists( 'YoastSEO_AMP_Backend', false ) ) {
28
  $this->options = YoastSEO_AMP_Options::get();
29
 
30
  // Add subitem to menu.
31
- add_filter( 'wpseo_submenu_pages', array( $this, 'add_submenu_page' ) );
32
 
33
  // Register AMP admin page as a Yoast SEO admin page.
34
- add_filter( 'wpseo_admin_pages', array( $this, 'add_admin_pages' ) );
35
 
36
- add_filter( 'wpseo_amp_supported_post_types', array( $this, 'remove_page_post_type' ) );
37
  }
38
 
39
  /**
@@ -60,15 +60,15 @@ if ( ! class_exists( 'YoastSEO_AMP_Backend', false ) ) {
60
  */
61
  public function add_submenu_page( $sub_menu_pages ) {
62
 
63
- $sub_menu_pages[] = array(
64
  'wpseo_dashboard',
65
  __( 'AMP', 'yoastseo-amp' ),
66
  __( 'AMP', 'yoastseo-amp' ),
67
  'manage_options',
68
  'wpseo_amp',
69
- array( $this, 'display' ),
70
- array( array( $this, 'enqueue_admin_page' ) ),
71
- );
72
 
73
  return $sub_menu_pages;
74
  }
@@ -77,6 +77,8 @@ if ( ! class_exists( 'YoastSEO_AMP_Backend', false ) ) {
77
  * Displays the admin page.
78
  */
79
  public function display() {
 
 
80
  require 'views/admin-page.php';
81
  }
82
 
@@ -87,7 +89,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Backend', false ) ) {
87
  wp_enqueue_style(
88
  'yoast_amp_css',
89
  plugin_dir_url( __FILE__ ) . 'assets/amp-admin-page.css',
90
- array( 'wp-color-picker' ),
91
  YoastSEO_AMP::VERSION
92
  );
93
 
@@ -95,7 +97,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Backend', false ) ) {
95
  wp_enqueue_script(
96
  'wpseo-admin-media',
97
  plugin_dir_url( __FILE__ ) . 'assets/wp-seo-admin-media.js',
98
- array( 'jquery', 'jquery-ui-core' ),
99
  YoastSEO_AMP::VERSION,
100
  true
101
  );
@@ -104,7 +106,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Backend', false ) ) {
104
  wp_enqueue_script(
105
  'yoast_amp_js',
106
  plugin_dir_url( __FILE__ ) . 'assets/amp-admin-page.js',
107
- array( 'jquery', 'wp-color-picker' ),
108
  YoastSEO_AMP::VERSION,
109
  true
110
  );
@@ -116,9 +118,9 @@ if ( ! class_exists( 'YoastSEO_AMP_Backend', false ) ) {
116
  * @return array
117
  */
118
  public function localize_media_script() {
119
- return array(
120
  'choose_image' => __( 'Use Logo', 'yoastseo-amp' ),
121
- );
122
  }
123
 
124
  /**
28
  $this->options = YoastSEO_AMP_Options::get();
29
 
30
  // Add subitem to menu.
31
+ add_filter( 'wpseo_submenu_pages', [ $this, 'add_submenu_page' ] );
32
 
33
  // Register AMP admin page as a Yoast SEO admin page.
34
+ add_filter( 'wpseo_admin_pages', [ $this, 'add_admin_pages' ] );
35
 
36
+ add_filter( 'Yoast\WP\AMP\supported_post_types', [ $this, 'remove_page_post_type' ] );
37
  }
38
 
39
  /**
60
  */
61
  public function add_submenu_page( $sub_menu_pages ) {
62
 
63
+ $sub_menu_pages[] = [
64
  'wpseo_dashboard',
65
  __( 'AMP', 'yoastseo-amp' ),
66
  __( 'AMP', 'yoastseo-amp' ),
67
  'manage_options',
68
  'wpseo_amp',
69
+ [ $this, 'display' ],
70
+ [ [ $this, 'enqueue_admin_page' ] ],
71
+ ];
72
 
73
  return $sub_menu_pages;
74
  }
77
  * Displays the admin page.
78
  */
79
  public function display() {
80
+ require_once 'form.php';
81
+
82
  require 'views/admin-page.php';
83
  }
84
 
89
  wp_enqueue_style(
90
  'yoast_amp_css',
91
  plugin_dir_url( __FILE__ ) . 'assets/amp-admin-page.css',
92
+ [ 'wp-color-picker' ],
93
  YoastSEO_AMP::VERSION
94
  );
95
 
97
  wp_enqueue_script(
98
  'wpseo-admin-media',
99
  plugin_dir_url( __FILE__ ) . 'assets/wp-seo-admin-media.js',
100
+ [ 'jquery', 'jquery-ui-core' ],
101
  YoastSEO_AMP::VERSION,
102
  true
103
  );
106
  wp_enqueue_script(
107
  'yoast_amp_js',
108
  plugin_dir_url( __FILE__ ) . 'assets/amp-admin-page.js',
109
+ [ 'jquery', 'wp-color-picker' ],
110
  YoastSEO_AMP::VERSION,
111
  true
112
  );
118
  * @return array
119
  */
120
  public function localize_media_script() {
121
+ return [
122
  'choose_image' => __( 'Use Logo', 'yoastseo-amp' ),
123
+ ];
124
  }
125
 
126
  /**
classes/blacklist-sanitizer.php CHANGED
@@ -84,7 +84,7 @@ class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
84
  foreach ( $tag_names as $tag_name ) {
85
  $elements = $node->getElementsByTagName( $tag_name );
86
  $length = $elements->length;
87
- if ( 0 === $length ) {
88
  continue;
89
  }
90
 
@@ -93,7 +93,7 @@ class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
93
  $parent_node = $element->parentNode;
94
  $parent_node->removeChild( $element );
95
 
96
- if ( 'body' !== $parent_node->nodeName && AMP_DOM_Utils::is_node_empty( $parent_node ) ) {
97
  $parent_node->parentNode->removeChild( $parent_node );
98
  }
99
  }
@@ -111,7 +111,7 @@ class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
111
  private function sanitize_a_attribute( $node, $attribute ) {
112
  $attribute_name = strtolower( $attribute->name );
113
 
114
- if ( 'rel' === $attribute_name && 'nofollow' !== $attribute->value ) {
115
  $node->removeAttribute( $attribute_name );
116
  }
117
  }
@@ -127,7 +127,7 @@ class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
127
  private function sanitize_pre_attribute( $node, $attribute ) {
128
  $attribute_name = strtolower( $attribute->name );
129
 
130
- if ( 'line' === $attribute_name ) {
131
  $node->removeAttribute( $attribute_name );
132
  }
133
  }
@@ -143,7 +143,7 @@ class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
143
  private function sanitize_cell_attribute( $node, $attribute ) {
144
  $attribute_name = strtolower( $attribute->name );
145
 
146
- if ( in_array( $attribute_name, array( 'width', 'height' ), true ) ) {
147
  $node->removeAttribute( $attribute_name );
148
  }
149
  }
@@ -159,7 +159,7 @@ class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
159
  private function sanitize_table_attribute( $node, $attribute ) {
160
  $attribute_name = strtolower( $attribute->name );
161
 
162
- if ( in_array( $attribute_name, array( 'border', 'cellspacing', 'cellpadding', 'summary' ), true ) ) {
163
  $node->removeAttribute( $attribute_name );
164
  }
165
  }
84
  foreach ( $tag_names as $tag_name ) {
85
  $elements = $node->getElementsByTagName( $tag_name );
86
  $length = $elements->length;
87
+ if ( $length === 0 ) {
88
  continue;
89
  }
90
 
93
  $parent_node = $element->parentNode;
94
  $parent_node->removeChild( $element );
95
 
96
+ if ( $parent_node->nodeName !== 'body' && AMP_DOM_Utils::is_node_empty( $parent_node ) ) {
97
  $parent_node->parentNode->removeChild( $parent_node );
98
  }
99
  }
111
  private function sanitize_a_attribute( $node, $attribute ) {
112
  $attribute_name = strtolower( $attribute->name );
113
 
114
+ if ( $attribute_name === 'rel' && $attribute->value !== 'nofollow' ) {
115
  $node->removeAttribute( $attribute_name );
116
  }
117
  }
127
  private function sanitize_pre_attribute( $node, $attribute ) {
128
  $attribute_name = strtolower( $attribute->name );
129
 
130
+ if ( $attribute_name === 'line' ) {
131
  $node->removeAttribute( $attribute_name );
132
  }
133
  }
143
  private function sanitize_cell_attribute( $node, $attribute ) {
144
  $attribute_name = strtolower( $attribute->name );
145
 
146
+ if ( in_array( $attribute_name, [ 'width', 'height' ], true ) ) {
147
  $node->removeAttribute( $attribute_name );
148
  }
149
  }
159
  private function sanitize_table_attribute( $node, $attribute ) {
160
  $attribute_name = strtolower( $attribute->name );
161
 
162
+ if ( in_array( $attribute_name, [ 'border', 'cellspacing', 'cellpadding', 'summary' ], true ) ) {
163
  $node->removeAttribute( $attribute_name );
164
  }
165
  }
classes/css-builder.php CHANGED
@@ -19,7 +19,7 @@ if ( ! class_exists( 'YoastSEO_AMP_CSS_Builder', false ) ) {
19
  *
20
  * @var array
21
  */
22
- private $items = array();
23
 
24
  /**
25
  * Adds the passed option to the CSS map.
@@ -31,10 +31,10 @@ if ( ! class_exists( 'YoastSEO_AMP_CSS_Builder', false ) ) {
31
  * @return void
32
  */
33
  public function add_option( $option_key, $selector, $property ) {
34
- $this->items[ $option_key ] = array(
35
  'selector' => $selector,
36
  'property' => $property,
37
- );
38
  }
39
 
40
  /**
@@ -46,7 +46,7 @@ if ( ! class_exists( 'YoastSEO_AMP_CSS_Builder', false ) ) {
46
  $options = YoastSEO_AMP_Options::get();
47
 
48
  $output = "\n";
49
- $css = array();
50
 
51
  $options = array_filter( $options );
52
  $apply = array_intersect_key( $this->items, $options );
@@ -55,7 +55,7 @@ if ( ! class_exists( 'YoastSEO_AMP_CSS_Builder', false ) ) {
55
  foreach ( $apply as $key => $placement ) {
56
 
57
  if ( ! isset( $css[ $placement['selector'] ] ) ) {
58
- $css[ $placement['selector'] ] = array();
59
  }
60
 
61
  $css[ $placement['selector'] ][ $placement['property'] ] = $options[ $key ];
19
  *
20
  * @var array
21
  */
22
+ private $items = [];
23
 
24
  /**
25
  * Adds the passed option to the CSS map.
31
  * @return void
32
  */
33
  public function add_option( $option_key, $selector, $property ) {
34
+ $this->items[ $option_key ] = [
35
  'selector' => $selector,
36
  'property' => $property,
37
+ ];
38
  }
39
 
40
  /**
46
  $options = YoastSEO_AMP_Options::get();
47
 
48
  $output = "\n";
49
+ $css = [];
50
 
51
  $options = array_filter( $options );
52
  $apply = array_intersect_key( $this->items, $options );
55
  foreach ( $apply as $key => $placement ) {
56
 
57
  if ( ! isset( $css[ $placement['selector'] ] ) ) {
58
+ $css[ $placement['selector'] ] = [];
59
  }
60
 
61
  $css[ $placement['selector'] ][ $placement['property'] ] = $options[ $key ];
classes/form.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * YoastSEO_AMP_Glue plugin file.
4
+ *
5
+ * @package YoastSEO_AMP_Glue\Admin
6
+ * @author Joost de Valk
7
+ * @copyright 2016 Yoast BV
8
+ * @license GPL-2.0+
9
+ */
10
+
11
+ /**
12
+ * Class YoastSEO_AMP_Form
13
+ */
14
+ class YoastSEO_AMP_Form extends Yoast_Form {
15
+
16
+ /**
17
+ * The options.
18
+ *
19
+ * @var array
20
+ */
21
+ protected $options;
22
+
23
+ /**
24
+ * YoastSEO_AMP_Form constructor.
25
+ */
26
+ public function __construct() {
27
+ $this->options = YoastSEO_AMP_Options::get();
28
+ }
29
+
30
+ /**
31
+ * Create a toggle switch input field using two radio buttons.
32
+ *
33
+ * @param string $var The variable within the option to create the radio buttons for.
34
+ * @param array $values Associative array of on/off keys and their values to be used as
35
+ * the label elements text for the radio buttons. Optionally, each
36
+ * value can be an array of visible label text and screen reader text.
37
+ * @param string $label The visual label for the radio buttons group, used as the fieldset legend.
38
+ * @param string $help Inline Help that will be printed out before the visible toggles text.
39
+ */
40
+ public function toggle_switch( $var, $values, $label, $help = '' ) {
41
+ if ( ! is_array( $values ) || $values === [] ) {
42
+ return;
43
+ }
44
+ $val = $this->get_option_value( $var, false );
45
+ if ( $val === true ) {
46
+ $val = 'on';
47
+ }
48
+ if ( $val === false ) {
49
+ $val = 'off';
50
+ }
51
+
52
+ $help_class = ! empty( $help ) ? ' switch-container__has-help' : '';
53
+
54
+ $var_esc = esc_attr( $var );
55
+
56
+ printf( '<div class="%s">', esc_attr( 'switch-container' . $help_class ) );
57
+
58
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The `$label` contains html.
59
+ echo '<fieldset id="', esc_attr( $var ), '" class="fieldset-switch-toggle"><legend>', $label, '</legend>', $help;
60
+
61
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The method returns html value.
62
+ echo $this->get_disabled_note( $var );
63
+ echo '<div class="switch-toggle switch-candy switch-yoast-seo">';
64
+
65
+ foreach ( $values as $key => $value ) {
66
+ $screen_reader_text_html = '';
67
+
68
+ if ( is_array( $value ) ) {
69
+ $screen_reader_text = $value['screen_reader_text'];
70
+ $screen_reader_text_html = '<span class="screen-reader-text"> ' . esc_html( $screen_reader_text ) . '</span>';
71
+ $value = $value['text'];
72
+ }
73
+
74
+ $key_esc = esc_attr( $key );
75
+ $for = $var_esc . '-' . $key_esc;
76
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The `$key_esc` value is already escaped.
77
+ echo '<input type="radio" id="' . $for . '" name="' . esc_attr( $this->option_name ) . '[' . $var_esc . ']" value="' . $key_esc . '" ' . checked( $val, $key_esc, false ) . disabled( $this->is_control_disabled( $var ), true, false ) . ' />',
78
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The `$screen_reader_text_html` value contains html.
79
+ '<label for="', $for, '">', esc_html( $value ), $screen_reader_text_html,'</label>';
80
+ }
81
+
82
+ echo '<a></a></div></fieldset><div class="clear"></div></div>' . PHP_EOL . PHP_EOL;
83
+ }
84
+
85
+ /**
86
+ * Media input.
87
+ *
88
+ * @param string $var Option name.
89
+ * @param string $label Label message.
90
+ */
91
+ public function media_input( $var, $label ) {
92
+ $val = $this->get_option_value( $var, '' );
93
+ $id_value = $this->get_option_value( $var . '_id', '' );
94
+
95
+ $var_esc = esc_attr( $var );
96
+
97
+ $this->label(
98
+ $label,
99
+ [
100
+ 'for' => 'wpseo_' . $var,
101
+ 'class' => 'select',
102
+ ]
103
+ );
104
+
105
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The `$var_esc` value is already escaped.
106
+ $id_field_id = 'wpseo_' . $var_esc . '_id';
107
+
108
+ echo '<span>';
109
+ echo '<input',
110
+ ' class="textinput"',
111
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The `$var_esc` value is already escaped.
112
+ ' id="wpseo_', $var_esc, '"',
113
+ ' type="text" size="36"',
114
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The `$var_esc` value is already escaped.
115
+ ' name="', esc_attr( $this->option_name ), '[', $var_esc, ']"',
116
+ ' value="', esc_attr( $val ), '"',
117
+ ' readonly="readonly"',
118
+ ' /> ';
119
+ echo '<input',
120
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The `$var_esc` value is already escaped.
121
+ ' id="wpseo_', $var_esc, '_button"',
122
+ ' class="wpseo_image_upload_button button"',
123
+ ' type="button"',
124
+ ' value="', esc_attr__( 'Upload Image', 'yoastseo-amp' ), '"',
125
+ ' data-target-id="', esc_attr( $id_field_id ), '"',
126
+ disabled( $this->is_control_disabled( $var ), true, false ),
127
+ ' /> ';
128
+ echo '<input',
129
+ ' class="wpseo_image_remove_button button"',
130
+ ' type="button"',
131
+ ' value="', esc_attr__( 'Clear Image', 'yoastseo-amp' ), '"',
132
+ disabled( $this->is_control_disabled( $var ), true, false ),
133
+ ' />';
134
+ echo '<input',
135
+ ' type="hidden"',
136
+ ' id="', esc_attr( $id_field_id ), '"',
137
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The `$var_esc` value is already escaped.
138
+ ' name="', esc_attr( $this->option_name ), '[', $var_esc, '_id]"',
139
+ ' value="', esc_attr( $id_value ), '"',
140
+ ' />';
141
+ echo '</span>';
142
+ echo '<br class="clear"/>';
143
+ }
144
+
145
+ /**
146
+ * Create a light switch input field using a single checkbox.
147
+ *
148
+ * @param string $var The variable within the option to create the checkbox for.
149
+ * @param string $label The label element text for the checkbox.
150
+ * @param array $buttons Array of two visual labels for the buttons (defaults Disabled/Enabled).
151
+ * @param bool $reverse Reverse order of buttons (default true).
152
+ * @param string $help Inline Help that will be printed out before the visible toggles text.
153
+ * @param bool $strong Whether the visual label is displayed in strong text. Default is false.
154
+ */
155
+ public function light_switch( $var, $label, $buttons = [], $reverse = true, $help = '', $strong = false ) {
156
+ $val = $this->get_option_value( $var, false );
157
+
158
+ if ( $val === true ) {
159
+ $val = 'on';
160
+ }
161
+
162
+ $class = 'switch-light switch-candy switch-yoast-seo';
163
+
164
+ if ( $reverse ) {
165
+ $class .= ' switch-yoast-seo-reverse';
166
+ }
167
+
168
+ if ( empty( $buttons ) ) {
169
+ $buttons = [ __( 'Disabled', 'yoastseo-amp' ), __( 'Enabled', 'yoastseo-amp' ) ];
170
+ }
171
+
172
+ list( $off_button, $on_button ) = $buttons;
173
+
174
+ $help_class = ! empty( $help ) ? ' switch-container__has-help' : '';
175
+
176
+ $strong_class = ( $strong ) ? ' switch-light-visual-label__strong' : '';
177
+
178
+ echo '<div class="switch-container', esc_attr( $help_class ), '">',
179
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: The `$help` value is already escaped.
180
+ '<span class="switch-light-visual-label' . esc_attr( $strong_class ) . '" id="', esc_attr( $var . '-label' ), '">', esc_html( $label ), '</span>' . $help,
181
+ '<label class="', esc_attr( $class ), '"><b class="switch-yoast-seo-jaws-a11y">&nbsp;</b>',
182
+ '<input type="checkbox" aria-labelledby="', esc_attr( $var . '-label' ), '" id="', esc_attr( $var ), '" name="', esc_attr( $this->option_name ), '[', esc_attr( $var ), ']" value="on"', checked( $val, 'on', false ), disabled( $this->is_control_disabled( $var ), true, false ), '/>',
183
+ '<span aria-hidden="true">
184
+ <span>', esc_html( $off_button ) ,'</span>
185
+ <span>', esc_html( $on_button ) ,'</span>
186
+ <a></a>
187
+ </span>
188
+ </label><div class="clear"></div></div>';
189
+ }
190
+
191
+ /**
192
+ * Create a textarea.
193
+ *
194
+ * @param string $var The variable within the option to create the textarea for.
195
+ * @param string $label The label to show for the variable.
196
+ * @param string|array $attr The CSS class or an array of attributes to assign to the textarea.
197
+ */
198
+ public function textarea( $var, $label, $attr = [] ) {
199
+ if ( ! is_array( $attr ) ) {
200
+ $attr = [
201
+ 'class' => $attr,
202
+ ];
203
+ }
204
+
205
+ $defaults = [
206
+ 'cols' => '',
207
+ 'rows' => '',
208
+ 'class' => '',
209
+ ];
210
+ $attr = wp_parse_args( $attr, $defaults );
211
+ $val = $this->get_option_value( $var, '' );
212
+
213
+ $this->label(
214
+ $label,
215
+ [
216
+ 'for' => $var,
217
+ 'class' => 'textinput',
218
+ ]
219
+ );
220
+ echo '<textarea cols="' . esc_attr( $attr['cols'] ) . '" rows="' . esc_attr( $attr['rows'] ) . '" class="textinput ' . esc_attr( $attr['class'] ) . '" id="' . esc_attr( $var ) . '" name="' . esc_attr( $this->option_name ) . '[' . esc_attr( $var ) . ']"', disabled( $this->is_control_disabled( $var ), true, false ), '>' . esc_textarea( $val ) . '</textarea><br class="clear" />';
221
+ }
222
+
223
+ /**
224
+ * Retrieves the option value.
225
+ *
226
+ * @param string $option_value The option value to retrieve.
227
+ * @param string|null $default The default value.
228
+ *
229
+ * @return mixed|string The option value.
230
+ */
231
+ protected function get_option_value( $option_value, $default = null ) {
232
+ if ( isset( $this->options[ $option_value ] ) ) {
233
+ return $this->options[ $option_value ];
234
+ }
235
+
236
+ return $default;
237
+ }
238
+ }
classes/frontend.php CHANGED
@@ -41,17 +41,17 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
41
  public function __construct() {
42
  $this->set_options();
43
 
44
- add_action( 'amp_init', array( $this, 'post_types' ) );
45
 
46
- add_action( 'amp_post_template_css', array( $this, 'additional_css' ) );
47
- add_action( 'amp_post_template_head', array( $this, 'extra_head' ) );
48
- add_action( 'amp_post_template_footer', array( $this, 'extra_footer' ) );
49
 
50
- add_filter( 'amp_post_template_data', array( $this, 'fix_amp_post_data' ) );
51
- add_filter( 'amp_post_template_metadata', array( $this, 'fix_amp_post_metadata' ), 10, 2 );
52
- add_filter( 'amp_post_template_analytics', array( $this, 'analytics' ) );
53
 
54
- add_filter( 'amp_content_sanitizers', array( $this, 'add_sanitizer' ) );
55
  }
56
 
57
  /**
@@ -74,7 +74,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
74
  public function add_sanitizer( $sanitizers ) {
75
  require_once 'blacklist-sanitizer.php';
76
 
77
- $sanitizers['Yoast_AMP_Blacklist_Sanitizer'] = array();
78
 
79
  return $sanitizers;
80
  }
@@ -104,21 +104,21 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
104
  }
105
  $tracking_code = Yoast_GA_Options::instance()->get_tracking_code();
106
 
107
- $analytics['yst-googleanalytics'] = array(
108
  'type' => 'googleanalytics',
109
- 'attributes' => array(),
110
- 'config_data' => array(
111
- 'vars' => array(
112
  'account' => $tracking_code,
113
- ),
114
- 'triggers' => array(
115
- 'trackPageview' => array(
116
  'on' => 'visible',
117
  'request' => 'pageview',
118
- ),
119
- ),
120
- ),
121
- );
122
 
123
  return $analytics;
124
  }
@@ -129,8 +129,8 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
129
  * @return void
130
  */
131
  public function post_types() {
132
- $post_types = get_post_types( array( 'public' => true ), 'objects' );
133
- if ( is_array( $post_types ) && $post_types !== array() ) {
134
  foreach ( $post_types as $post_type ) {
135
 
136
  $post_type_name = $post_type->name;
@@ -140,7 +140,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
140
  }
141
 
142
  // If AMP page support is not present, don't allow enabling it here.
143
- if ( 'page' === $post_type_name && ! post_type_supports( 'page', AMP_QUERY_VAR ) ) {
144
  continue;
145
  }
146
 
@@ -149,8 +149,8 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
149
  continue;
150
  }
151
 
152
- if ( 'post' === $post_type_name ) {
153
- add_action( 'wp', array( $this, 'disable_amp_for_posts' ) );
154
  continue;
155
  }
156
 
@@ -306,7 +306,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
306
  }
307
 
308
  // The logo needs to be 600px wide max, 60px high max.
309
- $logo = $this->get_image_object( $this->wpseo_options['company_logo'], array( 600, 60 ) );
310
  if ( is_array( $logo ) ) {
311
  $metadata['publisher']['logo'] = $logo;
312
  }
@@ -330,12 +330,12 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
330
  $image_src = wp_get_attachment_image_src( $image_id, $size );
331
 
332
  if ( is_array( $image_src ) ) {
333
- return array(
334
  '@type' => 'ImageObject',
335
  'url' => $image_src[0],
336
  'width' => $image_src[1],
337
  'height' => $image_src[2],
338
- );
339
  }
340
 
341
  return false;
@@ -380,18 +380,36 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
380
  */
381
  private function get_post_schema_type( $post ) {
382
  $type = 'WebPage';
383
- if ( 'post' === $post->post_type ) {
384
  $type = 'Article';
385
  }
386
 
387
  /**
388
  * Filter: 'yoastseo_amp_schema_type' - Allow changing the Schema.org type for the post.
389
  *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  * @api string $type The Schema.org type for the $post.
391
  *
392
  * @param WP_Post $post
393
  */
394
- $type = apply_filters( 'yoastseo_amp_schema_type', $type, $post );
395
 
396
  return $type;
397
  }
@@ -405,7 +423,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
405
  * @return array The version dependent class names.
406
  */
407
  private function get_class_selectors() {
408
- $selectors = array(
409
  'header-color' => 'nav.amp-wp-title-bar',
410
  'headings-color' => '.amp-wp-title, h2, h3, h4',
411
  'text-color' => '.amp-wp-content',
@@ -418,18 +436,18 @@ if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
418
  'link-color-hover' => 'a:hover, a:focus',
419
 
420
  'meta-color' => '.amp-wp-meta li, .amp-wp-meta li a',
421
- );
422
 
423
  // CSS classnames have been changed in version 0.4.0.
424
  if ( version_compare( AMP__VERSION, '0.4.0', '>=' ) ) {
425
- $selectors_v4 = array(
426
  'header-color' => 'header.amp-wp-header, html',
427
  'text-color' => 'div.amp-wp-article',
428
  'blockquote-bg-color' => '.amp-wp-article-content blockquote',
429
  'blockquote-border-color' => '.amp-wp-article-content blockquote',
430
  'blockquote-text-color' => '.amp-wp-article-content blockquote',
431
  'meta-color' => '.amp-wp-meta, .amp-wp-meta a',
432
- );
433
  $selectors = array_merge( $selectors, $selectors_v4 );
434
  }
435
 
41
  public function __construct() {
42
  $this->set_options();
43
 
44
+ add_action( 'amp_init', [ $this, 'post_types' ] );
45
 
46
+ add_action( 'amp_post_template_css', [ $this, 'additional_css' ] );
47
+ add_action( 'amp_post_template_head', [ $this, 'extra_head' ] );
48
+ add_action( 'amp_post_template_footer', [ $this, 'extra_footer' ] );
49
 
50
+ add_filter( 'amp_post_template_data', [ $this, 'fix_amp_post_data' ] );
51
+ add_filter( 'amp_post_template_metadata', [ $this, 'fix_amp_post_metadata' ], 10, 2 );
52
+ add_filter( 'amp_post_template_analytics', [ $this, 'analytics' ] );
53
 
54
+ add_filter( 'amp_content_sanitizers', [ $this, 'add_sanitizer' ] );
55
  }
56
 
57
  /**
74
  public function add_sanitizer( $sanitizers ) {
75
  require_once 'blacklist-sanitizer.php';
76
 
77
+ $sanitizers['Yoast_AMP_Blacklist_Sanitizer'] = [];
78
 
79
  return $sanitizers;
80
  }
104
  }
105
  $tracking_code = Yoast_GA_Options::instance()->get_tracking_code();
106
 
107
+ $analytics['yst-googleanalytics'] = [
108
  'type' => 'googleanalytics',
109
+ 'attributes' => [],
110
+ 'config_data' => [
111
+ 'vars' => [
112
  'account' => $tracking_code,
113
+ ],
114
+ 'triggers' => [
115
+ 'trackPageview' => [
116
  'on' => 'visible',
117
  'request' => 'pageview',
118
+ ],
119
+ ],
120
+ ],
121
+ ];
122
 
123
  return $analytics;
124
  }
129
  * @return void
130
  */
131
  public function post_types() {
132
+ $post_types = get_post_types( [ 'public' => true ], 'objects' );
133
+ if ( is_array( $post_types ) && $post_types !== [] ) {
134
  foreach ( $post_types as $post_type ) {
135
 
136
  $post_type_name = $post_type->name;
140
  }
141
 
142
  // If AMP page support is not present, don't allow enabling it here.
143
+ if ( $post_type_name === 'page' && ! post_type_supports( 'page', AMP_QUERY_VAR ) ) {
144
  continue;
145
  }
146
 
149
  continue;
150
  }
151
 
152
+ if ( $post_type_name === 'post' ) {
153
+ add_action( 'wp', [ $this, 'disable_amp_for_posts' ] );
154
  continue;
155
  }
156
 
306
  }
307
 
308
  // The logo needs to be 600px wide max, 60px high max.
309
+ $logo = $this->get_image_object( $this->wpseo_options['company_logo'], [ 600, 60 ] );
310
  if ( is_array( $logo ) ) {
311
  $metadata['publisher']['logo'] = $logo;
312
  }
330
  $image_src = wp_get_attachment_image_src( $image_id, $size );
331
 
332
  if ( is_array( $image_src ) ) {
333
+ return [
334
  '@type' => 'ImageObject',
335
  'url' => $image_src[0],
336
  'width' => $image_src[1],
337
  'height' => $image_src[2],
338
+ ];
339
  }
340
 
341
  return false;
380
  */
381
  private function get_post_schema_type( $post ) {
382
  $type = 'WebPage';
383
+ if ( $post->post_type === 'post' ) {
384
  $type = 'Article';
385
  }
386
 
387
  /**
388
  * Filter: 'yoastseo_amp_schema_type' - Allow changing the Schema.org type for the post.
389
  *
390
+ * @deprecated 0.6.0. Use the {@see 'Yoast\WP\AMP\schema_type'} filter instead.
391
+ *
392
+ * @api string $type The Schema.org type for the $post.
393
+ *
394
+ * @param WP_Post $post
395
+ */
396
+ $type = apply_filters_deprecated(
397
+ 'yoastseo_amp_schema_type',
398
+ [ $type, $post ],
399
+ 'YoastSEO AMP 0.6.0',
400
+ 'Yoast\WP\AMP\schema_type'
401
+ );
402
+
403
+ /**
404
+ * Filter: 'Yoast\WP\AMP\schema_type' - Allow changing the Schema.org type for the post.
405
+ *
406
+ * @since 0.6.0
407
+ *
408
  * @api string $type The Schema.org type for the $post.
409
  *
410
  * @param WP_Post $post
411
  */
412
+ $type = apply_filters( 'Yoast\WP\AMP\schema_type', $type, $post );
413
 
414
  return $type;
415
  }
423
  * @return array The version dependent class names.
424
  */
425
  private function get_class_selectors() {
426
+ $selectors = [
427
  'header-color' => 'nav.amp-wp-title-bar',
428
  'headings-color' => '.amp-wp-title, h2, h3, h4',
429
  'text-color' => '.amp-wp-content',
436
  'link-color-hover' => 'a:hover, a:focus',
437
 
438
  'meta-color' => '.amp-wp-meta li, .amp-wp-meta li a',
439
+ ];
440
 
441
  // CSS classnames have been changed in version 0.4.0.
442
  if ( version_compare( AMP__VERSION, '0.4.0', '>=' ) ) {
443
+ $selectors_v4 = [
444
  'header-color' => 'header.amp-wp-header, html',
445
  'text-color' => 'div.amp-wp-article',
446
  'blockquote-bg-color' => '.amp-wp-article-content blockquote',
447
  'blockquote-border-color' => '.amp-wp-article-content blockquote',
448
  'blockquote-text-color' => '.amp-wp-article-content blockquote',
449
  'meta-color' => '.amp-wp-meta, .amp-wp-meta a',
450
+ ];
451
  $selectors = array_merge( $selectors, $selectors_v4 );
452
  }
453
 
classes/options.php CHANGED
@@ -33,7 +33,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
33
  *
34
  * @var array
35
  */
36
- private $defaults = array(
37
  'version' => 1,
38
  'amp_site_icon' => '',
39
  'default_image' => '',
@@ -50,7 +50,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
50
  'extra-css' => '',
51
  'extra-head' => '',
52
  'analytics-extra' => '',
53
- );
54
 
55
  /**
56
  * Class instance.
@@ -64,14 +64,14 @@ if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
64
  */
65
  private function __construct() {
66
  // Register settings.
67
- add_action( 'admin_init', array( $this, 'register_settings' ) );
68
  }
69
 
70
  /**
71
  * Register the premium settings.
72
  */
73
  public function register_settings() {
74
- register_setting( 'wpseo_amp_settings', $this->option_name, array( $this, 'sanitize_options' ) );
75
  }
76
 
77
  /**
@@ -79,7 +79,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
79
  *
80
  * @param array $options Options as received in $_POST.
81
  *
82
- * @return mixed
83
  */
84
  public function sanitize_options( $options ) {
85
  $options['version'] = 1;
@@ -93,7 +93,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
93
  // Only allow meta and link tags in head.
94
  $options['extra-head'] = strip_tags( $options['extra-head'], '<link><meta>' );
95
 
96
- $colors = array(
97
  'header-color',
98
  'headings-color',
99
  'text-color',
@@ -102,7 +102,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
102
  'blockquote-text-color',
103
  'blockquote-bg-color',
104
  'blockquote-border-color',
105
- );
106
 
107
  foreach ( $colors as $color ) {
108
  $options[ $color ] = $this->sanitize_color( $options[ $color ], '' );
@@ -110,7 +110,7 @@ if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
110
 
111
  // Only allow 'on' or 'off'.
112
  foreach ( $options as $key => $value ) {
113
- if ( 'post_types-' === substr( $key, 0, 11 ) ) {
114
  $options[ $key ] = ( $value === 'on' ) ? 'on' : 'off';
115
  }
116
  }
@@ -215,15 +215,15 @@ if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
215
  * Get post types.
216
  */
217
  private function update_post_type_settings() {
218
- $post_type_names = array();
219
 
220
- $post_types = get_post_types( array( 'public' => true ), 'objects' );
221
 
222
- if ( is_array( $post_types ) && $post_types !== array() ) {
223
  foreach ( $post_types as $post_type ) {
224
  if ( ! isset( $this->options[ 'post_types-' . $post_type->name . '-amp' ] ) ) {
225
  $this->options[ 'post_types-' . $post_type->name . '-amp' ] = 'off';
226
- if ( 'post' === $post_type->name ) {
227
  $this->options[ 'post_types-' . $post_type->name . '-amp' ] = 'on';
228
  }
229
  }
@@ -263,11 +263,11 @@ if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
263
  $parts,
264
  1,
265
  null,
266
- array(
267
  '<script type="application/json">',
268
  trim( $json ),
269
  '</script>',
270
- )
271
  );
272
 
273
  return implode( "\n", $parts );
33
  *
34
  * @var array
35
  */
36
+ private $defaults = [
37
  'version' => 1,
38
  'amp_site_icon' => '',
39
  'default_image' => '',
50
  'extra-css' => '',
51
  'extra-head' => '',
52
  'analytics-extra' => '',
53
+ ];
54
 
55
  /**
56
  * Class instance.
64
  */
65
  private function __construct() {
66
  // Register settings.
67
+ add_action( 'admin_init', [ $this, 'register_settings' ] );
68
  }
69
 
70
  /**
71
  * Register the premium settings.
72
  */
73
  public function register_settings() {
74
+ register_setting( 'wpseo_amp_settings', $this->option_name, [ $this, 'sanitize_options' ] );
75
  }
76
 
77
  /**
79
  *
80
  * @param array $options Options as received in $_POST.
81
  *
82
+ * @return array
83
  */
84
  public function sanitize_options( $options ) {
85
  $options['version'] = 1;
93
  // Only allow meta and link tags in head.
94
  $options['extra-head'] = strip_tags( $options['extra-head'], '<link><meta>' );
95
 
96
+ $colors = [
97
  'header-color',
98
  'headings-color',
99
  'text-color',
102
  'blockquote-text-color',
103
  'blockquote-bg-color',
104
  'blockquote-border-color',
105
+ ];
106
 
107
  foreach ( $colors as $color ) {
108
  $options[ $color ] = $this->sanitize_color( $options[ $color ], '' );
110
 
111
  // Only allow 'on' or 'off'.
112
  foreach ( $options as $key => $value ) {
113
+ if ( substr( $key, 0, 11 ) === 'post_types-' ) {
114
  $options[ $key ] = ( $value === 'on' ) ? 'on' : 'off';
115
  }
116
  }
215
  * Get post types.
216
  */
217
  private function update_post_type_settings() {
218
+ $post_type_names = [];
219
 
220
+ $post_types = get_post_types( [ 'public' => true ], 'objects' );
221
 
222
+ if ( is_array( $post_types ) && $post_types !== [] ) {
223
  foreach ( $post_types as $post_type ) {
224
  if ( ! isset( $this->options[ 'post_types-' . $post_type->name . '-amp' ] ) ) {
225
  $this->options[ 'post_types-' . $post_type->name . '-amp' ] = 'off';
226
+ if ( $post_type->name === 'post' ) {
227
  $this->options[ 'post_types-' . $post_type->name . '-amp' ] = 'on';
228
  }
229
  }
263
  $parts,
264
  1,
265
  null,
266
+ [
267
  '<script type="application/json">',
268
  trim( $json ),
269
  '</script>',
270
+ ]
271
  );
272
 
273
  return implode( "\n", $parts );
classes/views/additional-css.php CHANGED
@@ -13,5 +13,5 @@ td, th {
13
  }
14
 
15
  a, a:active, a:visited {
16
- text-decoration: <?php echo ( ( 'underline' === $this->options['underline'] ) ? 'underline' : 'none' ); ?>;
17
  }
13
  }
14
 
15
  a, a:active, a:visited {
16
+ text-decoration: <?php echo ( ( $this->options['underline'] === 'underline' ) ? 'underline' : 'none' ); ?>;
17
  }
classes/views/admin-page.php CHANGED
@@ -13,11 +13,9 @@ if ( ! defined( 'WPSEO_VERSION' ) ) {
13
  exit();
14
  }
15
 
16
- $yoast_amp_yform = Yoast_Form::get_instance();
17
  $yoast_amp_yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' );
18
-
19
  ?>
20
-
21
  <h2 class="nav-tab-wrapper" id="wpseo-tabs">
22
  <a class="nav-tab" id="posttypes-tab" href="#top#posttypes"><?php esc_html_e( 'Post types', 'yoastseo-amp' ); ?></a>
23
  <a class="nav-tab" id="design-tab" href="#top#design"><?php esc_html_e( 'Design', 'yoastseo-amp' ); ?></a>
@@ -33,19 +31,39 @@ $yoast_amp_yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' )
33
  <?php
34
 
35
  // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPSEO hook.
36
- $yoast_amp_post_types = apply_filters( 'wpseo_sitemaps_supported_post_types', get_post_types( array( 'public' => true ), 'objects' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
- // Allow specific AMP post type overrides, especially needed for Page support.
39
- $yoast_amp_post_types = apply_filters( 'wpseo_amp_supported_post_types', $yoast_amp_post_types );
 
 
 
 
 
 
40
 
41
- if ( is_array( $yoast_amp_post_types ) && $yoast_amp_post_types !== array() ) {
42
  foreach ( $yoast_amp_post_types as $yoast_amp_pt ) {
43
  $yoast_amp_yform->toggle_switch(
44
  'post_types-' . $yoast_amp_pt->name . '-amp',
45
- array(
46
  'on' => __( 'Enabled', 'yoastseo-amp' ),
47
  'off' => __( 'Disabled', 'yoastseo-amp' ),
48
- ),
49
  $yoast_amp_pt->labels->name . ' (<code>' . $yoast_amp_pt->name . '</code>)'
50
  );
51
  }
@@ -98,10 +116,10 @@ $yoast_amp_yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' )
98
  $yoast_amp_yform->light_switch(
99
  'underline',
100
  __( 'Underline', 'yoastseo-amp' ),
101
- array(
102
  __( 'Underline', 'yoastseo-amp' ),
103
  __( 'No underline', 'yoastseo-amp' ),
104
- )
105
  );
106
  ?>
107
 
@@ -120,10 +138,10 @@ $yoast_amp_yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' )
120
  $yoast_amp_yform->textarea(
121
  'extra-css',
122
  __( 'Extra CSS', 'yoastseo-amp' ),
123
- array(
124
  'rows' => 5,
125
  'cols' => 100,
126
- )
127
  );
128
  ?>
129
 
@@ -149,10 +167,10 @@ $yoast_amp_yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' )
149
  $yoast_amp_yform->textarea(
150
  'extra-head',
151
  __( 'Extra code', 'yoastseo-amp' ),
152
- array(
153
  'rows' => 5,
154
  'cols' => 100,
155
- )
156
  );
157
  ?>
158
 
@@ -182,10 +200,10 @@ $yoast_amp_yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' )
182
  $yoast_amp_yform->textarea(
183
  'analytics-extra',
184
  __( 'Analytics code', 'yoastseo-amp' ),
185
- array(
186
  'rows' => 5,
187
  'cols' => 100,
188
- )
189
  );
190
  }
191
  else {
@@ -193,16 +211,15 @@ $yoast_amp_yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' )
193
  $yoast_amp_yform->textarea(
194
  'analytics-extra',
195
  __( 'Analytics code', 'yoastseo-amp' ),
196
- array(
197
  'rows' => 5,
198
  'cols' => 100,
199
- )
200
  );
201
  }
202
  ?>
203
  </div>
204
  </div>
205
-
206
  <?php
207
 
208
  $yoast_amp_yform->admin_footer();
13
  exit();
14
  }
15
 
16
+ $yoast_amp_yform = new YoastSEO_AMP_Form();
17
  $yoast_amp_yform->admin_header( true, 'wpseo_amp', false, 'wpseo_amp_settings' );
 
18
  ?>
 
19
  <h2 class="nav-tab-wrapper" id="wpseo-tabs">
20
  <a class="nav-tab" id="posttypes-tab" href="#top#posttypes"><?php esc_html_e( 'Post types', 'yoastseo-amp' ); ?></a>
21
  <a class="nav-tab" id="design-tab" href="#top#design"><?php esc_html_e( 'Design', 'yoastseo-amp' ); ?></a>
31
  <?php
32
 
33
  // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPSEO hook.
34
+ $yoast_amp_post_types = apply_filters( 'wpseo_sitemaps_supported_post_types', get_post_types( [ 'public' => true ], 'objects' ) );
35
+
36
+ /**
37
+ * Allow specific AMP post type overrides, especially needed for Page support.
38
+ *
39
+ * @deprecated 0.6.0. Use the {@see 'Yoast\WP\AMP\supported_post_types'} filter instead.
40
+ *
41
+ * @param array $post_types Post types to show in the sitemap.
42
+ */
43
+ $yoast_amp_post_types = apply_filters_deprecated(
44
+ 'wpseo_amp_supported_post_types',
45
+ [ $yoast_amp_post_types ],
46
+ 'YoastSEO AMP 0.6.0',
47
+ 'Yoast\WP\AMP\supported_post_types'
48
+ );
49
 
50
+ /**
51
+ * Allow specific AMP post type overrides, especially needed for Page support.
52
+ *
53
+ * @since 0.6.0
54
+ *
55
+ * @param array $post_types Post types to show in the sitemap.
56
+ */
57
+ $yoast_amp_post_types = apply_filters( 'Yoast\WP\AMP\supported_post_types', $yoast_amp_post_types );
58
 
59
+ if ( is_array( $yoast_amp_post_types ) && $yoast_amp_post_types !== [] ) {
60
  foreach ( $yoast_amp_post_types as $yoast_amp_pt ) {
61
  $yoast_amp_yform->toggle_switch(
62
  'post_types-' . $yoast_amp_pt->name . '-amp',
63
+ [
64
  'on' => __( 'Enabled', 'yoastseo-amp' ),
65
  'off' => __( 'Disabled', 'yoastseo-amp' ),
66
+ ],
67
  $yoast_amp_pt->labels->name . ' (<code>' . $yoast_amp_pt->name . '</code>)'
68
  );
69
  }
116
  $yoast_amp_yform->light_switch(
117
  'underline',
118
  __( 'Underline', 'yoastseo-amp' ),
119
+ [
120
  __( 'Underline', 'yoastseo-amp' ),
121
  __( 'No underline', 'yoastseo-amp' ),
122
+ ]
123
  );
124
  ?>
125
 
138
  $yoast_amp_yform->textarea(
139
  'extra-css',
140
  __( 'Extra CSS', 'yoastseo-amp' ),
141
+ [
142
  'rows' => 5,
143
  'cols' => 100,
144
+ ]
145
  );
146
  ?>
147
 
167
  $yoast_amp_yform->textarea(
168
  'extra-head',
169
  __( 'Extra code', 'yoastseo-amp' ),
170
+ [
171
  'rows' => 5,
172
  'cols' => 100,
173
+ ]
174
  );
175
  ?>
176
 
200
  $yoast_amp_yform->textarea(
201
  'analytics-extra',
202
  __( 'Analytics code', 'yoastseo-amp' ),
203
+ [
204
  'rows' => 5,
205
  'cols' => 100,
206
+ ]
207
  );
208
  }
209
  else {
211
  $yoast_amp_yform->textarea(
212
  'analytics-extra',
213
  __( 'Analytics code', 'yoastseo-amp' ),
214
+ [
215
  'rows' => 5,
216
  'cols' => 100,
217
+ ]
218
  );
219
  }
220
  ?>
221
  </div>
222
  </div>
 
223
  <?php
224
 
225
  $yoast_amp_yform->admin_footer();
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Glue for Yoast SEO & AMP ===
2
  Contributors: joostdevalk
3
  Tags: AMP, SEO
4
- Requires at least: 4.9
5
- Tested up to: 5.2.2
6
- Stable tag: 0.5
7
- Requires PHP: 5.2.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -35,6 +35,10 @@ To change your AMP page design, go to SEO -> AMP, and look at the design tab.
35
 
36
  == Changelog ==
37
 
 
 
 
 
38
  = 0.5 =
39
  * Bugfixes:
40
  * Fixes a problem where the AMP icon and Default image could not be unset when Yoast SEO 9.0+ has been installed.
1
  === Glue for Yoast SEO & AMP ===
2
  Contributors: joostdevalk
3
  Tags: AMP, SEO
4
+ Requires at least: 5.3
5
+ Tested up to: 5.4
6
+ Stable tag: 0.6
7
+ Requires PHP: 5.6.20
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
35
 
36
  == Changelog ==
37
 
38
+ = 0.6 =
39
+ * Bugfixes:
40
+ * Fixes a bug where the saved option values weren't reflected in the form fields.
41
+
42
  = 0.5 =
43
  * Bugfixes:
44
  * Fixes a problem where the AMP icon and Default image could not be unset when Yoast SEO 9.0+ has been installed.
yoastseo-amp.php CHANGED
@@ -11,7 +11,7 @@
11
  * Plugin Name: Glue for Yoast SEO & AMP
12
  * Plugin URI: https://wordpress.org/plugins/glue-for-yoast-seo-amp/
13
  * Description: Makes sure the default WordPress AMP plugin uses the proper Yoast SEO metadata
14
- * Version: 0.5
15
  * Author: Joost de Valk
16
  * Author URI: https://yoast.com
17
  * Text Domain: yoastseo-amp
@@ -25,7 +25,7 @@ if ( ! class_exists( 'YoastSEO_AMP', false ) ) {
25
  */
26
  class YoastSEO_AMP {
27
 
28
- const VERSION = '0.5.0';
29
 
30
  /**
31
  * YoastSEO_AMP constructor.
11
  * Plugin Name: Glue for Yoast SEO & AMP
12
  * Plugin URI: https://wordpress.org/plugins/glue-for-yoast-seo-amp/
13
  * Description: Makes sure the default WordPress AMP plugin uses the proper Yoast SEO metadata
14
+ * Version: 0.6
15
  * Author: Joost de Valk
16
  * Author URI: https://yoast.com
17
  * Text Domain: yoastseo-amp
25
  */
26
  class YoastSEO_AMP {
27
 
28
+ const VERSION = '0.6.0';
29
 
30
  /**
31
  * YoastSEO_AMP constructor.