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, $create)
{
if ($request['meta']) {
$user_id = $user->ID;
foreach ($request['meta'] as $key => $value) {
update_user_meta( $user_id, $key, $value );
}
}
}
add_action( 'rest_insert_user', 'aa_user_update', 12, 3 );
The ordinary fields of the user are updated normally by the API.
Related Posts:
- How to: Make JWT-authenticated requests to the WordPress API
- Why is my custom API endpoint not working?
- WordPress REST API validation
- Are there server performance benefits to fetching only specific fields when querying the REST API?
- How to define a query parameter with REST API?
- WordPress Rest API: How do we validate with our custom API key?
- Adding WordPress API Endpoint With Multiple Parameters
- authentication issue with rest api – rest_cannot_create
- Hiding API routes list
- Match REST API post output from custom endpoint
- How to change user avatar using REST API?
- rest api authentication
- x-wp-nonce is not allowed by Access-Control-Allow-Headers in preflight response
- How to get around WP REST API per page limit without pagination?
- Build on same WordPress or different install?
- Testing custom API endpoint with class dependency
- How to properly add custom entities in Gutenberg
- REST API custom endpoint without authentication for POST method?
- CORS & Remote access to WP via RestAPI
- Create Session with JWT
- Not all featured image sizes available in Rest API
- 403 Forbidden with gutenberg
- WordPress doesn’t send a notification email when submitting a comment using REST API
- Using WordPress RESTapi to call a php file instead of post or page
- WordPress REST API – Modify JSON before importing
- pagination in WP rest api
- Is there anyway to format my EndPoint URL in WordPress?
- Return WP_Error as WP_REST_Response
- How to use REST API to send user metadata?
- Can the new REST API now make WP into it’s own push notification server?
- Confused about AngularJS and WordPress
- Post API tax_relation field doesn’t work
- What is the meta field in the response of the user REST API?
- How to post an unserialized array via wordpress rest API as meta data
- Is there any way to clear cache when making REST API request?
- Use the backbone.js client to save custom post type meta
- Override WordPress POST REST API
- Creating a custom endpoint for rest, I see the endpoint exists in the wp-json, but the request is returning 404
- WordPress + Vue — Single page app giving me 404s when I use query params
- No ‘Access-Control-Allow-Origin’ when call rest API
- Get subscribers via REST API and send post notification
- Custom API endpoint to create gallery for post
- Register REST route with a multi-value parameter
- How do I add meta when creating a post with rest api?
- How to Get Featured Image from REST API?
- Allow “wp-admin” edit access through headless WP web application
- WordPress + REST API v2 and private pages Load by slug
- Validate rest-api call on create
- Error invalid parameters with REST API
- How to get featured image in WP rest api
- WordPress REST API rest_comment_invalid_author Sorry, you are not allowed to edit ‘author’ for comments
- How to delete user using rest api without reassigning
- How to send the body in wp_remote_post as “raw”?
- Accessing private posts through REST API, same code that works in remote doesn’t in local
- REST API and filtering by meta value
- Rest API: trouble receiving response through script (browser and Postman display correctly)
- Advanced Access Manager: RESTful endpoint to refresh token
- Custom Endpoints not working
- Is there a way I can fetch the WordPress Developer Code References with an API?
- Pull in ALL posts from the last two weeks using Rest API
- Extending REST API responses
- 403 error when publishing a post in wordpress. Error => Publishing failed. The response is not a valid JSON response
- Cannot use WordPress Application Passwords: “code”: “rest_no_route” “status”:404 for /wp-json/wp/v2/users/me/application-passwords
- How to add Relations of a CCT from JetEngine via WordPress Rest API
- Pass multiple tags slug to rest API
- Return a WP_REST_Response from an inner function (and not from the root callback)
- register_rest_route with method POST but in wp-json/ is showing GET
- Rest Api fetching only one random post
- WP REST API returns empty posts despite entries in wp_posts
- Accessing Custom REST endpoint with rest_do_request()
- WP CLI in WP 5.3 with PHP 7.4
- The REST API encountered an error in wordpress?
- Get wordpress post with featured image, category and tag from WordPress API
- Do something when publish a post in Gutenberg with hook rest_after_insert_post
- Uploading picture via REST API
- How to modify the HTML output of Gutenberg block? (Youtube)
- Can I use REST API if the site is protected with .htpasswd
- REST API and Loopback error
- Rest API: Register and Login errors aren’t specific
- How can I secure my custom rest api endpoint or add under a already existing rest group
- Autotrader API Integration
- WordPress RESTAPI – Restrict unknown
- Fix Characters WordPress Ionic App
- Accessing secure endpoint with X-WP-Nonce?
- Return all custom taxonomy terms for post in REST API v2? Currently limited to 10 terms
- Can we use website data which is having wp rest api plugin?
- WP Rest API V2 OR Operator in URL
- how can I add an URL parameter to a rest route using register_rest_route()?
- Is it possible to bulk update a table using WP Rest API?
- Call to undefined function upload_is_user_over_quota()
- Rest api request throttling
- Getting current core version from an WordPress installation
- How to block external access to register_rest_route callback?
- Filter output of posts (Rest API)
- WordPress Application Passwords not authorizing
- Rest API nonce is being cached
- WordPress custom endpoint returns Security violated
- custom REST endpoints and application passwords
- Hide custom posts from certain taxonomy in rest api
- Creating Application Password using REST API results in 401 regardless of JWT token