Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Default Author breaks permalink preview #8

Open
j9t opened this issue May 30, 2017 · 4 comments
Open

Default Author breaks permalink preview #8

j9t opened this issue May 30, 2017 · 4 comments

Comments

@j9t
Copy link

j9t commented May 30, 2017

(Observed in WordPress 4.7.5:) With Default Author activated and then writing a new post, the permalink preview stops working correctly.

The standard behavior is: User begins new post, as soon as title is in the preview for the post permalink appears; it matches what has been defined in the Permalinks settings and is editable.

As soon as Default author is enabled, this behavior stops: User begins new post, preview for the pot permalink appears, but it matches the fallback ?p=n format, and is not editable.

Have others observed this, too? Any easy fix? (I had a quick look at the code but didn’t spot anything glaring.)

@birgire
Copy link
Owner

birgire commented May 31, 2017

Thanks for commenting.

I just tested with 4.8 RC and I can verify what you describe.

I think it might be related how/when the status is changed from auto-draft to draft,
it might be different for our own posts than others?

When the draft is saved, then it works as expected.

I just spent 2 hours tracing this in the core, but without result, ;-)

@j9t
Copy link
Author

j9t commented May 31, 2017

:) Thanks for looking into this.

What I’ve also noticed is that the actual preview link breaks, too. As soon as Default Author is disabled, they work again.

@birgire
Copy link
Owner

birgire commented May 31, 2017

This is the preivew url for our own posts:

?p=123&preview=true

and it's now with the draft post status

When we change the post author with the wp_insert_post_data filter, then the preview url becomes like:

?p=3132&preview_id=123&preview_nonce=754d5e5c21&post_format=standard&_thumbnail_id=-1

and the post status is still auto-draft and that means a different behaviour of WP_Query

https://github.com/WordPress/WordPress/blob/21b1135b1c5759ecb9aaafbd57c32434d70069ea/wp-includes/class-wp-query.php#L2920

where there's a check if the status object is protected (or private) else the posts array is cleared:

https://github.com/WordPress/WordPress/blob/21b1135b1c5759ecb9aaafbd57c32434d70069ea/wp-includes/class-wp-query.php#L2933

The draft post status is registered as protected, but the auto-draft status is registered as internal and not explicitly as protected or private. So the posts array is cleared in the latter case (what we're experiencing here too).

So I think if we understand when/how the auto-draft is changed to draft, we might be closer solving it ;-)

@birgire
Copy link
Owner

birgire commented May 31, 2017

I finally found the code that's responsible, inside the wp_autosave() function:

https://github.com/WordPress/WordPress/blob/21b1135b1c5759ecb9aaafbd57c32434d70069ea/wp-admin/includes/post.php#L1814

namely this check

if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) {

or actually this part of it

get_current_user_id() == $post->post_author

where the current user id has to match the post author.

so that seems to cover the why part ;-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants