[wp-trac] [WordPress Trac] #18450: New safe action to add rewrite rules on

WordPress Trac wp-trac at lists.automattic.com
Wed Aug 17 08:31:35 UTC 2011


#18450: New safe action to add rewrite rules on
------------------------------------+------------------------------
 Reporter:  simonwheatley           |       Owner:
     Type:  enhancement             |      Status:  new
 Priority:  normal                  |   Milestone:  Awaiting Review
Component:  Rewrite Rules           |     Version:  3.2.1
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |
------------------------------------+------------------------------

Comment (by dd32):

 Replying to [comment:8 simonwheatley]:
 > Replying to [comment:2 nacin]:
 > > sil_call_add_rewrite_rules() should be called on init, always.
 > >
 > > On activate: Register rewrite rules and flush
 > >
 > > On init: Register rewrite rules
 >
 > The situation with hooking init to ```add_rewrite_rule``` calls is
 uncertain: If you run ```add_rewrite_rules``` on init at priority 10, then
 conditionally flush the rules

 Now that, You definately shouldn't do (flush on init).

 The current best way, and the only foolproof cross-compatible method that
 should have ever been used is as nacin said:

 On init, Register the rules. - This is so that the rules are loaded for
 other plugins if they flush, You should even be able to run this on
 admin_init if you don't want to add a few KB to the front end memory
 usage.[[BR]]
 '''AND'''[[BR]]
 On activation, Register the rules AND flush the rules. - This is to set
 the rules up, add them first (as init has already been called before the
 plugin was included), and then flush the rules to add them to the
 database, other plugins rules should've been loaded on init or admin_init
 at this point, so all plugins play nicely.

 The current situation is pretty common really, You should do the same
 thing when adding Taxonomies or Post Types, Register them on init,
 Register them in the activation function & flush.. If you're doing it any
 other way, I question why someone hasn't made documentation clearer for
 that..

 So; Adding another action, technically, will reduce memory usage (less
 array items in $wp_rewrite, but realy.. what, 1KB?), but will still
 require flushing the rules on activation, it'll save ONE line of code in
 most cases (no need for `$this->addRules();` in the activation function
 before `flush_rewrite_rules();`)

 If you've got a plugin installed which has to upgrade itself after
 upgrades, and it's modifyin rewrite rules, it should only do that after
 admin_init (or, late on admin_init), doing so before then (or on init) is
 a bad thing to do (as it won't play nice with plugins which add rules, AND
 you shouldn't do processes like that on the front end requests..)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18450#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list