admin管理员组文章数量:1125574
I’m developing a plugin that registers custom post types without support for title and editor. I’ve been working on this project for a couple of months now and when I began (WP version 6.3.1), it used to be the case that when I clicked “Publish”, these posts were saved with the title “Auto Draft”, a name similar to “auto-draft-123”, and the status “publish”. Now (WP version 6.4.3), when I click “Publish”, these type of posts are saved with a status of “draft”, without a name, and it’s impossible to change the status to “publish” without updating the value directly in the database (i.e. using Adminer) or taking some steps that I will describe below.
To replicate this issue, do the following:
- Register a custom post type without support for title nor the editor.
- Add a meta box to the custom post type with one or more custom fields.
- Create a new post with the registered CPT.
- Click publish.
The environment I’m working on is:
- WP version 6.4.3
- OS: Windows 10 Home Edition
- WP is run on Local by Flywheel version 8.2.1
These are the troubleshooting steps that I’ve taken so far:
- Created a new site on Local with zero plugins besides the one I’m developing, restricting the behavior of the plugin to that of only registering the CPT with no support for title nor the editor. The theme that was used for testing is Twenty-twenty-four.
- Erased browser cookies (Brave) and cleared the cache.
- Turned off and on the computer (just in case).
- I installed the previous version of WordPress in which I am 100% sure that my plugin used to work, which is 6.3.1. I did this in Local.
- I installed the previous version of Local in which I am 100% sure that my plugin used to work, which is 7.1.2.
- I setup a testing server with XAMPP, I manually downloaded the WP version 6.3.1 and installed it there.
- I tried with Chrome, Firefox, and Edge (besides Brave).
- The behavior in all the different environments was the same, the CPT Post with no support for title no editor is saved as “draft” when I click “Publish” and it’s impossible to change the status to “publish” by clicking “Publish”.
I currently don’t have access to a different Computer or OS.
There are some things that I found out though:
- When I click “Publish”, the parameter
post_status
is sent as “draft”. - If I add title and editor support to the CPT, but set
show_in_rest
as false, once the post is saved as “draft”, and add a title and some text to the editor, the post isn’t published when I click “Publish”, the status “draft” remains. - If I set
show_in_rest
as true, once the post is saved as “draft”, then the post can be published, changing its status to “publish” once I click “Publish” (with title and editor support).
The only way in which I can change the status to “publish” once the post is saved as “draft” without adding support for the editor and not showing in rest is by doing this:
- Set the status to “Pending Review” from the dropdown in the submit box in the post editing screen.
- On the list of posts, click “Quick Edit” and choose the status of “Scheduled” from the dropdown menu.
- Click “Update”.
I’m doing all of this using the Admin user.
I guess it may have to do with some recent update in Gutenberg that I’m not aware of, given that I tried an old version of WP (6.3.1) and the most recent one (6.4.3) that comes bundled with Local, and in both cases, the result is the same.
I’m developing a plugin that registers custom post types without support for title and editor. I’ve been working on this project for a couple of months now and when I began (WP version 6.3.1), it used to be the case that when I clicked “Publish”, these posts were saved with the title “Auto Draft”, a name similar to “auto-draft-123”, and the status “publish”. Now (WP version 6.4.3), when I click “Publish”, these type of posts are saved with a status of “draft”, without a name, and it’s impossible to change the status to “publish” without updating the value directly in the database (i.e. using Adminer) or taking some steps that I will describe below.
To replicate this issue, do the following:
- Register a custom post type without support for title nor the editor.
- Add a meta box to the custom post type with one or more custom fields.
- Create a new post with the registered CPT.
- Click publish.
The environment I’m working on is:
- WP version 6.4.3
- OS: Windows 10 Home Edition
- WP is run on Local by Flywheel version 8.2.1
These are the troubleshooting steps that I’ve taken so far:
- Created a new site on Local with zero plugins besides the one I’m developing, restricting the behavior of the plugin to that of only registering the CPT with no support for title nor the editor. The theme that was used for testing is Twenty-twenty-four.
- Erased browser cookies (Brave) and cleared the cache.
- Turned off and on the computer (just in case).
- I installed the previous version of WordPress in which I am 100% sure that my plugin used to work, which is 6.3.1. I did this in Local.
- I installed the previous version of Local in which I am 100% sure that my plugin used to work, which is 7.1.2.
- I setup a testing server with XAMPP, I manually downloaded the WP version 6.3.1 and installed it there.
- I tried with Chrome, Firefox, and Edge (besides Brave).
- The behavior in all the different environments was the same, the CPT Post with no support for title no editor is saved as “draft” when I click “Publish” and it’s impossible to change the status to “publish” by clicking “Publish”.
I currently don’t have access to a different Computer or OS.
There are some things that I found out though:
- When I click “Publish”, the parameter
post_status
is sent as “draft”. - If I add title and editor support to the CPT, but set
show_in_rest
as false, once the post is saved as “draft”, and add a title and some text to the editor, the post isn’t published when I click “Publish”, the status “draft” remains. - If I set
show_in_rest
as true, once the post is saved as “draft”, then the post can be published, changing its status to “publish” once I click “Publish” (with title and editor support).
The only way in which I can change the status to “publish” once the post is saved as “draft” without adding support for the editor and not showing in rest is by doing this:
- Set the status to “Pending Review” from the dropdown in the submit box in the post editing screen.
- On the list of posts, click “Quick Edit” and choose the status of “Scheduled” from the dropdown menu.
- Click “Update”.
I’m doing all of this using the Admin user.
I guess it may have to do with some recent update in Gutenberg that I’m not aware of, given that I tried an old version of WP (6.3.1) and the most recent one (6.4.3) that comes bundled with Local, and in both cases, the result is the same.
Share Improve this question asked Mar 2, 2024 at 18:31 user5728578user5728578 213 bronze badges1 Answer
Reset to default 1After thorough investigation, I identified the root cause of the issue.
TL;DR: A bug in my JavaScript code was causing the post form to be submitted without the necessary publish
parameter. Consequently, WordPress interpreted the request as an attempt to save a draft. I resolved the issue by updating the code to include the publish
parameter upon successful validation of the post's meta data.
Detailed Explanation:
During post submission, the value of the clicked submit button is transmitted as a parameter. For instance, the "Publish" button's value is sent as publish: Publish
, indicating to WordPress the intended action. If the publish
parameter is received and not empty, the post is published.
Delving further, when a post hasn't been published yet, the post_status
parameter defaults to draft
. This value is transmitted with the new post regardless of the button clicked for submission. If the publish
parameter is present and non-empty, the post_status
value changes to publish
, marking the post as published in the database. Otherwise, the post remains in draft status.
Upon analyzing the submitted data, I noticed that the publish
parameter was missing despite clicking the corresponding button.
Unbeknownst to me, I had implemented JavaScript validation code several months ago to validate post meta data before submission. However, I failed to test this validation logic before moving on to other parts of the plugin. Thus, while validation was indeed preventing form submission, the publish
parameter wasn't added upon successful validation.
本文标签:
版权声明:本文标题:Can't publish custom type posts that don't support title and editor, instead they're saved as draft 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736627192a1945700.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论