From 4004400047d5b6e16b889ea23563f37c6dad3e5f Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 6 Feb 2017 19:38:36 +0000 Subject: [PATCH] Taxonomy: Disallow overriding the `name` property when registering a taxonomy. Props wpfo for initial patch. Fixes #39308. git-svn-id: https://develop.svn.wordpress.org/trunk@40049 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-taxonomy.php | 2 ++ tests/phpunit/tests/taxonomy.php | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/wp-includes/class-wp-taxonomy.php b/src/wp-includes/class-wp-taxonomy.php index 4611ce9744..3a69b76551 100644 --- a/src/wp-includes/class-wp-taxonomy.php +++ b/src/wp-includes/class-wp-taxonomy.php @@ -333,6 +333,8 @@ final class WP_Taxonomy { } } + $args['name'] = $this->name; + foreach ( $args as $property_name => $property_value ) { $this->$property_name = $property_value; } diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index ca317bb395..9a4e8b2a0f 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -710,4 +710,15 @@ class Tests_Taxonomy extends WP_UnitTestCase { $this->assertFalse( taxonomy_exists( 'foo' ) ); } + /** + * @ticket 39308 + */ + public function test_taxonomy_name_property_should_not_get_overridden_by_passed_args() { + register_taxonomy( 'foo', 'post', array( 'name' => 'bar' ) ); + + $taxonomy = get_taxonomy( 'foo' ); + unregister_taxonomy( 'foo' ); + + $this->assertSame( 'foo', $taxonomy->name ); + } }