From 184e0586817f7968870a4c786ac98e08dc137ed7 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 14 Sep 2015 01:22:23 +0000 Subject: [PATCH] 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 --- src/wp-includes/post-functions.php | 2 ++ tests/phpunit/tests/post/types.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/wp-includes/post-functions.php b/src/wp-includes/post-functions.php index 1c410d7674..ea731753ac 100644 --- a/src/wp-includes/post-functions.php +++ b/src/wp-includes/post-functions.php @@ -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; } diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php index 5a1be694d8..02d4590da8 100644 --- a/tests/phpunit/tests/post/types.php +++ b/tests/phpunit/tests/post/types.php @@ -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' ); + } }