[wp-trac] [WordPress Trac] #26675: Rewrite of get_media_embedded_in_content() function to produce expected results.
WordPress Trac
noreply at wordpress.org
Wed Dec 18 22:14:28 UTC 2013
#26675: Rewrite of get_media_embedded_in_content() function to produce expected
results.
-------------------------+-----------------------------
Reporter: kopepasah | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: trunk
Severity: normal | Keywords:
-------------------------+-----------------------------
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
[http://core.trac.wordpress.org/ticket/26674 #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.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/26675>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list