[wp-trac] [WordPress Trac] #50002: Hack in get_sample_permalink() can cause filters like post_link, and pre_post_link to have inaccurate post_status in admin

WordPress Trac noreply at wordpress.org
Fri Apr 24 20:07:13 UTC 2020


#50002: Hack in get_sample_permalink() can cause filters like post_link, and
pre_post_link to have inaccurate post_status in admin
----------------------------+-----------------------------
 Reporter:  aubreypwd       |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  General         |    Version:  5.4
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 For context: https://github.com/aubreypwd/WordPress/issues/5

 When editing a post (that is a draft) in the admin, add a filter to
 `post_link` you'll notice that the pass for `get_sample_permalink()` shows
 that `$post->post_status` is set incorrectly (un-truthfully) to `publish`.

 This is because of a 12 year old block of code in
 `get_sample_permalink()`:

 {{{
 // Hack: get_permalink() would return ugly permalink for drafts, so we
 will fake that our post is published.
 if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) )
 ) {
         $post->post_status = 'publish';
         $post->post_name   = sanitize_title( $post->post_name ?
 $post->post_name : $post->post_title, $post->ID );
 }
 }}}

 In order for `post_link` and even `pre_post_link` filters to pass accurate
 info about a post, the patch I have attached is my first attempt at
 ensuring `get_sample_permalink()` still gets the same result, while not
 affecting `post_status`. Obviously I tested this, but I still feel some
 more testing will need to be done.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50002>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list