Make WordPress Core

Ticket #31135: 31135.2.patch

File 31135.2.patch, 1.8 KB (added by tyxla, 10 years ago)

Updating the first patch. Now using a single _doing_it_wrong() call for both taxonomy min and max, also adding unit tests for both cases.

  • src/wp-includes/taxonomy.php

     
    341341        );
    342342        $args = wp_parse_args( $args, $defaults );
    343343
    344         if ( strlen( $taxonomy ) > 32 ) {
    345                 _doing_it_wrong( __FUNCTION__, __( 'Taxonomies cannot exceed 32 characters in length' ), '4.0' );
    346                 return new WP_Error( 'taxonomy_too_long', __( 'Taxonomies cannot exceed 32 characters in length' ) );
     344        $taxonomy_length = strlen( $taxonomy );
     345        if ( $taxonomy_length < 1 || $taxonomy_length > 32 ) {
     346                _doing_it_wrong( __FUNCTION__, __( 'Taxonomies must be between 1 and 32 characters in length.' ), '4.2' );
     347                return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomies must be between 1 and 32 characters in length.' ) );
    347348        }
    348349
    349350        if ( false !== $args['query_var'] && ! empty( $wp ) ) {
  • tests/phpunit/tests/taxonomy.php

     
    137137
    138138                // clean up
    139139                unset($GLOBALS['wp_taxonomies'][$tax]);
     140
     141                // @ticket 31135
     142                register_taxonomy( '', 'post' );
     143                $this->expected_doing_it_wrong[] = 'register_taxonomy';
     144                $this->assertFalse( taxonomy_exists( '' ) );
     145                unset($GLOBALS['wp_taxonomies']['']);
     146
     147                // @ticket 31135
     148                register_taxonomy( 'taxonomy_name_longer_than_32_characters', 'post' );
     149                $this->expected_doing_it_wrong[] = 'register_taxonomy';
     150                $this->assertFalse( taxonomy_exists( 'taxonomy_name_longer_than_32_characters' ) );
     151                unset($GLOBALS['wp_taxonomies']['taxonomy_name_longer_than_32_characters']);
    140152        }
    141153
    142154        function test_register_hierarchical_taxonomy() {