WooCommerce – Add product with image via REST API

Ok my mistake, you can see my images array was not quite right: This is correct: ‘images’ => [ [ ‘src’ => ‘http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg’ ], [ ‘src’ => ‘http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg’ ] ], This was mine: ‘images’ => [ ‘src’ => ‘http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg’, ], Thought it would be best to leave this question/answer as over the years there are … Read more

Authenticate current user to REST API

I solved my problem. This got me on the right track: https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/ You can just make an api call via frontend and jquery. $.ajax( { url: ‘<?php echo esc_url_raw( rest_url()) ?>’ + ‘your/endpoint’, method: ‘GET’, beforeSend: function ( xhr ) { xhr.setRequestHeader( ‘X-WP-Nonce’, ‘<?php echo wp_create_nonce( ‘wp_rest’)?>’ ); } } ).done( function ( response ) … Read more

In the media Rest API, what is “missing_image_sizes”?

Basically, it corresponds to missing thumbnails or custom-sized images in your media library. And it’s (by default) a private field in the REST API and the value is one or more image sizes as returned by wp_get_registered_image_subsizes(). And the function which is used with that field is wp_get_missing_image_subsizes() which returns: (array) An array of the … Read more

No user found when using REST API

This is happening because you are not using nonces. Because you have not provided a nonce with the request, WordPress is treating you as if you are an unauthorized/non-logged in user. This is because wordpress has no way of knowing/validating the users state. To get this working, you will have to generate a nonce like … Read more

Filter DELETE REST API calls

pre_delete_post hook filters whether a post deletion should take place. So callback function must return a boolean value: true – whether to go forward with deletion, false – if not. pre_trash_post hook filters whether a post trashing should take place. So callback function must return a boolean value: true – whether to go forward with … Read more

Setting ?context=edit results in rest_forbidden_context, even for an Administrator user

Clearly your administrator is unable to modify those posts according to the roles and capabilities system. This is the code that is generating that error in WP_REST_Post_Types_Controller: public function get_items_permissions_check( $request ) { if ( ‘edit’ === $request[‘context’] ) { $types = get_post_types( array( ‘show_in_rest’ => true ), ‘objects’ ); foreach ( $types as $type … Read more

WordPress REST API V2: how to get list of all posts?

Out of the box and using the core available hooks and API, you can’t have more than 100 items per response on WordPress REST API for performance reasons. For the second part of the question, you may remove some fields from the response by using _fields parameter in your request as you can see in … Read more

WP_REST_Response() doesn’t seem to return the expected object

I believe WP_Rest_Response did return the proper response based on what your endpoint callback returns, but I think you just not understanding what fetch() returns, so please check the documentation on MDN for more details, but here’s an excerpt that might help you: The fetch() method takes one mandatory argument, the path to the resource … Read more