Skip to content

Commit aa9593d

Browse files
committed
Merge branch 'develop' of github.com:ampproject/amp-wp into add/validation-error-titles-to-block-warnings
* 'develop' of github.com:ampproject/amp-wp: Remove title tag from AMP SVG icons Use a Tooltip, thanks to Pierre's suggestion Correct failed unit test from dependency Remove @wordpress/nux, as it looks like it's not used anymore Remove DotTip from import statements Remove DotTip, as it caused a console warning Improve AMP preview button in WP 5.4 and with Gutenberg Make phpstan happy Remove multiple instances of div#fb-root Test removal of <p> tag Eliminate unnecessary double loop for XPath query since DOMNodeList is not live Remove phpstan.neon.dist from build Use `nodeName` property Remove registration of Facebook embed handler
2 parents 7041680 + ab65349 commit aa9593d

File tree

10 files changed

+144
-319
lines changed

10 files changed

+144
-319
lines changed

Gruntfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ module.exports = function( grunt ) {
3939
'vendor/*/*/*.yml',
4040
'vendor/*/*/.*.yml',
4141
'vendor/*/*/tests',
42+
'vendor/ampproject/common/phpstan.neon.dist',
4243
'vendor/ampproject/optimizer/bin',
44+
'vendor/ampproject/optimizer/phpstan.neon.dist',
4345
'vendor/bin',
4446
];
4547

assets/css/src/amp-block-editor.css

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66
/* AMP preview button wrapper */
77
.wp-core-ui #amp-wrapper-post-preview {
88
margin-left: -6px;
9+
margin-right: 6px;
910
}
1011

1112
/* AMP preview button */
1213
.wp-core-ui .amp-editor-post-preview {
1314
height: 34px;
14-
padding-left: 6px;
15-
padding-right: 6px;
15+
padding: 6px 12px;
1616
border-top-left-radius: 0;
1717
border-bottom-left-radius: 0;
18+
justify-content: center;
19+
align-items: center;
1820
}
1921

2022
.wp-core-ui .amp-editor-post-preview svg {
21-
width: 15px;
22-
height: 15px;
23+
width: 18px;
24+
height: 18px;
2325
margin: 0;
2426
}
2527

assets/images/amp-icon.svg

Lines changed: 0 additions & 1 deletion
Loading

assets/images/amp-white-icon.svg

Lines changed: 1 addition & 2 deletions
Loading

assets/src/block-editor/components/amp-preview.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import PropTypes from 'prop-types';
88
* WordPress dependencies
99
*/
1010
import { Component, createRef, renderToString } from '@wordpress/element';
11-
import { Icon, IconButton } from '@wordpress/components';
11+
import { Button, Icon, Tooltip } from '@wordpress/components';
1212
import { __ } from '@wordpress/i18n';
1313
import { withSelect, withDispatch } from '@wordpress/data';
14-
import { DotTip } from '@wordpress/nux';
1514
import { compose } from '@wordpress/compose';
1615
import { addQueryArgs } from '@wordpress/url';
1716

@@ -237,27 +236,25 @@ class AMPPreview extends Component {
237236

238237
return (
239238
isEnabled && ! errorMessages.length && ! isStandardMode && (
240-
<IconButton
241-
icon={ ampFilledIcon( { viewBox: '0 0 62 62' } ) }
242-
isLarge
243-
className="amp-editor-post-preview"
244-
href={ href }
245-
label={ __( 'Preview AMP', 'amp' ) }
246-
target={ this.getWindowTarget() }
247-
disabled={ ! isSaveable }
248-
onClick={ this.openPreviewWindow }
249-
ref={ this.buttonRef }
250-
>
251-
<span className="screen-reader-text">
252-
{
253-
/* translators: accessibility text */
254-
__( '(opens in a new tab)', 'amp' )
255-
}
256-
</span>
257-
<DotTip tipId="amp/editor.preview">
258-
{ __( 'Click “Preview” to load a preview of this page in AMP, so you can make sure you are happy with your blocks.', 'amp' ) }
259-
</DotTip>
260-
</IconButton>
239+
<Tooltip text={ __( 'Preview AMP', 'amp' ) } >
240+
<Button
241+
className="amp-editor-post-preview"
242+
href={ href }
243+
label={ __( 'Preview AMP', 'amp' ) }
244+
isSecondary
245+
disabled={ ! isSaveable }
246+
onClick={ this.openPreviewWindow }
247+
ref={ this.buttonRef }
248+
>
249+
{ ampFilledIcon( { viewBox: '0 0 62 62', width: 18, height: 18 } ) }
250+
<span className="screen-reader-text">
251+
{
252+
/* translators: accessibility text */
253+
__( '(opens in a new tab)', 'amp' )
254+
}
255+
</span>
256+
</Button>
257+
</Tooltip>
261258
)
262259
);
263260
}

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

Lines changed: 21 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111
* Class AMP_Facebook_Embed_Handler
1212
*/
1313
class AMP_Facebook_Embed_Handler extends AMP_Base_Embed_Handler {
14-
const URL_PATTERN = '#https?://(www\.)?facebook\.com/.*#i';
15-
16-
/**
17-
* Default width.
18-
*
19-
* @var int
20-
*/
21-
protected $DEFAULT_WIDTH = 600;
22-
2314
/**
2415
* Default height.
2516
*
@@ -45,57 +36,14 @@ class AMP_Facebook_Embed_Handler extends AMP_Base_Embed_Handler {
4536
* Registers embed.
4637
*/
4738
public function register_embed() {
48-
wp_embed_register_handler( $this->amp_tag, self::URL_PATTERN, [ $this, 'oembed' ], -1 );
39+
// Not implemented.
4940
}
5041

5142
/**
5243
* Unregisters embed.
5344
*/
5445
public function unregister_embed() {
55-
wp_embed_unregister_handler( $this->amp_tag, -1 );
56-
}
57-
58-
/**
59-
* WordPress OEmbed rendering callback.
60-
*
61-
* @param array $matches URL pattern matches.
62-
* @param array $attr Matched attributes.
63-
* @param string $url Matched URL.
64-
* @return string HTML markup for rendered embed.
65-
*/
66-
public function oembed( $matches, $attr, $url ) {
67-
return $this->render( [ 'url' => $url ] );
68-
}
69-
70-
/**
71-
* Gets the rendered embed markup.
72-
*
73-
* @param array $args Embed rendering arguments.
74-
* @return string HTML markup for rendered embed.
75-
*/
76-
public function render( $args ) {
77-
$args = wp_parse_args(
78-
$args,
79-
[
80-
'url' => false,
81-
]
82-
);
83-
84-
if ( empty( $args['url'] ) ) {
85-
return '';
86-
}
87-
88-
$this->did_convert_elements = true;
89-
90-
return AMP_HTML_Utils::build_tag(
91-
$this->amp_tag,
92-
[
93-
'data-href' => $args['url'],
94-
'layout' => 'responsive',
95-
'width' => $this->args['width'],
96-
'height' => $this->args['height'],
97-
]
98-
);
46+
// Not implemented.
9947
}
10048

10149
/**
@@ -131,14 +79,27 @@ public function sanitize_raw_embeds( Document $dom ) {
13179
*/
13280
$fb_root = $dom->getElementById( 'fb-root' );
13381
if ( $fb_root ) {
134-
$scripts = [];
135-
foreach ( $dom->xpath->query( '//script[ starts-with( @src, "https://connect.facebook.net" ) and contains( @src, "sdk.js" ) ]' ) as $script ) {
136-
$scripts[] = $script;
82+
/**
83+
* Script.
84+
*
85+
* @var DOMElement $script_query
86+
*/
87+
$script_query = $dom->xpath->query( '//script[ starts-with( @src, "https://connect.facebook.net" ) and contains( @src, "sdk.js" ) ]' );
88+
foreach ( $script_query as $script ) {
89+
$parent_node = $script->parentNode;
90+
$parent_node->removeChild( $script );
91+
92+
// Remove parent node if it is an empty <p> tag.
93+
if ( 'p' === $parent_node->nodeName && null === $parent_node->firstChild ) {
94+
$parent_node->parentNode->removeChild( $parent_node );
95+
}
13796
}
138-
foreach ( $scripts as $script ) {
139-
$script->parentNode->removeChild( $script );
97+
98+
// Remove other instances of <div id="fb-root">.
99+
$fb_root_query = $dom->xpath->query( '//div[ @id = "fb-root" ]' );
100+
foreach ( $fb_root_query as $fb_root ) {
101+
$fb_root->parentNode->removeChild( $fb_root );
140102
}
141-
$fb_root->parentNode->removeChild( $fb_root );
142103
}
143104
}
144105

package-lock.json

Lines changed: 0 additions & 157 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"@wordpress/hooks": "2.7.0",
4242
"@wordpress/i18n": "3.9.0",
4343
"@wordpress/jest-puppeteer-axe": "1.6.0",
44-
"@wordpress/nux": "3.12.3",
4544
"@wordpress/plugins": "2.12.0",
4645
"@wordpress/scripts": "5.1.0",
4746
"@wordpress/url": "2.9.0",

0 commit comments

Comments
 (0)