[theme-reviewers] Need A Final Call

Chip Bennett chip at chipbennett.net
Mon Jan 21 23:11:07 UTC 2013


The "after_setup_theme" name for that hook has always been a bit
misleading, to be sure. But, it's really the only one available to the
Theme to say even somewhat semantically, "this is where I'm going to define
things related specifically to me". And even though $content_width is a
global, it is still *entirely* Theme-dependent. It has no real use or
context outside of the presentation layer. (Even if used in the admin area,
it is used in the context of previewing the presentation layer.)

In the ideal world, another semantic hook, such as "configure_theme", would
be available for the Theme to define all of its add_theme_support() calls,
etc.

But, as it currently stands, we have the hooks you referenced:

plugins_loaded
functions.php
after_setup_theme
init

So, the most semantic hook for a Theme to define its configuration
(including $content_width, since it is Theme-dependent) is
after_setup_theme. That's why I say that defining $content_width directly
at functions.php execution is "arbitrary".


On Mon, Jan 21, 2013 at 5:43 PM, Otto <otto at ottodestruct.com> wrote:

> On Mon, Jan 21, 2013 at 4:00 PM, Chip Bennett <chip at chipbennett.net>
> wrote:
> > By the same token: by Themes always hooking into after_setup_theme to
> define
> > $content_width, a Plugin would always know that it is defined at that
> hook,
> > and would not have to rely on the somewhat-more-arbitrary plugins_loaded
> > (IIRC?) when functions.php executes.
>
> No, you have the order wrong.
>
> 1. Plugins load
> 2. do_action( 'plugins_loaded' );
> 3. Theme's functions.php loads (child first, then parent)
> 4. do_action( 'after_setup_theme' );
>
> After that, the only thing left as part of startup is the init action,
> basically.
>
> So if the theme hooked to after_setup_theme, and set its globals at
> that time, then a plugin needing that information would need to hook
> to after_setup_theme with a very high number for the priority (1000,
> say), to be sure that the theme has actually done its job already.
>
> One could reasonably argue that the plugin could hook to init to do
> this, but this seems like an somewhat improper (aka, lazy) use of init
> to me, from the plugin's perspective. The init action is overloaded
> already for lots of things.
>
> Also, "after_setup_theme", in it's very name, implies that it is run
> *after* the theme has been setup. Having the theme do setup related
> stuff on it (at least, setup related stuff that deeply affect other
> parts of the system, such as global variables), strikes me as a misuse
> of the hook. So I'd say that any "setup" that the theme needs to do
> which really affects the whole system should actually be outside of
> functions in the theme's functions.php file. For example, add_action
> calls and such are often outside of functions, to hook functions into
> other hooks. Setting up hooks is something that affects everything.
> Similarly, globals kind of affect everything too.
>
> -Otto
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20130121/5baf64d3/attachment-0001.htm>


More information about the theme-reviewers mailing list