Skip to content

Commit 84903f9

Browse files
Merge pull request #78 from WP-API/danielbachhuber-patch-1
Rename `register_api_field()` to `register_rest_field()` in docs
2 parents d53d1c5 + ead806c commit 84903f9

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

extending/modifying/index.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ title: Modifying Responses
33
---
44
The default endpoints of the WordPress REST API are designed to be sensible defaults in terms of what data is returned. This fits the 80/20 rule by providing for 80% of sites and uses, but these default collections of data cannot always fulfill the needs of every one of the millions of sites.
55

6-
The REST API is designed to be highly extensible, like the rest (no pun intended) of WordPress. This document details how to add additional data, including but not limited to post or user meta data to the responses of default endpoints, using the function `register_api_field`; a helper function designed to add fields to the response for a specific option.
6+
The REST API is designed to be highly extensible, like the rest (no pun intended) of WordPress. This document details how to add additional data, including but not limited to post or user meta data to the responses of default endpoints, using the function `register_rest_field`; a helper function designed to add fields to the response for a specific option.
77

8-
`register_api_field` provides a single way for modifying all responses for an object. For example, if it is used to add a field to the posts object, this field will be included in all responses, whether they are for single or multiple items.
8+
`register_rest_field` provides a single way for modifying all responses for an object. For example, if it is used to add a field to the posts object, this field will be included in all responses, whether they are for single or multiple items.
99

1010
In addition, it allows you to update that value from the endpoints the field is registered on.
1111

12-
It is important to note that in the context of this document, the term "field" refers to a field in the object returned by the API. It does not refer to a meta field of a post, comment or user. While it `register_api_field` can be used to add meta fields to a response, it can be used to add any data.
12+
It is important to note that in the context of this document, the term "field" refers to a field in the object returned by the API. It does not refer to a meta field of a post, comment or user. While it `register_rest_field` can be used to add meta fields to a response, it can be used to add any data.
1313

1414

1515
Important Note about Changing Responses
@@ -24,18 +24,18 @@ Adding fields is not dangerous, so if you need to modify data, it's much better
2424
Note that the API cannot prevent you from changing responses, but the code is structured to strongly discourage this. Internally, field registration is powered by filters, and these can be used if you absolutely have no other choice.
2525

2626

27-
What `register_api_field` Does
27+
What `register_rest_field` Does
2828
------------------------------
2929

30-
In the infrastructure for responses, the global variable $wp_rest_additional_fields, is used for holding the fields, by object name to be added to the responses to those objects. The REST API provides `register_api_field` as a utility function for adding to this global variable. Adding to it directly should be avoided to ensure maximum forward-compatibility.
30+
In the infrastructure for responses, the global variable $wp_rest_additional_fields, is used for holding the fields, by object name to be added to the responses to those objects. The REST API provides `register_rest_field` as a utility function for adding to this global variable. Adding to it directly should be avoided to ensure maximum forward-compatibility.
3131

3232
For each object -- a post type, or users, terms, comments, meta, etc, $wp_rest_additional_fields contains an array of fields, each of which can have a value for callbacks used to retrieve the value, update the value using any endpoint that field is added to that can be used for updating.
3333

3434

35-
How To Use `register_api_field`
35+
How To Use `register_rest_field`
3636
-------------------------------
3737

38-
The function `register_api_field` field accepts three parameters:
38+
The function `register_rest_field` field accepts three parameters:
3939

4040
1. `$object_type`: The name of the object, as a string, or an array of the names of objects the field is being registered to. When adding to posts type endpoints, the name of the post type(s) should be used. Alternatively "terms", "meta", "user" or "comments" may be used.
4141

@@ -57,7 +57,7 @@ Examples
5757
<?php
5858
add_action( 'rest_api_init', 'slug_register_starship' );
5959
function slug_register_starship() {
60-
register_api_field( 'post',
60+
register_rest_field( 'post',
6161
'starship',
6262
array(
6363
'get_callback' => 'slug_get_starship',
@@ -92,7 +92,7 @@ This example illustrates adding the post meta field "starship" to the response f
9292
*/
9393
add_action( 'rest_api_init', 'slug_register_spaceship' );
9494
function slug_register_spaceship() {
95-
register_api_field( 'post',
95+
register_rest_field( 'post',
9696
'starship',
9797
array(
9898
'get_callback' => 'slug_get_spaceship',
@@ -148,7 +148,7 @@ This example shows how to allow reading and writing of a post meta field. This w
148148
*/
149149
add_action( 'rest_api_init', 'slug_register_something_random' );
150150
function slug_register_starship() {
151-
register_api_field( 'post',
151+
register_rest_field( 'post',
152152
'something',
153153
array(
154154
'get_callback' => 'slug_get_something',

0 commit comments

Comments
 (0)