[wp-hackers] Getting the entire HTML page generated from WordPress

Otto otto at ottodestruct.com
Mon Feb 6 21:35:12 UTC 2012


Don't use the register_shutdown_function() call. WordPress already
does that for you automatically. Just use the "shutdown" action hook
instead.

-Otto



On Mon, Feb 6, 2012 at 2:19 PM, zhaiziming at gmail.com
<zhaiziming at gmail.com> wrote:
> Don't buffer your whole page, it is not a good idea for page response time.
> Instead, in your template file, use ob_start("your filter function") and
> ob_end_flush() to filter the_header(), the_content(), the_sidebar(), and
> the_footer() separately.
> Or if you really want to do a whole page filter. template_redirect is the
> best hook to start the buffer, and use php function
> register_shutdown_function() to flush the buffer.
>
> James Zhai
> http://www.zhaiziming.com/zZ/
>
>
>
> On 2/6/2012 11:58 AM, Mario Peshev wrote:
>>
>> Sure, I can do it in index.php or the wp-blog-header file, but I don't
>> feel
>> that suicidal yet :)
>>
>> Will try this out, thanks. I remember having some problems with the
>> shutdown hook, but it should work for normal posts and standard post types
>> I believe.
>>
>> Thanks,
>>
>> Mario Peshev
>> Training and Consulting Services @ DevriX
>> http://www.linkedin.com/in/mpeshev
>> http://devrix.com
>> http://peshev.net/blog
>>
>>
>>
>> On Mon, Feb 6, 2012 at 9:53 PM, Brian
>> Layman<wp-hackers at thecodecave.com>wrote:
>>
>>> That looks like it's the right idea..
>>>
>>> The basic paradigm is:
>>>
>>> Somewhere very early on do
>>> ob_end_clean(); // Ensure a clean buffer.
>>> ob_start();
>>>
>>> On the "wp" or "init" action should be fine.
>>>
>>> Then, as the very last thing you do, capture, process and echo the
>>> results
>>> $body = ob_get_contents();
>>> ob_end_clean();  // Clear the results so the unaltered stuff isn't sent
>>> echo makeItBetter($body);
>>>
>>> Perhaps in the "shutdown" action. (I've heard rumors of times shutdown is
>>> not called, I have no specifics on that. That may just have been when a
>>> die() was hit.)
>>>
>>> Headers, if you need them, can be gotten through $headers =
>>> headers_list();
>>>
>>> You could even do this code before and after the wp stuff in the main
>>> index.php, but you're likely to be slapped in the face with a large trout
>>> if you try something as hackish as that.
>>>
>>> Hope that helps,
>>>
>>> Brian Layman
>>> http://eHermitsInc.com
>>>
>>>
>>> On 2/6/2012 2:26 PM, Mario Peshev wrote:
>>>
>>>> I've tried one solution from stackexchange:
>>>>
>>>>
>>>> http://wordpress.**stackexchange.com/a/41351/**11506<http://wordpress.stackexchange.com/a/41351/11506>
>>>>
>>>> Didn't seem to work though
>>>>
>>>>  ______________________________**_________________
>>>
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.**com<wp-hackers at lists.automattic.com>
>>>
>>> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list