From 6b56a33bfaf2c3c5b2cff3576b26888474e31be6 Mon Sep 17 00:00:00 2001 From: gziolo Date: Mon, 16 Sep 2024 11:33:38 +0000 Subject: [PATCH] Meta: Add label argument to register_meta function With the introduction of Block Bindings, it became more common to see workflows where users need to see the custom fields that are available or connected. They were relying on the meta key, however it feelt too technical sometimes. The solution is adding a new label argument to include a human-readable name that can be used across the UI. Props santosguillamot, mamaduka, gziolo, timothyblynjacobs, peterwilsoncc. Fixes #61998. Built from https://develop.svn.wordpress.org/trunk@59023 git-svn-id: http://core.svn.wordpress.org/trunk@58419 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta.php | 3 +++ wp-includes/rest-api/fields/class-wp-rest-meta-fields.php | 1 + wp-includes/version.php | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index 32838b135d..6f6dd928e0 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -1369,6 +1369,7 @@ function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = * @since 5.3.0 Valid meta types expanded to include "array" and "object". * @since 5.5.0 The `$default` argument was added to the arguments array. * @since 6.4.0 The `$revisions_enabled` argument was added to the arguments array. + * @since 6.7.0 The `label` argument was added to the arguments array. * * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', * or any other object type with an associated meta table. @@ -1380,6 +1381,7 @@ function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = * the meta key will be registered on the entire object type. Default empty. * @type string $type The type of data associated with this meta key. * Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'. + * @type string $label A human-readable label of the data attached to this meta key. * @type string $description A description of the data attached to this meta key. * @type bool $single Whether the meta key has one value per object, or an array of values per object. * @type mixed $default The default value returned from get_metadata() if no value has been set yet. @@ -1412,6 +1414,7 @@ function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { $defaults = array( 'object_subtype' => '', 'type' => 'string', + 'label' => '', 'description' => '', 'default' => '', 'single' => false, diff --git a/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php b/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php index 5f3b55843e..aa0bc644bc 100644 --- a/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php +++ b/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php @@ -478,6 +478,7 @@ abstract class WP_REST_Meta_Fields { $default_schema = array( 'type' => $default_args['type'], + 'title' => empty( $args['label'] ) ? '' : $args['label'], 'description' => empty( $args['description'] ) ? '' : $args['description'], 'default' => isset( $args['default'] ) ? $args['default'] : null, ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 5e86294e34..7a90d61357 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-alpha-59022'; +$wp_version = '6.7-alpha-59023'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.