Version Description
The Yoast SEO AMP plugin is no longer needed. Through good collaboration with Google the functionality of this plugin is now part of both Yoast SEO and the official AMP plugin. If you still have this plugin running wed suggest updating both the Yoast SEO and AMP plugins and removing the glue plugin.
Download this release
Release Info
Developer | Yoast |
Plugin | Glue for Yoast SEO & AMP |
Version | 0.7 |
Comparing to | |
See all releases |
Code changes from version 0.6 to 0.7
- classes/assets/amp-admin-page.css +0 -8
- classes/assets/amp-admin-page.js +0 -3
- classes/assets/wp-seo-admin-media.js +0 -81
- classes/backend.php +0 -157
- classes/blacklist-sanitizer.php +0 -166
- classes/css-builder.php +0 -80
- classes/form.php +0 -238
- classes/frontend.php +0 -457
- classes/options.php +0 -276
- classes/views/additional-css.php +0 -17
- classes/views/admin-page.php +0 -225
- readme.txt +7 -23
- yoastseo-amp.php +22 -24
classes/assets/amp-admin-page.css
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
.yst_colorpicker {
|
2 |
-
clear: right;
|
3 |
-
}
|
4 |
-
|
5 |
-
label.checkbox {
|
6 |
-
display: block;
|
7 |
-
margin-bottom: 0.4em;
|
8 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/assets/amp-admin-page.js
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
jQuery(document).ready(function($){
|
2 |
-
$('.yst_colorpicker').wpColorPicker();
|
3 |
-
});
|
|
|
|
|
|
classes/assets/wp-seo-admin-media.js
DELETED
@@ -1,81 +0,0 @@
|
|
1 |
-
/* global wpseoMediaL10n */
|
2 |
-
/* global wp */
|
3 |
-
|
4 |
-
// Taken and adapted from http://www.webmaster-source.com/2013/02/06/using-the-wordpress-3-5-media-uploader-in-your-plugin-or-theme/
|
5 |
-
jQuery( document ).ready(
|
6 |
-
function( $ ) {
|
7 |
-
if ( typeof wp.media === "undefined" ) {
|
8 |
-
return;
|
9 |
-
}
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Returns the target HTML id for this button element.
|
13 |
-
*
|
14 |
-
* @param {Object} $button The image select button.
|
15 |
-
* @returns {string} The HTML id for the URL input field.
|
16 |
-
*/
|
17 |
-
function getTarget( $button ) {
|
18 |
-
$button = $( $button );
|
19 |
-
|
20 |
-
let target = $button.data( "target" );
|
21 |
-
|
22 |
-
// This is the implicit way to define which URL field to fill.
|
23 |
-
if ( ! target || target === "" ) {
|
24 |
-
target = $( $button ).attr( "id" ).replace( /_button$/, "" );
|
25 |
-
}
|
26 |
-
|
27 |
-
return target;
|
28 |
-
}
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Returns the hidden ID input element for this button.
|
32 |
-
*
|
33 |
-
* @param {Object} $button The image select button.
|
34 |
-
* @returns {string} The HTML id for the ID input field.
|
35 |
-
*/
|
36 |
-
function getIdTarget( $button ) {
|
37 |
-
$button = $( $button );
|
38 |
-
|
39 |
-
return $button.data( "target-id" );
|
40 |
-
}
|
41 |
-
|
42 |
-
$( ".wpseo_image_upload_button" ).each( function( index, element ) {
|
43 |
-
const urlInputHtmlId = getTarget( element );
|
44 |
-
const idInputHtmlId = getIdTarget( element );
|
45 |
-
|
46 |
-
const $urlInput = $( "#" + urlInputHtmlId );
|
47 |
-
const $idInput = $( "#" + idInputHtmlId );
|
48 |
-
|
49 |
-
// eslint-disable-next-line
|
50 |
-
var wpseoCustomUploader = wp.media.frames.file_frame = wp.media( {
|
51 |
-
title: wpseoMediaL10n.choose_image,
|
52 |
-
button: { text: wpseoMediaL10n.choose_image },
|
53 |
-
multiple: false,
|
54 |
-
} );
|
55 |
-
|
56 |
-
wpseoCustomUploader.on( "select", function() {
|
57 |
-
var attachment = wpseoCustomUploader.state().get( "selection" ).first().toJSON();
|
58 |
-
|
59 |
-
$urlInput.val( attachment.url );
|
60 |
-
$idInput.val( attachment.id );
|
61 |
-
}
|
62 |
-
);
|
63 |
-
|
64 |
-
const $uploadImageButton = $( element );
|
65 |
-
|
66 |
-
$uploadImageButton.click( function( e ) {
|
67 |
-
e.preventDefault();
|
68 |
-
wpseoCustomUploader.open();
|
69 |
-
} );
|
70 |
-
|
71 |
-
$uploadImageButton
|
72 |
-
.siblings( ".wpseo_image_remove_button" )
|
73 |
-
.on( "click", ( e ) => {
|
74 |
-
e.preventDefault();
|
75 |
-
|
76 |
-
$urlInput.val( "" );
|
77 |
-
$idInput.val( "" );
|
78 |
-
} );
|
79 |
-
} );
|
80 |
-
}
|
81 |
-
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/backend.php
DELETED
@@ -1,157 +0,0 @@
|
|
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 |
-
if ( ! class_exists( 'YoastSEO_AMP_Backend', false ) ) {
|
12 |
-
/**
|
13 |
-
* This class improves upon the AMP output by the default WordPress AMP plugin using Yoast SEO metadata.
|
14 |
-
*/
|
15 |
-
class YoastSEO_AMP_Backend {
|
16 |
-
|
17 |
-
/**
|
18 |
-
* YoastSEO_AMP_Glue options.
|
19 |
-
*
|
20 |
-
* @var array
|
21 |
-
*/
|
22 |
-
public $options;
|
23 |
-
|
24 |
-
/**
|
25 |
-
* YoastSEO_AMP_Backend constructor.
|
26 |
-
*/
|
27 |
-
public function __construct() {
|
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 |
-
/**
|
40 |
-
* Filters out page post-type if not enabled in the AMP plugin.
|
41 |
-
*
|
42 |
-
* @param array $post_types Post types enabled for AMP support.
|
43 |
-
*
|
44 |
-
* @return array
|
45 |
-
*/
|
46 |
-
public function remove_page_post_type( $post_types ) {
|
47 |
-
if ( ! post_type_supports( 'page', AMP_QUERY_VAR ) ) {
|
48 |
-
unset( $post_types['page'] );
|
49 |
-
}
|
50 |
-
|
51 |
-
return $post_types;
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Add submenu item.
|
56 |
-
*
|
57 |
-
* @param array $sub_menu_pages Currently registered sub-menu pages.
|
58 |
-
*
|
59 |
-
* @return array
|
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 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* Displays the admin page.
|
78 |
-
*/
|
79 |
-
public function display() {
|
80 |
-
require_once 'form.php';
|
81 |
-
|
82 |
-
require 'views/admin-page.php';
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Enqueue admin page JS.
|
87 |
-
*/
|
88 |
-
public function enqueue_admin_page() {
|
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 |
-
|
96 |
-
wp_enqueue_media(); // Enqueue files needed for upload functionality.
|
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 |
-
);
|
104 |
-
wp_localize_script( 'wpseo-admin-media', 'wpseoMediaL10n', $this->localize_media_script() );
|
105 |
-
|
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 |
-
);
|
113 |
-
}
|
114 |
-
|
115 |
-
/**
|
116 |
-
* Pass some variables to js for upload module.
|
117 |
-
*
|
118 |
-
* @return array
|
119 |
-
*/
|
120 |
-
public function localize_media_script() {
|
121 |
-
return [
|
122 |
-
'choose_image' => __( 'Use Logo', 'yoastseo-amp' ),
|
123 |
-
];
|
124 |
-
}
|
125 |
-
|
126 |
-
/**
|
127 |
-
* Add admin page to admin_pages so the correct assets are loaded by WPSEO.
|
128 |
-
*
|
129 |
-
* @param array $admin_pages Currently registered admin pages.
|
130 |
-
*
|
131 |
-
* @return array
|
132 |
-
*/
|
133 |
-
public function add_admin_pages( $admin_pages ) {
|
134 |
-
$admin_pages[] = 'wpseo_amp';
|
135 |
-
|
136 |
-
return $admin_pages;
|
137 |
-
}
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Render a color picker.
|
141 |
-
*
|
142 |
-
* @param string $var Option key.
|
143 |
-
* @param string $label Option name.
|
144 |
-
*
|
145 |
-
* @SuppressWarnings("PMD.UnusedPrivateMethod") // As this is used in a view.
|
146 |
-
*/
|
147 |
-
private function color_picker( $var, $label ) {
|
148 |
-
echo '<label class="checkbox" for="', esc_attr( $var ), '">', esc_html( $label ), '</label>';
|
149 |
-
echo '<input type="text" name="', esc_attr( 'wpseo_amp[' . $var . ']' ), '"';
|
150 |
-
if ( isset( $this->options[ $var ] ) ) {
|
151 |
-
echo ' value="' . esc_attr( $this->options[ $var ] ) . '"';
|
152 |
-
}
|
153 |
-
echo ' class="yst_colorpicker" id="', esc_attr( $var ), '"/>';
|
154 |
-
echo '<br/>';
|
155 |
-
}
|
156 |
-
}
|
157 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/blacklist-sanitizer.php
DELETED
@@ -1,166 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* YoastSEO_AMP_Glue plugin file.
|
4 |
-
*
|
5 |
-
* @package YoastSEO_AMP_Glue\Sanitizer
|
6 |
-
* @copyright 2016 Yoast BV
|
7 |
-
* @license GPL-2.0+
|
8 |
-
*/
|
9 |
-
|
10 |
-
if ( ! defined( 'AMP__DIR__' ) ) {
|
11 |
-
header( 'Status: 403 Forbidden' );
|
12 |
-
header( 'HTTP/1.1 403 Forbidden' );
|
13 |
-
exit();
|
14 |
-
}
|
15 |
-
|
16 |
-
require_once AMP__DIR__ . '/includes/sanitizers/class-amp-base-sanitizer.php';
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Strips blacklisted tags and attributes from content, on top of the ones the AMP plugin already removes.
|
20 |
-
*
|
21 |
-
* See following for blacklist:
|
22 |
-
* {@link https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#html-tags}
|
23 |
-
*/
|
24 |
-
class Yoast_AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
|
25 |
-
|
26 |
-
/**
|
27 |
-
* The actual sanitization function.
|
28 |
-
*/
|
29 |
-
public function sanitize() {
|
30 |
-
$body = $this->get_body_node();
|
31 |
-
$this->strip_attributes_recursive( $body );
|
32 |
-
}
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Passes through the DOM and removes stuff that shouldn't be there.
|
36 |
-
*
|
37 |
-
* @param DOMNode $node The DOM node to strip attributes from.
|
38 |
-
*
|
39 |
-
* @return void
|
40 |
-
*/
|
41 |
-
private function strip_attributes_recursive( $node ) {
|
42 |
-
if ( $node->nodeType !== XML_ELEMENT_NODE ) {
|
43 |
-
return;
|
44 |
-
}
|
45 |
-
|
46 |
-
if ( $node->hasAttributes() ) {
|
47 |
-
$node_name = $node->nodeName;
|
48 |
-
$length = $node->attributes->length;
|
49 |
-
for ( $i = --$length; $i >= 0; $i-- ) {
|
50 |
-
$attribute = $node->attributes->item( $i );
|
51 |
-
|
52 |
-
switch ( $node_name ) {
|
53 |
-
case 'a':
|
54 |
-
$this->sanitize_a_attribute( $node, $attribute );
|
55 |
-
break;
|
56 |
-
case 'pre':
|
57 |
-
$this->sanitize_pre_attribute( $node, $attribute );
|
58 |
-
break;
|
59 |
-
case 'table':
|
60 |
-
$this->sanitize_table_attribute( $node, $attribute );
|
61 |
-
break;
|
62 |
-
case 'td':
|
63 |
-
case 'th':
|
64 |
-
$this->sanitize_cell_attribute( $node, $attribute );
|
65 |
-
break;
|
66 |
-
}
|
67 |
-
}
|
68 |
-
}
|
69 |
-
|
70 |
-
foreach ( $node->childNodes as $child_node ) {
|
71 |
-
$this->strip_attributes_recursive( $child_node );
|
72 |
-
}
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Passes through the DOM and strips forbidden tags.
|
77 |
-
*
|
78 |
-
* @param DOMNode $node The DOM node to strip the forbidden tags from.
|
79 |
-
* @param array $tag_names The forbidden tag names.
|
80 |
-
*
|
81 |
-
* @return void
|
82 |
-
*/
|
83 |
-
private function strip_tags( $node, $tag_names ) {
|
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 |
-
|
91 |
-
for ( $i = --$length; $i >= 0; $i-- ) {
|
92 |
-
$element = $elements->item( $i );
|
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 |
-
}
|
100 |
-
}
|
101 |
-
}
|
102 |
-
|
103 |
-
/**
|
104 |
-
* Sanitizes anchor attributes.
|
105 |
-
*
|
106 |
-
* @param DOMNode $node The DOM node to sanitize the passed attribute from.
|
107 |
-
* @param DOMNode $attribute The attribute to sanitize.
|
108 |
-
*
|
109 |
-
* @return void
|
110 |
-
*/
|
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 |
-
}
|
118 |
-
|
119 |
-
/**
|
120 |
-
* Sanitizes pre tag attributes.
|
121 |
-
*
|
122 |
-
* @param DOMNode $node The DOM node to sanitize the passed attribute from.
|
123 |
-
* @param DOMNode $attribute The attribute to sanitize.
|
124 |
-
*
|
125 |
-
* @return void
|
126 |
-
*/
|
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 |
-
}
|
134 |
-
|
135 |
-
/**
|
136 |
-
* Sanitizes td / th tag attributes.
|
137 |
-
*
|
138 |
-
* @param DOMNode $node The DOM node to sanitize the passed attribute from.
|
139 |
-
* @param DOMNode $attribute The attribute to sanitize.
|
140 |
-
*
|
141 |
-
* @return void
|
142 |
-
*/
|
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 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Sanitize table tag attributes.
|
153 |
-
*
|
154 |
-
* @param DOMNode $node The DOM node to sanitize the passed attribute from.
|
155 |
-
* @param DOMNode $attribute The attribute to sanitize.
|
156 |
-
*
|
157 |
-
* @return void
|
158 |
-
*/
|
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 |
-
}
|
166 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/css-builder.php
DELETED
@@ -1,80 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* YoastSEO_AMP_Glue plugin file.
|
4 |
-
*
|
5 |
-
* @package YoastSEO_AMP_Glue\CSS_Builder
|
6 |
-
* @author Jip Moors
|
7 |
-
* @copyright 2016 Yoast BV
|
8 |
-
* @license GPL-2.0+
|
9 |
-
*/
|
10 |
-
|
11 |
-
if ( ! class_exists( 'YoastSEO_AMP_CSS_Builder', false ) ) {
|
12 |
-
/**
|
13 |
-
* Class to build CSS.
|
14 |
-
*/
|
15 |
-
class YoastSEO_AMP_CSS_Builder {
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Option to CSS lookup map.
|
19 |
-
*
|
20 |
-
* @var array
|
21 |
-
*/
|
22 |
-
private $items = [];
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Adds the passed option to the CSS map.
|
26 |
-
*
|
27 |
-
* @param string $option_key Option key.
|
28 |
-
* @param string $selector CSS Selector.
|
29 |
-
* @param string $property CSS Property that will hold the value of the option.
|
30 |
-
*
|
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 |
-
/**
|
41 |
-
* Builds the CSS, based on the passed options, to be used on the frontend.
|
42 |
-
*
|
43 |
-
* @return string The CSS to be used on the frontend.
|
44 |
-
*/
|
45 |
-
public function build() {
|
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 );
|
53 |
-
|
54 |
-
if ( is_array( $apply ) ) {
|
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 ];
|
62 |
-
}
|
63 |
-
}
|
64 |
-
|
65 |
-
if ( ! empty( $css ) ) {
|
66 |
-
foreach ( $css as $selector => $properties ) {
|
67 |
-
|
68 |
-
$inner = '';
|
69 |
-
foreach ( $properties as $property => $value ) {
|
70 |
-
$inner .= sprintf( "%s: %s;\n", $property, $value );
|
71 |
-
}
|
72 |
-
|
73 |
-
$output .= sprintf( "%s {\n%s}\n", $selector, $inner );
|
74 |
-
}
|
75 |
-
}
|
76 |
-
|
77 |
-
return $output;
|
78 |
-
}
|
79 |
-
}
|
80 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/form.php
DELETED
@@ -1,238 +0,0 @@
|
|
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"> </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
DELETED
@@ -1,457 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* YoastSEO_AMP_Glue plugin file.
|
4 |
-
*
|
5 |
-
* @package YoastSEO_AMP_Glue\Frontend
|
6 |
-
* @author Joost de Valk
|
7 |
-
* @copyright 2016 Yoast BV
|
8 |
-
* @license GPL-2.0+
|
9 |
-
*/
|
10 |
-
|
11 |
-
if ( ! class_exists( 'YoastSEO_AMP_Frontend' ) ) {
|
12 |
-
/**
|
13 |
-
* This class improves upon the AMP output by the default WordPress AMP plugin using Yoast SEO metadata.
|
14 |
-
*/
|
15 |
-
class YoastSEO_AMP_Frontend {
|
16 |
-
|
17 |
-
/**
|
18 |
-
* WPSEO_Frontend singleton instance.
|
19 |
-
*
|
20 |
-
* @var WPSEO_Frontend
|
21 |
-
*/
|
22 |
-
private $front;
|
23 |
-
|
24 |
-
/**
|
25 |
-
* YoastSEO_AMP_Glue options.
|
26 |
-
*
|
27 |
-
* @var array
|
28 |
-
*/
|
29 |
-
private $options;
|
30 |
-
|
31 |
-
/**
|
32 |
-
* All WPSEO options.
|
33 |
-
*
|
34 |
-
* @var array
|
35 |
-
*/
|
36 |
-
private $wpseo_options;
|
37 |
-
|
38 |
-
/**
|
39 |
-
* YoastSEO_AMP_Frontend constructor.
|
40 |
-
*/
|
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 |
-
/**
|
58 |
-
* Retrieve the plugin options and set the relevant properties.
|
59 |
-
*
|
60 |
-
* @return void
|
61 |
-
*/
|
62 |
-
private function set_options() {
|
63 |
-
$this->wpseo_options = WPSEO_Options::get_all();
|
64 |
-
$this->options = YoastSEO_AMP_Options::get();
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Adds the blacklist sanitizer to the array of available sanitizers.
|
69 |
-
*
|
70 |
-
* @param array $sanitizers The current list of sanitizers.
|
71 |
-
*
|
72 |
-
* @return array The new array of sanitizers.
|
73 |
-
*/
|
74 |
-
public function add_sanitizer( $sanitizers ) {
|
75 |
-
require_once 'blacklist-sanitizer.php';
|
76 |
-
|
77 |
-
$sanitizers['Yoast_AMP_Blacklist_Sanitizer'] = [];
|
78 |
-
|
79 |
-
return $sanitizers;
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Outputs the analytics tracking, if it has been set.
|
84 |
-
*
|
85 |
-
* @param array $analytics The available analytics options.
|
86 |
-
*
|
87 |
-
* @return array The analytics tracking code to output.
|
88 |
-
*/
|
89 |
-
public function analytics( $analytics ) {
|
90 |
-
// If Monster Insights is outputting analytics, don't do anything.
|
91 |
-
if ( ! empty( $analytics['monsterinsights-googleanalytics'] ) ) {
|
92 |
-
// Clear analytics-extra options because Monster Insights is taking care of everything.
|
93 |
-
$this->options['analytics-extra'] = '';
|
94 |
-
|
95 |
-
return $analytics;
|
96 |
-
}
|
97 |
-
|
98 |
-
if ( ! empty( $this->options['analytics-extra'] ) ) {
|
99 |
-
return $analytics;
|
100 |
-
}
|
101 |
-
|
102 |
-
if ( ! class_exists( 'Yoast_GA_Options' ) || Yoast_GA_Options::instance()->get_tracking_code() === null ) {
|
103 |
-
return $analytics;
|
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 |
-
}
|
125 |
-
|
126 |
-
/**
|
127 |
-
* Enables AMP for all the post types we want it for.
|
128 |
-
*
|
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;
|
137 |
-
|
138 |
-
if ( ! isset( $this->options[ 'post_types-' . $post_type_name . '-amp' ] ) ) {
|
139 |
-
continue;
|
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 |
-
|
147 |
-
if ( $this->options[ 'post_types-' . $post_type_name . '-amp' ] === 'on' ) {
|
148 |
-
add_post_type_support( $post_type_name, AMP_QUERY_VAR );
|
149 |
-
continue;
|
150 |
-
}
|
151 |
-
|
152 |
-
if ( $post_type_name === 'post' ) {
|
153 |
-
add_action( 'wp', [ $this, 'disable_amp_for_posts' ] );
|
154 |
-
continue;
|
155 |
-
}
|
156 |
-
|
157 |
-
remove_post_type_support( $post_type_name, AMP_QUERY_VAR );
|
158 |
-
}
|
159 |
-
}
|
160 |
-
}
|
161 |
-
|
162 |
-
/**
|
163 |
-
* Disables AMP for posts specifically.
|
164 |
-
*
|
165 |
-
* {@internal Runs later because of AMP plugin internals.}
|
166 |
-
*
|
167 |
-
* @return void
|
168 |
-
*/
|
169 |
-
public function disable_amp_for_posts() {
|
170 |
-
remove_post_type_support( 'post', AMP_QUERY_VAR );
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Transforms the site's canonical URL and site icon URL and to be AMP compliant.
|
175 |
-
*
|
176 |
-
* Also ensures that the proper analytics script is loaded (if applicable).
|
177 |
-
*
|
178 |
-
* @param array $data The current post data.
|
179 |
-
*
|
180 |
-
* @return array The transformed post data.
|
181 |
-
*/
|
182 |
-
public function fix_amp_post_data( $data ) {
|
183 |
-
if ( ! $this->front ) {
|
184 |
-
$this->front = WPSEO_Frontend::get_instance();
|
185 |
-
}
|
186 |
-
|
187 |
-
$data['canonical_url'] = $this->front->canonical( false );
|
188 |
-
|
189 |
-
if ( ! empty( $this->options['amp_site_icon'] ) ) {
|
190 |
-
$data['site_icon_url'] = $this->options['amp_site_icon'];
|
191 |
-
}
|
192 |
-
|
193 |
-
// If we are loading extra analytics, we need to load the module too.
|
194 |
-
if ( ! empty( $this->options['analytics-extra'] ) ) {
|
195 |
-
$data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
|
196 |
-
}
|
197 |
-
|
198 |
-
return $data;
|
199 |
-
}
|
200 |
-
|
201 |
-
/**
|
202 |
-
* Transforms the site's organization object, site description and post image to be AMP compliant.
|
203 |
-
*
|
204 |
-
* @param array $metadata The meta data to transform.
|
205 |
-
* @param WP_Post $post The post to transform the meta data for.
|
206 |
-
*
|
207 |
-
* @return array The transformed post meta data.
|
208 |
-
*/
|
209 |
-
public function fix_amp_post_metadata( $metadata, $post ) {
|
210 |
-
if ( ! $this->front ) {
|
211 |
-
$this->front = WPSEO_Frontend::get_instance();
|
212 |
-
}
|
213 |
-
|
214 |
-
$this->build_organization_object( $metadata );
|
215 |
-
|
216 |
-
$desc = $this->front->metadesc( false );
|
217 |
-
if ( $desc ) {
|
218 |
-
$metadata['description'] = $desc;
|
219 |
-
}
|
220 |
-
|
221 |
-
$image = isset( $metadata['image'] ) ? $metadata['image'] : null;
|
222 |
-
|
223 |
-
$metadata['image'] = $this->get_image( $post, $image );
|
224 |
-
$metadata['@type'] = $this->get_post_schema_type( $post );
|
225 |
-
|
226 |
-
return $metadata;
|
227 |
-
}
|
228 |
-
|
229 |
-
/**
|
230 |
-
* Adds additional CSS to the AMP output.
|
231 |
-
*
|
232 |
-
* @return void
|
233 |
-
*/
|
234 |
-
public function additional_css() {
|
235 |
-
require 'views/additional-css.php';
|
236 |
-
|
237 |
-
$selectors = $this->get_class_selectors();
|
238 |
-
|
239 |
-
$css_builder = new YoastSEO_AMP_CSS_Builder();
|
240 |
-
$css_builder->add_option( 'header-color', $selectors['header-color'], 'background' );
|
241 |
-
$css_builder->add_option( 'headings-color', $selectors['headings-color'], 'color' );
|
242 |
-
$css_builder->add_option( 'text-color', $selectors['text-color'], 'color' );
|
243 |
-
|
244 |
-
$css_builder->add_option( 'blockquote-bg-color', $selectors['blockquote-bg-color'], 'background-color' );
|
245 |
-
$css_builder->add_option( 'blockquote-border-color', $selectors['blockquote-border-color'], 'border-color' );
|
246 |
-
$css_builder->add_option( 'blockquote-text-color', $selectors['blockquote-text-color'], 'color' );
|
247 |
-
|
248 |
-
$css_builder->add_option( 'link-color', $selectors['link-color'], 'color' );
|
249 |
-
$css_builder->add_option( 'link-color-hover', $selectors['link-color-hover'], 'color' );
|
250 |
-
|
251 |
-
$css_builder->add_option( 'meta-color', $selectors['meta-color'], 'color' );
|
252 |
-
|
253 |
-
echo $css_builder->build();
|
254 |
-
|
255 |
-
if ( ! empty( $this->options['extra-css'] ) ) {
|
256 |
-
$safe_text = strip_tags( $this->options['extra-css'] );
|
257 |
-
$safe_text = wp_check_invalid_utf8( $safe_text );
|
258 |
-
$safe_text = _wp_specialchars( $safe_text, ENT_NOQUOTES );
|
259 |
-
echo $safe_text;
|
260 |
-
}
|
261 |
-
}
|
262 |
-
|
263 |
-
/**
|
264 |
-
* Outputs extra code in the head, if set.
|
265 |
-
*
|
266 |
-
* @return void
|
267 |
-
*/
|
268 |
-
public function extra_head() {
|
269 |
-
$options = WPSEO_Options::get_option( 'wpseo_social' );
|
270 |
-
|
271 |
-
if ( $options['twitter'] === true ) {
|
272 |
-
WPSEO_Twitter::get_instance();
|
273 |
-
}
|
274 |
-
|
275 |
-
if ( $options['opengraph'] === true ) {
|
276 |
-
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WPSEO global var.
|
277 |
-
$GLOBALS['wpseo_og'] = new WPSEO_OpenGraph();
|
278 |
-
}
|
279 |
-
|
280 |
-
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPSEO hook.
|
281 |
-
do_action( 'wpseo_opengraph' );
|
282 |
-
|
283 |
-
echo strip_tags( $this->options['extra-head'], '<link><meta>' );
|
284 |
-
}
|
285 |
-
|
286 |
-
/**
|
287 |
-
* Outputs analytics code in the footer, if set.
|
288 |
-
*
|
289 |
-
* @return void
|
290 |
-
*/
|
291 |
-
public function extra_footer() {
|
292 |
-
echo $this->options['analytics-extra'];
|
293 |
-
}
|
294 |
-
|
295 |
-
/**
|
296 |
-
* Builds the organization object if needed.
|
297 |
-
*
|
298 |
-
* @param array $metadata The data to base the organization object on.
|
299 |
-
*
|
300 |
-
* @return void
|
301 |
-
*/
|
302 |
-
private function build_organization_object( &$metadata ) {
|
303 |
-
// While it's using the blog name, it's actually outputting the company name.
|
304 |
-
if ( ! empty( $this->wpseo_options['company_name'] ) ) {
|
305 |
-
$metadata['publisher']['name'] = $this->wpseo_options['company_name'];
|
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 |
-
}
|
313 |
-
}
|
314 |
-
|
315 |
-
/**
|
316 |
-
* Builds an image object array from an image URL.
|
317 |
-
*
|
318 |
-
* @param string $image_url Image URL to build URL for.
|
319 |
-
* @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width
|
320 |
-
* and height values in pixels (in that order). Default 'full'.
|
321 |
-
*
|
322 |
-
* @return array|false The image object array or false if the image URL is empty.
|
323 |
-
*/
|
324 |
-
private function get_image_object( $image_url, $size = 'full' ) {
|
325 |
-
if ( empty( $image_url ) ) {
|
326 |
-
return false;
|
327 |
-
}
|
328 |
-
|
329 |
-
$image_id = attachment_url_to_postid( $image_url );
|
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;
|
342 |
-
}
|
343 |
-
|
344 |
-
/**
|
345 |
-
* Retrieves the Schema.org image for the passed post.
|
346 |
-
*
|
347 |
-
* If an OpenGraph image is available for the post, that one will be used. Otherwise, the default image is used.
|
348 |
-
* If neither exist, the passed image is used instead.
|
349 |
-
*
|
350 |
-
* @param WP_Post $post The post to retrieve the image for.
|
351 |
-
* @param string|string[]|array|array[]|null $image The currently set post image(s). Can be either a URL string,
|
352 |
-
* an array of URL strings, an array as a single ImageObject,
|
353 |
-
* or an array of multiple ImageObject arrays. Null if none set.
|
354 |
-
*
|
355 |
-
* @return string|string[]|array|array[]|null The Schema.org-compliant image for the post.
|
356 |
-
*/
|
357 |
-
private function get_image( $post, $image ) {
|
358 |
-
$og_image = $this->get_image_object( WPSEO_Meta::get_value( 'opengraph-image', $post->ID ) );
|
359 |
-
if ( is_array( $og_image ) ) {
|
360 |
-
return $og_image;
|
361 |
-
}
|
362 |
-
|
363 |
-
// Posts without an image fail validation in Google, leading to Search Console errors.
|
364 |
-
if ( empty( $image ) && ! empty( $this->options['default_image'] ) ) {
|
365 |
-
$default_image = $this->get_image_object( $this->options['default_image'] );
|
366 |
-
if ( is_array( $default_image ) ) {
|
367 |
-
return $default_image;
|
368 |
-
}
|
369 |
-
}
|
370 |
-
|
371 |
-
return $image;
|
372 |
-
}
|
373 |
-
|
374 |
-
/**
|
375 |
-
* Gets the Schema.org type for the post, based on the post type.
|
376 |
-
*
|
377 |
-
* @param WP_Post $post The post to retrieve the data for.
|
378 |
-
*
|
379 |
-
* @return string The Schema.org type.
|
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 |
-
}
|
416 |
-
|
417 |
-
/**
|
418 |
-
* Gets the class names used by the AMP plugin.
|
419 |
-
*
|
420 |
-
* The AMP plugin changed the class names for a number of selectors between releases.
|
421 |
-
* This method makes sure the correct CSS class name is used depending on the used version of the AMP plugin.
|
422 |
-
*
|
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',
|
430 |
-
|
431 |
-
'blockquote-bg-color' => '.amp-wp-content blockquote',
|
432 |
-
'blockquote-border-color' => '.amp-wp-content blockquote',
|
433 |
-
'blockquote-text-color' => '.amp-wp-content blockquote',
|
434 |
-
|
435 |
-
'link-color' => 'a, a:active, a:visited',
|
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 |
-
|
454 |
-
return $selectors;
|
455 |
-
}
|
456 |
-
}
|
457 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/options.php
DELETED
@@ -1,276 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* YoastSEO_AMP_Glue plugin file.
|
4 |
-
*
|
5 |
-
* @package YoastSEO_AMP_Glue\Options
|
6 |
-
* @author Jip Moors
|
7 |
-
* @copyright 2016 Yoast BV
|
8 |
-
* @license GPL-2.0+
|
9 |
-
*/
|
10 |
-
|
11 |
-
if ( ! class_exists( 'YoastSEO_AMP_Options' ) ) {
|
12 |
-
/**
|
13 |
-
* Class to manage the YoastSEO_AMP option.
|
14 |
-
*/
|
15 |
-
class YoastSEO_AMP_Options {
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Name of the option in the database.
|
19 |
-
*
|
20 |
-
* @var string
|
21 |
-
*/
|
22 |
-
private $option_name = 'wpseo_amp';
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Current options.
|
26 |
-
*
|
27 |
-
* @var array
|
28 |
-
*/
|
29 |
-
private $options;
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Option defaults.
|
33 |
-
*
|
34 |
-
* @var array
|
35 |
-
*/
|
36 |
-
private $defaults = [
|
37 |
-
'version' => 1,
|
38 |
-
'amp_site_icon' => '',
|
39 |
-
'default_image' => '',
|
40 |
-
'header-color' => '',
|
41 |
-
'headings-color' => '',
|
42 |
-
'text-color' => '',
|
43 |
-
'meta-color' => '',
|
44 |
-
'link-color' => '',
|
45 |
-
'link-color-hover' => '',
|
46 |
-
'underline' => 'underline',
|
47 |
-
'blockquote-text-color' => '',
|
48 |
-
'blockquote-bg-color' => '',
|
49 |
-
'blockquote-border-color' => '',
|
50 |
-
'extra-css' => '',
|
51 |
-
'extra-head' => '',
|
52 |
-
'analytics-extra' => '',
|
53 |
-
];
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Class instance.
|
57 |
-
*
|
58 |
-
* @var self
|
59 |
-
*/
|
60 |
-
private static $instance;
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Constructor.
|
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 |
-
/**
|
78 |
-
* Sanitize options.
|
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;
|
86 |
-
|
87 |
-
// Sanitize extra CSS field.
|
88 |
-
$extra_css = strip_tags( $options['extra-css'] );
|
89 |
-
$extra_css = wp_check_invalid_utf8( $extra_css );
|
90 |
-
$extra_css = _wp_specialchars( $extra_css, ENT_NOQUOTES );
|
91 |
-
$options['extra-css'] = $extra_css;
|
92 |
-
|
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',
|
100 |
-
'meta-color',
|
101 |
-
'link-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 ], '' );
|
109 |
-
}
|
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 |
-
}
|
117 |
-
|
118 |
-
$options['analytics-extra'] = $this->sanitize_analytics_code( $options['analytics-extra'] );
|
119 |
-
|
120 |
-
return $options;
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Sanitize hexadecimal color.
|
125 |
-
*
|
126 |
-
* @param string $color String to test for valid color.
|
127 |
-
* @param string $default Value the string will get when no color is found.
|
128 |
-
*
|
129 |
-
* @return string Color or $default.
|
130 |
-
*/
|
131 |
-
private function sanitize_color( $color, $default ) {
|
132 |
-
if ( preg_match( '~^#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})$~', $color, $matches ) ) {
|
133 |
-
return $matches[0];
|
134 |
-
}
|
135 |
-
|
136 |
-
return $default;
|
137 |
-
}
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Sanitize analytics code.
|
141 |
-
*
|
142 |
-
* @param string $source Raw input.
|
143 |
-
*
|
144 |
-
* @return string Sanitized code.
|
145 |
-
*/
|
146 |
-
private function sanitize_analytics_code( $source ) {
|
147 |
-
$source = trim( $source );
|
148 |
-
|
149 |
-
if ( empty( $source ) ) {
|
150 |
-
return '';
|
151 |
-
}
|
152 |
-
|
153 |
-
// If no <amp-analytics> occurs in the code, the code is invalid.
|
154 |
-
if ( strpos( $source, '<amp-analytics ' ) === false ) {
|
155 |
-
return '';
|
156 |
-
}
|
157 |
-
|
158 |
-
if ( strpos( $source, '<script type="application/json">' ) === false ) {
|
159 |
-
return strip_tags( $source, '<amp-analytics>' );
|
160 |
-
}
|
161 |
-
|
162 |
-
return $this->sanitize_analytics_json( $source );
|
163 |
-
}
|
164 |
-
|
165 |
-
/**
|
166 |
-
* Get the options.
|
167 |
-
*
|
168 |
-
* @return array
|
169 |
-
*/
|
170 |
-
public static function get() {
|
171 |
-
|
172 |
-
$me = self::get_instance();
|
173 |
-
$me->fetch_options();
|
174 |
-
|
175 |
-
return $me->options;
|
176 |
-
}
|
177 |
-
|
178 |
-
/**
|
179 |
-
* Get the singleton instance of this class.
|
180 |
-
*
|
181 |
-
* @return YoastSEO_AMP_Options
|
182 |
-
*/
|
183 |
-
public static function get_instance() {
|
184 |
-
if ( ! isset( self::$instance ) ) {
|
185 |
-
self::$instance = new self();
|
186 |
-
}
|
187 |
-
|
188 |
-
return self::$instance;
|
189 |
-
}
|
190 |
-
|
191 |
-
/**
|
192 |
-
* Collect options.
|
193 |
-
*
|
194 |
-
* @SuppressWarnings("PMD.UnusedPrivateMethod")
|
195 |
-
*/
|
196 |
-
private function fetch_options() {
|
197 |
-
$saved_options = $this->options;
|
198 |
-
if ( ! is_array( $this->options ) ) {
|
199 |
-
$saved_options = get_option( 'wpseo_amp' );
|
200 |
-
|
201 |
-
// Apply defaults.
|
202 |
-
$this->options = wp_parse_args( $saved_options, $this->defaults );
|
203 |
-
}
|
204 |
-
|
205 |
-
// Make sure all post types are present.
|
206 |
-
$this->update_post_type_settings();
|
207 |
-
|
208 |
-
// Save changes to database.
|
209 |
-
if ( $this->options !== $saved_options ) {
|
210 |
-
update_option( $this->option_name, $this->options );
|
211 |
-
}
|
212 |
-
}
|
213 |
-
|
214 |
-
/**
|
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 |
-
}
|
230 |
-
|
231 |
-
$post_type_names[] = $post_type->name;
|
232 |
-
}
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
-
/**
|
237 |
-
* Sanitizes an analytics string when it has JSON in it.
|
238 |
-
*
|
239 |
-
* @param string $code The code to sanitize.
|
240 |
-
*
|
241 |
-
* @return string Sanitized string.
|
242 |
-
*/
|
243 |
-
private function sanitize_analytics_json( $code ) {
|
244 |
-
// Strip all tags, to verify JSON input.
|
245 |
-
$json = strip_tags( $code );
|
246 |
-
|
247 |
-
// Non-parsable JSON is always bad.
|
248 |
-
if ( is_null( json_decode( $json, true ) ) ) {
|
249 |
-
return '';
|
250 |
-
}
|
251 |
-
|
252 |
-
$allowed_tags = strip_tags( $code, '<amp-analytics>' );
|
253 |
-
|
254 |
-
// Strip JSON content so we can apply verified script tag.
|
255 |
-
$tag = str_replace( $json, '', $allowed_tags );
|
256 |
-
|
257 |
-
$parts = explode( '><', $tag );
|
258 |
-
$parts[0] .= '>';
|
259 |
-
$parts[1] = '<' . $parts[1];
|
260 |
-
|
261 |
-
// Rebuild with script tag and JSON content.
|
262 |
-
array_splice(
|
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 );
|
274 |
-
}
|
275 |
-
}
|
276 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/views/additional-css.php
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* YoastSEO_AMP_Glue plugin file.
|
4 |
-
*
|
5 |
-
* @package YoastSEO_AMP_Glue
|
6 |
-
* @copyright 2016 Yoast BV
|
7 |
-
* @license GPL-2.0+
|
8 |
-
*/
|
9 |
-
|
10 |
-
?>
|
11 |
-
td, th {
|
12 |
-
text-align: left;
|
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
DELETED
@@ -1,225 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* YoastSEO_AMP_Glue plugin file.
|
4 |
-
*
|
5 |
-
* @package YoastSEO_AMP_Glue
|
6 |
-
* @copyright 2016 Yoast BV
|
7 |
-
* @license GPL-2.0+
|
8 |
-
*/
|
9 |
-
|
10 |
-
if ( ! defined( 'WPSEO_VERSION' ) ) {
|
11 |
-
header( 'Status: 403 Forbidden' );
|
12 |
-
header( 'HTTP/1.1 403 Forbidden' );
|
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>
|
22 |
-
<a class="nav-tab" id="analytics-tab" href="#top#analytics"><?php esc_html_e( 'Analytics', 'yoastseo-amp' ); ?></a>
|
23 |
-
</h2>
|
24 |
-
|
25 |
-
<div class="tabwrapper">
|
26 |
-
|
27 |
-
<div id="posttypes" class="wpseotab">
|
28 |
-
<h2><?php esc_html_e( 'Post types that have AMP support', 'yoastseo-amp' ); ?></h2>
|
29 |
-
<p><?php esc_html_e( 'Generally you\'d want this to be your news post types.', 'yoastseo-amp' ); ?><br/>
|
30 |
-
<?php esc_html_e( 'Post is enabled by default, feel free to enable any of them.', 'yoastseo-amp' ); ?></p>
|
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 |
-
}
|
70 |
-
}
|
71 |
-
|
72 |
-
if ( ! post_type_supports( 'page', AMP_QUERY_VAR ) ) :
|
73 |
-
?>
|
74 |
-
<br>
|
75 |
-
<strong><?php esc_html_e( 'Please note:', 'yoastseo-amp' ); ?></strong>
|
76 |
-
<?php esc_html_e( 'Currently pages are not supported by the AMP plugin.', 'yoastseo-amp' ); ?>
|
77 |
-
<?php
|
78 |
-
endif;
|
79 |
-
?>
|
80 |
-
</p>
|
81 |
-
</div>
|
82 |
-
|
83 |
-
<div id="design" class="wpseotab">
|
84 |
-
<h3><?php esc_html_e( 'Images', 'yoastseo-amp' ); ?></h3>
|
85 |
-
|
86 |
-
<?php
|
87 |
-
$yoast_amp_yform->media_input( 'amp_site_icon', __( 'AMP icon', 'yoastseo-amp' ) );
|
88 |
-
?>
|
89 |
-
<p class="desc"><?php esc_html_e( 'Must be at least 32px × 32px', 'yoastseo-amp' ); ?></p>
|
90 |
-
<br/>
|
91 |
-
|
92 |
-
<?php
|
93 |
-
$yoast_amp_yform->media_input( 'default_image', __( 'Default image', 'yoastseo-amp' ) );
|
94 |
-
?>
|
95 |
-
<p class="desc"><?php esc_html_e( 'Used when a post doesn\'t have an image associated with it.', 'yoastseo-amp' ); ?>
|
96 |
-
<br><?php esc_html_e( 'The image must be at least 696px wide.', 'yoastseo-amp' ); ?></p>
|
97 |
-
<br/>
|
98 |
-
|
99 |
-
<h3><?php esc_html_e( 'Content colors', 'yoastseo-amp' ); ?></h3>
|
100 |
-
|
101 |
-
<?php
|
102 |
-
$this->color_picker( 'header-color', __( 'AMP Header color', 'yoastseo-amp' ) );
|
103 |
-
$this->color_picker( 'headings-color', __( 'Title color', 'yoastseo-amp' ) );
|
104 |
-
$this->color_picker( 'text-color', __( 'Text color', 'yoastseo-amp' ) );
|
105 |
-
$this->color_picker( 'meta-color', __( 'Post meta info color', 'yoastseo-amp' ) );
|
106 |
-
?>
|
107 |
-
<br/>
|
108 |
-
|
109 |
-
<h3><?php esc_html_e( 'Links', 'yoastseo-amp' ); ?></h3>
|
110 |
-
<?php
|
111 |
-
$this->color_picker( 'link-color', __( 'Text color', 'yoastseo-amp' ) );
|
112 |
-
$this->color_picker( 'link-color-hover', __( 'Hover color', 'yoastseo-amp' ) );
|
113 |
-
?>
|
114 |
-
|
115 |
-
<?php
|
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 |
-
|
126 |
-
<br/>
|
127 |
-
|
128 |
-
<h3><?php esc_html_e( 'Blockquotes', 'yoastseo-amp' ); ?></h3>
|
129 |
-
<?php
|
130 |
-
$this->color_picker( 'blockquote-text-color', __( 'Text color', 'yoastseo-amp' ) );
|
131 |
-
$this->color_picker( 'blockquote-bg-color', __( 'Background color', 'yoastseo-amp' ) );
|
132 |
-
$this->color_picker( 'blockquote-border-color', __( 'Border color', 'yoastseo-amp' ) );
|
133 |
-
?>
|
134 |
-
<br/>
|
135 |
-
|
136 |
-
<h3><?php esc_html_e( 'Extra CSS', 'yoastseo-amp' ); ?></h3>
|
137 |
-
<?php
|
138 |
-
$yoast_amp_yform->textarea(
|
139 |
-
'extra-css',
|
140 |
-
__( 'Extra CSS', 'yoastseo-amp' ),
|
141 |
-
[
|
142 |
-
'rows' => 5,
|
143 |
-
'cols' => 100,
|
144 |
-
]
|
145 |
-
);
|
146 |
-
?>
|
147 |
-
|
148 |
-
<br/>
|
149 |
-
|
150 |
-
<h3>
|
151 |
-
<?php
|
152 |
-
/* translators: %s: 'head' - as in HTML head - wrapped in <code> tags. */
|
153 |
-
printf( esc_html__( 'Extra code in %s', 'yoastseo-amp' ), '<code><head></code>' );
|
154 |
-
?>
|
155 |
-
</h3>
|
156 |
-
<p>
|
157 |
-
<?php
|
158 |
-
printf(
|
159 |
-
/* translators: 1: 'meta'; 2: 'link' - both wrapped in <code> tags. */
|
160 |
-
esc_html__( 'Only %1$s and %2$s tags are allowed, other tags will be removed automatically.', 'yoastseo-amp' ),
|
161 |
-
'<code>meta</code>',
|
162 |
-
'<code>link</code>'
|
163 |
-
);
|
164 |
-
?>
|
165 |
-
</p>
|
166 |
-
<?php
|
167 |
-
$yoast_amp_yform->textarea(
|
168 |
-
'extra-head',
|
169 |
-
__( 'Extra code', 'yoastseo-amp' ),
|
170 |
-
[
|
171 |
-
'rows' => 5,
|
172 |
-
'cols' => 100,
|
173 |
-
]
|
174 |
-
);
|
175 |
-
?>
|
176 |
-
|
177 |
-
</div>
|
178 |
-
|
179 |
-
<div id="analytics" class="wpseotab">
|
180 |
-
<h2><?php esc_html_e( 'AMP Analytics', 'yoastseo-amp' ); ?></h2>
|
181 |
-
|
182 |
-
<?php
|
183 |
-
if ( class_exists( 'Yoast_GA_Options' ) ) {
|
184 |
-
echo '<p>', esc_html__( 'Because your Google Analytics plugin by Yoast is active, your AMP pages will also be tracked.', 'yoastseo-amp' ), '<br>';
|
185 |
-
$yoastseo_amp_ga_tracking_code = Yoast_GA_Options::instance()->get_tracking_code();
|
186 |
-
if ( $yoastseo_amp_ga_tracking_code === null ) {
|
187 |
-
esc_html_e( 'Make sure to connect your Google Analytics plugin properly.', 'yoastseo-amp' );
|
188 |
-
}
|
189 |
-
else {
|
190 |
-
printf(
|
191 |
-
/* translators: %s: google analytics tracking code. */
|
192 |
-
esc_html__( 'Pageviews will be tracked using the following account: %s.', 'yoastseo-amp' ),
|
193 |
-
'<code>' . esc_html( $yoastseo_amp_ga_tracking_code ) . '</code>'
|
194 |
-
);
|
195 |
-
}
|
196 |
-
|
197 |
-
echo '</p>';
|
198 |
-
|
199 |
-
echo '<p>', esc_html__( 'Optionally you can override the default AMP tracking code with your own by putting it below:', 'yoastseo-amp' ), '</p>';
|
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 {
|
210 |
-
echo '<p>', esc_html__( 'Optionally add a valid google analytics tracking code.', 'yoastseo-amp' ), '</p>';
|
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,40 +1,24 @@
|
|
1 |
=== Glue for Yoast SEO & AMP ===
|
2 |
Contributors: joostdevalk
|
3 |
Tags: AMP, SEO
|
4 |
-
Requires at least: 5.
|
5 |
Tested up to: 5.4
|
6 |
-
Stable tag: 0.
|
7 |
Requires PHP: 5.6.20
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
-
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
The Yoast SEO: AMP Glue plugin integrates [Yoast SEO](https://wordpress.org/plugins/wordpress-seo/) into your AMP pages. This makes sure your meta-data is implemented correctly.
|
18 |
-
|
19 |
-
Next to the technical SEO improvements, the Yoast SEO: AMP Glue plugin also provides a simple way to customize your AMP pages.
|
20 |
-
It adds rudimental styling in the form of colors and link styles, so your AMP pages can maintain the feeling your main pages have.
|
21 |
-
To change your AMP page design, go to SEO -> AMP, and look at the design tab.
|
22 |
-
|
23 |
-
== Installation ==
|
24 |
-
|
25 |
-
1. Upload the plugin files to the `/wp-content/plugins/yoast-seo-amp` directory, or install the plugin through the WordPress plugins screen directly.
|
26 |
-
1. Activate the plugin through the 'Plugins' screen in WordPress
|
27 |
-
1. Go to SEO -> AMP to change your design and enable custom post types.
|
28 |
-
1. You're done.
|
29 |
-
|
30 |
-
== Screenshots ==
|
31 |
-
|
32 |
-
1. Example AMP page, design changed with this plugin.
|
33 |
-
2. Post type support in the plugin.
|
34 |
-
3. Design settings in the plugin.
|
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.
|
1 |
=== Glue for Yoast SEO & AMP ===
|
2 |
Contributors: joostdevalk
|
3 |
Tags: AMP, SEO
|
4 |
+
Requires at least: 5.2
|
5 |
Tested up to: 5.4
|
6 |
+
Stable tag: 0.7
|
7 |
Requires PHP: 5.6.20
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
+
The Yoast SEO AMP plugin is no longer needed. Through good collaboration with Google the functionality of this plugin is now part of both Yoast SEO and the official AMP plugin.
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
+
The Yoast SEO AMP plugin is no longer needed. Through good collaboration with Google the functionality of this plugin is now part of both Yoast SEO and the official AMP plugin. If you still have this plugin running we’d suggest updating both the Yoast SEO and AMP plugins and removing the glue plugin.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
== Changelog ==
|
18 |
|
19 |
+
= 0.7 =
|
20 |
+
The Yoast SEO AMP plugin is no longer needed. Through good collaboration with Google the functionality of this plugin is now part of both Yoast SEO and the official AMP plugin. If you still have this plugin running we’d suggest updating both the Yoast SEO and AMP plugins and removing the glue plugin.
|
21 |
+
|
22 |
= 0.6 =
|
23 |
* Bugfixes:
|
24 |
* Fixes a bug where the saved option values weren't reflected in the form fields.
|
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.
|
15 |
* Author: Joost de Valk
|
16 |
* Author URI: https://yoast.com
|
17 |
* Text Domain: yoastseo-amp
|
@@ -25,37 +25,35 @@ if ( ! class_exists( 'YoastSEO_AMP', false ) ) {
|
|
25 |
*/
|
26 |
class YoastSEO_AMP {
|
27 |
|
28 |
-
const VERSION = '0.
|
29 |
|
30 |
/**
|
31 |
* YoastSEO_AMP constructor.
|
32 |
*/
|
33 |
public function __construct() {
|
34 |
-
|
35 |
-
require 'classes/options.php';
|
36 |
-
|
37 |
-
if ( is_admin() ) {
|
38 |
-
require 'classes/backend.php';
|
39 |
-
new YoastSEO_AMP_Backend();
|
40 |
-
return;
|
41 |
-
}
|
42 |
-
|
43 |
-
require 'classes/css-builder.php';
|
44 |
-
require 'classes/frontend.php';
|
45 |
-
new YoastSEO_AMP_Frontend();
|
46 |
}
|
47 |
-
}
|
48 |
-
}
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
58 |
}
|
59 |
|
60 |
-
|
61 |
}
|
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.7
|
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.7';
|
29 |
|
30 |
/**
|
31 |
* YoastSEO_AMP constructor.
|
32 |
*/
|
33 |
public function __construct() {
|
34 |
+
add_action( 'admin_notices', [ $this, 'sunset_notification' ] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
}
|
|
|
|
|
36 |
|
37 |
+
/**
|
38 |
+
* Outputs a WordPress admin notice.
|
39 |
+
*
|
40 |
+
* @return void
|
41 |
+
*/
|
42 |
+
public function sunset_notification() {
|
43 |
+
global $pagenow;
|
44 |
+
|
45 |
+
if ( in_array( $pagenow, [ 'plugins.php', 'plugin-install.php', 'update-core.php' ], true ) ) {
|
46 |
+
printf(
|
47 |
+
'<div class="notice notice-info"><p>%1$s</p></div>',
|
48 |
+
sprintf(
|
49 |
+
/* translators: 1: Expands to "Yoast SEO AMP". */
|
50 |
+
esc_html__( 'The %1$s plugin is no longer needed. Through good collaboration with Google the functionality of this plugin is now part of both Yoast SEO and the official AMP plugin. If you still have this plugin running we’d suggest updating both the Yoast SEO and AMP plugins and removing the glue plugin.', 'yoastseo-amp' ),
|
51 |
+
'Yoast SEO AMP'
|
52 |
+
)
|
53 |
+
);
|
54 |
+
}
|
55 |
}
|
56 |
}
|
57 |
|
58 |
+
new YoastSEO_AMP();
|
59 |
}
|