Skip to content

Commit

Permalink
Hooks an as yet non-existent filter in get_sample_permalink to provid…
Browse files Browse the repository at this point in the history
…e a correct sample permalink in situations where the post_name has been hacked for a particular context.

Related WP trac ticket for the filter: http://core.trac.wordpress.org/attachment/ticket/22338

See #77
  • Loading branch information
simonwheatley committed Oct 31, 2012
1 parent c0fd957 commit 749cd96
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions class-post-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function __construct() {
$this->add_filter( 'post_link', 'post_type_link', null, 3 );
$this->add_filter( 'post_type_archive_link', null, null, 2 );
$this->add_filter( 'post_type_link', null, null, 3 );
$this->add_filter( 'get_sample_permalink', null, null, 5 );
$this->add_filter( 'single_template' );
$this->add_filter( 'the_posts', null, null, 2 );

Expand Down Expand Up @@ -773,6 +774,24 @@ public function post_type_link( $post_link, $post, $leavename ) {
return user_trailingslashit( $post_link );
}

/**
* Hooks the get_sample_permalink filter to provide a correct sample permalink
* in situations where the post_name has been hacked for a particular context.
*
* @filter get_sample_permalink (not yet in existence, see http://core.trac.wordpress.org/attachment/ticket/22338)
*
* @param array $permalink The array, like array( $permalink, $post_name )
* @param string $title A desired title (could be null)
* @param string $name A desired post name (could be null)
* @param int $id The Post ID
* @param object $post A (hacked) Post object
* @return array The array, like array( $permalink, $post_name )
*/
public function get_sample_permalink( $permalink, $title, $name, $id, $post ) {
$permalink[ 0 ] = $this->post_type_link( $permalink[ 0 ], $post, $leavename );
return $permalink;
}

/**
* Hooks the WP page_link filter to ensure correct virtual language directory prefix, etc.
*
Expand Down

0 comments on commit 749cd96

Please sign in to comment.