Options/Meta APIs: Document type juggling of meta data.
Document that unserialised data types are stored as strings in the database and returned as such by the meta data functions. For example, setting meta data to the integer value `1` will be returned as `"1"` when subsequently queried via `get_metadata()` and the related functions. Props sukhendu2002, azaozz, jrf, rodrigosprimo. Fixes ticket:61950. Built from https://develop.svn.wordpress.org/trunk@59657 git-svn-id: http://core.svn.wordpress.org/trunk@59000 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -432,7 +432,13 @@ function get_comment_count( $post_id = 0 ) {
|
||||
*
|
||||
* @param int $comment_id Comment ID.
|
||||
* @param string $meta_key Metadata name.
|
||||
* @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 same key should not be added.
|
||||
* Default false.
|
||||
* @return int|false Meta ID on success, false on failure.
|
||||
@@ -481,6 +487,11 @@ function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
|
||||
* False for an invalid `$comment_id` (non-numeric, zero, or negative value).
|
||||
* An empty array if a valid but non-existing comment ID is passed and `$single` is false.
|
||||
* An empty string if a valid but non-existing comment 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 are returned as strings
|
||||
* Arrays and objects retain their original type.
|
||||
*/
|
||||
function get_comment_meta( $comment_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'comment', $comment_id, $key, $single );
|
||||
|
||||
@@ -23,7 +23,13 @@ require ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php';
|
||||
* 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.
|
||||
@@ -570,6 +576,11 @@ function delete_metadata( $meta_type, $object_id, $meta_key, $meta_value = '', $
|
||||
* or if `$meta_type` is not specified.
|
||||
* 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 );
|
||||
|
||||
@@ -1026,7 +1026,13 @@ function clean_blog_cache( $blog ) {
|
||||
*
|
||||
* @param int $site_id Site ID.
|
||||
* @param string $meta_key Metadata name.
|
||||
* @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 same key should not be added.
|
||||
* Default false.
|
||||
* @return int|false Meta ID on success, false on failure.
|
||||
@@ -1071,6 +1077,11 @@ function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
|
||||
* False for an invalid `$site_id` (non-numeric, zero, or negative value).
|
||||
* An empty array if a valid but non-existing site ID is passed and `$single` is false.
|
||||
* An empty string if a valid but non-existing site 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_site_meta( $site_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'blog', $site_id, $key, $single );
|
||||
|
||||
@@ -2558,7 +2558,13 @@ function get_posts( $args = null ) {
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
* @param string $meta_key Metadata name.
|
||||
* @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 same key should not be added.
|
||||
* Default false.
|
||||
* @return int|false Meta ID on success, false on failure.
|
||||
@@ -2615,6 +2621,11 @@ function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
|
||||
* False for an invalid `$post_id` (non-numeric, zero, or negative value).
|
||||
* An empty array if a valid but non-existing post ID is passed and `$single` is false.
|
||||
* An empty string if a valid but non-existing post 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_post_meta( $post_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'post', $post_id, $key, $single );
|
||||
|
||||
@@ -1386,7 +1386,13 @@ function get_terms( $args = array(), $deprecated = '' ) {
|
||||
*
|
||||
* @param int $term_id Term ID.
|
||||
* @param string $meta_key Metadata name.
|
||||
* @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 same key should not be added.
|
||||
* Default false.
|
||||
* @return int|false|WP_Error Meta ID on success, false on failure.
|
||||
@@ -1432,6 +1438,11 @@ function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
|
||||
* False for an invalid `$term_id` (non-numeric, zero, or negative value).
|
||||
* An empty array if a valid but non-existing term ID is passed and `$single` is false.
|
||||
* An empty string if a valid but non-existing term 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 are returned as strings
|
||||
* Arrays and objects retain their original type.
|
||||
*/
|
||||
function get_term_meta( $term_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'term', $term_id, $key, $single );
|
||||
|
||||
@@ -1151,7 +1151,13 @@ function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) {
|
||||
*
|
||||
* @param int $user_id User ID.
|
||||
* @param string $meta_key Metadata name.
|
||||
* @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 same key should not be added.
|
||||
* Default false.
|
||||
* @return int|false Meta ID on success, false on failure.
|
||||
@@ -1200,6 +1206,11 @@ function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
|
||||
* False for an invalid `$user_id` (non-numeric, zero, or negative value).
|
||||
* An empty array if a valid but non-existing user ID is passed and `$single` is false.
|
||||
* An empty string if a valid but non-existing user 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_user_meta( $user_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'user', $user_id, $key, $single );
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.8-alpha-59656';
|
||||
$wp_version = '6.8-alpha-59657';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user