awesomemotive / sugarcalendar-core

Sugar Calendar plugin for WordPress
https://wordpress.org/plugins/sugar-calendar-lite/
38 stars 14 forks source link

Use the classic editor with REST #223

Open alexstandiford opened 3 years ago

alexstandiford commented 3 years ago

It appears that the "editor" setting is the only way to enable Sugar Calendar events via REST, but it doesn't seem to be possible to use the classic editor and also use REST. It would be nice if it were possible to use the classic editor and REST.

I think this is happening because the block editor is being disabled by manipulating the show_in_rest parameter. This solves the problem, but it disables the Sugar Calendar in REST endpoint, as well.

Instead, I suggest that Sugar Calendar always leaves the show_in_rest as true, and instead uses the'use_block_editor_for_post_type' filter is used to disable/enable the block-based editor. This will make it possible to switch between editors and still keep the REST API intact.

To Replicate:

  1. Set the editor setting to the block-based editor
  2. Visit {your-site}/wp-json/wp/v2/sc_event
  3. Observe post data response
  4. Change the editor setting to the classic editor
  5. Visit {your-site}/wp-json/wp/v2/sc_event
  6. Note that the REST endpoint is not available
JJJ commented 3 years ago

Hey @alexstandiford 👋

I see what you're saying. I used the show_in_rest parameter because the use_block_editor_for_post_type function returns true by default instead of false, and Sugar Calendar technically still requires the opposite to avoid the double-negative of having our false setting mean true in the filter.

WordPress never should have forced the default to true there. 😤

Also, I didn't want to publicly expose only the Post Type (Events) and Taxonomy (Calendars) data without offering something for the data currently covered by BerlinDB (Dates, Times, Recurring, etc...)

It seemed inevitable to me that exposing the easy stuff immediately reveals to API users that the hard stuff is not available. When we do it, I don't want us to rush to do it because we shipped something halfway.

Related: https://github.com/berlindb/core/issues/26 Also related: https://github.com/sugarcalendar/sc-manager

alexstandiford commented 3 years ago

Thanks @jjj!

In the meantime, I shared another issue that talks a bit on how I work around this. Sharing it here just in-case someone stumbles on this.