[wp-hackers] generate_page_rewrite_rules() and save_mod_rewrite_rules()

Ryan Boren ryan at boren.nu
Fri Oct 15 00:08:42 UTC 2004


On Thu, 2004-10-14 at 16:32 -0500, Dennis Williamson wrote:
> I was looking in the CVS at options-permalink.php and admin-functions.php 
> and trying to follow the code flow. It looks to me like there may be some 
> redundancy. This is how I see the flow (showing only what is pertinent):
>
> If I see this correctly, save_mod_rewrite_rules() gets executed once extra 
> and $home_path, $writable and $usingpi get set every time "save" is called, 
> plus in options-permalink.php itself. Am I wrong about this redundancy? Can 
> it be fixed by removing the extras and using globals? Thus:
>
> [In options-permalink.php]
> 
> 	continue...

generate_page_rewrite_rules() is called from other files, so
save_mod_rewrite_rules() needs to perform its own checks.  options-
permalinks needs to know $writable and $usingpi for other purposes, so
it sets up its own copies.  This could be refactored a bit, but its not
as bad as it seems.  I'd rather not use globals for $writable and
$usingpi.  The only code path where they are setup twice is through
options-permalink.  Not a big deal.  $home_path is used in several
different places, including wp-blog-header, and could stand to at least
be factored out into a function.  It too is called only once for all
code paths except options-permalink, so caching really isn't a big deal
there either.

So, we already have a  using_index_permalinks() function that could be
used to setup $usingpi in both options-permalinks and
save_mod_rewrite_rules().  Using that will eliminate some duplication.

$home_path setup can be moved into a function and called where needed,
eliminating more duplication.

Ryan





More information about the hackers mailing list