Changeset 42527
- Timestamp:
- 01/18/2018 05:17:23 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-list-util.php
r42343 r42527 141 141 */ 142 142 public function pluck( $field, $index_key = null ) { 143 $newlist = array(); 144 143 145 if ( ! $index_key ) { 144 146 /* … … 148 150 foreach ( $this->output as $key => $value ) { 149 151 if ( is_object( $value ) ) { 150 $ this->output[ $key ] = $value->$field;152 $newlist[ $key ] = $value->$field; 151 153 } else { 152 $this->output[ $key ] = $value[ $field ]; 153 } 154 } 154 $newlist[ $key ] = $value[ $field ]; 155 } 156 } 157 158 $this->output = $newlist; 159 155 160 return $this->output; 156 161 } … … 160 165 * to the end of the stack. This is how array_column() behaves. 161 166 */ 162 $newlist = array();163 167 foreach ( $this->output as $value ) { 164 168 if ( is_object( $value ) ) { -
trunk/tests/phpunit/tests/functions/listFilter.php
r42526 r42527 211 211 } 212 212 213 /** 214 * @ticket 16895 215 */ 216 function test_wp_list_pluck_containing_references() { 217 $ref_list = array( 218 & $this->object_list['foo'], 219 & $this->object_list['bar'], 220 ); 221 222 $this->assertInstanceOf( 'stdClass', $ref_list[0] ); 223 $this->assertInstanceOf( 'stdClass', $ref_list[1] ); 224 225 $list = wp_list_pluck( $ref_list, 'name' ); 226 $this->assertEquals( 227 array( 228 'foo', 229 'bar', 230 ), 231 $list 232 ); 233 234 $this->assertInstanceOf( 'stdClass', $ref_list[0] ); 235 $this->assertInstanceOf( 'stdClass', $ref_list[1] ); 236 } 237 238 /** 239 * @ticket 16895 240 */ 241 function test_wp_list_pluck_containing_references_keys() { 242 $ref_list = array( 243 & $this->object_list['foo'], 244 & $this->object_list['bar'], 245 ); 246 247 $this->assertInstanceOf( 'stdClass', $ref_list[0] ); 248 $this->assertInstanceOf( 'stdClass', $ref_list[1] ); 249 250 $list = wp_list_pluck( $ref_list, 'name', 'id' ); 251 $this->assertEquals( 252 array( 253 'f' => 'foo', 254 'b' => 'bar', 255 ), 256 $list 257 ); 258 259 $this->assertInstanceOf( 'stdClass', $ref_list[0] ); 260 $this->assertInstanceOf( 'stdClass', $ref_list[1] ); 261 } 262 213 263 function test_filter_object_list_nested_array_and() { 214 264 $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND' );
Note: See TracChangeset
for help on using the changeset viewer.