Describe the bug
When publishing a page, that was a draft and also was assigned to have a parent page, the parent is removed when the child page is published.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
When publishing a page that already has a parent page assigned, keep that structure.
Desktop (please complete the following information):
Smartphone (please complete the following information):
not tested
Additional context
Hey @luminuu,
thanks for reporting this issue. I can also reproduce it with the current master.
I couldn't recreate this issue following the steps above. I could only get it to occur when when the parent page is made to be a draft after being published, not the child page.
Steps to recreate the issue:
Unfortunately this is actually the same behavior as the classic editor. One could argue that you should be able to set page hierarchy regardless of publish status, but I think the reasoning behind it is to avoid confusion about visibility of a page.
Thank you for your tests @luminuu, @Soean, and @earnjam. In my tests, I found the same situation described by @earnjam so I'm am closing this issue for now, if any additional details exist and this problem is persisting feel free to reopen and I will look further.
I can still reproduce the bug in the current master with the steps described by @luminuu
Its important to add content to the page before you publish it.
I can't reproduce personally. I first thought it was related to the second meta box save (do you have meta boxes on your page), but even with meta boxes, I'm not able to reproduce with the exact steps. Could this be a conflict with another plugin?
No plugins active. I think it's something with the autosave function.
I was able to reproduce without even publishing the page. Yes, so just make some changes and wait for the autosave to trigger. After that you can see in the listing that the parent is not set anymore.
cc @aduth @adamsilverstein
I imagine it has something to do with this line, and a confusion on parent in the revision sense (attach revision to the original post) and parent the page parent.
Also suspect:
Because we're passing parent (as in, the post to which the revision should be attached), I imagine it's treating this as a field to update on the post itself. This is the wrong behavior in that it will override the assigned parent field.
This may require one of two changes:
parent unless the post is publishedparent in calling wp_update_post for the draft & auto-draft caseMy preference would be the second of these.
I imagine it has something to do with this line, and a confusion on
parentin the revision sense (attach revision to the original post) andparentthe page parent.
Why do we even include this in the body of the payload? If the parent is already part of the fragment of the request URL, e.g. POST /wp/v2/pages/<parent>/autosaves.
I still think the REST API should be disregarding the value all the same, if it's intended that the only fields to be updateable on the post are title, content, and excerpt.
Proposed fix at #11513