Make WordPress Core

Opened 14 years ago

Closed 13 years ago

#16092 closed enhancement (fixed)

add_permastruct() should allow more control over WP_Rewrite::generate_rewrite_rules()

Reported by: dnxpert's profile dnxpert Owned by: john's profile John
Milestone: 3.4 Priority: normal
Severity: normal Version: 3.0.4
Component: Rewrite Rules Keywords: has-patch
Focuses: Cc:

Description

Hi guys,

In wp-includes/rewrite.php the function rewrite_rules calls "generate_rewrite_rules" with default parameters when creating rules for extra_permastructs.

Hence, all extra_permastructs get rules for paging, feeds, walk dirs and all end points, and yet no rules for commenting.

This logic kind of renders the add_permastructs function pointless - it definitely forced me to add my "extra" permastructs manually by using one of the available filters in the rewrite_rules function - since I didn't want any of the rules generate_rewrite_rules creates by default - I only happened to want the comment paging rule.

Wouldn't the logical thing be to allow add_permastructs function callers to decide what rewrite rules they need for each extra permastruct they add?

Attachments (2)

16092.diff (5.2 KB) - added by duck_ 13 years ago.
16092.use-new-args.diff (1.3 KB) - added by duck_ 13 years ago.

Download all attachments as: .zip

Change History (7)

#1 @scribu
14 years ago

  • Cc scribu added

#2 @duck_
13 years ago

  • Keywords has-patch added; extra permastructs rewrite removed
  • Summary changed from default parameters used with generate_rewrite_rules for creating rules for extra_permastructs to add_permastruct() should allow more control over WP_Rewrite::generate_rewrite_rules()

The attached patch changes the function and class method signatures to:

add_permastruct( $name, $struct, $args = array() )

$args mirrors the arguments that can be passed to generate_rewrite_rules() as well as the old $with_front parameter.

The patch changes the structure of WP_Rewrite::$extra_permastructs, but:

  • this is a private property (per the docs)
  • backwards compatibility is maintained in WP_Rewrite::rewrite_rules() -- this should probably be extended to WP_Rewrite::get_extra_permastruct() too.
  • there is a precedent, see [13773]

I also added some extra documentation. I was considering on also adding warnings for the 'paged' and 'walk_dirs' which have to stay true by default for back compat, see #19876.

Related: [13438] / #10912, [13773] / #12605, #19871, #16840

Last edited 13 years ago by duck_ (previous) (diff)

@duck_
13 years ago

#3 @duck_
13 years ago

In [19743]:

Upgrade add_permastruct() to allow more control over WP_Rewrite::generate_rewrite_rules(). See #16092.

The third argument is now a configuration array that mirrors the parameters of generate_rewrite_rules()
and allows for add_permastruct() specific args (i.e. with_front). The full configuration is stored in
WP_Rewrite::$extra_permastructs to be used by WP_Rewrite::rewrite_rules().

#4 @duck_
13 years ago

  • Milestone changed from Awaiting Review to 3.4

#5 @duck_
13 years ago

  • Resolution set to fixed
  • Status changed from new to closed

In [19779]:

Use new $args parameter for (WP_Rewrite::)add_permastruct(). Fixes #16092.

Use array_intersect_key() to keep WP_Rewrite::$extra_permastructs free of unnecessary/unknown keys + values.

Note: See TracTickets for help on using tickets.