[wp-hackers] Make WP_Rewrite eaiser to use

Peter Westwood peter.westwood at ftwr.co.uk
Mon Feb 6 06:35:00 GMT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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.

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.

westi
- --
Peter Westwood
http://blog.ftwr.co.uk
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFD5u4UVPRdzag0AcURAtDqAJ4kekm61ghbRyIiv72IuGe6B5Cy/gCfSS3u
Gq8cYEI3OP2qpRFDRqJ5MUQ=
=ip0S
-----END PGP SIGNATURE-----



More information about the wp-hackers mailing list