WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/18/2018 05:17:23 AM (3 years ago)
Author:
dd32
Message:

General: Allow wp_list_pluck() to operate on arrays of references without overwriting the referenced items.

Fixes #16895.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-list-util.php

    r42343 r42527  
    141141     */
    142142    public function pluck( $field, $index_key = null ) {
     143        $newlist = array();
     144
    143145        if ( ! $index_key ) {
    144146            /*
     
    148150            foreach ( $this->output as $key => $value ) {
    149151                if ( is_object( $value ) ) {
    150                     $this->output[ $key ] = $value->$field;
     152                    $newlist[ $key ] = $value->$field;
    151153                } else {
    152                     $this->output[ $key ] = $value[ $field ];
    153                 }
    154             }
     154                    $newlist[ $key ] = $value[ $field ];
     155                }
     156            }
     157
     158            $this->output = $newlist;
     159
    155160            return $this->output;
    156161        }
     
    160165         * to the end of the stack. This is how array_column() behaves.
    161166         */
    162         $newlist = array();
    163167        foreach ( $this->output as $value ) {
    164168            if ( is_object( $value ) ) {
Note: See TracChangeset for help on using the changeset viewer.