Objects are passed by-reference since PHP 5. In `_get_custom_object_labels()`, cast `$object->labels` back to `object` before returning. This function is weird.

Adds unit test.

Props Toro_Unit.
Fixes #33023.


git-svn-id: https://develop.svn.wordpress.org/trunk@34102 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-09-14 01:22:23 +00:00
parent 5a93988ca3
commit 184e058681
2 changed files with 19 additions and 0 deletions

View File

@ -1393,6 +1393,8 @@ function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
$defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
}
$labels = array_merge( $defaults, $object->labels );
$object->labels = (object) $object->labels;
return (object) $labels;
}

View File

@ -142,4 +142,21 @@ class Tests_Post_Types extends WP_UnitTestCase {
$this->assertFalse( post_type_exists( 'foo' ) );
}
/**
* @ticket 33023
*/
public function test_get_post_type_object_casting() {
register_post_type( 'foo' );
$before = get_post_type_object( 'foo' )->labels;
get_post_type_labels( get_post_type_object( 'foo' ) );
$after = get_post_type_object( 'foo' )->labels;
$this->assertEquals( $before, $after );
_unregister_post_type( 'foo' );
}
}