Changeset 48402
- Timestamp:
- 07/07/2020 08:45:55 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
src/wp-includes/meta.php (modified) (9 diffs)
-
src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php (modified) (1 diff)
-
tests/phpunit/tests/meta/registerMeta.php (modified) (2 diffs)
-
tests/phpunit/tests/rest-api/rest-post-meta-fields.php (modified) (2 diffs)
-
tests/phpunit/tests/rest-api/rest-term-meta-fields.php (modified) (1 diff)
-
tests/phpunit/tests/rest-api/rest-users-controller.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/meta.php
r48214 r48402 211 211 // Compare existing value to new value if no prev value given and the key exists only once. 212 212 if ( empty( $prev_value ) ) { 213 $old_value = get_metadata ( $meta_type, $object_id, $meta_key );214 if ( count( $old_value )== 1 ) {213 $old_value = get_metadata_raw( $meta_type, $object_id, $meta_key ); 214 if ( is_countable( $old_value ) && count( $old_value ) === 1 ) { 215 215 if ( $old_value[0] === $meta_value ) { 216 216 return false; … … 486 486 * If there's a problem with the parameters passed to the function, boolean `false` is returned. 487 487 * 488 * @since 2.9.0488 * @since 5.5.0 489 489 * 490 490 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', … … 497 497 * @return mixed The metadata value or array of values. See description above for further details. 498 498 */ 499 function get_metadata ( $meta_type, $object_id, $meta_key = '', $single = false ) {499 function get_metadata_raw( $meta_type, $object_id, $meta_key = '', $single = false ) { 500 500 if ( ! $meta_type || ! is_numeric( $object_id ) ) { 501 501 return false; … … 554 554 } 555 555 556 return null; 557 } 558 559 /** 560 * Retrieves raw metadata for the specified object. 561 * 562 * @since 2.9.0 563 * @uses get_metadata_raw() 564 * 565 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 566 * or any other object type with an associated meta table. 567 * @param int $object_id ID of the object metadata is for. 568 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for 569 * the specified object. Default empty. 570 * @param bool $single Optional. If true, return only the first value of the specified meta_key. 571 * This parameter has no effect if meta_key is not specified. Default false. 572 * @return mixed Single metadata value, or array of values 573 */ 574 function get_metadata( $meta_type, $object_id, $meta_key = '', $single = false ) { 575 $value = get_metadata_raw( $meta_type, $object_id, $meta_key, $single ); 576 if ( ! is_null( $value ) ) { 577 return $value; 578 } 579 580 return get_metadata_default( $meta_type, $meta_key, $single, $object_id ); 581 } 582 583 /** 584 * Retrieve metadata data default for the specified object. 585 * 586 * @since 5.5.0 587 * 588 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 589 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for 590 * the specified object. 591 * @param bool $single Optional, default is false. 592 * If true, return only the first value of the specified meta_key. 593 * This parameter has no effect if meta_key is not specified. 594 * @param int $object_id Optional, default is 0. 595 * ID of the object metadata is for 596 * @return mixed Single metadata value, or array of values 597 */ 598 function get_metadata_default( $meta_type, $meta_key, $single = false, $object_id = 0 ) { 556 599 if ( $single ) { 557