PHP Class WP_REST_Meta_Fields, wordpress

Since: 4.7.0
Show file Open project: johnpbloch/wordpress

Public Methods

Method Description
get_field_schema ( ) : array Retrieves the object's meta schema, conforming to JSON Schema.
get_value ( integer $object_id, WP_REST_Request $request ) : WP_Error | object Retrieves the meta field value.
prepare_value ( mixed $value, WP_REST_Request $request, array $args ) : mixed Prepares a meta value for output.
register_field ( ) Registers the meta field.
update_value ( WP_REST_Request $request, integer $object_id ) : WP_Error | null Updates meta values.

Protected Methods

Method Description
delete_meta_value ( integer $object_id, string $meta_key, string $name ) : boolean | WP_Error Deletes a meta value for an object.
get_meta_type ( ) : string Retrieves the object meta type.
get_registered_fields ( ) : array Retrieves all the registered meta fields.
get_rest_field_type ( ) : string Retrieves the object type for register_rest_field().
prepare_value_for_response ( mixed $value, WP_REST_Request $request, array $args ) : mixed Prepares a meta value for a response.
update_meta_value ( integer $object_id, string $meta_key, string $name, mixed $value ) : boolean | WP_Error Updates a meta value for an object.
update_multi_meta_value ( integer $object_id, string $meta_key, string $name, array $values ) : boolean | WP_Error Updates multiple meta values for an object.

Method Details

delete_meta_value() protected method

Deletes a meta value for an object.
Since: 4.7.0
protected delete_meta_value ( integer $object_id, string $meta_key, string $name ) : boolean | WP_Error
$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.
return boolean | WP_Error True if meta field is deleted, WP_Error otherwise.

get_field_schema() public method

Retrieves the object's meta schema, conforming to JSON Schema.
Since: 4.7.0
public get_field_schema ( ) : array
return array Field schema data.

get_meta_type() abstract protected method

Retrieves the object meta type.
Since: 4.7.0
abstract protected get_meta_type ( ) : string
return string One of 'post', 'comment', 'term', 'user', or anything else supported by `_get_meta_table()`.

get_registered_fields() protected method

Retrieves all the registered meta fields.
Since: 4.7.0
protected get_registered_fields ( ) : array
return array Registered fields.

get_rest_field_type() abstract protected method

Retrieves the object type for register_rest_field().
Since: 4.7.0
abstract protected get_rest_field_type ( ) : string
return string The REST field type, such as post type name, taxonomy name, 'comment', or `user`.

get_value() public method

Retrieves the meta field value.
Since: 4.7.0
public get_value ( integer $object_id, WP_REST_Request $request ) : WP_Error | object
$object_id integer Object ID to fetch meta for.
$request WP_REST_Request Full details about the request.
return WP_Error | object Object containing the meta values by name, otherwise WP_Error object.

prepare_value() public static method

Default preparation for meta fields. Override by passing the prepare_callback in your show_in_rest options.
Since: 4.7.0
public static prepare_value ( mixed $value, WP_REST_Request $request, array $args ) : mixed
$value mixed Meta value from the database.
$request WP_REST_Request Request object.
$args array REST-specific options for the meta key.
return mixed Value prepared for output. If a non-JsonSerializable object, null.

prepare_value_for_response() protected method

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.
Since: 4.7.0
protected prepare_value_for_response ( mixed $value, WP_REST_Request $request, array $args ) : mixed
$value mixed Meta value to prepare.
$request WP_REST_Request Current request object.
$args array Options for the field.
return mixed Prepared value.

register_field() public method

Registers the meta field.
See also: register_rest_field()
Since: 4.7.0
public register_field ( )

update_meta_value() protected method

Updates a meta value for an object.
Since: 4.7.0
protected update_meta_value ( integer $object_id, string $meta_key, string $name, mixed $value ) : boolean | WP_Error
$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.
return boolean | WP_Error True if the meta field was updated, WP_Error otherwise.

update_multi_meta_value() protected method

Alters the list of values in the database to match the list of provided values.
Since: 4.7.0
protected update_multi_meta_value ( integer $object_id, string $meta_key, string $name, array $values ) : boolean | WP_Error
$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.
return boolean | WP_Error True if meta fields are updated, WP_Error otherwise.

update_value() public method

Updates meta values.
Since: 4.7.0
public update_value ( WP_REST_Request $request, integer $object_id ) : WP_Error | null
$request WP_REST_Request Full details about the request.
$object_id integer Object ID to fetch meta for.
return WP_Error | null WP_Error if one occurs, null on success.