Version Description
(Mar 4, 2016) =
- Jetpack Stats support.
- Better version of Merriweather and use system fonts for sans-serif (props mattmiklic).
- Move font to stylesheet so it can be more easily overridden (props mattmiklic).
- Fix: Template loading issues on Windows. (Thanks to everyone who reported this, especially w33zy for pointing out the
validate_fileissue.) - Fix: don't run AMP on post comment feeds (props kraftbj).
- Fix: un-break pagination when using a static home page with multiple pages.
- Fix: force amp-iframe to use https to validate correctly (props mister-ben).
- Fix: validation for
targetandvideo/audioattributes. - Fix: clipped images in galleries (thanks tobaco).
Download this release
Release Info
| Developer | batmoo |
| Plugin | |
| Version | 0.3.2 |
| Comparing to | |
| See all releases | |
Code changes from version 0.3.1 to 0.3.2
- amp.php +7 -4
- includes/amp-post-template-actions.php +34 -0
- includes/class-amp-post-template.php +17 -8
- includes/embeds/class-amp-gallery-embed.php +1 -0
- includes/sanitizers/class-amp-audio-sanitizer.php +1 -1
- includes/sanitizers/class-amp-blacklist-sanitizer.php +8 -3
- includes/sanitizers/class-amp-iframe-sanitizer.php +4 -1
- includes/sanitizers/class-amp-video-sanitizer.php +1 -1
- jetpack-helper.php +40 -0
- readme.md +70 -24
- readme.txt +18 -5
- templates/single.php +1 -2
- templates/style.php +47 -2
amp.php
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
* Plugin URI: https://github.com/automattic/amp-wp
|
| 6 |
* Author: Automattic
|
| 7 |
* Author URI: https://automattic.com
|
| 8 |
-
* Version: 0.3.
|
| 9 |
* Text Domain: amp
|
| 10 |
* Domain Path: /languages/
|
| 11 |
* License: GPLv2 or later
|
|
@@ -44,19 +44,22 @@ function amp_init() {
|
|
| 44 |
|
| 45 |
add_action( 'wp', 'amp_maybe_add_actions' );
|
| 46 |
|
| 47 |
-
if ( class_exists( 'Jetpack' ) ) {
|
| 48 |
require_once( AMP__DIR__ . '/jetpack-helper.php' );
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
function amp_maybe_add_actions() {
|
| 53 |
-
if ( ! is_singular() ) {
|
| 54 |
return;
|
| 55 |
}
|
| 56 |
|
| 57 |
$is_amp_endpoint = is_amp_endpoint();
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
$supports = post_supports_amp( $post );
|
| 61 |
|
| 62 |
if ( ! $supports ) {
|
| 5 |
* Plugin URI: https://github.com/automattic/amp-wp
|
| 6 |
* Author: Automattic
|
| 7 |
* Author URI: https://automattic.com
|
| 8 |
+
* Version: 0.3.2
|
| 9 |
* Text Domain: amp
|
| 10 |
* Domain Path: /languages/
|
| 11 |
* License: GPLv2 or later
|
| 44 |
|
| 45 |
add_action( 'wp', 'amp_maybe_add_actions' );
|
| 46 |
|
| 47 |
+
if ( class_exists( 'Jetpack' ) && ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
|
| 48 |
require_once( AMP__DIR__ . '/jetpack-helper.php' );
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
function amp_maybe_add_actions() {
|
| 53 |
+
if ( ! is_singular() || is_feed() ) {
|
| 54 |
return;
|
| 55 |
}
|
| 56 |
|
| 57 |
$is_amp_endpoint = is_amp_endpoint();
|
| 58 |
|
| 59 |
+
// Cannot use `get_queried_object` before canonical redirect; see https://core.trac.wordpress.org/ticket/35344
|
| 60 |
+
global $wp_query;
|
| 61 |
+
$post = $wp_query->post;
|
| 62 |
+
|
| 63 |
$supports = post_supports_amp( $post );
|
| 64 |
|
| 65 |
if ( ! $supports ) {
|
includes/amp-post-template-actions.php
CHANGED
|
@@ -42,3 +42,37 @@ function amp_post_template_add_schemaorg_metadata( $amp_template ) {
|
|
| 42 |
<script type="application/ld+json"><?php echo json_encode( $metadata ); ?></script>
|
| 43 |
<?php
|
| 44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
<script type="application/ld+json"><?php echo json_encode( $metadata ); ?></script>
|
| 43 |
<?php
|
| 44 |
}
|
| 45 |
+
|
| 46 |
+
add_action( 'amp_post_template_data', 'amp_post_template_add_analytics_script' );
|
| 47 |
+
function amp_post_template_add_analytics_script( $data ) {
|
| 48 |
+
if ( ! empty( $data['amp_analytics'] ) ) {
|
| 49 |
+
$data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
|
| 50 |
+
}
|
| 51 |
+
return $data;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
add_action( 'amp_post_template_footer', 'amp_post_template_add_analytics_data' );
|
| 55 |
+
function amp_post_template_add_analytics_data( $amp_template ) {
|
| 56 |
+
$analytics_entries = $amp_template->get( 'amp_analytics' );
|
| 57 |
+
if ( empty( $analytics_entries ) ) {
|
| 58 |
+
return;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
foreach ( $analytics_entries as $id => $analytics_entry ) {
|
| 62 |
+
if ( ! isset( $analytics_entry['type'], $analytics_entry['attributes'], $analytics_entry['config_data'] ) ) {
|
| 63 |
+
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Analytics entry for %s is missing one of the following keys: `type`, `attributes`, or `config_data` (array keys: %s)', 'amp' ), esc_html( $id ), esc_html( implode( ', ', array_keys( $analytics_entry ) ) ) ), '0.3.2' );
|
| 64 |
+
continue;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
$script_element = AMP_HTML_Utils::build_tag( 'script', array(
|
| 68 |
+
'type' => 'application/json',
|
| 69 |
+
), json_encode( $analytics_entry['config_data'] ) );
|
| 70 |
+
|
| 71 |
+
$amp_analytics_attr = array_merge( array(
|
| 72 |
+
'id' => $id,
|
| 73 |
+
'type' => $analytics_entry['type'],
|
| 74 |
+
), $analytics_entry['attributes'] );
|
| 75 |
+
|
| 76 |
+
echo AMP_HTML_Utils::build_tag( 'amp-analytics', $amp_analytics_attr, $script_element );
|
| 77 |
+
}
|
| 78 |
+
}
|
includes/class-amp-post-template.php
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
| 3 |
require_once( AMP__DIR__ . '/includes/class-amp-content.php' );
|
| 4 |
|
| 5 |
require_once( AMP__DIR__ . '/includes/sanitizers/class-amp-blacklist-sanitizer.php' );
|
|
@@ -47,6 +50,18 @@ class AMP_Post_Template {
|
|
| 47 |
|
| 48 |
'amp_runtime_script' => 'https://cdn.ampproject.org/v0.js',
|
| 49 |
'amp_component_scripts' => array(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
);
|
| 51 |
|
| 52 |
$this->build_post_content();
|
|
@@ -242,13 +257,11 @@ class AMP_Post_Template {
|
|
| 242 |
}
|
| 243 |
|
| 244 |
private function is_valid_template( $template ) {
|
| 245 |
-
|
| 246 |
-
$content_dir = $this->normalize_path( WP_CONTENT_DIR );
|
| 247 |
-
if ( 0 !== strpos( $template, $content_dir ) ) {
|
| 248 |
return false;
|
| 249 |
}
|
| 250 |
|
| 251 |
-
if (
|
| 252 |
return false;
|
| 253 |
}
|
| 254 |
|
|
@@ -258,8 +271,4 @@ class AMP_Post_Template {
|
|
| 258 |
|
| 259 |
return true;
|
| 260 |
}
|
| 261 |
-
|
| 262 |
-
private function normalize_path( $path ) {
|
| 263 |
-
return str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $path );
|
| 264 |
-
}
|
| 265 |
}
|
| 1 |
<?php
|
| 2 |
|
| 3 |
+
require_once( AMP__DIR__ . '/includes/utils/class-amp-dom-utils.php' );
|
| 4 |
+
require_once( AMP__DIR__ . '/includes/utils/class-amp-html-utils.php' );
|
| 5 |
+
|
| 6 |
require_once( AMP__DIR__ . '/includes/class-amp-content.php' );
|
| 7 |
|
| 8 |
require_once( AMP__DIR__ . '/includes/sanitizers/class-amp-blacklist-sanitizer.php' );
|
| 50 |
|
| 51 |
'amp_runtime_script' => 'https://cdn.ampproject.org/v0.js',
|
| 52 |
'amp_component_scripts' => array(),
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Add amp-analytics tags.
|
| 56 |
+
*
|
| 57 |
+
* This filter allows you to easily insert any amp-analytics tags without needing much heavy lifting.
|
| 58 |
+
*
|
| 59 |
+
* @since 0.4
|
| 60 |
+
*.
|
| 61 |
+
* @param array $analytics An associative array of the analytics entries we want to output. Each array entry must have a unique key, and the value should be an array with the following keys: `type`, `attributes`, `script_data`. See readme for more details.
|
| 62 |
+
* @param object $post The current post.
|
| 63 |
+
*/
|
| 64 |
+
'amp_analytics' => apply_filters( 'amp_post_template_analytics', array(), $this->post ),
|
| 65 |
);
|
| 66 |
|
| 67 |
$this->build_post_content();
|
| 257 |
}
|
| 258 |
|
| 259 |
private function is_valid_template( $template ) {
|
| 260 |
+
if ( false !== strpos( $template, '..' ) ) {
|
|
|
|
|
|
|
| 261 |
return false;
|
| 262 |
}
|
| 263 |
|
| 264 |
+
if ( false !== strpos( $template, './' ) ) {
|
| 265 |
return false;
|
| 266 |
}
|
| 267 |
|
| 271 |
|
| 272 |
return true;
|
| 273 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
}
|
includes/embeds/class-amp-gallery-embed.php
CHANGED
|
@@ -120,6 +120,7 @@ class AMP_Gallery_Embed_Handler extends AMP_Base_Embed_Handler {
|
|
| 120 |
'src' => $image['url'],
|
| 121 |
'width' => $image['width'],
|
| 122 |
'height' => $image['height'],
|
|
|
|
| 123 |
)
|
| 124 |
);
|
| 125 |
}
|
| 120 |
'src' => $image['url'],
|
| 121 |
'width' => $image['width'],
|
| 122 |
'height' => $image['height'],
|
| 123 |
+
'layout' => 'responsive',
|
| 124 |
)
|
| 125 |
);
|
| 126 |
}
|
includes/sanitizers/class-amp-audio-sanitizer.php
CHANGED
|
@@ -58,7 +58,7 @@ class AMP_Audio_Sanitizer extends AMP_Base_Sanitizer {
|
|
| 58 |
case 'loop':
|
| 59 |
case 'muted':
|
| 60 |
if ( 'false' !== $value ) {
|
| 61 |
-
$out[ $name ] = '
|
| 62 |
}
|
| 63 |
break;
|
| 64 |
case 'autoplay':
|
| 58 |
case 'loop':
|
| 59 |
case 'muted':
|
| 60 |
if ( 'false' !== $value ) {
|
| 61 |
+
$out[ $name ] = '';
|
| 62 |
}
|
| 63 |
break;
|
| 64 |
case 'autoplay':
|
includes/sanitizers/class-amp-blacklist-sanitizer.php
CHANGED
|
@@ -92,9 +92,14 @@ class AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer {
|
|
| 92 |
} elseif ( 'rev' === $attribute_name ) {
|
| 93 |
// rev removed from HTML5 spec, which was used by Jetpack Markdown.
|
| 94 |
$node->removeAttribute( $attribute_name );
|
| 95 |
-
} elseif ( 'target' === $attribute_name
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
}
|
| 100 |
|
| 92 |
} elseif ( 'rev' === $attribute_name ) {
|
| 93 |
// rev removed from HTML5 spec, which was used by Jetpack Markdown.
|
| 94 |
$node->removeAttribute( $attribute_name );
|
| 95 |
+
} elseif ( 'target' === $attribute_name ) {
|
| 96 |
+
if ( '_blank' === $attribute->value || '_new' === $attribute->value ) {
|
| 97 |
+
// _new is not allowed; swap with _blank
|
| 98 |
+
$node->setAttribute( $attribute_name, '_blank' );
|
| 99 |
+
} else {
|
| 100 |
+
// only _blank is allowed
|
| 101 |
+
$node->removeAttribute( $attribute_name );
|
| 102 |
+
}
|
| 103 |
}
|
| 104 |
}
|
| 105 |
|
includes/sanitizers/class-amp-iframe-sanitizer.php
CHANGED
|
@@ -83,7 +83,6 @@ class AMP_Iframe_Sanitizer extends AMP_Base_Sanitizer {
|
|
| 83 |
|
| 84 |
foreach ( $attributes as $name => $value ) {
|
| 85 |
switch ( $name ) {
|
| 86 |
-
case 'src':
|
| 87 |
case 'sandbox':
|
| 88 |
case 'height':
|
| 89 |
case 'class':
|
|
@@ -91,6 +90,10 @@ class AMP_Iframe_Sanitizer extends AMP_Base_Sanitizer {
|
|
| 91 |
$out[ $name ] = $value;
|
| 92 |
break;
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
case 'width':
|
| 95 |
if ( $value === '100%' ) {
|
| 96 |
continue;
|
| 83 |
|
| 84 |
foreach ( $attributes as $name => $value ) {
|
| 85 |
switch ( $name ) {
|
|
|
|
| 86 |
case 'sandbox':
|
| 87 |
case 'height':
|
| 88 |
case 'class':
|
| 90 |
$out[ $name ] = $value;
|
| 91 |
break;
|
| 92 |
|
| 93 |
+
case 'src':
|
| 94 |
+
$out[ $name ] = set_url_scheme( $value, 'https' );
|
| 95 |
+
break;
|
| 96 |
+
|
| 97 |
case 'width':
|
| 98 |
if ( $value === '100%' ) {
|
| 99 |
continue;
|
includes/sanitizers/class-amp-video-sanitizer.php
CHANGED
|
@@ -58,7 +58,7 @@ class AMP_Video_Sanitizer extends AMP_Base_Sanitizer {
|
|
| 58 |
case 'loop':
|
| 59 |
case 'muted':
|
| 60 |
if ( 'false' !== $value ) {
|
| 61 |
-
$out[ $name ] = '
|
| 62 |
}
|
| 63 |
break;
|
| 64 |
case 'autoplay':
|
| 58 |
case 'loop':
|
| 59 |
case 'muted':
|
| 60 |
if ( 'false' !== $value ) {
|
| 61 |
+
$out[ $name ] = '';
|
| 62 |
}
|
| 63 |
break;
|
| 64 |
case 'autoplay':
|
jetpack-helper.php
CHANGED
|
@@ -9,6 +9,9 @@ add_action( 'pre_amp_render_post', 'amp_jetpack_mods' );
|
|
| 9 |
*
|
| 10 |
**/
|
| 11 |
function amp_jetpack_mods() {
|
|
|
|
|
|
|
|
|
|
| 12 |
amp_jetpack_disable_sharing();
|
| 13 |
amp_jetpack_disable_related_posts();
|
| 14 |
}
|
|
@@ -29,3 +32,40 @@ function amp_jetpack_disable_related_posts() {
|
|
| 29 |
remove_filter( 'the_content', array( $jprp, 'filter_add_target_to_dom' ), 40 );
|
| 30 |
}
|
| 31 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
*
|
| 10 |
**/
|
| 11 |
function amp_jetpack_mods() {
|
| 12 |
+
if ( Jetpack::is_module_active( 'stats' ) ) {
|
| 13 |
+
add_action( 'amp_post_template_footer', 'jetpack_amp_add_stats_pixel' );
|
| 14 |
+
}
|
| 15 |
amp_jetpack_disable_sharing();
|
| 16 |
amp_jetpack_disable_related_posts();
|
| 17 |
}
|
| 32 |
remove_filter( 'the_content', array( $jprp, 'filter_add_target_to_dom' ), 40 );
|
| 33 |
}
|
| 34 |
}
|
| 35 |
+
|
| 36 |
+
function jetpack_amp_add_stats_pixel( $amp_template ) {
|
| 37 |
+
if ( ! has_action( 'wp_footer', 'stats_footer' ) ) {
|
| 38 |
+
return;
|
| 39 |
+
}
|
| 40 |
+
?>
|
| 41 |
+
<amp-pixel src="<?php echo esc_url( jetpack_amp_build_stats_pixel_url() ); ?>"></amp-pixel>
|
| 42 |
+
<?php
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Generate the stats pixel.
|
| 47 |
+
*
|
| 48 |
+
* Looks something like:
|
| 49 |
+
* https://pixel.wp.com/g.gif?v=ext&j=1%3A3.9.1&blog=1234&post=5678&tz=-4&srv=example.com&host=example.com&ref=&rand=0.4107963021218808
|
| 50 |
+
*/
|
| 51 |
+
function jetpack_amp_build_stats_pixel_url() {
|
| 52 |
+
global $wp_the_query;
|
| 53 |
+
if ( function_exists( 'stats_build_view_data' ) ) { // added in https://github.com/Automattic/jetpack/pull/3445
|
| 54 |
+
$data = stats_build_view_data();
|
| 55 |
+
} else {
|
| 56 |
+
$blog = Jetpack_Options::get_option( 'id' );
|
| 57 |
+
$tz = get_option( 'gmt_offset' );
|
| 58 |
+
$v = 'ext';
|
| 59 |
+
$blog_url = parse_url( site_url() );
|
| 60 |
+
$srv = $blog_url['host'];
|
| 61 |
+
$j = sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION );
|
| 62 |
+
$post = $wp_the_query->get_queried_object_id();
|
| 63 |
+
$data = compact( 'v', 'j', 'blog', 'post', 'tz', 'srv' );
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
$data['host'] = rawurlencode( $_SERVER['HTTP_HOST'] );
|
| 67 |
+
$data['rand'] = 'RANDOM'; // amp placeholder
|
| 68 |
+
$data['ref'] = 'DOCUMENT_REFERRER'; // amp placeholder
|
| 69 |
+
$data = array_map( 'rawurlencode' , $data );
|
| 70 |
+
return add_query_arg( $data, 'https://pixel.wp.com/g.gif' );
|
| 71 |
+
}
|
readme.md
CHANGED
|
@@ -28,12 +28,12 @@ If you're using an off-the-shelf theme (like from the WordPress.org Theme Direct
|
|
| 28 |
|
| 29 |
If you're using a custom theme:
|
| 30 |
|
| 31 |
-
- `functions.php` (or a
|
| 32 |
- Any of the options above.
|
| 33 |
|
| 34 |
### Theme Mods
|
| 35 |
|
| 36 |
-
The default template will attempt to draw from various theme mods, such as site icon
|
| 37 |
|
| 38 |
#### Site Icon
|
| 39 |
|
|
@@ -51,18 +51,14 @@ function xyz_amp_set_site_icon_url( $data ) {
|
|
| 51 |
}
|
| 52 |
```
|
| 53 |
|
| 54 |
-
#### Custom Header
|
| 55 |
-
|
| 56 |
-
This needs to be implemented.
|
| 57 |
-
|
| 58 |
#### Logo Only
|
| 59 |
|
| 60 |
If you want to hide the site text and just show a logo, use the `amp_post_template_css` action. The following colours the title bar black, hides the site title, and replaces it with a centered logo:
|
| 61 |
|
| 62 |
```
|
| 63 |
add_action( 'amp_post_template_css', 'xyz_amp_additional_css_styles' );
|
| 64 |
-
|
| 65 |
-
function
|
| 66 |
// only CSS here please...
|
| 67 |
?>
|
| 68 |
nav.amp-wp-title-bar {
|
|
@@ -152,6 +148,7 @@ function xyz_amp_modify_json_metadata( $metadata, $post ) {
|
|
| 152 |
'height' => 60,
|
| 153 |
'width' => 600,
|
| 154 |
);
|
|
|
|
| 155 |
return $metadata;
|
| 156 |
}
|
| 157 |
```
|
|
@@ -276,23 +273,12 @@ Note: the file should only include CSS, not the `<style>` opening and closing ta
|
|
| 276 |
If you want to add stuff to the head or footer of the default AMP template, use the `amp_post_template_head` and `amp_post_template_footer` actions.
|
| 277 |
|
| 278 |
```php
|
| 279 |
-
add_action( 'amp_post_template_footer', '
|
| 280 |
|
| 281 |
function xyz_amp_add_analytics( $amp_template ) {
|
| 282 |
$post_id = $amp_template->get( 'post_id' );
|
| 283 |
-
// see https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/amp-analytics.md for more on amp-analytics
|
| 284 |
?>
|
| 285 |
-
<amp-
|
| 286 |
-
<script type="application/json">
|
| 287 |
-
{
|
| 288 |
-
"requests": {
|
| 289 |
-
"pageview": "https://example.com/analytics?url=${canonicalUrl}&title=${title}&acct=${account}",
|
| 290 |
-
"event": "https://example.com/analytics?eid=${eventId}&elab=${eventLabel}&acct=${account}"
|
| 291 |
-
}
|
| 292 |
-
// ...
|
| 293 |
-
}
|
| 294 |
-
</script>
|
| 295 |
-
</amp-analytics>
|
| 296 |
<?php
|
| 297 |
}
|
| 298 |
```
|
|
@@ -484,7 +470,7 @@ class XYZ_AMP_Ad_Injection_Sanitizer extends AMP_Base_Sanitizer {
|
|
| 484 |
// Otherwise, add it to the end.
|
| 485 |
$p_nodes = $body->getElementsByTagName( 'p' );
|
| 486 |
if ( $p_nodes->length > 6 ) {
|
| 487 |
-
$p_nodes->item( 4 )->insertBefore( $ad_node );
|
| 488 |
} else {
|
| 489 |
$body->appendChild( $ad_node );
|
| 490 |
}
|
|
@@ -504,9 +490,60 @@ function xyz_amp_add_ad_sanitizer( $sanitizer_classes, $post ) {
|
|
| 504 |
}
|
| 505 |
```
|
| 506 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
## Custom Post Type Support
|
| 508 |
|
| 509 |
-
By default, the plugin only creates AMP content for posts. You can add support for other post_types
|
| 510 |
|
| 511 |
```php
|
| 512 |
add_action( 'amp_init', 'xyz_amp_add_review_cpt' );
|
|
@@ -528,13 +565,22 @@ function xyz_amp_set_custom_template( $file, $type, $post ) {
|
|
| 528 |
}
|
| 529 |
return $file;
|
| 530 |
}
|
| 531 |
-
|
| 532 |
```
|
| 533 |
|
| 534 |
We may provide better ways to handle this in the future.
|
| 535 |
|
| 536 |
## Plugin integrations
|
| 537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 538 |
### Yoast SEO
|
| 539 |
|
| 540 |
If you're using [Yoast SEO](https://wordpress.org/plugins/wordpress-seo/), check out the companion plugin here: https://github.com/Yoast/yoastseo-amp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
If you're using a custom theme:
|
| 30 |
|
| 31 |
+
- `functions.php` (or via a 'require' call to files that load from `functions.php`).
|
| 32 |
- Any of the options above.
|
| 33 |
|
| 34 |
### Theme Mods
|
| 35 |
|
| 36 |
+
The default template will attempt to draw from various theme mods, such as site icon, if supported by the active theme.
|
| 37 |
|
| 38 |
#### Site Icon
|
| 39 |
|
| 51 |
}
|
| 52 |
```
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
#### Logo Only
|
| 55 |
|
| 56 |
If you want to hide the site text and just show a logo, use the `amp_post_template_css` action. The following colours the title bar black, hides the site title, and replaces it with a centered logo:
|
| 57 |
|
| 58 |
```
|
| 59 |
add_action( 'amp_post_template_css', 'xyz_amp_additional_css_styles' );
|
| 60 |
+
|
| 61 |
+
function xyz_amp_additional_css_styles( $amp_template ) {
|
| 62 |
// only CSS here please...
|
| 63 |
?>
|
| 64 |
nav.amp-wp-title-bar {
|
| 148 |
'height' => 60,
|
| 149 |
'width' => 600,
|
| 150 |
);
|
| 151 |
+
|
| 152 |
return $metadata;
|
| 153 |
}
|
| 154 |
```
|
| 273 |
If you want to add stuff to the head or footer of the default AMP template, use the `amp_post_template_head` and `amp_post_template_footer` actions.
|
| 274 |
|
| 275 |
```php
|
| 276 |
+
add_action( 'amp_post_template_footer', 'xyz_amp_add_pixel' );
|
| 277 |
|
| 278 |
function xyz_amp_add_analytics( $amp_template ) {
|
| 279 |
$post_id = $amp_template->get( 'post_id' );
|
|
|
|
| 280 |
?>
|
| 281 |
+
<amp-pixel src="https://example.com/hi.gif?x=RANDOM"></amp-pixel>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
<?php
|
| 283 |
}
|
| 284 |
```
|
| 470 |
// Otherwise, add it to the end.
|
| 471 |
$p_nodes = $body->getElementsByTagName( 'p' );
|
| 472 |
if ( $p_nodes->length > 6 ) {
|
| 473 |
+
$p_nodes->item( 4 )->parentNode->insertBefore( $ad_node, $p_nodes->item( 4 ));
|
| 474 |
} else {
|
| 475 |
$body->appendChild( $ad_node );
|
| 476 |
}
|
| 490 |
}
|
| 491 |
```
|
| 492 |
|
| 493 |
+
## Analytics
|
| 494 |
+
|
| 495 |
+
To output proper analytics tags, you can use the `amp_post_template_analytics` filter:
|
| 496 |
+
|
| 497 |
+
```
|
| 498 |
+
add_filter( 'amp_post_template_analytics', 'xyz_amp_add_custom_analytics' );
|
| 499 |
+
function xyz_amp_add_custom_analytics( $analytics ) {
|
| 500 |
+
if ( ! is_array( $analytics ) ) {
|
| 501 |
+
$analytics = array();
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
// https://developers.google.com/analytics/devguides/collection/amp-analytics/
|
| 505 |
+
$analytics['xyz-googleanalytics'] = array(
|
| 506 |
+
'type' => 'googleanalytics',
|
| 507 |
+
'attributes' => array(
|
| 508 |
+
// 'data-credentials' => 'include',
|
| 509 |
+
),
|
| 510 |
+
'config_data' => array(
|
| 511 |
+
'vars' => array(
|
| 512 |
+
'account' => "UA-XXXXX-Y"
|
| 513 |
+
),
|
| 514 |
+
'triggers' => array(
|
| 515 |
+
'trackPageview' => array(
|
| 516 |
+
'on' => 'visible',
|
| 517 |
+
'request' => 'pageview',
|
| 518 |
+
),
|
| 519 |
+
),
|
| 520 |
+
),
|
| 521 |
+
);
|
| 522 |
+
|
| 523 |
+
// https://www.parsely.com/docs/integration/tracking/google-amp.html
|
| 524 |
+
$analytics['xyz-parsely'] = array(
|
| 525 |
+
'type' => 'parsely',
|
| 526 |
+
'attributes' => array(),
|
| 527 |
+
'config_data' => array(
|
| 528 |
+
'vars' => array(
|
| 529 |
+
'apikey' => 'YOUR APIKEY GOES HERE',
|
| 530 |
+
)
|
| 531 |
+
),
|
| 532 |
+
);
|
| 533 |
+
|
| 534 |
+
return $analytics;
|
| 535 |
+
}
|
| 536 |
+
```
|
| 537 |
+
|
| 538 |
+
Each analytics entry must include a unique array key and the following attributes:
|
| 539 |
+
|
| 540 |
+
- `type`: `(string)` one of the [valid vendors](https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/amp-analytics.md#analytics-vendors) for amp-analytics.
|
| 541 |
+
- `attributes`: `(array)` any [additional valid attributes](https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/amp-analytics.md#attributes) to add to the `amp-analytics` element.
|
| 542 |
+
- `config_data`: `(array)` the [config data](https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/amp-analytics.md#configuration) to include in the `amp-analytics` script tag. This is `json_encode`-d on output.
|
| 543 |
+
|
| 544 |
## Custom Post Type Support
|
| 545 |
|
| 546 |
+
By default, the plugin only creates AMP content for posts. You can add support for other post_types using the post_type parameter used when registering the custom post type (assume our post_type is `xyz-review`):
|
| 547 |
|
| 548 |
```php
|
| 549 |
add_action( 'amp_init', 'xyz_amp_add_review_cpt' );
|
| 565 |
}
|
| 566 |
return $file;
|
| 567 |
}
|
|
|
|
| 568 |
```
|
| 569 |
|
| 570 |
We may provide better ways to handle this in the future.
|
| 571 |
|
| 572 |
## Plugin integrations
|
| 573 |
|
| 574 |
+
### Jetpack
|
| 575 |
+
|
| 576 |
+
Jetpack integration is baked in. More support for things like Related Posts to come.
|
| 577 |
+
|
| 578 |
### Yoast SEO
|
| 579 |
|
| 580 |
If you're using [Yoast SEO](https://wordpress.org/plugins/wordpress-seo/), check out the companion plugin here: https://github.com/Yoast/yoastseo-amp
|
| 581 |
+
|
| 582 |
+
## Compatibility Issues
|
| 583 |
+
|
| 584 |
+
The following plugins have been known to cause issues with this plugin:
|
| 585 |
+
|
| 586 |
+
- Cloudflare Rocket Loader (modifies the output of the AMP page, which breaks validation.)
|
readme.txt
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
Contributors: batmoo, joen, automattic
|
| 3 |
Tags: amp, mobile
|
| 4 |
Requires at least: 4.4
|
| 5 |
-
Tested up to: 4.
|
| 6 |
-
Stable tag: 0.3.
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
|
|
@@ -34,15 +34,28 @@ You can find details about customization options at https://github.com/Automatti
|
|
| 34 |
|
| 35 |
== Changelog ==
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
= 0.3.1 (Feb 24, 2016) =
|
| 38 |
|
| 39 |
-
*
|
|
|
|
| 40 |
* Fix for password-protected posts.
|
| 41 |
* Fix dimension extraction for schema-less or relative image URLs.
|
| 42 |
* Better fallback for images with no dimensions.
|
| 43 |
-
* Validation fixes for `a` tags.
|
| 44 |
* Updated AMP boilerplate.
|
| 45 |
-
* Allow `on` tags for elements.
|
| 46 |
* Prefixed class names.
|
| 47 |
|
| 48 |
= 0.3 (Feb 18, 2016) =
|
| 2 |
Contributors: batmoo, joen, automattic
|
| 3 |
Tags: amp, mobile
|
| 4 |
Requires at least: 4.4
|
| 5 |
+
Tested up to: 4.5
|
| 6 |
+
Stable tag: 0.3.2
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
|
| 34 |
|
| 35 |
== Changelog ==
|
| 36 |
|
| 37 |
+
= 0.3.2 (Mar 4, 2016) =
|
| 38 |
+
|
| 39 |
+
* Jetpack Stats support.
|
| 40 |
+
* Better version of Merriweather and use system fonts for sans-serif (props mattmiklic).
|
| 41 |
+
* Move font to stylesheet so it can be more easily overridden (props mattmiklic).
|
| 42 |
+
* Fix: Template loading issues on Windows. (Thanks to everyone who reported this, especially w33zy for pointing out the `validate_file` issue.)
|
| 43 |
+
* Fix: don't run AMP on post comment feeds (props kraftbj).
|
| 44 |
+
* Fix: un-break pagination when using a static home page with multiple pages.
|
| 45 |
+
* Fix: force amp-iframe to use https to validate correctly (props mister-ben).
|
| 46 |
+
* Fix: validation for `target` and `video`/`audio` attributes.
|
| 47 |
+
* Fix: clipped images in galleries (thanks tobaco).
|
| 48 |
+
|
| 49 |
= 0.3.1 (Feb 24, 2016) =
|
| 50 |
|
| 51 |
+
* Allow custom query var (props vaurdan).
|
| 52 |
+
* Fix AMP URLs for non-pretty permalinks (props rakuishi).
|
| 53 |
* Fix for password-protected posts.
|
| 54 |
* Fix dimension extraction for schema-less or relative image URLs.
|
| 55 |
* Better fallback for images with no dimensions.
|
| 56 |
+
* Validation fixes for `a` tags (props kraftbj).
|
| 57 |
* Updated AMP boilerplate.
|
| 58 |
+
* Allow `on` tags for elements (props Steven Evatt).
|
| 59 |
* Prefixed class names.
|
| 60 |
|
| 61 |
= 0.3 (Feb 18, 2016) =
|
templates/single.php
CHANGED
|
@@ -3,7 +3,6 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
|
| 6 |
-
<link href="https://fonts.googleapis.com/css?family=Merriweather:400,400italic,700,700italic|Open+Sans:400,700,400italic,700italic" rel="stylesheet" type="text/css">
|
| 7 |
<?php do_action( 'amp_post_template_head', $this ); ?>
|
| 8 |
|
| 9 |
<style amp-custom>
|
|
@@ -24,7 +23,7 @@
|
|
| 24 |
</div>
|
| 25 |
</nav>
|
| 26 |
<div class="amp-wp-content">
|
| 27 |
-
<h1 class="amp-wp-title"><?php echo
|
| 28 |
<ul class="amp-wp-meta">
|
| 29 |
<?php $this->load_parts( apply_filters( 'amp_post_template_meta_parts', array( 'meta-author', 'meta-time', 'meta-taxonomy' ) ) ); ?>
|
| 30 |
</ul>
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
|
|
|
|
| 6 |
<?php do_action( 'amp_post_template_head', $this ); ?>
|
| 7 |
|
| 8 |
<style amp-custom>
|
| 23 |
</div>
|
| 24 |
</nav>
|
| 25 |
<div class="amp-wp-content">
|
| 26 |
+
<h1 class="amp-wp-title"><?php echo wp_kses_data( $this->get( 'post_title' ) ); ?></h1>
|
| 27 |
<ul class="amp-wp-meta">
|
| 28 |
<?php $this->load_parts( apply_filters( 'amp_post_template_meta_parts', array( 'meta-author', 'meta-time', 'meta-taxonomy' ) ) ); ?>
|
| 29 |
</ul>
|
templates/style.php
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
/* Generic WP styling */
|
| 2 |
amp-img.alignright { float: right; margin: 0 0 1em 1em; }
|
| 3 |
amp-img.alignleft { float: left; margin: 0 1em 1em 0; }
|
|
@@ -77,11 +118,11 @@ a:focus {
|
|
| 77 |
}
|
| 78 |
|
| 79 |
|
| 80 |
-
/*
|
| 81 |
.amp-wp-meta,
|
| 82 |
nav.amp-wp-title-bar,
|
| 83 |
.wp-caption-text {
|
| 84 |
-
font-family: "
|
| 85 |
font-size: 15px;
|
| 86 |
}
|
| 87 |
|
|
@@ -192,6 +233,10 @@ amp-vine {
|
|
| 192 |
background: #f3f6f8;
|
| 193 |
}
|
| 194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
.amp-wp-iframe-placeholder {
|
| 196 |
background: #f3f6f8 url( <?php echo esc_url( $this->get( 'placeholder_image_url' ) ); ?> ) no-repeat center 40%;
|
| 197 |
background-size: 48px 48px;
|
| 1 |
+
/* Merriweather fonts */
|
| 2 |
+
@font-face {
|
| 3 |
+
font-family:'Merriweather';
|
| 4 |
+
src:url('https://s1.wp.com/i/fonts/merriweather/merriweather-regular-webfont.woff2') format('woff2'),
|
| 5 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-regular-webfont.woff') format('woff'),
|
| 6 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-regular-webfont.ttf') format('truetype'),
|
| 7 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-regular-webfont.svg#merriweatherregular') format('svg');
|
| 8 |
+
font-weight:400;
|
| 9 |
+
font-style:normal;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
@font-face {
|
| 13 |
+
font-family:'Merriweather';
|
| 14 |
+
src:url('https://s1.wp.com/i/fonts/merriweather/merriweather-italic-webfont.woff2') format('woff2'),
|
| 15 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-italic-webfont.woff') format('woff'),
|
| 16 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-italic-webfont.ttf') format('truetype'),
|
| 17 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-italic-webfont.svg#merriweatheritalic') format('svg');
|
| 18 |
+
font-weight:400;
|
| 19 |
+
font-style:italic;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
@font-face {
|
| 23 |
+
font-family:'Merriweather';
|
| 24 |
+
src:url('https://s1.wp.com/i/fonts/merriweather/merriweather-bold-webfont.woff2') format('woff2'),
|
| 25 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-bold-webfont.woff') format('woff'),
|
| 26 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-bold-webfont.ttf') format('truetype'),
|
| 27 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-bold-webfont.svg#merriweatherbold') format('svg');
|
| 28 |
+
font-weight:700;
|
| 29 |
+
font-style:normal;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
@font-face {
|
| 33 |
+
font-family:'Merriweather';
|
| 34 |
+
src:url('https://s1.wp.com/i/fonts/merriweather/merriweather-bolditalic-webfont.woff2') format('woff2'),
|
| 35 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-bolditalic-webfont.woff') format('woff'),
|
| 36 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-bolditalic-webfont.ttf') format('truetype'),
|
| 37 |
+
url('https://s1.wp.com/i/fonts/merriweather/merriweather-bolditalic-webfont.svg#merriweatherbold_italic') format('svg');
|
| 38 |
+
font-weight:700;
|
| 39 |
+
font-style:italic;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
/* Generic WP styling */
|
| 43 |
amp-img.alignright { float: right; margin: 0 0 1em 1em; }
|
| 44 |
amp-img.alignleft { float: left; margin: 0 1em 1em 0; }
|
| 118 |
}
|
| 119 |
|
| 120 |
|
| 121 |
+
/* UI Fonts */
|
| 122 |
.amp-wp-meta,
|
| 123 |
nav.amp-wp-title-bar,
|
| 124 |
.wp-caption-text {
|
| 125 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif;
|
| 126 |
font-size: 15px;
|
| 127 |
}
|
| 128 |
|
| 233 |
background: #f3f6f8;
|
| 234 |
}
|
| 235 |
|
| 236 |
+
amp-carousel > amp-img > img {
|
| 237 |
+
object-fit: contain;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
.amp-wp-iframe-placeholder {
|
| 241 |
background: #f3f6f8 url( <?php echo esc_url( $this->get( 'placeholder_image_url' ) ); ?> ) no-repeat center 40%;
|
| 242 |
background-size: 48px 48px;
|
