[wp-trac] Re: [WordPress Trac] #7795: Activate and Deactivate Theme
hooks
WordPress Trac
wp-trac at lists.automattic.com
Thu Dec 18 22:58:03 GMT 2008
#7795: Activate and Deactivate Theme hooks
-------------------------------------------------+--------------------------
Reporter: jacobsantos | Owner: anonymous
Type: enhancement | Status: new
Priority: normal | Milestone: 2.8
Component: Template | Version: 2.7
Severity: normal | Resolution:
Keywords: theme API, has-patch, needs-testing |
-------------------------------------------------+--------------------------
Comment (by DD32):
> You are hooking into the file name of the main theme, in which case it
will always be THEME_NAME/functions.php
Errr... 'doh! Here was I thinking i needed to check which theme it was
coming from -- Err, Actually, You do need to. In the case of a child and
parent theme, you'd want both activation hooks to run, and as such, you'd
need to be able to tell which one is calling.
The reason for the "must be in theme root" was because of the
{{{__FILE__}}} -> theme name, {{{__FILE__}}} returns c:\...\..\ on
windows, and the Theme dir constant is C:\...\..../wp-content/..... so a
simple str_replace and all that would need to be done, And i was thinking
of optimization at the time, its code thats potentially going to run on
every page load (I guess a !is_admin() line could short circuit it?
The other option would've been to do:
{{{
$theme = preg_replace('|^.*/themes/|', '', dirname($file));
$theme = preg_replace('|[/\\\].*$|', '', $theme);
OR
$theme = preg_replace('|^.*/themes/|', '', dirname($file));
if ( $pos = strpos($theme, '/') )
$theme = substr($theme, 0, $pos);
}}}
(Since /themes/ is hard-coded)
I'm really open to suggestions on a better way there..
--
Ticket URL: <http://trac.wordpress.org/ticket/7795#comment:10>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list