PHP Class WP_REST_Meta_Fields, wordpress

Since: 4.7.0
Afficher le fichier Open project: johnpbloch/wordpress

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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.
Résultat boolean | WP_Error True if meta field is deleted, WP_Error otherwise.

get_field_schema() public méthode

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

get_meta_type() abstract protected méthode

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

get_registered_fields() protected méthode

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

get_rest_field_type() abstract protected méthode

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

get_value() public méthode

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.
Résultat WP_Error | object Object containing the meta values by name, otherwise WP_Error object.

prepare_value() public static méthode

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.
Résultat mixed Value prepared for output. If a non-JsonSerializable object, null.

prepare_value_for_response() protected méthode

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.
Résultat mixed Prepared value.

register_field() public méthode

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

update_meta_value() protected méthode

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.
Résultat boolean | WP_Error True if the meta field was updated, WP_Error otherwise.

update_multi_meta_value() protected méthode

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.
Résultat boolean | WP_Error True if meta fields are updated, WP_Error otherwise.

update_value() public méthode

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.
Résultat WP_Error | null WP_Error if one occurs, null on success.