mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-16 11:35:48 +00:00
General: Allow wp_list_pluck()
to operate on arrays of references without overwriting the referenced items.
Fixes #16895. Built from https://develop.svn.wordpress.org/trunk@42527 git-svn-id: http://core.svn.wordpress.org/trunk@42356 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
26a5d758d5
commit
44c89cac5a
@ -140,6 +140,8 @@ class WP_List_Util {
|
||||
* `$list` will be preserved in the results.
|
||||
*/
|
||||
public function pluck( $field, $index_key = null ) {
|
||||
$newlist = array();
|
||||
|
||||
if ( ! $index_key ) {
|
||||
/*
|
||||
* This is simple. Could at some point wrap array_column()
|
||||
@ -147,11 +149,14 @@ class WP_List_Util {
|
||||
*/
|
||||
foreach ( $this->output as $key => $value ) {
|
||||
if ( is_object( $value ) ) {
|
||||
$this->output[ $key ] = $value->$field;
|
||||
$newlist[ $key ] = $value->$field;
|
||||
} else {
|
||||
$this->output[ $key ] = $value[ $field ];
|
||||
$newlist[ $key ] = $value[ $field ];
|
||||
}
|
||||
}
|
||||
|
||||
$this->output = $newlist;
|
||||
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
@ -159,7 +164,6 @@ class WP_List_Util {
|
||||
* When index_key is not set for a particular item, push the value
|
||||
* to the end of the stack. This is how array_column() behaves.
|
||||
*/
|
||||
$newlist = array();
|
||||
foreach ( $this->output as $value ) {
|
||||
if ( is_object( $value ) ) {
|
||||
if ( isset( $value->$index_key ) ) {
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.0-alpha-42526';
|
||||
$wp_version = '5.0-alpha-42527';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
x
Reference in New Issue
Block a user