I am building a website VueJS and wordpress rest api. I am now working on author rest api. When i send get users :
get
I have the following result :
[
{
"id": 1,
"name": "Christian DOE",
"url": "",
"description": "Whats'up men ",
"link": "/",
"slug": "christian,
"avatar_urls": {
"24": ";d=mm&r=g",
"48": ";d=mm&r=g",
"96": ";d=mm&r=g"
},
"meta": [],
"acf": [],
"_links": {
"self": [
{
"href": ""
}
],
"collection": [
{
"href": ""
}
]
}
},
{
"id": 3,
"name": "Jean Charles",
"url": "",
"description": "It's me ",
"link": "/",
"slug": "charles",
"avatar_urls": {
"24": ";d=mm&r=g",
"48": ";d=mm&r=g",
"96": ";d=mm&r=g"
},
"meta": [],
"acf": [],
"_links": {
"self": [
{
"href": ""
}
],
"collection": [
{
"href": ""
}
]
}
},
{
"id": 2,
"name": "utilisateurtest",
"url": "",
"description": "Me aand me ",
"link": "/",
"slug": "utilisateurtest",
"avatar_urls": {
"24": ";d=mm&r=g",
"48": ";d=mm&r=g",
"96": ";d=mm&r=g"
},
"meta": [],
"acf": [],
"_links": {
"self": [
{
"href": ""
}
],
"collection": [
{
"href": ""
}
]
}
}
]
My aim is to customize users rest api : i would like to have a list of user social link users.
Is there a plugin i can use to : 1. to set the user social link ? 2. To get those links exposed by rest api ?
I've tried the following solution :
1.I upload a wordpress plugin to add some data. It's Simple Author plugin I am able to add some additional data to user ( social link list ) 2. I create a plugin to add this meta data be filled when i retrieved users from rest api. Here my plugin code :
add_action( 'rest_api_init', 'adding_user_meta_rest' );
function adding_user_meta_rest() {
register_rest_field( 'user',
'collapsed_widgets',
array(
'get_callback' => 'user_meta_callback',
'update_callback' => null,
'schema' => null,
)
);
}
function user_meta_callback( $user, $field_name, $request) {
return get_user_meta( $user[ 'id' ], $field_name, true );
}
I've tried a rest api get users request but i did not have the meta data listed in my response.
If you have an idea, i would like to know.
Thanks for your help.