[wp-trac] [WordPress Trac] #12935: Evolve the URL routing system

WordPress Trac wp-trac at lists.automattic.com
Thu May 27 22:56:41 UTC 2010


#12935: Evolve the URL routing system
--------------------------+-------------------------------------------------
 Reporter:  mikeschinkel  |       Owner:  ryan
     Type:  enhancement   |      Status:  new 
 Priority:  normal        |   Milestone:  3.1 
Component:  Permalinks    |     Version:  3.0 
 Severity:  normal        |    Keywords:      
--------------------------+-------------------------------------------------

Comment(by mikeschinkel):

 Replying to [comment:30 scribu]:
 > > BTW, i'm not sharing the code for the WP_Routes class yet because I
 want to refactor is significant before I expose it to public scrutiny.
 >
 > Release early, release often. :)

 Heh. Point taken.

 I will as soon as I think I'll have time to follow up (right now I don't
 have time to code anything more for a little while, at least.)

 > == Optional path segments ==
 >
 > > One thing I have yet to figure out is how best to specify optional
 path segments. I'm loath to introduce new special characters to the URL
 template but I am considering using square brackets like so and would like
 to get other's input on this?
 >
 > >
 {{{register_route_path('%pagename%/[%%trackback_feed_page_paged_comment_page%%]');}}}
 >
 > That's an acceptable notation, except it gets confusing if you want to
 specify multiple optional segments:
 >
 > {{{register_route_path('%a%/[%b%]/[%c%]');}}}
 >
 > {{{register_route_path('%a%/[%b%][/%c%]');}}}
 >
 > {{{register_route_path('%a%/[%b%/][%c%]');}}}
 >
 > Since we're not inspecting full paths anymore, maybe we could register
 an array instead of a string:
 >
 > {{{register_route_path(array('%a%', array('%b%', %c%)));}}}
 >
 > The first level elements are mandatory, while the second level elements
 are optional.

 I like that as an idea, but I would like to allow for specifying via a
 string too.  IOW, it would be conceptually similar to how both of these
 work the same:

 {{{
 $drafts_query = new WP_Query(
 "post_type=post&post_status=draft&posts_per_page=1&orderby=modified&order=DESC&&author=".$GLOBALS[current_user]->ID);

 $drafts_query = new WP_Query( array(
         'post_type' => 'post',
         'post_status' => 'draft',
         'posts_per_page' => 1,
         'orderby' => 'modified',
         'order' => 'DESC',
         'author' => $GLOBALS['current_user']->ID,
 ) );
 }}}

 BTW, explicitly stated I'm thinking that `register_route_path()` would
 define the last path segment and allow the other path segments to to be
 used internally as selectors, i.e. the following:

 {{{
 register_route_path('%foo%/%bar%/[%baz%]');

 register_route_path('%foo%/%bar%/%baz%',array(
         'optional' => true,
 ) );
 }}}

 would both be an appropriate way to indicate that `"%baz%"` is an optional
 child of the path `"%foo%/%bar%"`.  Internally is would `explode()` on
 slashes, navigate and/or build the path tree, and then set (or modify) the
 properties for the last path segment.

 We could even potentially specify it this way as an alternate to the above
 (i.e. we could support both approaches):

 {{{
 register_route_segment('%baz%',array(
   'parent_path' => array('%foo%','%bar%'),
   'optional' => true,
 ));
 }}}


 BTW, I'm wondering if `"optional"` or `"is_optional"` is a better name for
 the property?

 Also, if a segment is partially optional (i.e. `"foo/%foo%[-%foo_num%]"`)
 is it better to add a `"is_partially_optional"` property or having both
 `"is_var"` and `"is_optional"` to be `true` to indicate that it is
 ''partially optional''?  (I'm presuming that when routes are pre-processed
 during plugin activation that details like this can be pre-evaluated so
 that all that is needed for the normal case is to `unserialize()` the
 route tree.)

 '''One more important note: AFTER WORKING ON THIS MUCH OF THE DETAILS OF
 THE OPENING WRITEUP FOR THIS TICKET HAVE CHANGED AS I HAVE LEARNED WHAT'S
 ACTUALLY REQUIRED.  SO IT IS IMPORTANT IF THIS TICKET INTERESTS YOU FOR
 YOU TO READ IT ALL.'''

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


More information about the wp-trac mailing list