Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register _classifai_error meta as single #106

Merged
merged 1 commit into from
Jul 24, 2019

Conversation

johnwatkins0
Copy link
Member

@johnwatkins0 johnwatkins0 commented Jul 24, 2019

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 in SavePostHandler.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:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

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

@jeffpaul jeffpaul added the type:bug Something isn't working. label Jul 24, 2019
@jeffpaul jeffpaul added this to the 1.4.0 milestone Jul 24, 2019
@helen helen modified the milestones: 1.4.0, 1.3.2 Jul 24, 2019
@helen helen merged commit b971013 into develop Jul 24, 2019
@jeffpaul jeffpaul deleted the fix/unexpected-end-of-json-input branch October 21, 2020 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gutenberg - Unexpected end of JSON input in JS console when saving post
3 participants