[wp-hackers] post_content_filtered

denis at semiologic.com denis at semiologic.com
Wed Apr 20 01:46:57 GMT 2005


Quoting Mark Jaquith <mark.wordpress at txfx.net>:

> which is much faster.  Having to modify the theme is a necessary evil,
> at least the way I saw it.  I've tried plugins that run as a filter on X
> and then try to modify filters on X live, and it really doesn't work so
> well.


I was just discussing the following workflow with Jérôme Lavigné:


on display post: -- sem_smart_cache_display()

- plugin hook at priority 1 on the_content detects if cache needs an update
(e.g. older than 24h)

if no cache update is necessary:

- make a copy of the_content filter array, traverse the_content filter array,
remove all filters, add a sem_no_smart_cache filter at the end of the array;
return post_content_filtered
- at sem_no_smart_cache(), restore the the_content filter array for use by the
next post; return as normal

if cache update is necessary:

- make a copy of the_content filter array, traverse the_content filter array and
add a sem_do_smart_cache filter at the end of the array; return post_content
- at sem_do_smart_cache(), do to_smart_cache[$ID]=$post_content and restore the
the_content filter array for use by the next post; return as normal


on edit/publish: -- sem_smart_cache_save()

- apply_filters to the content and do to_smart_cache[$ID]=$post_content, but be
wary
of disabling the priority 1 filter first to avoid strange behaviors


on shutdown: -- sem_smart_cache_shutdown()

- at 'shutdown' hook, we can safely do the sql inserts without bothering the
user with delays


this workflow requires no particular action by the user -- as opposed to
replacing the the_content() call in a template. the only requirement is some
rigor, a time stamp in the post metas, and perhaps an option (number of hours
between each update).


for comments, straightforward caching with no refresh is obviously the right
thing to do.


One downside: There is potential for huge bugs if another plugin is modifying
the the_content loop as well. I'll live with it risk. ;)

--
Denis
http://www.semiologic.com


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


More information about the wp-hackers mailing list