Make WordPress Core


Ignore:
Timestamp:
01/17/2025 12:10:08 AM (5 months ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-site.php

    r59009 r59657  
    10271027 * @param int    $site_id    Site ID.
    10281028 * @param string $meta_key   Metadata name.
    1029  * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
     1029 * @param mixed  $meta_value Metadata value. Arrays and objects are stored as serialized data and
     1030 *                           will be returned as the same type when retrieved. Other data types will
     1031 *                           be stored as strings in the database:
     1032 *                           - false is stored and retrieved as an empty string ('')
     1033 *                           - true is stored and retrieved as '1'
     1034 *                           - numbers (both integer and float) are stored and retrieved as strings
     1035 *                           Must be serializable if non-scalar.
    10301036 * @param bool   $unique     Optional. Whether the same key should not be added.
    10311037 *                           Default false.
     
    10721078 *               An empty array if a valid but non-existing site ID is passed and `$single` is false.
    10731079 *               An empty string if a valid but non-existing site ID is passed and `$single` is true.
     1080 *               Note: Non-serialized values are returned as strings:
     1081 *               - false values are returned as empty strings ('')
     1082 *               - true values are returned as '1'
     1083 *               - numbers (both integer and float) are returned as strings
     1084 *               Arrays and objects retain their original type.
    10741085 */
    10751086function get_site_meta( $site_id, $key = '', $single = false ) {
Note: See TracChangeset for help on using the changeset viewer.