WP-API / docs

The content for developer.wordpress.org/rest-api

Home Page:https://developer.wordpress.org/rest-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backbone API docs seem incomplete and/or out of date

noknokcody opened this issue · comments

I've recently become super interested in using the backbone javascript client for some React-based settings pages but I'm finding it increasingly difficult to use. I feel like the documentation needs a bit of an update.

Specifically speaking this link here

Some of the problems I've noticed are as follows

Extending custom post types won't take the new URL root

Documentation specifies the following for custom post types

// Extend wp.api.models.Post and wp.api.collections.Posts to load a custom post type
const CustomPost = wp.api.models.Post.extend( {
  urlRoot: wpApiSettings.root + 'wp/v2/custom_post_slug',
  defaults: {
    type: 'custom_post_slug',
  },
} );

Yet when you extend the model and try save to the API it completely ignores the specified URL root.

image

Documentation relating to custom post type collections specifies an ambiguous type.

In the section relating to custom post type collections it mentions an ambiguous type 'BLProduct'. Is this supposed to be CustomPost?

const CustomPosts = wp.api.collections.Posts.extend( {
  url: wpApiSettings.root + 'wp/v2/custom_post_slug',
  model: BLProduct,
} );
const someCustomPosts = new CustomPosts();
someCustomPosts.fetch().then( ( posts ) => {
  // do something with the custom posts
} );

Some other minor issues I've discovered.

  • No documentation on post.setMeta functions (they also seem to error out when doing so).
  • No documentation on how to use the MetaData models
  • Code does not appear to be open-sourced so debugging problems like these is really difficult

Backbone client seems like an extremely powerful and handy tool and I feel it really needs some attention and love from wordpress.