Rest API Hook When Post Is Requested

My original answer was all wrong, so it’s been removed in it’s entirety. Neither the posts_selection nor wp hook are fired during the REST API request. The hook you need is rest_pre_echo_response. This hook passes three parameters: The response data to send to the client The server instance. The request used to generate the response. … Read more

REST API multiple media upload

While not optimal, there is nothing stopping you from sending two requests at the same time and to continue your logic after both responses are received. This is relatively easy with jQuery or JS promises, but most likely possible in all languages which has an API to send HTTP requests asynchronously. Just keep in mind … Read more

Get the Category Name instead of ID from WP-API

This code will add categories_names field to wp rest api response: function wpse_287931_register_categories_names_field() { register_rest_field( ‘project’, ‘categories_names’, array( ‘get_callback’ => ‘wpse_287931_get_categories_names’, ‘update_callback’ => null, ‘schema’ => null, ) ); } add_action( ‘rest_api_init’, ‘wpse_287931_register_categories_names_field’ ); function wpse_287931_get_categories_names( $object, $field_name, $request ) { $formatted_categories = array(); $categories = get_the_category( $object[‘id’] ); foreach ($categories as $category) { $formatted_categories[] … Read more

Can I authenticate with both WooCommerce consumer key and JWT?

Yes this is possible by structuring your requests appropriately. For system requests use OAuth 1.0 (consumer key as before), but encode it to include the OAuth credentials in the URL not in the headers. Having the OAuth credentials in the Authorisation header triggers the JWT error. GET https://DOMAIN/wp-json/wc/v1/subscriptions * Authorization: `OAuth 1.0` * Consumer key: … Read more

How to use the WP REST API for new user registration (sign up form)?

hopefully you’ve found the answer already. Here’s our solution, for your reference. 😀 The following code should add User Registration via REST API to your WordPress Website. It supports Registration of ‘subscriber’ and ‘customer’. Add it to your function.php add_action(‘rest_api_init’, ‘wp_rest_user_endpoints’); /** * Register a new user * * @param WP_REST_Request $request Full details about … Read more