Unuasalble Template Filters
-
I have been working on a plugin that allows user to select different themes for different posts and pages.
I could find out that the filters:
- ‘template’ called in function get_template
- ‘template_directory’called in function get_template_directory
- ‘stylesheet’ called in function get_stylesheet
- ‘stylesheet_directory’ called in function get_stylesheet_directory
(all in theme.php) are all useless and do not make any difference during execution.
I looked further and found out that those functions are called from ‘wp-settings.php’ and the result is assigned to a “constant” used afterwards in the code as follows:
- define(‘TEMPLATEPATH’, get_template_directory());
- define(‘STYLESHEETPATH’, get_stylesheet_directory());
This also happens before the ‘init’ action execution which also made it impossible to hook on the filters above at the early initiation and startup.
Solution:
Stop assigning the template directories to contants and always use the function calls in the following files:- wp-settings.php
- comment-template.php
- general-template.php
- template-loader.php
- theme.php
One thing to take into consideration is the include of the ‘functions.php’ that requires the current theme to be defined (later in ‘wp-settings.php’). Please study the possibility of delaying this include until a later stage when the theme for the current page is identified.
Regards,
/Kaf
- The topic ‘Unuasalble Template Filters’ is closed to new replies.