Open aubreypwd opened 4 years ago
As you can see the permalink structure, when viewing a post in the admin (that's in draft), seems to go through post_link
filter, but when it does the status is wrong on the post.
Found that on "file": "/app/public/wp-admin/includes/post.php" "line": 1360,
my draft post always has publish
as post_status
...
This is our culprit, here the post_status
, for some reason, is being set to publish
even though it's not really true?
https://github.com/aubreypwd/WordPress/commit/5fbca12c9e2a462c2ae2d4d3d71dae84473d1a11
(Also https://core.trac.wordpress.org/changeset/6633) seems to be the source of the change/addition by "matt" and is 12 year old code...
Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
Not seeing a current ticket in Trac: https://core.trac.wordpress.org/search?q=post_status+get_permalink+post_link&noquickjump=1&changeset=on&ticket=on
When the "hack" is present, we get:
http://wordpress.test/%postname%/
When it is commented out, we get:
http://wordpress.test/?p=1
So it seems the whole goal of setting the post (untruthfully) to publish
is to get the %postname%
format.
With the hack present, this happens:
When it is not, that if is not processed.
[24-Apr-2020 18:32:06 UTC] stdClass Object
(
[/app/public/wp-content/mu-plugins/dev.php] => 5
[0] => http://wordpress.test/?p=1
[1] => draft
)
[24-Apr-2020 18:32:06 UTC] stdClass Object
(
[/app/public/wp-content/mu-plugins/dev.php] => 5
[0] => http://wordpress.test/%postname%/
[1] => publish
)
[24-Apr-2020 18:32:06 UTC] stdClass Object
(
[/app/public/wp-content/mu-plugins/dev.php] => 5
[0] => http://wordpress.test/?p=1
[1] => draft
)
[24-Apr-2020 18:32:06 UTC] stdClass Object
(
[/app/public/wp-content/mu-plugins/dev.php] => 5
[0] => http://wordpress.test/?p=1
[1] => draft
)
Logging the current result of :
<?php
add_filter( 'post_link', function( string $permalink, WP_Post $post, bool $leavename ) {
// if ( stristr( $permalink, '%' ) ) {
error_log( print_r( (object) [ __FILE__ => __LINE__,
$permalink,
$post->post_status,
], true ) );
// }
}, 10, 3 );
Got some code written up:
Diff: https://github.com/aubreypwd/WordPress/compare/5.4...aubreypwd:issue/5 Patch: https://github.com/aubreypwd/WordPress/compare/5.4...aubreypwd:issue/5.patch
This moves the hack to the right place where we don't have to abuse post_status
to achieve the same affect, and it uses the $post->filter = 'sample'
flag instead to decide when to perform the conditions of the if
above.
Trac ticket: https://core.trac.wordpress.org/ticket/50002
Add a filter for
post_link
and see that, in the admin, sometimes the\WP_Post
comes back with->post_status
set topublic
even when the post isdraft
. It can be confirmed by usingget_post_status
which seems to give the correct post status.