WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#20390 closed enhancement (invalid)

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

Reported by: 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)

comment:1 scribu2 years ago

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

You already have the 'shutdown' hook.

comment:2 egorpromo2 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 2 years ago by egorpromo (previous) (diff)

comment:3 scribu2 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 2 years ago by scribu (previous) (diff)

comment:4 follow-up: scribu2 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.

comment:5 in reply to: ↑ 4 egorpromo2 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 2 years ago by egorpromo (previous) (diff)
Note: See TracTickets for help on using tickets.