Rewrite of get_media_embedded_in_content() function to produce expected results.
|Reported by:||kopepasah||Owned by:|
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.