[wp-trac] [WordPress Trac] #16687: %postname% permalinks should not trigger verbose rewrite rules

WordPress Trac wp-trac at lists.automattic.com
Wed Apr 20 09:55:54 UTC 2011


#16687: %postname% permalinks should not trigger verbose rewrite rules
-----------------------------+------------------
 Reporter:  nacin            |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  3.2
Component:  Rewrite Rules    |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |
-----------------------------+------------------

Comment (by duck_):

 I tested using a single regular expression and then checking the matched
 portion against attachment post_names instead of the set of OR'd
 conditions:

 {{{
 if ( preg_match( '#^[^/]+/([^/]+)#', $request['post_or_page'], $matches )
 &&
     $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts
 WHERE post_name = %s AND post_type = 'attachment' LIMIT 1", $matches[1] )
 ) )
   $request['attachment_id'] = $id;
 }}}

 This works well in most cases. But as I had thought there can be problems
 with conflicting attachment/page slugs. To test try this set-up:

  * 3 pages with slugs: page-1, conflict, page-2. Where the succeeding page
 is a child of the previous
  * 1 attachment (attached to a post) with slug conflict (has to be added
 before the page see #17170)

 Now visit /page-1/conflict/ and /page-1/conflict/page-2/ in both cases the
 attachment is displayed when using the plugin with the above mod. On trunk
 the pages are displayed (though a notice is triggered for
 /page-1/conflict/ if the post/attachment is tested by get_page_by_path
 first, wp-includes.php line 3157). Plugin v002 as uploaded previously will
 show the attachment for the first but not the second since it will
 recognise there are three parts the last of which is not 'trackback', a
 feed or 'comment-page-xx'.

 This shouldn't be a problem if attachments were guaranteed to have
 globally unique slugs. If this were the case then the single regular
 expression might be the way to go.

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


More information about the wp-trac mailing list