Opened 7 years ago
Closed 7 years ago
#35321 closed defect (bug) (fixed)
Inserting a term with a description of null results in the term being created, but not its relationship to a taxonomy
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | Cc: |
Description
Given the following:
<?php $t = wp_insert_term( 'Foo', 'bar', array( "description"=> null ) );
And given that bar
is a registered taxonomy:
With debug on, you get:
WordPress database error: [Column 'description' cannot be null] INSERT INTO `wp_term_taxonomy` (`term_id`, `taxonomy`, `description`, `parent`, `count`) VALUES (119, 'bar', NULL, 0, 0)
And otherwise it fails silently.
The problem: The term is still created! If you dump $t
you'll see:
Array ( [term_id] => 119 [term_taxonomy_id] => 0 )
Expected behavior: Return a WP_Error on the SQL failure rather than create a term without a taxonomy.
Attachments (2)
Change History (8)
#4
@
7 years ago
- Milestone changed from Awaiting Review to 4.5
Passing NULL
really is an odd thing here IMHO, however, as this previously worked I see no harm in casting it.
The other option would be something like this instead:
if ( ! $args['description'] ) { $args['description'] = ''; }
Note: See
TracTickets for help on using
tickets.
I disagree that a WP_Error should be returned, it seems like passing
NULL
should be allowed and converted to an empty string. Though there should probably be some discussion on what happens to the newly created term if the subsequent term taxonomy insert fails.