[wp-hackers] Avoiding Side-effects in Filters & Actions
mikeschinkel at newclarity.net
Thu Apr 2 06:24:42 GMT 2009
"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.
Custom Wordpress Plugins
More information about the wp-hackers