[wp-hackers] Make WP_Rewrite eaiser to use

Peter Westwood peter.westwood at ftwr.co.uk
Mon Feb 6 08:31:56 GMT 2006

On Mon, February 6, 2006 6:35 am, Peter Westwood wrote:
> Sam Angove wrote:
>>> ----------------------------------------------------------------------------
>>> 1. add_rewrite_rule(): A function for adding a straight rewrite rule.
>>> [snip]
>>> * Theoretically it could then filter rewrite_rules_array and add the
>>> rules itself, but I think we should add a function to WP_Rewrite for
>>> adding 'extra' rules that needn't be generated by
>>> generate_rewrite_rules().
>> I don't have a problem with it, but why is filtering the array so bad?
>> The current way is very easy, and it's more elegant for adding
>> multiple rules.
>> function add_arbitrary_rules($rules) {
>>     $url = get_settings('home');
>>     $rules[$url.'/arbitrary/(wibble)/?$'] = 'index.php?var=$matches[1]';
>>     $rules[$url.'/arbitrary/(wobble)/?$'] = 'index.php?var=$matches[1]';
>>     return $rules;
>> }
>> add_filter('rewrite_rules_array', 'add_arbitrary_rules');
> Doing things this way breaks when we need index.php/permalinks/ the
> whole reason for providing an API is that WP_Rewrite can take care of
> the nasty stuff like that and let you get on with writing your plugin.

Scratch that comment..  I realised on my way into work this morning that
I'm talking rubbish here.  Thats what I get for replying to emails at 6:30
in the morning five minutes after I wake up :-(

> This level of abstraction is usefull, and opens up the addition of rule
> types to more plugin developers - they need not understand PCRE to add a
> new endpoint type for example.

This point is still valid though :-)

Peter Westwood
Blog: http://blog.ftwr.co.uk

More information about the wp-hackers mailing list