--- a/wp/wp-includes/meta.php Fri Sep 05 18:40:08 2025 +0200
+++ b/wp/wp-includes/meta.php Fri Sep 05 18:52:52 2025 +0200
@@ -23,7 +23,13 @@
* or any other object type with an associated meta table.
* @param int $object_id ID of the object metadata is for.
* @param string $meta_key Metadata key.
- * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
+ * @param mixed $meta_value Metadata value. Arrays and objects are stored as serialized data and
+ * will be returned as the same type when retrieved. Other data types will
+ * be stored as strings in the database:
+ * - false is stored and retrieved as an empty string ('')
+ * - true is stored and retrieved as '1'
+ * - numbers (both integer and float) are stored and retrieved as strings
+ * Must be serializable if non-scalar.
* @param bool $unique Optional. Whether the specified metadata key should be unique for the object.
* If true, and the object already has a value for the specified metadata key,
* no change will be made. Default false.
@@ -568,7 +574,13 @@
* The value of the meta field if `$single` is true.
* False for an invalid `$object_id` (non-numeric, zero, or negative value),
* or if `$meta_type` is not specified.
- * An empty string if a valid but non-existing object ID is passed.
+ * An empty array if a valid but non-existing object ID is passed and `$single` is false.
+ * An empty string if a valid but non-existing object ID is passed and `$single` is true.
+ * Note: Non-serialized values are returned as strings:
+ * - false values are returned as empty strings ('')
+ * - true values are returned as '1'
+ * - numbers (both integer and float) are returned as strings
+ * Arrays and objects retain their original type.
*/
function get_metadata( $meta_type, $object_id, $meta_key = '', $single = false ) {
$value = get_metadata_raw( $meta_type, $object_id, $meta_key, $single );
@@ -1153,10 +1165,10 @@
return (bool) $check;
}
- $cache_key = $meta_type . '_meta';
+ $cache_group = $meta_type . '_meta';
$non_cached_ids = array();
$cache = array();
- $cache_values = wp_cache_get_multiple( $object_ids, $cache_key );
+ $cache_values = wp_cache_get_multiple( $object_ids, $cache_group );
foreach ( $cache_values as $id => $cached_object ) {
if ( false === $cached_object ) {
@@ -1202,7 +1214,7 @@
}
$data[ $id ] = $cache[ $id ];
}
- wp_cache_add_multiple( $data, $cache_key );
+ wp_cache_add_multiple( $data, $cache_group );
return $cache;
}
@@ -1368,6 +1380,7 @@
* @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.
@@ -1379,6 +1392,7 @@
* 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.
@@ -1411,6 +1425,7 @@
$defaults = array(
'object_subtype' => '',
'type' => 'string',
+ 'label' => '',
'description' => '',
'default' => '',
'single' => false,