Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#20390 closed enhancement (invalid)

Add call of shutdown_action_hook() function at the end of 'template_loader.php' file

Reported by: egorpromo's profile egorpromo Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.1
Component: General Keywords:
Focuses: Cc:

Description

In some cases theme authors need to hook on the most end of wordpress execution. The excellent place for it is the end of 'template_loader.php' file.

I encounter problem when I try delete my $_COOKIE (needed in the HTML output) at the end of my templates files because I need my some session variables only once. I think it is better to use hook that I have proposed above.

do_action('after_template_include');

Change History (5)

#1 @scribu
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

You already have the 'shutdown' hook.

#2 @egorpromo
13 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Summary changed from Add 'after_template_include' action hook at the end of 'template_loader.php' to Add call of shutdown_action_hook() function at the end of 'template_loader.php' file

'shutdown' hook is applied inside shutdown_action_hook() function of the wp-includes/load.php file.

I've made simple analysis and discovered some details:

1) if I add function on 'shutdown' action hook when happen nothing. I tried output large portion of HTML-code via this hook but I can't see it.
2) In documentation made by phpdocumentor (example 1 and example 2 ) I can't see any reference to using of shutdown_action_hook() function
3) In official documentation I can’t see using of shutdown_action_hook() function also.

I suppose shutdown_action_hook() function is not used anywhere in wordpress core. Wordpress just has definition of this function but not call it. So I propose to call shutdown_action_hook() at the end of template_loader.php file.

shutdown_action_hook();
Last edited 13 years ago by egorpromo (previous) (diff)

#3 @scribu
13 years ago

1) if I add function on 'shutdown' action hook when happen nothing. I tried output large portion of HTML-code via this hook but I can't see it.

This works for me:

function some_html_content() {
?>
This will show up right at the end of every page.
<?php
}
add_action( 'shutdown', 'some_html_content' );

Note that it shows up after the </html> tag, so you can't use it to output valid HTML. That would be the case even if you placed it right at the end of template-loader.php

2) In documentation made by phpdocumentor ( example 1 and example 2 ) I can't see any reference to using of shutdown_action_hook() function

In wp-settings.php:

register_shutdown_function( 'shutdown_action_hook' );

Don't rely on phpdocumentor next time. Searching directly through the source code is the only reliable indicator.

Last edited 13 years ago by scribu (previous) (diff)

#4 follow-up: @scribu
13 years ago

If you want to output something before the </html> tag, you should use the 'wp_footer' hook.

Also, please try asking on wp-hackers or on http://wordpress.stackexchange.com/ before opening a ticket.

#5 in reply to: ↑ 4 @egorpromo
13 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

You are right. All works. First time I made something incorect and awfull. This ticket must be closed and invalid.

Last edited 13 years ago by egorpromo (previous) (diff)
Note: See TracTickets for help on using tickets.