最合适的回答,由SO网友:Danilo P. da Silva 整理而成
刚刚在另一个堆栈溢出问题中找到了解决方案。使用函数register_meta()
:
register_meta(\'user\', \'icq\', array(
"type" => "string",
"show_in_rest" => true
));
现在,我可以使用以下命令发出请求:
{
"username" : "johndoe",
"email": "[email protected]",
"password": "qwerty",
"meta": {
"icq": "11223344"
}
}
答案是:
{
"id": 49,
"username": "johndoe",
"name": "johndoe",
"first_name": "",
"last_name": "",
"email": "[email protected]",
"url": "",
"description": "",
"link": "http://localhost/author/johndoe/",
"locale": "en_US",
"nickname": "johndoe",
"slug": "johndoe",
"roles": [
"subscriber"
],
"registered_date": "2018-01-13T11:53:57+00:00",
"capabilities": {
"read": true,
"level_0": true,
"subscriber": true
},
"extra_capabilities": {
"subscriber": true
},
"avatar_urls": {
"24": "http://2.gravatar.com/avatar/29a1df4646cb3417c19994a59a3e022a?s=24&d=mm&r=g",
"48": "http://2.gravatar.com/avatar/29a1df4646cb3417c19994a59a3e022a?s=48&d=mm&r=g",
"96": "http://2.gravatar.com/avatar/29a1df4646cb3417c19994a59a3e022a?s=96&d=mm&r=g"
},
"meta": {
"icq": [
"11223344"
]
},
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wp/v2/users/49"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wp/v2/users"
}
]
}
}
如果我想在中显示/编辑
/wp-admin/
我也只是使用这个函数:
function more_contactmethods( $contactmethods ) {
$contactmethods[\'icq\'] = \'ICQ\';
return $contactmethods;
}
add_filter( \'user_contactmethods\', \'more_contactmethods\' );