General: Add more error checking to WP_List_Util::pluck()
.
Values for the input array in `WP_List_Util::pluck()` or `wp_list_pluck()` must be either objects or arrays. This commit adds a check to ensure that the value retrieved in the loop is an array before treating it as such, and throws a `_doing_it_wrong()` notice if it is neither an object nor an array. Follow-up to [14108], [15686], [18602], [28900], [38928]. Props afragen, costdev, audrasjb. Fixes #56650. Built from https://develop.svn.wordpress.org/trunk@55423 git-svn-id: http://core.svn.wordpress.org/trunk@54956 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5f0e3de1f8
commit
66937c7dce
@ -166,8 +166,14 @@ class WP_List_Util {
|
|||||||
foreach ( $this->output as $key => $value ) {
|
foreach ( $this->output as $key => $value ) {
|
||||||
if ( is_object( $value ) ) {
|
if ( is_object( $value ) ) {
|
||||||
$newlist[ $key ] = $value->$field;
|
$newlist[ $key ] = $value->$field;
|
||||||
} else {
|
} elseif ( is_array( $value ) ) {
|
||||||
$newlist[ $key ] = $value[ $field ];
|
$newlist[ $key ] = $value[ $field ];
|
||||||
|
} else {
|
||||||
|
_doing_it_wrong(
|
||||||
|
__METHOD__,
|
||||||
|
__( 'Values for the input array must be either objects or arrays.' ),
|
||||||
|
'6.2.0'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,12 +193,18 @@ class WP_List_Util {
|
|||||||
} else {
|
} else {
|
||||||
$newlist[] = $value->$field;
|
$newlist[] = $value->$field;
|
||||||
}
|
}
|
||||||
} else {
|
} elseif ( is_array( $value ) ) {
|
||||||
if ( isset( $value[ $index_key ] ) ) {
|
if ( isset( $value[ $index_key ] ) ) {
|
||||||
$newlist[ $value[ $index_key ] ] = $value[ $field ];
|
$newlist[ $value[ $index_key ] ] = $value[ $field ];
|
||||||
} else {
|
} else {
|
||||||
$newlist[] = $value[ $field ];
|
$newlist[] = $value[ $field ];
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
_doing_it_wrong(
|
||||||
|
__METHOD__,
|
||||||
|
__( 'Values for the input array must be either objects or arrays.' ),
|
||||||
|
'6.2.0'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.2-beta3-55422';
|
$wp_version = '6.2-beta3-55423';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user