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
publishparameter. Consequently, WordPress interpreted the request as an attempt to save a draft. I resolved the issue by updating the code to include thepublishparameter 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 thepublishparameter is received and not empty, the post is published.Delving further, when a post hasn’t been published yet, the
post_statusparameter defaults todraft. This value is transmitted with the new post regardless of the button clicked for submission. If thepublishparameter is present and non-empty, thepost_statusvalue 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
publishparameter 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
publishparameter wasn’t added upon successful validation.