[wp-testers] Permalinks, Plugins, and Mod Rewrite

Andy Skelton skeltoac at gmail.com
Thu Aug 16 00:11:45 GMT 2007


On 8/15/07, Dan Milward <dan at instinct.co.nz> wrote:
> I have a question about how to best utilize permalinks and plugins

It depends! Most of the performance degradation caused by large
rewrite arrays is incurred during the foreach/preg_match loop of
WP::parse_query (wp-includes/classes.php) so if you want to cheat the
devil, you have to do it before this loop. You should set up a test
dataset with thousands of your items to see if it's really worth
subverting this part of core.

There is not a ready-made way to short-circuit parse_query. However,
it's not hard to use different hooks to accomplish this.

Here's one possibility: Keep an array of all "podcast" sub-tokens and
their related ID's in an option row. Apply a filter on
pre_option_rewrite_rules that checks whether the REQUEST_URI looks
like a "podcast" request, checks whether the sub-token is in the saved
array, returns a specially-crafted rewrite array of found, else
returns false so that the rewrite rules will be checked normally.

And another possibility: Keep the same token/ID lookup array as above
and use the 'init' action hook to check for one of your tokens and
hijack the page load. That is, if token found, output and die during
the init action, before control returns to wp-blog-header.php, which
is where wp() is called and rewrite happens.

So there are lots of ways to do something like you've described. Of
course I don't know what you want to do once you know you have one of
your special token requests so I can't tell you the best way to do it.
:-)

Cheers,
Andy


More information about the wp-testers mailing list