Changeset 57698
- Timestamp:
- 02/22/2024 09:50:10 PM (8 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-list-util.php
r56549 r57698 166 166 foreach ( $this->output as $key => $value ) { 167 167 if ( is_object( $value ) ) { 168 $newlist[ $key ] = $value->$field; 168 if ( property_exists( $value, $field ) ) { 169 $newlist[ $key ] = $value->$field; 170 } 169 171 } elseif ( is_array( $value ) ) { 170 $newlist[ $key ] = $value[ $field ]; 172 if ( array_key_exists( $field, $value ) ) { 173 $newlist[ $key ] = $value[ $field ]; 174 } 171 175 } else { 172 176 _doing_it_wrong( … … 189 193 foreach ( $this->output as $value ) { 190 194 if ( is_object( $value ) ) { 191 if ( isset( $value->$index_key ) ) { 192 $newlist[ $value->$index_key ] = $value->$field; 193 } else { 194 $newlist[] = $value->$field; 195 if ( property_exists( $value, $field ) ) { 196 if ( property_exists( $value, $index_key ) ) { 197 $newlist[ $value->$index_key ] = $value->$field; 198 } else { 199 $newlist[] = $value->$field; 200 } 195 201 } 196 202 } elseif ( is_array( $value ) ) { 197 if ( isset( $value[ $index_key ] ) ) { 198 $newlist[ $value[ $index_key ] ] = $value[ $field ]; 199 } else { 200 $newlist[] = $value[ $field ]; 203 if ( array_key_exists( $field, $value ) ) { 204 if ( array_key_exists( $index_key, $value ) ) { 205 $newlist[ $value[ $index_key ] ] = $value[ $field ]; 206 } else { 207 $newlist[] = $value[ $field ]; 208 } 201 209 } 202 210 } else { -
trunk/tests/phpunit/tests/functions/wpListPluck.php
r56971 r57698 272 272 ), 273 273 array( 274 'foo' => 'foo',275 274 '123' => '456', 276 275 'lorem' => 'ipsum', … … 286 285 array( 287 286 'bar', 288 'bar' => 'foo',289 287 'value' => 'baz', 288 ), 289 ), 290 'arrays with key missing' => array( 291 array( 292 array( 293 'foo' => 'bar', 294 'bar' => 'baz', 295 'abc' => 'xyz', 296 ), 297 array( 298 'foo' => 'foo', 299 '123' => '456', 300 'lorem' => 'ipsum', 301 'key' => 'bar', 302 ), 303 array( 304 'foo' => 'baz', 305 'key' => 'value', 306 ), 307 ), 308 'key', 309 null, 310 array( 311 1 => 'bar', 312 2 => 'value', 290 313 ), 291 314 ), … … 343 366 ), 344 367 (object) array( 345 'foo' => 'foo',346 368 '123' => '456', 347 369 'lorem' => 'ipsum', … … 357 379 array( 358 380 'bar', 359 'bar' => 'foo',360 381 'value' => 'baz', 361 382 ), 362 383 ), 384 'objects with field missing' => array( 385 array( 386 (object) array( 387 'foo' => 'bar', 388 'bar' => 'baz', 389 'abc' => 'xyz', 390 ), 391 (object) array( 392 'foo' => 'foo', 393 '123' => '456', 394 'lorem' => 'ipsum', 395 'key' => 'bar', 396 ), 397 (object) array( 398 'foo' => 'baz', 399 'key' => 'value', 400 ), 401 ), 402 'key', 403 null, 404 array( 405 1 => 'bar', 406 2 => 'value', 407 ), 408 ), 363 409 ); 364 410 }
Note: See TracChangeset
for help on using the changeset viewer.