WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#4514 closed enhancement (wontfix)

Add output handler hook

Reported by: Denis-de-Bernardy Owned by:
Milestone: Priority: lowest
Severity: trivial Version:
Component: General Keywords: needs-patch
Focuses: Cc:

Description

...in between init and the template loader, right here in wp-blog-header.php:

require_once( dirname(__FILE__) . '/wp-config.php');

wp();
gzip_compression();

require_once(ABSPATH . WPINC . '/template-loader.php');

please use this instead:

require_once( dirname(__FILE__) . '/wp-config.php');

wp();
gzip_compression();

do_action('ob_start');

require_once(ABSPATH . WPINC . '/template-loader.php');

it would really be convenient for plugins that use output buffers...

Attachments (1)

4514.diff (319 bytes) - added by rob1n 7 years ago.

Download all attachments as: .zip

Change History (15)

rob1n7 years ago

comment:1 rob1n7 years ago

  • Keywords has-patch added
  • Milestone changed from 2.2.2 to 2.3 (trunk)
  • Priority changed from normal to lowest
  • Severity changed from normal to trivial

comment:2 foolswisdom7 years ago

Come on Denis, attach patches please.

comment:3 westi7 years ago

-10

Not needed as you already have the template_redirect action at the top of template-loader.php

comment:4 markjaquith7 years ago

  • Milestone 2.3 (trunk) deleted
  • Resolution set to worksforme
  • Status changed from new to closed

re-open if there is a reason template_redirect won't work for this purpose.

comment:5 follow-up: Denis-de-Bernardy7 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

There are times where you need the 'init' hook to be fired before starting the output buffer (e.g. you do or don't want to trigger an event on admin screens, or you need the wp_query to have run so internals are properly set), but before the template_redirect.

One could arguably use the template_redirect hook with an extremely low priority, e.g. -1000000. In practice, however, I've found (I've a bunch of plugins that start output buffers on this hook) that conflicts arise because an odd plugin here or there hooks into the template_redirect plugin before I do, and things end up not working together.

In these cases, I end up checking on wp_head if the output buffer has been started or not. And in the end I find it rather annoying.

D.

comment:6 foolswisdom7 years ago

  • Milestone set to 2.4

comment:7 in reply to: ↑ 5 Otto427 years ago

Replying to Denis-de-Bernardy:

One could arguably use the template_redirect hook with an extremely low priority, e.g. -1000000. In practice, however, I've found (I've a bunch of plugins that start output buffers on this hook) that conflicts arise because an odd plugin here or there hooks into the template_redirect plugin before I do, and things end up not working together.

Adding a new action that's arguably in the same place isn't going to remedy that. All that will happen is that other plugins will hook to this new action as well, and then you have the same issue.

The -1000000 is actually a better solution, IMO.

comment:8 Denis-de-Bernardy7 years ago

if the hook is called "start_ob", I sincerely doubt plugins will be use it for anything else.

on a different note, it may make a lot of sense for WP to actually start the output buffer itself, and to run it through later on with its own ob handler.

e.g. something that goes like:

ob_start('wp_ob_handler');

function wp_ob_handler{$buffer)
{
  if ( /* preg_match the <body> area of html docs */ )
    $body = apply_filters('html_ob', $body);
    ...

  else
    $xml = apply_filters('xml_ob', $xml);
    ...

  return $buffer;
}

comment:9 darkdragon6 years ago

  • Keywords new-hook added

comment:10 darkdragon6 years ago

  • Summary changed from could we add a plugin hook? to Add output handler hook

comment:11 darkdragon6 years ago

  • Keywords needs-patch added; new-hook has-patch removed
  • Milestone 2.5 deleted
  • Resolution set to fixed
  • Status changed from reopened to closed

After some thought about this, I don't think this is a great idea. I would recommend using a more generic word because there are a few times when this level of action would have came in useful.

There are other solutions which can be used in such cases. I'm not so certain the problem calls for a dedicated action. Good luck with your plugin, but if you can expand the root problem and actual use cases. Without those, it is uncertain whether a different solution might be better to solve your problem based on what you are trying to do.

comment:12 darkdragon6 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:13 darkdragon6 years ago

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

comment:14 darkdragon6 years ago

Patch is also stale.

Note: See TracTickets for help on using tickets.