Skip to content

Commit 2a0d121

Browse files
committed
Merge branch 'develop' into update/guide-lighter-media
2 parents 25d1057 + 778c1dd commit 2a0d121

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+266
-303
lines changed

assets/css/amp-stories.css

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ amp-story-grid-layer[template="fill"] .wp-block-image {
4242
overflow-wrap: break-word;
4343
}
4444

45+
.wp-block-amp-amp-story-text {
46+
font-weight: normal;
47+
}
48+
4549
.is-style-rounded,
4650
.is-style-rounded img {
4751
border-radius: 5px;
-32.7 KB
Loading
-94.6 KB
Loading
12.2 KB
Loading
17.1 KB
Loading
15.4 KB
Loading
4.73 KB
Loading
19.1 KB
Loading
-67.8 KB
Loading
-626 KB
Loading
-202 KB
Loading
-392 KB
Loading

assets/src/stories-editor/blocks/amp-story-cta/edit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class CallToActionEdit extends Component {
8787
color: textColor.color,
8888
fontSize: fontSize.size ? fontSize.size + 'px' : undefined,
8989
} }
90-
keepPlaceholderOnFocus
9190
/>
9291
</div>
9392
{ isSelected && (
@@ -98,6 +97,7 @@ class CallToActionEdit extends Component {
9897
<URLInput
9998
value={ url }
10099
onChange={ ( value ) => setAttributes( { url: value } ) }
100+
autoFocus={ false /* eslint-disable-line jsx-a11y/no-autofocus */ }
101101
/>
102102
<IconButton icon="editor-break" label={ __( 'Apply', 'amp' ) } type="submit" />
103103
</form>

assets/src/stories-editor/blocks/amp-story-text/edit.js

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class TextBlockEdit extends Component {
132132
backgroundColor: appliedBackgroundColor,
133133
color: textColor.color,
134134
fontSize: ampFitText ? autoFontSize + 'px' : userFontSize,
135-
fontWeight: 'h1' === tagName || 'h2' === tagName ? 700 : 'normal',
136135
textAlign: align,
137136
position: ampFitText && content.length ? 'static' : undefined,
138137
} }

assets/src/stories-editor/blocks/amp-story-text/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const name = 'amp/amp-story-text';
1515
const supports = {
1616
anchor: true,
1717
reusable: true,
18-
className: false,
18+
className: true,
1919
};
2020

2121
const schema = {

assets/src/stories-editor/components/higher-order/with-amp-story-settings.js

-3
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,6 @@ export default createHigherOrderComponent(
410410
checked={ ampFitText }
411411
onChange={ () => {
412412
setAttributes( { ampFitText: ! ampFitText } );
413-
if ( ! ampFitText ) {
414-
setFontSize( attributes.autoFontSize );
415-
}
416413
} }
417414
/>
418415
{ ! ampFitText && (

assets/src/stories-editor/components/resizable-box/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ const EnhancedResizableBox = ( props ) => {
116116
textElement = blockElement.querySelector( '.wp-block-amp-amp-story-post-date' );
117117
break;
118118
}
119+
} else {
120+
textElement = null;
119121
}
120122

121123
if ( ampFitText && 'amp/amp-story-text' === blockName ) {

codecov.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ coverage:
55
project:
66
default:
77
target: auto
8+
threshold: 0.1%
89

910
comment: off
1011

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dealerdirect/phpcodesniffer-composer-installer": "0.5.0",
2121
"phpcompatibility/php-compatibility": "9.1.1",
2222
"wp-coding-standards/wpcs": "2.1.1",
23-
"xwp/wp-dev-lib": "1.1.1"
23+
"xwp/wp-dev-lib": "1.1.2"
2424
},
2525
"suggest": {
2626
"ext-intl": "Enables use of idn_to_utf8() to convert punycode domains to UTF-8 for use with an AMP Cache.",

composer.lock

+6-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/admin/class-amp-story-templates.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AMP_Story_Templates {
1616
*
1717
* @var string
1818
*/
19-
const STORY_TEMPLATES_VERSION = '0.2.8';
19+
const STORY_TEMPLATES_VERSION = '0.3.0';
2020

2121
/**
2222
* Slug for templates' taxonomy.
@@ -201,6 +201,26 @@ public static function get_story_templates() {
201201
'title' => __( 'Template: Travel Vertical', 'amp' ),
202202
'name' => 'travel-vertical',
203203
),
204+
array(
205+
'title' => __( 'Template: Fandom Title', 'amp' ),
206+
'name' => 'fandom-title',
207+
),
208+
array(
209+
'title' => __( 'Template: Fandom CTA', 'amp' ),
210+
'name' => 'fandom-cta',
211+
),
212+
array(
213+
'title' => __( 'Template: Fandom Fact', 'amp' ),
214+
'name' => 'fandom-fact',
215+
),
216+
array(
217+
'title' => __( 'Template: Fandom Fact Text', 'amp' ),
218+
'name' => 'fandom-fact-text',
219+
),
220+
array(
221+
'title' => __( 'Template: Fandom Intro', 'amp' ),
222+
'name' => 'fandom-intro',
223+
),
204224
);
205225
}
206226

includes/class-amp-http.php

+21
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class AMP_HTTP {
2222
/**
2323
* Headers sent (or attempted to be sent).
2424
*
25+
* This is used primarily for the benefit of unit testing. Otherwise, `headers_list()` should be used.
26+
*
2527
* @since 1.0
2628
* @see AMP_HTTP::send_header()
2729
* @var array[]
@@ -490,4 +492,23 @@ public static function filter_comment_post_redirect( $url, $comment ) {
490492

491493
return null;
492494
}
495+
496+
/**
497+
* Get the Content-Type for the response.
498+
*
499+
* @since 1.2
500+
*
501+
* @return string Content type.
502+
*/
503+
public static function get_response_content_type() {
504+
$content_type = ini_get( 'default_mimetype' );
505+
foreach ( headers_list() as $header ) {
506+
list( $name, $value ) = explode( ':', $header, 2 );
507+
if ( 'content-type' === strtolower( $name ) ) {
508+
$content_type = trim( $value );
509+
break;
510+
}
511+
}
512+
return $content_type;
513+
}
493514
}

includes/class-amp-theme-support.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,8 @@ public static function prepare_response( $response, $args = array() ) {
17251725
);
17261726
}
17271727

1728-
if ( '<' !== substr( ltrim( $response ), 0, 1 ) ) {
1728+
// Abort if the response was not HTML.
1729+
if ( 'text/html' !== substr( AMP_HTTP::get_response_content_type(), 0, 9 ) || '<' !== substr( ltrim( $response ), 0, 1 ) ) {
17291730
return $response;
17301731
}
17311732

includes/embeds/class-amp-gallery-embed.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ public function render( $args ) {
204204
return '';
205205
}
206206

207+
$max_width = 0;
208+
$max_height = 0;
209+
207210
$images = array();
208211
foreach ( $args['images'] as $props ) {
209212
$image_atts = array(
@@ -212,6 +215,8 @@ public function render( $args ) {
212215
'height' => $props['height'],
213216
'layout' => 'responsive',
214217
);
218+
$max_width = max( $max_width, $props['width'] );
219+
$max_height = max( $max_height, $props['height'] );
215220
if ( ! empty( $args['lightbox'] ) ) {
216221
$image_atts['lightbox'] = '';
217222
$image_atts['on'] = 'tap:' . AMP_Img_Sanitizer::AMP_IMAGE_LIGHTBOX_ID;
@@ -239,8 +244,8 @@ public function render( $args ) {
239244
return AMP_HTML_Utils::build_tag(
240245
'amp-carousel',
241246
array(
242-
'width' => $this->args['width'],
243-
'height' => $this->args['height'],
247+
'width' => $max_width,
248+
'height' => $max_height,
244249
'type' => 'slides',
245250
'layout' => 'responsive',
246251
),

includes/options/class-amp-options-manager.php

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class AMP_Options_Manager {
2727
'supported_post_types' => array( 'post' ),
2828
'analytics' => array(),
2929
'auto_accept_sanitization' => true,
30-
'accept_tree_shaking' => true,
3130
'all_templates_supported' => true,
3231
'supported_templates' => array( 'is_singular' ),
3332
'enable_response_caching' => true,
@@ -135,7 +134,6 @@ public static function validate_options( $new_options ) {
135134
}
136135

137136
$options['auto_accept_sanitization'] = ! empty( $new_options['auto_accept_sanitization'] );
138-
$options['accept_tree_shaking'] = ! empty( $new_options['accept_tree_shaking'] );
139137
$options['enable_amp_stories'] = ! empty( $new_options['enable_amp_stories'] );
140138

141139
// Validate post type support.

includes/options/class-amp-options-menu.php

-30
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,8 @@ public function render_validation_handling() {
270270
'code' => 'non_existent',
271271
)
272272
);
273-
remove_filter( 'amp_validation_error_sanitized', array( 'AMP_Validation_Manager', 'filter_tree_shaking_validation_error_as_accepted' ) );
274-
$tree_shaking_sanitization = AMP_Validation_Error_Taxonomy::get_validation_error_sanitization(
275-
array(
276-
'code' => AMP_Style_Sanitizer::TREE_SHAKING_ERROR_CODE,
277-
)
278-
);
279273

280274
$forced_sanitization = 'with_filter' === $auto_sanitization['forced'];
281-
$forced_tree_shaking = $forced_sanitization || 'with_filter' === $tree_shaking_sanitization['forced'];
282275
?>
283276

284277
<?php if ( $forced_sanitization ) : ?>
@@ -320,22 +313,6 @@ public function render_validation_handling() {
320313
</div>
321314
<?php endif; ?>
322315

323-
<?php if ( $forced_tree_shaking ) : ?>
324-
<input type="hidden" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[accept_tree_shaking]' ); ?>" value="<?php echo AMP_Options_Manager::get_option( 'accept_tree_shaking' ) ? 'on' : ''; ?>">
325-
<?php else : ?>
326-
<div class="amp-tree-shaking">
327-
<p>
328-
<label for="accept_tree_shaking">
329-
<input id="accept_tree_shaking" type="checkbox" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[accept_tree_shaking]' ); ?>" <?php checked( AMP_Options_Manager::get_option( 'accept_tree_shaking' ) ); ?>>
330-
<?php esc_html_e( 'Automatically remove CSS rules that are not relevant to a given page (tree shaking).', 'amp' ); ?>
331-
</label>
332-
</p>
333-
<p class="description">
334-
<?php esc_html_e( 'AMP limits the total amount of CSS to no more than 50KB; any more than this will cause a validation error. The need to tree shake the CSS is not done by default because in some situations (in particular for dynamic content) it can result in CSS rules being removed that are needed.', 'amp' ); ?>
335-
</p>
336-
</div>
337-
<?php endif; ?>
338-
339316
<script>
340317
(function( $ ) {
341318
var getThemeSupportMode = function() {
@@ -346,21 +323,14 @@ public function render_validation_handling() {
346323
return checkedInput.val();
347324
};
348325

349-
var updateTreeShakingHiddenClass = function() {
350-
var checkbox = $( '#auto_accept_sanitization' );
351-
$( '.amp-tree-shaking' ).toggleClass( 'hidden', checkbox.prop( 'checked' ) && 'native' !== getThemeSupportMode() );
352-
};
353-
354326
var updateHiddenClasses = function() {
355327
var themeSupportMode = getThemeSupportMode();
356328
$( '.amp-auto-accept-sanitize' ).toggleClass( 'hidden', 'native' === themeSupportMode );
357329
$( '.amp-validation-field' ).toggleClass( 'hidden', 'disabled' === themeSupportMode );
358330
$( '.amp-auto-accept-sanitize-canonical' ).toggleClass( 'hidden', 'native' !== themeSupportMode );
359-
updateTreeShakingHiddenClass();
360331
};
361332

362333
$( 'input[type=radio][name="amp-options[theme_support]"]' ).change( updateHiddenClasses );
363-
$( '#auto_accept_sanitization' ).change( updateTreeShakingHiddenClass );
364334

365335
updateHiddenClasses();
366336
})( jQuery );

includes/sanitizers/class-amp-gallery-block-sanitizer.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,16 @@ public function sanitize() {
128128
continue;
129129
}
130130

131+
list( $width, $height ) = $this->get_carousel_dimensions( $node );
132+
131133
$amp_carousel = AMP_DOM_Utils::create_node(
132134
$this->dom,
133135
'amp-carousel',
134136
array(
135-
'height' => $this->get_carousel_height( $node ),
137+
'width' => $width,
138+
'height' => $height,
136139
'type' => 'slides',
137-
'layout' => 'fixed-height',
140+
'layout' => 'responsive',
138141
)
139142
);
140143
foreach ( $images as $image ) {
@@ -150,15 +153,20 @@ public function sanitize() {
150153
* Get carousel height by containing images.
151154
*
152155
* @param DOMElement $element The UL element.
153-
* @return int Height.
156+
* @return array {
157+
* Dimensions.
158+
*
159+
* @type int $width Width.
160+
* @type int $height Height.
161+
* }
154162
*/
155-
protected function get_carousel_height( $element ) {
163+
protected function get_carousel_dimensions( $element ) {
156164
$images = $element->getElementsByTagName( 'amp-img' );
157165
$num_images = $images->length;
158166
$max_height = 0;
159167
$max_width = 0;
160168
if ( 0 === $num_images ) {
161-
return self::FALLBACK_HEIGHT;
169+
return array( self::FALLBACK_WIDTH, self::FALLBACK_HEIGHT );
162170
}
163171
foreach ( $images as $image ) {
164172
/**
@@ -170,17 +178,13 @@ protected function get_carousel_height( $element ) {
170178
if ( is_numeric( $image_height ) ) {
171179
$max_height = max( $max_height, $image_height );
172180
}
173-
$image_width = $image->getAttribute( 'height' );
181+
$image_width = $image->getAttribute( 'width' );
174182
if ( is_numeric( $image_width ) ) {
175183
$max_width = max( $max_width, $image_width );
176184
}
177185
}
178186

179-
if ( ! empty( $this->args['content_max_width'] ) && $max_height > 0 && $max_width > $this->args['content_max_width'] ) {
180-
$max_height = ( $max_width * $this->args['content_max_width'] ) / $max_height;
181-
}
182-
183-
return ! $max_height ? self::FALLBACK_HEIGHT : $max_height;
187+
return array( $max_width, $max_height );
184188
}
185189

186190
/**

0 commit comments

Comments
 (0)