[wp-hackers] Avoiding Side-effects in Filters & Actions
Peter Westwood
peter.westwood at ftwr.co.uk
Thu Apr 2 06:37:56 GMT 2009
I'm not sure where you want the context or what type of context you
want but you can use the is_ template tags with plugin code not just
themes
Things like is_tag(), is_ page() etc
--
Peter Westwood
http://peter.Westwood.name
On 2 Apr 2009, at 07:24, Mike Schinkel <mikeschinkel at newclarity.net>
wrote:
> "scribu" <scribu at gmail.com> wrote:
>> Mike Schinkel <mikeschinkel at newclarity.net> wrote:
>>> What I was hoping for was a robust way to identify the current
>>> context so that there isn't a need to go adding more hooks all
>>> the time.
>>
>> I've recently run into this issue myself. However, I don't see
>> how that context could be identified, given the current nature
>> of filters.
>
> Yeah, I hate to say but you are probably right, at least not without
> a comprehensive solution. Currently it seems we have to examine
> artifacts like $_SERVER['REQUEST_URI'] and $wp_query to determine
> the current content vs. having a standard variable to inspect, i.e.
> something like a $wp_context variable that would consolidate the
> various context values such as an identifier for the current page,
> current category (if applicable), current tag (if applicable),
> current query (if applicable), etc. Yes most (all?) of this is
> available via inspecting other global variables or calling certain
> functions but often that information is not context-free and those
> creates subtle bugs.
>
> For this to really work well it would likely need to be set in
> certain places in core (i.e. for one of many examples in function
> query() in /includes/wp-db.php) but I know from experience on this
> list that suggestions to modify core are met with significant
> resistance. Still, it would be nice to see an effort to establish a
> proper and well-known context object to make it much easier to
> robustly identify context in filters and actions and if there was a
> will do to that I'd certainly be interested in contributing time
> towards such an effort.
>
> -Mike Schinkel
> Custom Wordpress Plugins
> http://mikeschinkel.com/custom-wordpress-plugins
> _______________________________________________
> 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