-
Notifications
You must be signed in to change notification settings - Fork 385
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a6fda64
Add skeleton for create-embed-test-post script
westonruter 6ef9768
Fix syntax of PATH_EXCLUDES_PATTERN and add PHPCS exclude-pattern
westonruter 550ed65
Issue 806 : Add media and embeds to test page.
369696b
Merge branch 'add/806-add-script-for-testing-content' of https://gith…
7c77752
Issue 806 : Align equals signs vertically.
128836c
Issue 804 : Test WordPress post embeds.
b8ba836
Issue 806 : code improvement
ThierryA 0b729b1
Fix rendering of SoundCloud embeds and correct parameters for soundcl…
westonruter 938be72
Fix phpunit tests in WP<4.9 due to oEmbeds formerly requiring post co…
westonruter 45c538c
Fix handling of polldaddy oEmbeds in AMP
westonruter 52b306b
Issue 806 : Add instructions for using the wp-cli test page script.
13132ed
Merge branch 'add/806-add-script-for-testing-content' of https://gith…
eaf5157
Issue 804 : Add Amazon, Animoto, and Speakerdeck URLs
8e34745
Issue 804 : Update the Scribd URL.
b22e12a
Restore required attachment count in create-embed-test-post; refactor…
westonruter f1ee3de
Remove DoubleArrowNotAligned PHPCS suppression
westonruter a91d7ad
Fix order of sanitizers to ensure whitelist applies at end, after ifr…
westonruter 499e580
Issue 806 : Update the Photobucket and Scribd URLs.
6309f41
Issue 806 : Merge in feature branch, resolve conflicts.
d2dd032
Issue 806 : Remove Vine embed, add Screencast embed.
8732936
Issue 806 : Add tests for Someecards.
5bce94f
Fix phpcs issues in class-amp-rule-spec.php
westonruter e885b7a
Issue 806 : Correct embeds, including Imgur, Polldaddy, Screencast.
a485be1
Merge branch 'add/806-add-script-for-testing-content' of https://gith…
ed6088d
Issue 806 : Update Photobucket, Tumblr, remove Imgur.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
SYNC_README_MD=0 | ||
PATH_EXCLUDES_PATTERN=includes/lib/* | ||
|
||
if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then | ||
PATH_EXCLUDES_PATTERN="$PATH_EXCLUDES_PATTERN,bin/create-embed-test-post.php" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,304 @@ | ||
<?php | ||
/** | ||
* Create embed test post. | ||
* | ||
* @package AMP | ||
*/ | ||
|
||
if ( ! defined( 'WP_CLI' ) ) { | ||
echo "Must be run in WP-CLI via: wp eval-file bin/create-embed-test-post.php\n"; | ||
exit( 1 ); | ||
} | ||
|
||
$data_entries = array( | ||
array( | ||
'prepare' => 'amp_test_prepare_image_attachments', | ||
'heading' => 'Media Gallery', | ||
'content' => function( $data ) { | ||
return sprintf( '[gallery ids="%s"]', implode( ',', $data['ids'] ) ); | ||
}, | ||
), | ||
array( | ||
'heading' => 'Media Image', | ||
'content' => amp_image_markup(), | ||
), | ||
array( | ||
'heading' => 'Media Caption', | ||
'content' => '[caption width=150]' . amp_image_markup() . 'Example image caption[/caption]', | ||
), | ||
array( | ||
'heading' => 'Media Video', | ||
'content' => '[video src=https://videos.files.wordpress.com/DK5mLrbr/video-ca6dc0ab4a_hd.mp4]', | ||
), | ||
array( | ||
'heading' => 'Media Audio', | ||
'content' => '[audio src=https://wptavern.com/wp-content/uploads/2017/11/EPISODE-296-Gutenberg-Telemetry-Calypso-and-More-With-Matt-Mullenweg.mp3]', | ||
), | ||
array( | ||
'prepare' => 'amp_test_prepare_video_attachments', | ||
'heading' => 'Video Playlist', | ||
'content' => function( $data ) { | ||
return isset( $data['ids'] ) ? sprintf( '[playlist type="video" ids="%s"]', implode( ',', $data['ids'] ) ) : 'There are no videos, so no playlist is expected'; | ||
}, | ||
), | ||
array( | ||
'prepare' => 'amp_test_prepare_audio_attachments', | ||
'heading' => 'Audio Playlist', | ||
'content' => function( $data ) { | ||
return isset( $data['ids'] ) ? sprintf( '[playlist ids="%s"]', implode( ',', $data['ids'] ) ) : 'There audio files, so no playlist is expected'; | ||
}, | ||
), | ||
array( | ||
'heading' => 'CloudUp Image Embed', | ||
'content' => 'https://cloudup.com/iWn3EIpgjev', | ||
), | ||
array( | ||
'heading' => 'CloudUp Video Embed', | ||
'content' => 'https://cloudup.com/ioyW8a_Tjme', | ||
), | ||
array( | ||
'heading' => 'CloudUp Gallery Embed', | ||
'content' => 'https://cloudup.com/cQNdYtQLO5U', | ||
), | ||
array( | ||
'heading' => 'CollegeHumor Embed', | ||
'content' => 'http://www.collegehumor.com/video/40002823/how-to-actually-finish-something-for-once', | ||
), | ||
array( | ||
'heading' => 'DailyMotion Embed', | ||
'content' => 'http://www.dailymotion.com/embed/video/x6bacgf', | ||
), | ||
array( | ||
'heading' => 'Facebook Post Embed', | ||
'content' => 'https://www.facebook.com/WordPress/posts/10155651799877911', | ||
), | ||
array( | ||
'heading' => 'Facebook Video Embed', | ||
'content' => 'https://www.facebook.com/WordPress/videos/10154702401472911/', | ||
), | ||
array( | ||
'heading' => 'Flickr Image Embed', | ||
'content' => 'https://www.flickr.com/photos/sylvainmessier/38089894895/in/explore-2017-12-11/', | ||
), | ||
array( | ||
'heading' => 'Flickr Video Embed', | ||
'content' => 'https://flic.kr/p/5TPDWa', | ||
), | ||
array( | ||
'heading' => 'Funny Or Die Video Embed', | ||
'content' => 'http://FunnyOrDie.com/m/b1dn', | ||
), | ||
array( | ||
'heading' => 'Hulu Embed', | ||
'content' => 'https://www.hulu.com/watch/807443', | ||
), | ||
array( | ||
'heading' => 'Imgur Embed', | ||
'content' => '<blockquote class="imgur-embed-pub" lang="en" data-id="HNQ2WRt"><a href="//imgur.com/HNQ2WRt">Takeoff</a></blockquote>', | ||
), | ||
array( | ||
'heading' => 'Instagram Embed', | ||
'content' => 'https://www.instagram.com/p/bNd86MSFv6/', | ||
), | ||
array( | ||
'heading' => 'Isuu Embed', | ||
'content' => 'https://issuu.com/ajcwfu/docs/seatatthetablefinal', | ||
), | ||
array( | ||
'heading' => 'Kickstarter Embed', | ||
'content' => 'https://www.kickstarter.com/projects/iananderson/save-froots-magazine', | ||
), | ||
array( | ||
'heading' => 'Meetup Embed', | ||
'content' => 'https://www.meetup.com/WordPress-Mexico', | ||
), | ||
array( | ||
'heading' => 'Mixcloud Embed', | ||
'content' => 'https://www.mixcloud.com/TheWireMagazine/adventures-in-sound-and-music-hosted-by-derek-walmsley-7-december-2017/', | ||
), | ||
array( | ||
'heading' => 'Photobucket Embed', | ||
'content' => 'http://s1284.photobucket.com/user/adonchin/media/20171116_181841_zpsrjuop6u7.jpg.html', | ||
), | ||
array( | ||
'heading' => 'Polldaddy Embed', | ||
'content' => 'https://polldaddy.com/poll/7012505/', | ||
), | ||
array( | ||
'heading' => 'Reddit Embed', | ||
'content' => 'https://www.reddit.com/r/Android/comments/7jbkub/google_maps_will_soon_tell_you_when_its_time_to/?ref=share&ref_source=link', | ||
), | ||
array( | ||
'heading' => 'Reverb Nation Embed', | ||
'content' => 'https://www.reverbnation.com/fernandotorresleiva/song/28755694-breve-amor-new-version', | ||
), | ||
array( | ||
'heading' => 'Scribd Embed', | ||
'content' => '[scribd id=124550852 key=key-1hh4hsgsvzz8jdl28w3v mode=scroll]', | ||
), | ||
array( | ||
'heading' => 'SlideShare Embed', | ||
'content' => 'https://www.slideshare.net/slideshow/embed_code/key/u6WNbsR5worSzC', | ||
), | ||
array( | ||
'heading' => 'SmugMug Embed', | ||
'content' => 'https://stuckincustoms.smugmug.com/Portfolio/i-GnwtS8R/A', | ||
), | ||
array( | ||
'heading' => 'Soundcloud Embed', | ||
'content' => 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor', | ||
), | ||
array( | ||
'heading' => 'Speaker Deck Embed', | ||
'content' => 'https://speakerdeck.com/caitiem20/distributed-sagas-a-protocol-for-coordinating-microservices', | ||
), | ||
array( | ||
'heading' => 'Spotify Embed', | ||
'content' => 'https://open.spotify.com/track/2XULDEvijLgHttFgLzzpM5', | ||
), | ||
array( | ||
'heading' => 'Ted Embed', | ||
'content' => 'https://www.ted.com/talks/derek_sivers_how_to_start_a_movement', | ||
), | ||
array( | ||
'heading' => 'Tumblr Post Embed', | ||
'content' => 'https://embed.tumblr.com/embed/post/CHB7nLkCLl-ODZ7tdPU9SQ/168290317795', | ||
), | ||
array( | ||
'heading' => 'Twitter Embed', | ||
'content' => 'https://twitter.com/WordPress/status/936550699336437760', | ||
), | ||
array( | ||
'heading' => 'VideoPress Embed', | ||
'content' => 'https://videopress.com/v/kUJmAcSf', | ||
), | ||
array( | ||
'heading' => 'Vimeo Embed', | ||
'content' => 'https://vimeo.com/59172123', | ||
), | ||
array( | ||
'heading' => 'Vine Embed', | ||
'content' => '[vine url="https://vine.co/v/bEIHZpD2JWz"]', | ||
), | ||
array( | ||
'heading' => 'WordPress Plugin Directory Embed', | ||
'content' => 'https://wordpress.org/plugins/amp/', | ||
), | ||
array( | ||
'heading' => 'WordPress TV Embed', | ||
'content' => 'https://videopress.com/v/DK5mLrbr', | ||
), | ||
array( | ||
'heading' => 'YouTube Embed', | ||
'content' => 'https://www.youtube.com/watch?v=XOY3ZUO6P0k', | ||
), | ||
); | ||
|
||
/** | ||
* Prepare test by ensuring attachments exist. | ||
* | ||
* @param array $data Entry data. | ||
* @return array Data. | ||
*/ | ||
function amp_test_prepare_image_attachments( $data ) { | ||
$attachments = get_children( array( | ||
'post_parent' => 0, | ||
'post_status' => 'inherit', | ||
'post_type' => 'attachment', | ||
'post_mime_type' => 'image', | ||
) ); | ||
$data['ids'] = wp_list_pluck( $attachments, 'ID' ); | ||
|
||
$image_count_needed = 5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if ( count( $data['ids'] ) < $image_count_needed ) { | ||
$data['ids'] = wp_list_pluck( amp_get_media_items( 'image', $image_count_needed ), 'ID' ); | ||
} | ||
return $data; | ||
} | ||
|
||
/** | ||
* Get the markup for an image. | ||
* | ||
* @return string $image Markup for the image. | ||
*/ | ||
function amp_image_markup() { | ||
$image_posts = amp_get_media_items( 'image', 1 ); | ||
$image = reset( $image_posts ); | ||
return isset( $image->ID ) ? wp_get_attachment_image( $image->ID ) : null; | ||
} | ||
|
||
/** | ||
* Get video IDs to test a video playlist. | ||
* | ||
* @param array $data Entry data. | ||
* @return array $data Entry data, with video IDs. | ||
*/ | ||
function amp_test_prepare_video_attachments( $data ) { | ||
$data['ids'] = wp_list_pluck( amp_get_media_items( 'video' ), 'ID' ); | ||
return $data; | ||
} | ||
|
||
/** | ||
* Get audio IDs to test an audio playlist. | ||
* | ||
* @param array $data Entry data. | ||
* @return array $data Data, with video IDs. | ||
*/ | ||
function amp_test_prepare_audio_attachments( $data ) { | ||
$data['ids'] = wp_list_pluck( amp_get_media_items( 'audio' ), 'ID' ); | ||
return $data; | ||
} | ||
|
||
/** | ||
* Get media items, using a \WP_Query. | ||
* | ||
* @param integer $type The post_mime_type of the media item. | ||
* @param integer $image_count The number of images for which to query. | ||
* @return array $media_items The media items from the query. | ||
*/ | ||
function amp_get_media_items( $type, $image_count = 10 ) { | ||
$query = new \WP_Query( array( | ||
'post_type' => 'attachment', | ||
'post_mime_type' => $type, | ||
'post_status' => 'inherit', | ||
'posts_per_page' => $image_count, | ||
) ); | ||
return $query->get_posts(); | ||
} | ||
|
||
// Run the script. | ||
$page = get_page_by_path( '/amp-test-embeds/' ); | ||
if ( $page ) { | ||
$page_id = $page->ID; | ||
} else { | ||
$page_id = wp_insert_post( array( | ||
'post_name' => 'amp-test-embeds', | ||
'post_title' => 'AMP Test Embeds', | ||
'post_type' => 'page', | ||
) ); | ||
} | ||
|
||
$content = ''; | ||
foreach ( $data_entries as $data_entry ) { | ||
if ( isset( $data_entry['prepare'] ) ) { | ||
$data_entry = array_merge( | ||
$data_entry, | ||
call_user_func( $data_entry['prepare'], $data_entry ) | ||
); | ||
} | ||
|
||
$content .= sprintf( "<h1>%s</h1>\n", $data_entry['heading'] ); | ||
if ( is_callable( $data_entry['content'] ) ) { | ||
$content .= call_user_func( $data_entry['content'], $data_entry ); | ||
} else { | ||
$content .= $data_entry['content']; | ||
} | ||
$content .= "\n\n"; | ||
} | ||
|
||
wp_update_post( wp_slash( array( | ||
'ID' => $page_id, | ||
'post_content' => $content, | ||
) ) ); | ||
|
||
WP_CLI::success( sprintf( 'Please take a look at: %s', get_permalink( $page_id ) ) ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.