WordPress.org

Make WordPress Core

Changeset 29196


Ignore:
Timestamp:
07/16/2014 09:51:40 PM (6 years ago)
Author:
wonderboymusic
Message:

Avoid a race condition when multiple windows are open so that orphaned terms cannot be created by accident.

Adds a unit test.

Props dlh.
Fixes #19205.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r29129 r29196  
    24192419    }
    24202420    $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
    2421     $args = wp_parse_args($args, $defaults);
     2421    $args = wp_parse_args( $args, $defaults );
     2422
     2423    if ( $args['parent'] > 0 && ! term_exists( (int) $args['parent'] ) ) {
     2424        return new WP_Error( 'missing_parent', __( 'The selected parent term no longer exists' ) );
     2425    }
    24222426    $args['name'] = $term;
    24232427    $args['taxonomy'] = $taxonomy;
  • trunk/tests/phpunit/tests/term.php

    r28953 r29196  
    691691        $this->assertEquals( 'This description is even more amazing!', $terms[0]->description );
    692692    }
     693
     694    /**
     695     * @ticket 19205
     696     */
     697    function test_orphan_category() {
     698        $cat_id1 = $this->factory->category->create();
     699
     700        wp_delete_category( $cat_id1 );
     701
     702        $cat_id2 = $this->factory->category->create( array( 'parent' => $cat_id1 ) );
     703        $this->assertWPError( $cat_id2 );
     704    }
    693705}
Note: See TracChangeset for help on using the changeset viewer.