| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | class WP_Output_Buffer { |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * These priorities are suggestions for plugin and theme developers |
|---|
| 7 | * to help modify the output at the right time. |
|---|
| 8 | */ |
|---|
| 9 | const DEFAULT_PRIORITIES = array( |
|---|
| 10 | 'CONTENT' => 10, |
|---|
| 11 | 'CACHE_BEFORE' => 90000, |
|---|
| 12 | 'CACHE' => 100000, |
|---|
| 13 | 'CACHE_AFTER' => 110000, |
|---|
| 14 | ); |
|---|
| 15 | |
|---|
| 16 | private static $enabled = false; |
|---|
| 17 | |
|---|
| 18 | public static function enable() { |
|---|
| 19 | self::$enabled = true; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | public function __construct() { |
|---|
| 23 | static $inited; |
|---|
| 24 | if (!$inited) { |
|---|
| 25 | add_action('init', array( |
|---|
| 26 | $this, |
|---|
| 27 | 'init' |
|---|
| 28 | )); |
|---|
| 29 | $inited = true; |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | public function init() { |
|---|
| 34 | |
|---|
| 35 | if (self::$enabled) { |
|---|
| 36 | ob_start(array( |
|---|
| 37 | $this, |
|---|
| 38 | "output_callback" |
|---|
| 39 | )); |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | public function output_callback($buffer, $phase) { |
|---|
| 44 | |
|---|
| 45 | if ($phase & PHP_OUTPUT_HANDLER_FINAL || $phase & PHP_OUTPUT_HANDLER_END) { |
|---|
| 46 | return apply_filters('output_buffer', $buffer); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | return $buffer; |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | new WP_Output_Buffer(); |
|---|