why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function

The root problem is a misunderstanding of how async functions work. const onChangeContent = async ( newUrl ) => { onChangeContent is not a function/async function. It is an object, specifically a Promise. The async and await are just shorthand. These 2 functions are identical: async function foo() { return 1 } function foo() { … Read more

how to create JSON array [] for REST response?

Just use another array() inside user array() $response = array(); $response[] = array( ‘version’ => ‘1.0’, ‘user’ => array( array( ‘first_name’ => ‘Razon’, ‘last_name’ => ‘komar pal’, ’email’ => ‘[email protected]’, ‘id’ => 10, ) ), ); return rest_ensure_response($response); It will output like: [ { “version”: “1.0”, “user”: [ { “first_name”: “Razon”, “last_name”: “komar pal”, “email”: … Read more

register/login api

Is there support out of the box for this in WordPress or do you need to create a custom route etc? No, there is no endpoint for user login and registration. You would need to install an authentication plugin designed for remote auth such as the OAuth2 plugin, or wait until 5.6 adds application passwords. … Read more

URL issue retrieving Custom Post Types using Backbone JS API

Actually, you don’t have to extend the Post model (wp.api.models.Post) or Posts collection (wp.api.collections.Posts) because the documentation says: you will get new models and collections when you add REST API support to your custom post type And that means, your custom post type will be automatically added to the wp.api.models and wp.api.collections list, i.e. wp.api.models.<key> … Read more