REST API: Check the results of `get_metadata()` in `WP_REST_Meta_Fields` methods.
This avoids PHP warnings in case the function returns boolean `false` instead of an array. Props david.binda. Fixes #53099. Built from https://develop.svn.wordpress.org/trunk@50793 git-svn-id: http://core.svn.wordpress.org/trunk@50402 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cbfa060298
commit
8cd601c8ba
|
@ -94,8 +94,10 @@ abstract class WP_REST_Meta_Fields {
|
|||
} else {
|
||||
$value = array();
|
||||
|
||||
foreach ( $all_values as $row ) {
|
||||
$value[] = $this->prepare_value_for_response( $row, $request, $args );
|
||||
if ( is_array( $all_values ) ) {
|
||||
foreach ( $all_values as $row ) {
|
||||
$value[] = $this->prepare_value_for_response( $row, $request, $args );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,6 +283,10 @@ abstract class WP_REST_Meta_Fields {
|
|||
$current_values = get_metadata( $meta_type, $object_id, $meta_key, false );
|
||||
$subtype = get_object_subtype( $meta_type, $object_id );
|
||||
|
||||
if ( ! is_array( $current_values ) ) {
|
||||
$current_values = array();
|
||||
}
|
||||
|
||||
$to_remove = $current_values;
|
||||
$to_add = $values;
|
||||
|
||||
|
@ -377,7 +383,9 @@ abstract class WP_REST_Meta_Fields {
|
|||
$old_value = get_metadata( $meta_type, $object_id, $meta_key );
|
||||
$subtype = get_object_subtype( $meta_type, $object_id );
|
||||
|
||||
if ( 1 === count( $old_value ) && $this->is_meta_value_same_as_stored_value( $meta_key, $subtype, $old_value[0], $value ) ) {
|
||||
if ( is_array( $old_value ) && 1 === count( $old_value )
|
||||
&& $this->is_meta_value_same_as_stored_value( $meta_key, $subtype, $old_value[0], $value )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.8-alpha-50792';
|
||||
$wp_version = '5.8-alpha-50793';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue