-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add create-embed-test-post script and fix support for various embeds #829
Conversation
bin/create-embed-test-post.php
Outdated
'content' => function( $data ) { | ||
return sprintf( '[gallery ids="%s"]', implode( ',', $data['ids'] ) ); | ||
}, | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs now to be fleshed out with all that can be thrown at content in a vanilla WordPress install.
In Development Hi @westonruter, |
Go for it! |
As time allows, we'll also want to do something similar for Gutenberg blocks. |
Use Weston's wp-cli script to create a test post. Add media items to the post content. And add several embeds. Several embeds are still not rendering, Even on a standard, non-AMP page.
…ub.com/Automattic/amp-wp into add/806-add-script-for-testing-content
Before, the equals sign alignment caused a PHPCS warning. Fix this, to enable the Travis build to succeed.
create-embed-test-post.php needs to test all post content. As Weston mentioned, embedded posts are part of this.
Request For Review Hi @ThierryA or @westonruter, This adds most of the allowed embeds to the post content. It also tests for other media types, as listed in Issue #806. Also, @ThierryA's comment in #806 lists whether these newly-added embeds render properly in the AMP page. There are some embeds that don't even render in the standard WordPress page, like Scribd and Photobucket. If you'd like, I could work on Gutenberg block support tomorrow (Wednesday). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kienstra and @westonruter, great work! I pushed this commit which does the following:
- simplify code
- remove PHP5.2 Travis exclude as it is no longer needed
- add errors handling
Ready for your review and adjustments if need.
PS: this PR is approved from my perspective.
bin/create-embed-test-post.php
Outdated
@@ -35,10 +209,63 @@ function amp_test_prepare_image_attachments( $data ) { | |||
) ); | |||
$data['ids'] = wp_list_pluck( $attachments, 'ID' ); | |||
|
|||
// @todo Add some attachments if count( $data['ids'] ) < 5. | |||
$image_count_needed = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of a case where this would be needed as a fallback rather than directly getting the images like we do for the other shortcodes (please advise if I am missing something). This commit simplifies this.
@kienstra @westonruter I think it would be great to document this script and steps to run it somewhere, whether it is in the |
…oud shortcode * Hook into oEmbed filters for rewriting SoundCloud embeds as AMP components. * Ensure Jetpack is active while unit tests are run. * Explicitly install and activate Jetpack during unit tests. * Fix error message in create-embed-test-post.php * Fix phpcs for Soundcloud code.
* Use noscript response from oEmbed as default content. * Include WPCOM_AMP_Polldaddy_Embed by default even when not on WordPress.com; deprecate wpcom/shortcodes.php. * Fix DailyMotion and FunnyOrDie test URLs. * Clean phpcs for class-amp-polldaddy-embed.php
wpcom/class-amp-polldaddy-embed.php
Outdated
*/ | ||
public function filter_embed_oembed_html( $cache, $url, $attr ) { | ||
$parsed_url = wp_parse_url( $url ); | ||
if ( $url && false === strpos( $parsed_url['host'], 'polldaddy.com' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may need to include looking at poll.fm
, but I've never seen any PollDaddy URLs look like that: https://github.com/WordPress/wordpress-develop/blob/c6326694380722ccbdd78e21a2bd0d079383291c/src/wp-includes/class-oembed.php#L69
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the risk is minimal, this could throw a PHP warning if the url passed doesn't have an host.
Documenting wp-cli Script In contributing.md Hi @ThierryA,
That's a good idea. If it's alright, I'll add steps to use the Also, I need to add the oEmbed URLs that @westonruter requested. |
bin/create-embed-test-post.php
Outdated
'Please make sure at least %1$s "%2$s" attachments are accessible and run this script again.', | ||
$image_count, | ||
$type, | ||
$posts_count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed now that the message changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I will restore it. I also realized we should use $query->found_posts
and $query->post_count
here.
@@ -9,22 +9,49 @@ | |||
* Class AMP_SoundCloud_Embed_Handler | |||
*/ | |||
class AMP_SoundCloud_Embed_Handler extends AMP_Base_Embed_Handler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the @since
tag for new code and changes would be helpful.
private function render_embed_fallback( $url ) { | ||
return AMP_HTML_Utils::build_tag( 'a', | ||
array( | ||
'href' => esc_url( $url ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% sure why we excluded this rule. It is now inconsistent throughout the project which doesn't really make sense since we require the variable operators to be aligned.
PS: this is indeed not a blocker but I think it would be better to keep the code style as consistent as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree. I'll remove the WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned
suppression.
tests/test-amp-soundcloud-embed.php
Outdated
* So on WP<4.9 we set a post global to ensure oEmbeds get processed. | ||
*/ | ||
if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) { | ||
$post = get_post( $this->factory()->post->create() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tips: get_post( $this->factory()->post->create() )
can be replaced with $this->factory()->post->create_and_get()
.
*/ | ||
public function filter_embed_oembed_html( $cache, $url ) { | ||
$parsed_url = wp_parse_url( $url ); | ||
if ( $url && false === strpos( $parsed_url['host'], 'soundcloud.com' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the risk is minimal, this could throw a PHP warning if the url passed doesn't have an host.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this can ever happen.
wpcom/class-amp-polldaddy-embed.php
Outdated
*/ | ||
public function filter_embed_oembed_html( $cache, $url, $attr ) { | ||
$parsed_url = wp_parse_url( $url ); | ||
if ( $url && false === strpos( $parsed_url['host'], 'polldaddy.com' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the risk is minimal, this could throw a PHP warning if the url passed doesn't have an host.
@kienstra sounds good to me. |
Add steps to contributing.md to use create-embed-test-post.php. Include a step that this should be inside an environment like VVV.
…ub.com/Automattic/amp-wp into add/806-add-script-for-testing-content
I noticed that the
We need to figure out why the |
Add these URLs to test oEmbed. Use the Amazon testing URLs in: https://core.trac.wordpress.org/ticket/38181 Props @jsepia for these URLs.
Use the URL from @wonderboymusic in: https://core.trac.wordpress.org/ticket/28379.
* Add missing since tag * Update filter_embed_oembed_html calls since $url is required * Add DEFAULT_BASE_BRANCH=develop * Use create_and_get in test
…ame sanitizer has run Issue introduced in 575ac66
Thanks to ohthenoes for the Photobucket link in: https://core.trac.wordpress.org/ticket/13754 And thanks to @wonderboymusic for the Scribd URL from: https://core.trac.wordpress.org/ticket/28379.
The only conflict was from array alignment. It was a whitespace-only edit.
Add a Screencast embed, thanks to designsimply's URL in: https://core.trac.wordpress.org/ticket/24660 Because Vine isn't supported anymore, remove its test URL. @see wordpress-develop/src/wp-includes/class-oembed.php
Both the full URL, and the short URL ending with the TLD .ly. They both render well in AMP.
Tests For All oEmbed Providers Hi @westonruter, Still, some of them aren't rendering properly, even on a non-AMP page. Including Imgur, Photobucket, and Screencast. I'm working on those now. |
Change the URLs for most of these. And remove the soundcloud shortcode. This isn't supported natively.
…ub.com/Automattic/amp-wp into add/806-add-script-for-testing-content
Use mrdenn1s's image from his Trac ticket: https://core.trac.wordpress.org/ticket/28345 It looks like Imgur oEmbeds no longer work in WordPress. @see https://core.trac.wordpress.org/ticket/42247
Tests For Almost All oEmbeds Hi @westonruter, |
Fixes #806.