[wp-trac] [WordPress Trac] #12240: Let plugins filter post permalink before core replacements

WordPress Trac wp-trac at lists.automattic.com
Tue Mar 2 04:35:22 UTC 2010


#12240: Let plugins filter post permalink before core replacements
--------------------------+-------------------------------------------------
 Reporter:  shidouhikari  |       Owner:  ryan                       
     Type:  enhancement   |      Status:  new                        
 Priority:  normal        |   Milestone:  3.0                        
Component:  Permalinks    |     Version:  2.9.1                      
 Severity:  normal        |    Keywords:  has-patch reporter-feedback
--------------------------+-------------------------------------------------

Comment(by shidouhikari):

 Replying to [comment:8 Denis-de-Bernardy]:

 Take a look at link-template.php. What get_permalink() does is get the
 post permastruct and search for each rewrite tag in it, and when found the
 tag is replaced by that post's correspondent value. When it's done with
 all tags, we have the final permalink to that post, and then 'post_link'
 filter is run.

 It passes the final pernalink, after the permastruct is processed, and
 doing so we can't customly replace default tags, which forces us to create
 new ones that Wordpress won't process and will leave for 'post_link'
 filter.


 Since Wordpress's rewrite rule doesn't verify if some tags value is really
 related to a post (I mean, you can use %tag% in permalink, get a post's
 permalink generated by it and change that default tag to another one
 that's not assigned to that post, and you'll still receive that post), we
 could write a plugin to change the default value Wordpress chooses for
 those tags, and generate custom permalinks that would be recognized by
 rewrite rules parser without needing to hack it.

 It's just an exemple of what direct access to permastruct before permalink
 is generated can be done. In another exemple, a plugin could add a metabox
 to the post form, where the user could add keywords to be used for %tag%.
 These keywords would be searched for existing tags, and if not found new
 ones would be created, and these tags IDs stored in a metadata. When the
 permalink is asked, the plugin replaces %tag% for these custom tags,
 giving a huge variety of possibilities to be used in permalinks, outside
 the post slug. And without needing to create new rewrite tags for it,
 since any tag is accepted by rewrite rule parser.


 Today this can't be done, because we don't have access to the permalink
 before its tags are processed, we only have access to it after the
 processing is finished. So we must create new tags, so that
 get_permalink() leave then alone, and we can replace them for what we want
 there. And doing so we must also add the custom tag to rewrite parser.



 Try to use the exemple I provided and you can see it can't be done with
 'post_link'. Because when the filter is called, %category% is already
 replaced by a category and it's not available anymore.

 But if a filter is used before get_permalink() starts parsing the
 permastruct, any tag can be customly parsed by a plugin, enhancing
 Wordpress's default behavior.

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


More information about the wp-trac mailing list