[wp-hackers] Drupal's "Butler" (was: Loading JS & CSS from inside a plugin)
otto at ottodestruct.com
Wed Mar 23 07:48:19 UTC 2011
On Tue, Mar 22, 2011 at 10:03 PM, Dave Ross <dave at davidmichaelross.com> wrote:
> Otto, thanks for the heads-up on plugin_dir_url(). That
> might be exactly what I'm looking for, or I see it calls plugins_url() which
> is actually documented in the Codex and I somehow missed up 'til now.
BTW, I tend to use plugins_dir_url(__FILE__).'file.js' because it's easy to
remember for me. However, a similar call of plugins_url('file.js',
__FILE__) works equally well and uses that function more the way it
was intended to be used. Either is good.
> When I ask for a WordPress equivalent to Butler, I'm not saying we should
> steal their idea outright, but I can definitely see an advantage to
> centralizing & standardizing how common plugin tasks are handled. I don't
> want to have to think about all the different configurations and plugin
> combinations out there. Have my plugin call a method to get the absolute URL
> for a file in the plugin's dir at the current site URL (like plugin_dir_url
> I guess). If something fails, let it be because WP Subdomains or WPMU didn't
> implement Butler's version of the plugins_url filter, not because I didn't
> create a special case.
There's actually a ton of functions like this. Check through the
link-template.php file. Generally speaking, you don't have to roll
your own unless you're doing something exceedingly weird.
> It could also standardize the options API, like
> they're doing in Drupal, so it's less of a crapshoot whether a plugin uses
> separate entries for each setting or one big serialized array.
The "right" way depends on context. I generally recommend a serialized
array because most plugins tend to need all their options at once
anyway. It's not like you need only half the options on any given page
load. However, if your case does need something like that, it's
As for standardizing the options API, we have that. It's called the
> Widget Logic
> would be a good candidate for inclusion in a WordPress "Butler", too, so
> widgets can be included on a page based on "context".
This has been discussed off and on for a long time. Nobody can agree
on the User Interface. Widget Logic's interface is, well, awful. Other
similar interfaces that add options to widgets to select where they
appear and such using checkboxes are equally bad. They're all very
nerd-oriented, basically. Until there's a simpler and more obvious way
invented, I expect this to remain in the realm of plugins.
More information about the wp-hackers