Opened 5 years ago
Last modified 5 years ago
#50002 new defect (bug)
Hack in get_sample_permalink() can cause filters like post_link, and pre_post_link to have inaccurate post_status in admin
Reported by: | aubreypwd | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.4 |
Component: | Posts, Post Types | Keywords: | has-patch needs-testing needs-unit-tests |
Focuses: | administration | Cc: |
Description
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.
Attachments (1)
Change History (2)
Note: See
TracTickets for help on using
tickets.
First pass at fixing this that does not modify post_status but does not affect the desired result (please test!).