[wp-hackers] wp-config.php, wp-load.php, and ABSPATH
Otto
otto at ottodestruct.com
Wed Sep 16 15:03:02 UTC 2009
On Wed, Sep 16, 2009 at 9:21 AM, Stephen Rider
<wp-hackers at striderweb.com> wrote:
> An interesting technique, and something I will definitely file for future
> reference, but not really appropriate for the CSS example I gave. Is it
> really the *best* way to have to have a bunch of GET string attached to
> every page of a site just to customize some CSS??? Talk about ugly URLS for
> such a minor thing.
>
> I think the best is to simply output the custom CSS to wp-head.
I was mainly just addressing the general idea, not a CSS specific
example. For CSS, it might indeed be best to output it with an
attachment to wp-head.
But in general, if you want to make a separate file that will be
called separately and which you think needs to include wp-config or
similar to get access to wp functions, then this approach is the
better way to go.
The example I gave was somewhat limited. For example, I showed
SOME_IDENTIFIER=1, but that could easily be
SOME_IDENTIFIER=somestring, and you could use a switch-case construct
to make it return one of several things, depending on what somestring
is.
Obviously, this approach should only be used when you need access to
WP functions in a separate call to the site. It'll work for JS
requests as well, although admin-ajax seems simpler for that case.
> Question: Do enqueued CSS or scripts come specifically before or after
> wp-head output? Is it ***definitive*** or does it depend on the theme?
In the code:
add_action('wp_head', 'wp_print_styles', 8);
add_action('wp_head', 'wp_print_head_scripts', 9);
So, they have 8 and 9 priorities, respectively. If you add something
without changing the default priority, you get a priority of 10,
meaning the styles/scripts come first.
> P.S. -- In all of this, I'm not sure I've ever heard a satisfactory
> explanation for WHY all these things should be enqueued anyway.
> Dependencies, sure, but why for a stylesheet or script that doesn't have
> any dependencies?
Duplication prevention. If you enqueue the same script (by identifier)
multiple times from multiple plugins, it will still only output the
script link once. If you tried to output it twice, then it'd cause a
page error, most likely, since it'd be trying to redefine functions.
-Otto
More information about the wp-hackers
mailing list