--- a/wp/wp-includes/meta.php Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/meta.php Fri Sep 05 18:40:08 2025 +0200
@@ -10,6 +10,8 @@
* @subpackage Meta
*/
+require ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php';
+
/**
* Adds metadata for the specified object.
*
@@ -171,7 +173,7 @@
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
* @param mixed $prev_value Optional. Previous value to check before updating.
* If specified, only update existing metadata entries with
- * this value. Otherwise, update all entries. Default empty.
+ * this value. Otherwise, update all entries. Default empty string.
* @return int|bool The new meta field ID if a field with the given key didn't exist
* and was therefore added, true on successful update,
* false on failure or if the value passed to the function
@@ -369,6 +371,7 @@
* Pass `null`, `false`, or an empty string to skip this check.
* (For backward compatibility, it is not possible to pass an empty string
* to delete those entries with an empty string for a value.)
+ * Default empty string.
* @param bool $delete_all Optional. If true, delete matching metadata entries for all objects,
* ignoring the specified object_id. Otherwise, only delete
* matching metadata entries for the specified object_id. Default false.
@@ -558,7 +561,7 @@
* 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 Optional. Metadata key. If not specified, retrieve all metadata for
- * the specified object. Default empty.
+ * the specified object. Default empty string.
* @param bool $single Optional. If true, return only the first value of the specified `$meta_key`.
* This parameter has no effect if `$meta_key` is not specified. Default false.
* @return mixed An array of values if `$single` is false.
@@ -585,7 +588,7 @@
* 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 Optional. Metadata key. If not specified, retrieve all metadata for
- * the specified object. Default empty.
+ * the specified object. Default empty string.
* @param bool $single Optional. If true, return only the first value of the specified `$meta_key`.
* This parameter has no effect if `$meta_key` is not specified. Default false.
* @return mixed An array of values if `$single` is false.
@@ -907,8 +910,10 @@
$original_key = $meta->meta_key;
$object_id = $meta->{$column};
- // If a new meta_key (last parameter) was specified, change the meta key,
- // otherwise use the original key in the update statement.
+ /*
+ * If a new meta_key (last parameter) was specified, change the meta key,
+ * otherwise use the original key in the update statement.
+ */
if ( false === $meta_key ) {
$meta_key = $original_key;
} elseif ( ! is_string( $meta_key ) ) {
@@ -1078,7 +1083,7 @@
*
* @since 3.4.0
*
- * @param int $meta_ids Deleted metadata entry ID.
+ * @param int $meta_id Deleted metadata entry ID.
*/
do_action( "deleted_{$meta_type}meta", $meta_id );
}
@@ -1230,8 +1235,14 @@
* @param string $type Type of meta.
* @param string $primary_table Primary database table name.
* @param string $primary_id_column Primary ID column name.
- * @param object $context Optional. The main query object
- * @return array Associative array of `JOIN` and `WHERE` SQL.
+ * @param object $context Optional. The main query object. Default null.
+ * @return string[]|false {
+ * Array containing JOIN and WHERE SQL clauses to append to the main query,
+ * or false if no table exists for the requested meta type.
+ *
+ * @type string $join SQL fragment to append to the main JOIN clause.
+ * @type string $where SQL fragment to append to the main WHERE clause.
+ * }
*/
function get_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $context = null ) {
$meta_query_obj = new WP_Meta_Query( $meta_query );
@@ -1268,7 +1279,7 @@
*
* @param string $meta_key Metadata key.
* @param string $meta_type Optional. Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
- * or any other object type with an associated meta table. Default empty.
+ * or any other object type with an associated meta table. Default empty string.
* @return bool Whether the meta key is considered protected.
*/
function is_protected_meta( $meta_key, $meta_type = '' ) {
@@ -1298,7 +1309,7 @@
* @param mixed $meta_value Metadata value to sanitize.
* @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.
- * @param string $object_subtype Optional. The subtype of the object type.
+ * @param string $object_subtype Optional. The subtype of the object type. Default empty string.
* @return mixed Sanitized $meta_value.
*/
function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = '' ) {
@@ -1356,6 +1367,7 @@
* @since 4.9.8 The `$object_subtype` argument was added to the arguments array.
* @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.
*
* @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.
@@ -1381,6 +1393,8 @@
* support for custom fields for registered meta to be accessible via REST.
* When registering complex meta values this argument may optionally be an
* array with 'schema' or 'prepare_callback' keys instead of a boolean.
+ * @type bool $revisions_enabled Whether to enable revisions support for this meta_key. Can only be used when the
+ * object type is 'post'.
* }
* @param string|array $deprecated Deprecated. Use `$args` instead.
* @return bool True if the meta key was successfully registered in the global array, false if not.
@@ -1403,6 +1417,7 @@
'sanitize_callback' => null,
'auth_callback' => null,
'show_in_rest' => false,
+ 'revisions_enabled' => false,
);
// There used to be individual args for sanitize and auth callbacks.
@@ -1449,6 +1464,17 @@
}
$object_subtype = ! empty( $args['object_subtype'] ) ? $args['object_subtype'] : '';
+ if ( $args['revisions_enabled'] ) {
+ if ( 'post' !== $object_type ) {
+ _doing_it_wrong( __FUNCTION__, __( 'Meta keys cannot enable revisions support unless the object type supports revisions.' ), '6.4.0' );
+
+ return false;
+ } elseif ( ! empty( $object_subtype ) && ! post_type_supports( $object_subtype, 'revisions' ) ) {
+ _doing_it_wrong( __FUNCTION__, __( 'Meta keys cannot enable revisions support unless the object subtype supports revisions.' ), '6.4.0' );
+
+ return false;
+ }
+ }
// If `auth_callback` is not provided, fall back to `is_protected_meta()`.
if ( empty( $args['auth_callback'] ) ) {
@@ -1574,7 +1600,7 @@
* @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.
* @param string $meta_key Metadata key.
- * @param string $object_subtype Optional. The subtype of the object type.
+ * @param string $object_subtype Optional. The subtype of the object type. Default empty string.
* @return bool True if the meta key is registered to the object type and, if provided,
* the object subtype. False if not.
*/
@@ -1593,7 +1619,7 @@
* @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.
* @param string $meta_key Metadata key.
- * @param string $object_subtype Optional. The subtype of the object type.
+ * @param string $object_subtype Optional. The subtype of the object type. Default empty string.
* @return bool True if successful. False if the meta key was not registered.
*/
function unregister_meta_key( $object_type, $meta_key, $object_subtype = '' ) {
@@ -1635,15 +1661,15 @@
}
/**
- * Retrieves a list of registered meta keys for an object type.
+ * Retrieves a list of registered metadata args for an object type, keyed by their meta keys.
*
* @since 4.6.0
* @since 4.9.8 The `$object_subtype` parameter was added.
*
* @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.
- * @param string $object_subtype Optional. The subtype of the object type.
- * @return string[] List of registered meta keys.
+ * @param string $object_subtype Optional. The subtype of the object type. Default empty string.
+ * @return array[] List of registered metadata args, keyed by their meta keys.
*/
function get_registered_meta_keys( $object_type, $object_subtype = '' ) {
global $wp_meta_keys;