Opened 13 years ago
Closed 13 years ago
#18390 closed enhancement (wontfix)
apply_filters for a theme's functions.php
Reported by: | ofshard | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.2.1 |
Component: | Themes | Keywords: | close |
Focuses: | Cc: |
Description
My primary intention with this suggestion is for switching a page's theme on the fly. Currently the only method I know of for this is to change the active theme before functions.php is included and then switching back sometime after, which I don't find very thread safe.
Anyway, I suggest that lines 278-283 in wp-settings.php which currently read:
if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) { if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) ) include( STYLESHEETPATH . '/functions.php' ); if ( file_exists( TEMPLATEPATH . '/functions.php' ) ) include( TEMPLATEPATH . '/functions.php' ); }
be altered to implement the 'theme_functions' and 'theme_parent_functions' filters as below:
if ( !defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ){ $path = (file_exists(STYLESHEETPATH . '/functions.php')) ? STYLESHEETPATH . '/functions.php' : ''; $functions = apply_filters('theme_functions', $path); if( $functions != '' ) include($functions); $path = (TEMPLATEPATH !== STYLESHEETPATH && file_exists(TEMPLATEPATH . '/functions.php')) ? TEMPLATEPATH . '/functions.php' : ''; $functions = apply_filters('theme_parent_functions', $path); if( $functions != '' ) include($functions); }
Change History (6)
#1
in reply to:
↑ description
@
13 years ago
#2
@
13 years ago
See also: #18298 - Deprecate those constants and use the function counterparts. Those functions have filters which would also kick in for this scenario I believe.
#3
@
13 years ago
Incorporating that, my suggestion would look like this instead:
if ( !defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ){ $stylesheet_dir = get_stylesheet_directory(); $template_dir = get_template_directory(); $path = (file_exists($stylesheet_dir . '/functions.php')) ? $stylesheet_dir . '/functions.php' : ''; $functions = apply_filters('theme_functions', $path); if( $functions != '' ) include($functions); $path = ($template_dir !== $stylesheet_dir && file_exists($template_dir . '/functions.php')) ? $template_dir . '/functions.php' : ''; $functions = apply_filters('theme_parent_functions', $path); if( $functions != '' ) include($functions); }
#4
@
13 years ago
Why exactly do you need to filter the Functions.php location if you can completely change the active theme on the fly using filters that already exist such as template_directory and those within get_stylesheet_directory()?
The Theme Switcher Plugin does exactly that.
Well, I believe you can alter the functions.php included by filtering 'stylesheet_directory' and 'template_directory' in the action 'setup_theme' as well (which is thread safe). The suggestion still stands though.