woocommerce / woocommerce-rest-api

This is the WooCommerce core REST API Package. It runs standalone as a feature plugin too.
71 stars 46 forks source link

Fix compatibility for WP 5.5 #232

Closed vedanshujain closed 4 years ago

vedanshujain commented 4 years ago

This PR has a couple of changes in response to https://core.trac.wordpress.org/changeset/48306

  1. Type mixed is now changed to appropriate scalar type with addition of null. So final type is now array( {scalar}, 'null' ).
  2. [High Impact] For settings API, the allowed type is now changed to array, string, null, and if an array, then allowed item type is string or null. This means that only one of nesting is now allowed for WooCommerce settings via API. Would appreciate the feedback here on if this is backward compatible or not. Looks like we have to mandatorily define the child properties if the native property is array or object. This means that just saying that type is object is not allowed, we have to define all the properties of children (and their children, etc if any).
  3. Added a method to convert from type => date-time to type => string, format => date-time.
vedanshujain commented 4 years ago

note that code standard failures are unrelated to changes in this PR. I will address them in different PR directly.

vedanshujain commented 4 years ago

Combined test results with core for different WP version in the merge/src PR : https://travis-ci.org/github/woocommerce/woocommerce/builds/715231616

vedanshujain commented 4 years ago

@jonathansadowski so an example is, we will not be able to support a setting option where value is of type object. Whereas previously with mixed type we would have as there is no validation basically.

That said, we currently only define text, email, number, color, password, textarea, select, multiselect, radio, image_width and checkbox. setting types and all of these can be supported by the new type that I added. Only multiselect here needs array support rest of these can be supported by the string. (I went and explored all the settings from wp-json/wc/v3/settings/ endpoint to verify.)