From 22fc19e06db68fb0e6afaeb00230e24aab5e4621 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 13 Feb 2015 16:26:37 +0000 Subject: [PATCH] Return a `WP_Error` if an empty name is provided when registering a taxonomy. Fixes #31135 Props tyxla, MikeHansenMe git-svn-id: https://develop.svn.wordpress.org/trunk@31449 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/taxonomy.php | 6 +++--- tests/phpunit/tests/taxonomy.php | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 2f8cef9a8c..71c422d60b 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -345,9 +345,9 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { ); $args = wp_parse_args( $args, $defaults ); - if ( strlen( $taxonomy ) > 32 ) { - _doing_it_wrong( __FUNCTION__, __( 'Taxonomies cannot exceed 32 characters in length' ), '4.0' ); - return new WP_Error( 'taxonomy_too_long', __( 'Taxonomies cannot exceed 32 characters in length' ) ); + if ( empty( $taxonomy ) || strlen( $taxonomy ) > 32 ) { + _doing_it_wrong( __FUNCTION__, __( 'Taxonomy names must be between 1 and 32 characters in length.' ), '4.2' ); + return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomy names must be between 1 and 32 characters in length.' ) ); } if ( false !== $args['query_var'] && ! empty( $wp ) ) { diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index dc153926b8..529b18cf74 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -153,6 +153,15 @@ class Tests_Taxonomy extends WP_UnitTestCase { unset($GLOBALS['wp_taxonomies'][$tax]); } + /** + * @ticket 31135 + * + * @expectedIncorrectUsage register_taxonomy + */ + function test_register_short_taxonomy() { + $this->assertInstanceOf( 'WP_Error', register_taxonomy( '', 'post', array() ) ); + } + /** * @ticket 21593 *