#26631 closed task (blessed) (fixed)
Add a "playlist" shortcode
Reported by: | wonderboymusic | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | needs-testing has-patch needs-unit-tests |
Focuses: | Cc: |
Description
Gallery = list of images, Playlist = list of audio files. There's a gallery
shortcode, there should be a playlist
shortcode. The existing audio
shortcode is only meant to create the markup for 1 <audio>
. Playlist generation shouldn't be shoe-horned in there. A playlist probably needs a lot more wiring up with JS anyways.
The UI for managing galleries is great, the same UI can used for playlists.
Attachments (21)
Change History (87)
#2
@
11 years ago
This is pretty cool. One thing I'm noticing is how much gallery code it duplicates and modifies. Some of it looks to be completely new, just following the set pattern. Totally kosher. But how much of it is shared code that could benefit from solid abstraction? Not saying it needs it now in order to go in, but it is good to evaluate it from this perspective, as at some point, core or a plugin will want video playlists, document collections, etc.
#3
@
11 years ago
Yeah - there needs to be a generic "collection" manager. First pass was just brute force making it exist, I actually have no clue what most of the code does.
#4
@
11 years ago
I'd also love to see a more generic way of handling collections beyond just images -- thanks for starting this up!
#6
@
11 years ago
We may be able to abstract it and make it work for both - the gallery sorting definitely needs to become type-agnostic. The shortcodes may be the only place where branching the implementation is necessary
#7
@
11 years ago
- Keywords needs-testing has-patch needs-ui needs-docs needs-unit-tests added
- Milestone changed from Future Release to 3.9
Updated the patch with latest progress:
- Abstracts
wp.media.gallery
code inwp.media.collection
whichwp.media.gallery
,wp.media.playlist
, andwp.media['video-playlist']
use. - Abstracts
wp.media.controller.GalleryAdd
andwp.media.controller.GalleryEdit
intowp.media.controller.CollectionAdd
andwp.media.controller.CollectionEdit
which all 3 use with minimal registration code - Allows any new types/shortcodes to be simply added by convention with a few lines of code, the only excessive code is registering new Toolbars and Menus when you add a new type, there really isn't any way around it
- Adds TinyMCE view switch for
[playlist]
and[video-playlist]
using thewpplaylist
plugin, which I added. Theoretically, all media shortcodes could use the same TinyMCE plugin - all it does it turn a shortcode into HTML and the reverse. Adding another plugin each time seems excessive. - Abstracts the shortcode handlers for
[playlist]
and[video-playlist]
into one helper function:function wp_playlist_shortcode( $attr ) { return wp_get_playlist( $attr, 'audio' ); } add_shortcode( 'playlist', 'wp_playlist_shortcode' ); function wp_video_playlist_shortcode( $attr ) { return wp_get_playlist( $attr, 'video' ); } add_shortcode( 'video-playlist', 'wp_video_playlist_shortcode' );
The player on the front end will use a MediaElementPlayer
object and some custom Backbone Views. The ME class is necessary to control the player from code and sequence tracks / support next-prev, etc. Next steps will be skinning the audio player to show metadata and images.
This code actually works now - audio and video, all clips will play one after the other.
Gonna shoot for this or something like it in 3.9.
#8
@
11 years ago
26631.3.diff adds more settings related to theme/skinning the playlists
#9
@
11 years ago
I accidentally added a 3rd T
in a function when I clicked save and made the patch, refreshed
#10
@
11 years ago
26631.4.diff adds a UI for the audio playlist shortcode, theoretically works for video as well
This ticket was mentioned in IRC in #wordpress-ui by bassgang. View the logs.
11 years ago
This ticket was mentioned in IRC in #wordpress-dev by bassgang. View the logs.
11 years ago
#13
@
11 years ago
patch -p0 < 26631.5.diff
gives me
patching file src/wp-content/themes/twentyfourteen/functions.php patching file src/wp-includes/class-wp-editor.php Hunk #1 succeeded at 236 (offset 4 lines). patching file src/wp-includes/css/editor.css Hunk #1 succeeded at 481 (offset 9 lines). Hunk #2 succeeded at 492 (offset 9 lines). Hunk #3 succeeded at 508 (offset 9 lines). patching file src/wp-includes/css/media-views.css Hunk #1 succeeded at 595 (offset 6 lines). Hunk #2 succeeded at 1416 (offset 6 lines). Hunk #3 succeeded at 1692 (offset 6 lines). Hunk #4 succeeded at 1740 (offset 6 lines). Hunk #5 succeeded at 1765 (offset 6 lines). Hunk #6 succeeded at 1791 (offset 6 lines). Hunk #7 succeeded at 1800 (offset 6 lines). Hunk #8 succeeded at 1873 (offset 6 lines). Hunk #9 succeeded at 1910 (offset 6 lines). patching file src/wp-includes/js/media-editor.js patching file src/wp-includes/js/media-views.js Hunk #1 succeeded at 461 (offset 1 line). Hunk #2 FAILED at 755. Hunk #3 succeeded at 842 (offset 4 lines). Hunk #4 succeeded at 1793 (offset 5 lines). Hunk #5 succeeded at 1854 (offset 5 lines). Hunk #6 succeeded at 1866 (offset 5 lines). Hunk #7 succeeded at 1880 (offset 5 lines). Hunk #8 succeeded at 1936 (offset 6 lines). Hunk #9 succeeded at 2100 (offset 6 lines). Hunk #10 succeeded at 2220 (offset 6 lines). Hunk #11 succeeded at 5154 (offset 12 lines). 1 out of 11 hunks FAILED -- saving rejects to file src/wp-includes/js/media-views.js.rej patching file src/wp-includes/js/mediaelement/wp-mediaelement.css patching file src/wp-includes/js/plupload/handlers.js patching file src/wp-includes/js/swfupload/handlers.js patching file src/wp-includes/js/tinymce/langs/wp-langs-en.js patching file src/wp-includes/js/tinymce/skins/wordpress/wp-content.css patching file src/wp-includes/media-template.php patching file src/wp-includes/media.php Hunk #2 succeeded at 2186 (offset 18 lines). Hunk #3 succeeded at 2215 (offset 18 lines). patching file src/wp-includes/script-loader.php
@wonderboymusic can you please update the diff? Thanks.
#14
@
11 years ago
26631.6.diff refreshes the patch against latest trunk.
Gonna do another round of UI. wp.media.collection.instance()
and the like could use a review by a @gcorne. It should be obvious what I am trying to abstract, there are probably other ways to do it. Could use some eyes.
#15
@
11 years ago
26631.8.diff is a good alpha.
- Adds
playlist
andvideo-playlist
to thewpgallery
TinyMCE plugin (whereaudio
andvideo
currently reside) - Makes Attachment Settings checkboxes work for
playlist
andvideo-playlist
, this logic is weird in general for checkboxes anddata-setting
- Supports the Featured Image in the media model on Edit Media page for audio and video when supported
- Supports
poster
images for videos invideo-playlist
- Makes
audio
responsive to size of$content_width
- Loads videos at proper aspect ratio in relation to
$content_width
- Supports
light
anddark
styles - Works out of the box in 2010, 2011, 2012, 2013, and 2014 themes - tested in all 5
- Adds
theme_supports_thumbnails( $post )
andpost_supports_thumbnails( $post )
to check more than just$post->post_type
in scenarios that need to checkpost_type_supports( 'attachment:video', 'thumbnail' )
andcurrent_theme_supports( 'post-thumbnails', 'attachment:video' )
- contains all of the code to abstract Gallery JS code into "Collection code
#21
@
11 years ago
26631.9.diff is 1/2 of the size of .8.diff
and way more sane. It is also strictly playlist changes.
#23
@
11 years ago
Edit: damn i saw this an hour ago, i thought i clicked on "submit" but no, so i did, then i saw you already fixed it, delete this -_- thanks
Hello, tell me if i'm wrong but i just read the code and i saw this:
if ( 'attachment' && $post_ID ) {
i think it's
if ( 'attachment' === $post_type && $post_ID ) {
See you
#26
@
11 years ago
- Keywords needs-docs removed
In 27240:
(The changeset message doesn't reference this ticket)
(Forgot to mention the ticket number in the original commit)
This ticket was mentioned in IRC in #wordpress-dev by DH-Shredder. View the logs.
11 years ago
#34
follow-up:
↓ 35
@
11 years ago
Defaults don't seem to work for me in Chrome on OS X. If you create a new playlist and don't touch any of it's settings (which are checked by default), the inserted shortcode's attributes are all false because they're undefined in media.collection.shortcodeAttrs
. We can handle it the same way as we do in media.collection.attachments
, see 26631.12.diff.
#35
in reply to:
↑ 34
@
11 years ago
Replying to kovshenin:
Defaults don't seem to work for me in Chrome on OS X. If you create a new playlist and don't touch any of it's settings (which are checked by default), the inserted shortcode's attributes are all false because they're undefined in
media.collection.shortcodeAttrs
. We can handle it the same way as we do inmedia.collection.attachments
, see 26631.12.diff.
They *aren't* set if you check them, which is driving me crazy. It's backward. Just hadn't gotten around to leaving a comment on that yet :)
#37
follow-up:
↓ 38
@
11 years ago
- Keywords needs-ui removed
@xknown: I would imagine styles will be filterable soon, so let's leave that alone for now. The idea is that your theme or plugin could eventually add new theming styles in the settings dropdown.
#38
in reply to:
↑ 37
@
11 years ago
Replying to wonderboymusic:
@xknown: I would imagine styles will be filterable soon, so let's leave that alone for now. The idea is that your theme or plugin could eventually add new theming styles in the settings dropdown.
Ok. However, it still needs to be escaped/sanitized. The current implementation is vulnerable to XSS.
#39
@
11 years ago
If an attachment neither has a meta title nor a caption the content of ".wp-playlist-current-item" is empty in an audio playlist in the current implementation, which looks not so good. 26631.13.diff fixes this due to falling back to "data.title" if "data.meta.title" and "data.caption" are both not available.
#42
follow-up:
↓ 46
@
11 years ago
Next step is to make the value for "style" filterable in Playlist Settings and in the shortcode attribute whitelist. Ideally, a plugin or theme could install additional styles.
I don't think we want to bundle more in core, although I do like the idea of a playlist that has a "cover image" - I have some SoundCloud embeds on the homepage of this site: http://highforthis.com. The image could change with each track.
Since assets (JS/CSS) are only loaded on the first instance of a playlist shortcode, we can probably fire an action (something like wp_playlist_{$style}
) where one could hook. We should make our enqueue'ing using the action so it can be easily unhooked.
#46
in reply to:
↑ 42
@
11 years ago
Replying to wonderboymusic:
Next step is to make the value for "style" filterable in Playlist Settings and in the shortcode attribute whitelist. Ideally, a plugin or theme could install additional styles.
I feel like we shouldn't have the style option, at least not here. In most cases, the selected style should probably be the same for all of your playlists until/unless you change your theme. I'd rather see this as a sitewide option if we feel like we need to have it (at least for light/dark), or if possible try to find a way to remove the option altogether (haven't thought of anything yet). Themes and plugins can, of course, still add their own implementations, and even add this sort of an option, but I don't think it's necessary out-of-the-box so that we can keep it as simple as possible.
Tested in IE11 and it works great, by the way.
#50
@
11 years ago
I am going to do something similar for CollectionEdit
.
My goal here:
- Reusable classes that can just be instantiated with attributes, and don't require extending every time
- When new features are added, it would good if more code was shared, versus duplicating 200 lines and only changing one or two properties
- Use actual objects instead of hacking together factories
#51
@
11 years ago
I worked up a few patches that adjust the code a bit and make one small visual change.
26631.14.patch adds some braces to a couple if/else statements to make jshint happy.
26631.15.patch refactors CollectionEdit
and CollectionAdd
.
- Instead of generating new constructors use the
initialize
method to set attributes based on thecollectionType
- Use the reference to the
SettingsView
instead of grabbing it from the namespace. This better matches with existingAttachmentDisplay
attribute. - Switch from using
tag
tocollectionType
to better communicate the purpose of the attribute. - Make the design of the
CollectionEdit
andCollectionAdd
consistent with one another
The refactoring cuts down the lines of code by about 20 lines and also in my opinion makes the code a little easier to follow. I am curious to know whether or not others agree.
One small concern I have about this change is that it removes the GalleryEdit
and GalleryAdd
constructors, which a plugin may be manipulating. A search of the .org plugin repository didn't return any results so removing them is probably not a big deal.
26631.16.patch adjusts the priority of the separator in the Edit Playlist and Edit Video Playlist menus to match the structure of the Edit Gallery menu.
#56
follow-up:
↓ 64
@
11 years ago
I think the "Create Playlist" tab in the media manager should be renamed "Create Audio Playlist" so it doesn't look as odd with the "Create Video Playlist" below it.
The"Create Gallery" tab should then probably be renamed "Create Image Gallery" to fit better with the two playlist tabs below it.
This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.
11 years ago
#58
@
11 years ago
Took a stab at cleaning up the playlist settings a bit in playlist-settings.jpg.
#60
@
11 years ago
If anybody wants some easy props, 26631.14.diff needs some filter docs
This ticket was mentioned in IRC in #wordpress-dev by DrewAPicture. View the logs.
11 years ago
#64
in reply to:
↑ 56
@
11 years ago
Replying to johnbillion:
I think the "Create Playlist" tab in the media manager should be renamed "Create Audio Playlist" so it doesn't look as odd with the "Create Video Playlist" below it.
I support this suggestion. In my opinion a playlist does not necessarily defaults to audio so that renaming "Create Playlist" to "Create Audio Playlist" is clearer.
#65
@
11 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 27512:
26631.diff is a work in progress, but it indeed allows you to make playlists in the same way you make galleries - one caveat: the shortcode doesn't do anything yet - only outputs
THISISMYPLAYLIST