General: Handle missing field in WP_List_Util::pluck().
Handles when the `$field` (i.e. key or property) is missing in one of the `$input_list` items by checking the key (array) or property (object) exists before using it for assignment. Resolves the following bugs: * a PHP warning for undefined key|property. * `null` being set for that array or object within the returned list. The changes resolve the issues in both `WP_List_Util::pluck()` (if invoked directly) and `wp_list_pluck()`. Also includes an additional test for the scenario where the `wp_list_pluck()` `$index_key` is not `null`, the `$field` is missing in one of the `$input_list` items. Follow-up to [55423], [51663], [42527], [38928]. Props iamarunchaitanyajami, davidbinda, hellofromTonya, helgatheviking. Fixes #59774. Built from https://develop.svn.wordpress.org/trunk@57698 git-svn-id: http://core.svn.wordpress.org/trunk@57199 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0006dd82d8
commit
648cab6abe
|
@ -165,9 +165,13 @@ 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;
|
if ( property_exists( $value, $field ) ) {
|
||||||
|
$newlist[ $key ] = $value->$field;
|
||||||
|
}
|
||||||
} elseif ( is_array( $value ) ) {
|
} elseif ( is_array( $value ) ) {
|
||||||
$newlist[ $key ] = $value[ $field ];
|
if ( array_key_exists( $field, $value ) ) {
|
||||||
|
$newlist[ $key ] = $value[ $field ];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_doing_it_wrong(
|
_doing_it_wrong(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
|
@ -188,16 +192,20 @@ class WP_List_Util {
|
||||||
*/
|
*/
|
||||||
foreach ( $this->output as $value ) {
|
foreach ( $this->output as $value ) {
|
||||||
if ( is_object( $value ) ) {
|
if ( is_object( $value ) ) {
|
||||||
if ( isset( $value->$index_key ) ) {
|
if ( property_exists( $value, $field ) ) {
|
||||||
$newlist[ $value->$index_key ] = $value->$field;
|
if ( property_exists( $value, $index_key ) ) {
|
||||||
} else {
|
$newlist[ $value->$index_key ] = $value->$field;
|
||||||
$newlist[] = $value->$field;
|
} else {
|
||||||
|
$newlist[] = $value->$field;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elseif ( is_array( $value ) ) {
|
} elseif ( is_array( $value ) ) {
|
||||||
if ( isset( $value[ $index_key ] ) ) {
|
if ( array_key_exists( $field, $value ) ) {
|
||||||
$newlist[ $value[ $index_key ] ] = $value[ $field ];
|
if ( array_key_exists( $index_key, $value ) ) {
|
||||||
} else {
|
$newlist[ $value[ $index_key ] ] = $value[ $field ];
|
||||||
$newlist[] = $value[ $field ];
|
} else {
|
||||||
|
$newlist[] = $value[ $field ];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_doing_it_wrong(
|
_doing_it_wrong(
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.5-beta2-57697';
|
$wp_version = '6.5-beta2-57698';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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