[wp-trac] [WordPress Trac] #22352: Update get_permalink() to allow for permalink structure argument

WordPress Trac noreply at wordpress.org
Sat Nov 3 02:06:33 UTC 2012


#22352: Update get_permalink() to allow for permalink structure argument
-------------------------------------------------+-------------------------
 Reporter:  doublesharp                          |       Owner:
     Type:  enhancement                          |      Status:  closed
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Permalinks                           |  Review
 Severity:  normal                               |     Version:  trunk
 Keywords:  has-patch needs-testing dev-         |  Resolution:  invalid
  feedback                                       |
-------------------------------------------------+-------------------------
Changes (by doublesharp):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Ack, you are 100% correct, that would be exactly the way to do it. Got a
 bit carried away dealing with the bug in ticket:22351 trying to create a
 permalink from the "old permalink_structure" which is (not correctly)
 being passed by the "permalink_structure_changed" action. In hindsight
 it's easy enough to keep this value in an instance variable and reference
 it from the hooked filter, so:

 {{{
 class MyClass {
     private $old_structure;
     public function get_old_structure(){
         return $this->old_structure;
     }
     public function permalink_structure_changed($old_structure,
 $new_structure){
         $this->old_structure = $old_structure;
         add_filter( 'pre_post_link', array($this, 'get_old_structure') );
         $old_permalink = get_permalink($post_id, false);
         remove_filter( 'pre_post_link', array($this, 'get_old_structure')
 );
         // more code...
     }
 }
 $myclass = new MyClass();
 add_action( 'permalink_structure_changed', array( $myclass,
 'permalink_structure_changed' ), 10, 2 );
 }}}

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


More information about the wp-trac mailing list