Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugin amp from 2.0.10 to 2.0.11 #42

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/amp/amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: https://amp-wp.org
* Author: AMP Project Contributors
* Author URI: https://github.com/ampproject/amp-wp/graphs/contributors
* Version: 2.0.10
* Version: 2.0.11
* License: GPLv2 or later
* Requires at least: 4.9
* Requires PHP: 5.6
Expand All @@ -15,7 +15,7 @@

define( 'AMP__FILE__', __FILE__ );
define( 'AMP__DIR__', dirname( __FILE__ ) );
define( 'AMP__VERSION', '2.0.10' );
define( 'AMP__VERSION', '2.0.11' );

/**
* Errors encountered while loading the plugin.
Expand Down
7 changes: 5 additions & 2 deletions plugins/amp/includes/admin/class-amp-post-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function enqueue_admin_assets() {
*/
public function enqueue_block_assets() {
$post = get_post();
if ( ! in_array( $post->post_type, AMP_Post_Type_Support::get_eligible_post_types(), true ) ) {
if ( ! $post instanceof WP_Post || ! in_array( $post->post_type, AMP_Post_Type_Support::get_eligible_post_types(), true ) ) {
return;
}

Expand Down Expand Up @@ -438,7 +438,10 @@ public function get_error_messages( $errors ) {
if ( in_array( 'skip-post', $errors, true ) ) {
$error_messages[] = __( 'A plugin or theme has disabled AMP support.', 'amp' );
}
if ( count( array_diff( $errors, [ 'post-type-support', 'skip-post', 'template_unsupported', 'no_matching_template' ] ) ) > 0 ) {
if ( in_array( 'invalid-post', $errors, true ) ) {
$error_messages[] = __( 'The post data could not be successfully retrieved.', 'amp' );
}
if ( count( array_diff( $errors, [ 'post-type-support', 'skip-post', 'template_unsupported', 'no_matching_template', 'invalid-post' ] ) ) > 0 ) {
$error_messages[] = __( 'Unavailable for an unknown reason.', 'amp' );
}

Expand Down
6 changes: 5 additions & 1 deletion plugins/amp/includes/amp-post-template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
* @internal
*/
function amp_post_template_init_hooks() {
add_action( 'amp_post_template_head', 'noindex' );
if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '5.7', '>=' ) ) {
add_action( 'amp_post_template_head', 'wp_robots' );
} else {
add_action( 'amp_post_template_head', 'noindex' );
}
add_action( 'amp_post_template_head', 'amp_post_template_add_title' );
add_action( 'amp_post_template_head', 'amp_post_template_add_canonical' );
add_action( 'amp_post_template_head', 'amp_post_template_add_fonts' );
Expand Down
8 changes: 7 additions & 1 deletion plugins/amp/includes/class-amp-post-type-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ public static function add_post_type_support() {
* @return array Error codes for why a given post does not have AMP support.
*/
public static function get_support_errors( $post ) {
if ( ! ( $post instanceof WP_Post ) ) {
if ( ! $post instanceof WP_Post ) {
$post = get_post( $post );
}

// If there's still not a valid post, then we have to abort.
if ( ! $post instanceof WP_Post ) {
return [ 'invalid-post' ];
}

$errors = [];

if ( ! in_array( $post->post_type, self::get_supported_post_types(), true ) ) {
Expand Down
63 changes: 55 additions & 8 deletions plugins/amp/includes/embeds/class-amp-core-block-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ public function ampify_video_block( $block_content, $block ) {
/**
* Ampify cover block.
*
* This specifically fixes the layout of the block when a background video is assigned.
* This ensures that the background img/video in a cover block has object-fit=cover and the appropriate object-position
* attribute so that they will be carried over to to the amp-img/amp-video and propagated to the img/video in the
* light shadow DOM.
*
* @see \AMP_Video_Sanitizer::filter_video_dimensions()
*
Expand All @@ -224,14 +226,59 @@ public function ampify_video_block( $block_content, $block ) {
* @return string Filtered block content.
*/
public function ampify_cover_block( $block_content, $block ) {
if ( isset( $block['attrs']['backgroundType'] ) && 'video' === $block['attrs']['backgroundType'] ) {
$block_content = preg_replace(
'/(?<=<video\s)/',
'layout="fill" object-fit="cover" ',
$block_content
);
$is_video_background = (
isset( $block['attrs']['backgroundType'] )
&&
'video' === $block['attrs']['backgroundType']
);
$is_image_element = ! (
! empty( $block['attrs']['hasParallax'] )
||
! empty( $block['attrs']['isRepeated'] )
);

// Object fit/position is not relevant when background image has fixed positioning or is repeated.
// In other words, it is not relevant when a <video> or a <img> is not going to be used.
// See <https://github.com/WordPress/gutenberg/blob/54c9066d4/packages/block-library/src/cover/save.js#L54-L72>.
if ( ! ( $is_video_background || $is_image_element ) ) {
return $block_content;
}
return $block_content;

$pattern = sprintf(
'#<%s(?= )[^>]*? class="(?:[^"]*? )?wp-block-cover__%s-background(?: [^"]*?)?"#',
$is_video_background ? 'video' : 'img',
$is_video_background ? 'video' : 'image'
);
return preg_replace_callback(
$pattern,
static function ( $matches ) use ( $block ) {
$replacement = $matches[0];

// The background image/video for the cover block by definition needs object-fit="cover" on the resulting amp-ing/amp-video.
$replacement .= ' object-fit="cover"';

// Add the fill layout to skip needlessly obtaining the dimensions.
$replacement .= ' layout="fill"';

// Add object-position from the block's attributes to add to the img/video to be copied onto the amp-img/amp-video.
// The AMP runtime copies object-position attribute onto the underlying img/video for a given amp-img/amp-video.
// This is needed since the object-position property directly on an amp-img/amp-video will have no effect since
// since it is merely a wrapper for the underlying img/video element which actually supports the CSS property.
if ( isset( $block['attrs']['focalPoint']['x'], $block['attrs']['focalPoint']['y'] ) ) {
// See logic in Gutenberg for writing focal point to object-position attr:
// <https://github.com/WordPress/gutenberg/blob/54c9066/packages/block-library/src/cover/save.js#L71>.
$replacement .= sprintf(
' object-position="%d%% %d%%"',
round( (float) $block['attrs']['focalPoint']['x'] * 100 ),
round( (float) $block['attrs']['focalPoint']['y'] * 100 )
);
}

return $replacement;
},
$block_content,
1
);
}

/**
Expand Down
36 changes: 28 additions & 8 deletions plugins/amp/includes/sanitizers/class-amp-base-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,34 @@ public function prepare_validation_error( array $error = [], array $data = [] )
}

// Capture element contents.
if (
( 'script' === $node->nodeName && ! $node->hasAttribute( 'src' ) )
||
// Include stylesheet text except for amp-custom and amp-keyframes since it is large and since it should
// already be detailed in the stylesheets metabox.
( 'style' === $node->nodeName && ! $node->hasAttribute( 'amp-custom' ) && ! $node->hasAttribute( 'amp-keyframes' ) )
) {
$error['text'] = $node->textContent;
$is_inline_script = ( 'script' === $node->nodeName && ! $node->hasAttribute( 'src' ) );
$is_inline_style = ( 'style' === $node->nodeName && ! $node->hasAttribute( 'amp-custom' ) && ! $node->hasAttribute( 'amp-keyframes' ) );
if ( $is_inline_script || $is_inline_style ) {
$text_content = $node->textContent;
if ( $is_inline_script ) {
// For inline scripts, normalize string and number literals to prevent nonces, random numbers, and timestamps
// from generating endless number of validation errors.
$error['text'] = preg_replace(
[
// Regex credit to <https://stackoverflow.com/a/5696141/93579>.
'/"[^"\\\\\n]*(?:\\\\.[^"\\\\\n]*)*"/s',
'/\'[^\'\\\\\n]*(?:\\\\.[^\'\\\\\n]*)*\'/s',
'/(\b|-)\d+\.\d+\b/',
'/(\b|-)\d+\b/',
],
[
'__DOUBLE_QUOTED_STRING__',
'__SINGLE_QUOTED_STRING__',
'__FLOAT__',
'__INT__',
],
$text_content
);
} elseif ( $is_inline_style ) {
// Include stylesheet text except for amp-custom and amp-keyframes since it is large and since it should
// already be detailed in the stylesheets metabox.
$error['text'] = $text_content;
}
}

// Suppress 'ver' param from enqueued scripts and styles.
Expand Down
18 changes: 7 additions & 11 deletions plugins/amp/includes/sanitizers/class-amp-comments-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,27 @@ public function sanitize() {
* @param DOMElement $comment_form Comment form.
*/
protected function process_comment_form( $comment_form ) {
/**
* Element.
*
* @var DOMElement $element
*/

/**
* Named input elements.
*
* @var DOMElement[][] $form_fields
*/
$form_fields = [];
foreach ( $comment_form->getElementsByTagName( 'input' ) as $element ) {
/** @var DOMElement $element */
$name = $element->getAttribute( 'name' );
if ( $name ) {
$form_fields[ $name ][] = $element;
}
}
foreach ( $comment_form->getElementsByTagName( 'textarea' ) as $element ) {
/** @var DOMElement $element */
$name = $element->getAttribute( 'name' );
if ( $name ) {
$form_fields[ $name ][] = $element;
}
}

/**
* Named input elements.
*
* @var DOMElement[][] $form_fields
*/
if ( empty( $form_fields['comment_post_ID'] ) ) {
return;
}
Expand Down
6 changes: 6 additions & 0 deletions plugins/amp/includes/sanitizers/class-amp-video-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ private function filter_attributes( $attributes ) {
$out['noloading'] = $value;
break;

// Skip copying playsinline attributes which are automatically added by amp-video:
// <https://github.com/ampproject/amphtml/blob/264e5c0/extensions/amp-video/0.1/amp-video.js#L234-L236>.
case 'playsinline':
case 'webkit-playsinline':
break;

default:
$out[ $name ] = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/amp/includes/utils/class-amp-dom-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* Functionality to simplify working with Dom\Documents and DOMElements.
*
* @internal
* @since 0.2
*/
class AMP_DOM_Utils {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ class AMP_Validation_Manager {
/**
* The errors encountered when validating.
*
* @var array[][] {
* @type array $error Error code.
* @type bool $sanitized Whether sanitized.
* @type string $slug Hash of the error.
* @var array[] {
* @type array $error Error data.
* @type bool $sanitized Whether sanitized.
* }
*/
public static $validation_results = [];
Expand Down
4 changes: 2 additions & 2 deletions plugins/amp/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: google, xwp, automattic, westonruter, albertomedina, schlessera, swissspidy, pierlo, johnwatkins0, joshuawold, ryankienstra
Tags: amp, mobile, optimization, accelerated mobile pages, framework, components, blocks, performance, ux, seo, official
Requires at least: 4.9
Tested up to: 5.6
Stable tag: 2.0.10
Tested up to: 5.7
Stable tag: 2.0.11
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Requires PHP: 5.6
Expand Down
26 changes: 20 additions & 6 deletions plugins/amp/src/Admin/OnboardingWizardSubmenuPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
namespace AmpProject\AmpWP\Admin;

use AMP_Options_Manager;
use AmpProject\AmpWP\AmpSlugCustomizationWatcher;
use AmpProject\AmpWP\DevTools\UserAccess;
use AmpProject\AmpWP\Infrastructure\Conditional;
use AmpProject\AmpWP\Infrastructure\Delayed;
use AmpProject\AmpWP\Infrastructure\Registerable;
use AmpProject\AmpWP\Infrastructure\Service;
use AmpProject\AmpWP\Option;
use AmpProject\AmpWP\QueryVar;
use AmpProject\AmpWP\Services;

Expand Down Expand Up @@ -217,7 +215,7 @@ public function enqueue_assets( $hook_suffix ) {
$theme = wp_get_theme();
$is_reader_theme = $this->reader_themes->theme_data_exists( get_stylesheet() );

$exit_link = menu_page_url( AMP_Options_Manager::OPTION_NAME, false );
$amp_settings_link = menu_page_url( AMP_Options_Manager::OPTION_NAME, false );

$setup_wizard_data = [
'AMP_OPTIONS_KEY' => AMP_Options_Manager::OPTION_NAME,
Expand All @@ -228,11 +226,11 @@ public function enqueue_assets( $hook_suffix ) {
'APP_ROOT_ID' => self::APP_ROOT_ID,
'CUSTOMIZER_LINK' => add_query_arg(
[
'return' => rawurlencode( $exit_link ),
'return' => rawurlencode( $amp_settings_link ),
],
admin_url( 'customize.php' )
),
'CLOSE_LINK' => wp_get_referer() ?: $exit_link,
'CLOSE_LINK' => $this->get_close_link(),
// @todo As of June 2020, an upcoming WP release will allow this to be retrieved via REST.
'CURRENT_THEME' => [
'name' => $theme->get( 'Name' ),
Expand All @@ -242,7 +240,7 @@ public function enqueue_assets( $hook_suffix ) {
'url' => $theme->get( 'ThemeURI' ),
],
'USING_FALLBACK_READER_THEME' => $this->reader_themes->using_fallback_theme(),
'FINISH_LINK' => $exit_link,
'FINISH_LINK' => $amp_settings_link,
'OPTIONS_REST_PATH' => '/amp/v1/options',
'READER_THEMES_REST_PATH' => '/amp/v1/reader-themes',
'UPDATES_NONCE' => wp_create_nonce( 'updates' ),
Expand Down Expand Up @@ -290,4 +288,20 @@ protected function add_preload_rest_paths() {
$this->rest_preloader->add_preloaded_path( $path );
}
}

/**
* Determine URL that should be used to close the Onboarding Wizard.
*
* @return string Close link.
*/
public function get_close_link() {
$referer = wp_get_referer();

if ( $referer && 'wp-login.php' !== wp_basename( wp_parse_url( $referer, PHP_URL_PATH ) ) ) {
return $referer;
}

// Default to the AMP Settings page if a referrer link could not be determined.
return menu_page_url( AMP_Options_Manager::OPTION_NAME, false );
}
}
3 changes: 2 additions & 1 deletion plugins/amp/src/Admin/OptionsMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use AmpProject\AmpWP\Infrastructure\Conditional;
use AmpProject\AmpWP\Infrastructure\Registerable;
use AmpProject\AmpWP\Infrastructure\Service;
use AmpProject\AmpWP\Option;

/**
* OptionsMenu class.
Expand Down Expand Up @@ -134,6 +133,8 @@ public function get_menu_slug() {
* Add menu.
*/
public function add_menu_items() {
require_once ABSPATH . '/wp-admin/includes/plugin.php';

/*
* Note that the admin items for Validated URLs and Validation Errors will also be placed under this admin menu
* page when the current user can manage_options.
Expand Down
Loading