Class: WP_REST_User_Meta_Fields

Extends WP_REST_Meta_Fields

Core class used to manage meta values for users via the REST API.

Properties



Methods

WP_REST_User_Meta_Fields:: check_meta_is_array( mixed $value, WP_REST_Request $request, string $param )

Check the 'meta' value of a request is an associative array. Since 4.7.0.

Arguments

Name Type(s) Default Value Description
$value mixed

The meta value submitted in the request.

$request WP_REST_Request

Full details about the request.

$param string

The parameter name.

Returns

WP_Error | string

The meta array, if valid, otherwise an error.


WP_REST_User_Meta_Fields:: delete_meta_value( integer $object_id, string $meta_key, string $name )

Deletes a meta value for an object. Since 4.7.0.

Arguments

Name Type(s) Default Value Description
$object_id integer

Object ID the field belongs to.

$meta_key string

Key for the field.

$name string

Name for the field that is exposed in the REST API.

Returns

boolean | WP_Error

True if meta field is deleted, WP_Error otherwise.


WP_REST_User_Meta_Fields:: get_field_schema( )

Retrieves the object's meta schema, conforming to JSON Schema. Since 4.7.0.

Returns

array

Field schema data.


WP_REST_User_Meta_Fields:: get_meta_subtype( )

Retrieves the object meta subtype. Since 4.9.8.

Returns

string

Subtype for the meta type, or empty string if no specific subtype.


WP_REST_User_Meta_Fields:: get_meta_type( )

Retrieves the object meta type. Since 4.7.0.

Returns

string

One of 'post', 'comment', 'term', 'user', or anything else supported by _get_meta_table().


WP_REST_User_Meta_Fields:: get_registered_fields( )

Retrieves all the registered meta fields. Since 4.7.0.

Returns

array

Registered fields.


WP_REST_User_Meta_Fields:: get_rest_field_type( )

Retrieves the object type for register_rest_field(). Since 4.7.0.

Returns

string

The REST field type, such as post type name, taxonomy name, 'comment', or user.


WP_REST_User_Meta_Fields:: get_value( integer $object_id, WP_REST_Request $request )

Retrieves the meta field value. Since 4.7.0.

Arguments

Name Type(s) Default Value Description
$object_id integer

Object ID to fetch meta for.

$request WP_REST_Request

Full details about the request.

Returns

WP_Error | object

Object containing the meta values by name, otherwise WP_Error object.


WP_REST_User_Meta_Fields:: prepare_value( mixed $value, WP_REST_Request $request, array $args )

Prepares a meta value for output. Since 4.7.0.

Default preparation for meta fields. Override by passing the prepare_callback in your show_in_rest options.

Arguments

Name Type(s) Default Value Description
$value mixed

Meta value from the database.

$request WP_REST_Request

Request object.

$args array

REST-specific options for the meta key.

Returns

mixed

Value prepared for output. If a non-JsonSerializable object, null.


WP_REST_User_Meta_Fields:: prepare_value_for_response( mixed $value, WP_REST_Request $request, array $args )

Prepares a meta value for a response. Since 4.7.0.

This is required because some native types cannot be stored correctly in the database, such as booleans. We need to cast back to the relevant type before passing back to JSON.

Arguments

Name Type(s) Default Value Description
$value mixed

Meta value to prepare.

$request WP_REST_Request

Current request object.

$args array

Options for the field.

Returns

mixed

Prepared value.


WP_REST_User_Meta_Fields:: register_field( )

Registers the meta field. Since 4.7.0.


WP_REST_User_Meta_Fields:: update_meta_value( integer $object_id, string $meta_key, string $name, mixed $value )

Updates a meta value for an object. Since 4.7.0.

Arguments

Name Type(s) Default Value Description
$object_id integer

Object ID to update.

$meta_key string

Key for the custom field.

$name string

Name for the field that is exposed in the REST API.

$value mixed

Updated value.

Returns

boolean | WP_Error

True if the meta field was updated, WP_Error otherwise.


WP_REST_User_Meta_Fields:: update_multi_meta_value( integer $object_id, string $meta_key, string $name, array $values )

Updates multiple meta values for an object. Since 4.7.0.

Alters the list of values in the database to match the list of provided values.

Arguments

Name Type(s) Default Value Description
$object_id integer

Object ID to update.

$meta_key string

Key for the custom field.

$name string

Name for the field that is exposed in the REST API.

$values array

List of values to update to.

Returns

boolean | WP_Error

True if meta fields are updated, WP_Error otherwise.


WP_REST_User_Meta_Fields:: update_value( array $meta, integer $object_id )

Updates meta values. Since 4.7.0.

Arguments

Name Type(s) Default Value Description
$meta array

Array of meta parsed from the request.

$object_id integer

Object ID to fetch meta for.

Returns

WP_Error | null

WP_Error if one occurs, null on success.


WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.