ekn2
Forum Replies Created
-
After 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 thepublish
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 thepublish
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 todraft
. This value is transmitted with the new post regardless of the button clicked for submission. If thepublish
parameter is present and non-empty, thepost_status
value changes topublish
, 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.