Opened 11 years ago
Closed 10 years ago
#26675 closed enhancement (fixed)
Rewrite of get_media_embedded_in_content() function to produce expected results.
Reported by: | kopepasah | Owned by: | DrewAPicture |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 3.6 |
Component: | Media | Keywords: | good-first-bug has-patch commit 2nd-opinion |
Focuses: | Cc: |
Description
The get_media_embedded_in_content() function does not output the media in the array in the order it appears in the content (as it should). Rather, it loops through each tag and gets the media in the order of tag (if get_tag_regex() worked correctly, see #26674).
The attached patch adds a third parameter 'sortby' to declare how the results should sort. By default it sorts by 'type' and the remains as it is now. If a user declares the 'sortby' parameter as 'source', the results would appear in the order they are found in the content (which is what I expected).
Also preg_match() was changed to preg_match_all() to find all the media of a type (instead of just one).
Lastly, the regex used in the 'source' sort by is a modification of the get_tag_regex() to try subpatterns in alternation. An optional fix would be to add the named group in the get_tag_regex() function, but that is another patch.
Side note: I added 'img' to the option of allowed media types (because it is media). If anyone has a reason this should not be in there, I would like to know why. I did not find any complications while testing.
Attachments (5)
Change History (25)
This ticket was mentioned in IRC in #wordpress-dev by kopepasah. View the logs.
11 years ago
#4
@
11 years ago
Nacin, great suggestions. I will submit another patch based on those.
For the images, should I add an additional parameter or a filter. I personally vote filter, as this will allow users to not only add additional media types to search for (e.g. img), but also search for a specific media type (e.g. iframe) or multiple types (e.g. audio & video). With that being said, it will also allow for searching for any HTML element if a users sets the filter that way, but that could be edge case.
What do you think?
#5
@
11 years ago
Nacin,
I've attached 26675-2014.01.19.patch to address your suggestions.
I removed the $sortby parameter and changed the sorting to how the media was located in the content. Should we add an additional parameter to allow for sorting of by media item and not by found?
I also added a filter (get_media_embedded_in_content_allowed) to customize the allowed embedded media types. I think this is a better alternative than adding an additional parameter.
Feedback is appreciated.
This ticket was mentioned in IRC in #wordpress-dev by kopepasah. View the logs.
11 years ago
#8
@
10 years ago
- Keywords needs-docs added; needs-testing removed
- Milestone changed from Future Release to 4.2
#10
@
10 years ago
- Keywords good-first-bug added; has-patch removed
'get_media_embedded_in_content_allowed'
need filter docs
This ticket was mentioned in Slack in #core by drew. View the logs.
10 years ago
#12
@
10 years ago
- Keywords 4.2-beta added
@wonderboymusic: What's left here? This will ride into Beta 1, see [31574].
#13
@
10 years ago
- Keywords has-patch added; needs-docs removed
Patch 26675.3.diff adds filter docs.
This ticket was mentioned in Slack in #core by drew. View the logs.
10 years ago
#16
@
10 years ago
- Owner changed from wonderboymusic to DrewAPicture
- Status changed from assigned to reviewing
#19
@
10 years ago
- Keywords 2nd-opinion added
- Resolution fixed deleted
- Status changed from closed to reopened
I think that the filter name doesn't fit into core's existing *_allowed_* filters.
Examples:
- wp_kses_allowed_html
- kses_allowed_protocols
- wp_nav_menu_container_allowedtags
- customize_allowed_urls
The current name pretends that you are able to disable the use of get_media_embedded_in_content()
. But that's wrong, you can filter the allowed media types for get_media_embedded_in_content()
. Based on the existing names the filter should end with _allowed(_media)_types
.
I suggest get_media_embedded_in_content_allowed_types
or media_embedded_in_content_allowed_types
as the name for this filter.
Hey, Justin. I think we could get away with sorting these by how they appear in the content always, without a parameter. Would be nice to still use get_tag_regex() but I get how the sorting makes it tough.
"media" was designed to refer to "audio" or "video" (or some other form of interaction).
We could make it additionally allow for "img" (probably not as a default). The problem with images is they can be inserted all sorts of ways. Gallery shortcodes, captioned images, image HTML, etc., etc. We actually had some image extraction functions as a counterpart to this function, but they weren't really good enough to ship in core, because of all of the edge cases. Sticking to these elements makes us limit the edge cases pretty well, and we ditched the other functions later in the 3.6 cycle.