#28284 closed defect (bug) (fixed)
Calling `wp_oembed_add_provider()` before the `plugins_loaded` action shouldn't be allowed
Reported by: | johnbillion | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.0 | Priority: | low |
Severity: | major | Version: | 2.9 |
Component: | Embeds | Keywords: | has-patch |
Focuses: | docs | Cc: |
Description
If a plugin calls wp_oembed_add_provider()
before the plugins_loaded
hook (ie. as soon as the plugin file is included), it can prevent other plugins from hooking into the oembed_providers
filter.
This happens because wp_oembed_add_provider()
calls _wp_oembed_get_object()
which instantiates the WP_oEmbed
class which immediately applies the oembed_providers
filter in its constructor. If another plugin is hooked into this filter but isn't yet loaded, it's straight outta luck because the filter has already been applied.
To prevent this problem, we should add a check to wp_oembed_add_provider()
which triggers a _doing_it_wrong()
call if the plugins_loaded
action hasn't fired. This gives other plugins a chance to hook into the oembed_providers
filter.
Alternatively we could move the oembed_providers
filter so it fires JIT (in the get_html()
method) rather than when the class is instantiated.
Attachments (2)
Change History (12)
#2
@
11 years ago
- Severity changed from normal to major
Hello this problem seems valid, I've had this problem before, when I make a plugin called this method / function wp_oembed_add_provider () in my plugin that was the first to carry on my Musted Used plugins (MU-PLUGINS) and other third party installed normally (PLUGINS) stopped working as well.
I have not analyzed the code but the description seems quite valid alternative to isolate plugins possão not call wp_oembed_add_provider () directly, it would need to go trough a hook filter type, you can then add providers without affecting the scope of operation of other plugins, this can be a knife to the neck of a planter riding based on third-party plugins, and somehow this makes as developers of plugins to use hooks as expected.
I'm relatively new here, I would analyze and fix it, how to proceed?
#4
@
11 years ago
- Keywords has-patch added
In 28284.diff: if add/remove helper functions called before plugins_loaded, don't instantiate the oembed object, but rather use a static class variable to hold "just in time" additions and removals, which are then executed when the object is actually created.
#5
@
10 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 28846:
#6
@
10 years ago
- Keywords needs-docs added
- Resolution fixed deleted
- Status changed from closed to reopened
At the very least, we need basic docblocks on any new functions or methods, though the more complete the better. See WP_oEmbed::_add_provider_early()
and WP_oEmbed::_remove_provider_early()
.
Seems sensible.
Not sure about moving the filter though. Seems like that might unnecessarily invite problems for plugins already leveraging it. Might just be worth moving it early to give plugin devs plenty of time to raise issues.