This should do the job and decouples PRE_TEMPLATE from the output processing.
It is now there simply if the user wants to run code before the template is put together and before redirection headers are sent.
I.E. it does not need to be initialised to capture and process output html which is now all done by the POST_TEMPLATE hook.
/* Call themed template. */
if (defined('plugins')) {
plugin_call_hook('PRE_TEMPLATE');
if (isset($plugin_hooks['POST_TEMPLATE'])) {
ob_start();
}
}
require($WWW_ROOT_DISK . fud_theme .'language.inc'); // Initialize theme's language helper functions.
require($WWW_ROOT_DISK . fud_theme . $t .'.php');
if (defined('plugins') && isset($plugin_hooks['POST_TEMPLATE'])) {
echo plugin_call_hook('POST_TEMPLATE', ob_get_contents());
ob_end_clean();
}
}
The sample plugin (file: x.plugin) to capture and process output becomes:
<?php
plugin_add_hook('POST_TEMPLATE', 'plugin_x_process_output');
function plugin_x_process_output($data) {
//$modified_data = Modify $data, add headers, footers, go mad...
return $modified_data;
}
?>
PRE_TEMPLATE could be used in another sample plugin (file: y.plugin):
<?php
plugin_add_hook('PRE_TEMPLATE', 'plugin_y_background_work');
function plugin_y_background_work() {
//Do whatever....
}
?>
Not tested though.