Register _classifai_error meta as single #106
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
This is a one-line change intended to resolve #105. The description of the issue this addresses can be found there. Essentially, JS is expecting a WP meta value returned from the REST API to be a string that can be parsed as JSON, and the REST API is returning an array. To fix this, we update the configuration passed to the WP
register_meta
function to tell to tell WP to expect a single value rather than an array.See: https://codex.wordpress.org/Function_Reference/register_meta
Alternate Designs
If there is any likelihood multiple values of
_classifai_error
might be intentionally associated with a given post, then this fix might instead involve additional checks at the JS level to validate whether the error notice should display. Currently, however,_classifai_error
is assumed to be a single value elsewhere in the plugin, including inSavePostHandler.php
where the value is updated, retrieved, and deleted.Benefits
"Post updated" notices display as expected. Elimination of JS error reduces risk of other unknown side effects.
Verification Process
With all features of the plugin correctly configured, edit a post with the JS console open. When saving the post, confirm the JS error screenshotted in #105 doesn't show, and that the relevant "Post updated" notice shows.
Checklist:
The file I touched is not currently covered by tests (beyond testing the class works as a singleton) so I didn't add any tests, but I'd be happy to add an integration test confirming the meta value in REST responses if that would be considered beneficial.
Applicable Issues
#105