How add meta fields to a user with the wp-api?

I have managed to do this with hooking into rest_insert_user. I send an array like this: var data = { first_name: user.first_name, last_name: user.last_name, name: user.display_name, email: user.email, description: user.description, meta: { ‘wpcf-phone’: user.phone, ‘wpcf-institution’: user.institution, ‘wpcf-birthday’: Math.round(new Date(user.birthday).getTime()/1000) } }; And treat only the meta data through the hook as this: function aa_user_update($user, $request, … Read more

403 Forbidden with gutenberg

In case anybody comes across this, I had the following in my apache config <Directory “/home/*/Sites”> AllowOverride All FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory> The WP API was trying to use the method PUT. I also believe it sometimes uses the method DELETE. Changing above code … Read more

WP API ignores filter parameter

WP API will ignore filter values it doesn’t understand, so the following are essentially identical: curl -gv “myamazingsite.co.uk/wp-json/wp/v2/media/?filter[id]=123” curl -gv “myamazingsite.co.uk/wp-json/wp/v2/media/” Any filter keys that are valid, however, will be used to filter the results, so if there are no images for the year 2015, the following will return nothing ([]). curl -gv “myamazingsite.co.uk/wp-json/wp/v2/media/?filter[year]=2015” I’m … Read more

How can I return an image from a custom REST API endpoint?

echo in the rest-api and not valid! You should using return to make output to Rest API. For example: function prefix_generate_cover_photo( WP_REST_Request $request ) { // Get method params $params = $request->get_params(); // Data $data = array( ‘url’ => ‘The image url’, ‘title’ => ‘The image title’, ); // Create the response object $response = … Read more