Ensure 'description' is a string in wp_insert_term()
.
Passing `'description' => null` when creating a term can cause MySQL notices, as the description column in the terms table does not allow for null values. We correct this by intepreting a `null` description as an empty string. Props TimothyBlynJacobs. Fixes #35321. git-svn-id: https://develop.svn.wordpress.org/trunk@36214 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c67abd1c66
commit
3a9bc32949
@ -2579,8 +2579,13 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
|
||||
if ( $args['parent'] > 0 && ! term_exists( (int) $args['parent'] ) ) {
|
||||
return new WP_Error( 'missing_parent', __( 'Parent term does not exist.' ) );
|
||||
}
|
||||
|
||||
$args['name'] = $term;
|
||||
$args['taxonomy'] = $taxonomy;
|
||||
|
||||
// Coerce null description to strings, to avoid database errors.
|
||||
$args['description'] = (string) $args['description'];
|
||||
|
||||
$args = sanitize_term($args, $taxonomy, 'db');
|
||||
|
||||
// expected_slashed ($name)
|
||||
|
@ -642,6 +642,23 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35321
|
||||
*/
|
||||
public function test_wp_insert_term_with_null_description() {
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$term = wp_insert_term( 'foo', 'wptests_tax', array(
|
||||
'description' => null
|
||||
) );
|
||||
|
||||
$term_object = get_term( $term['term_id'] );
|
||||
|
||||
$this->assertInstanceOf( 'WP_Term', $term_object );
|
||||
$this->assertSame( '', $term_object->description );
|
||||
}
|
||||
|
||||
/** Helpers **********************************************************/
|
||||
|
||||
public function deleted_term_cb( $term, $tt_id, $taxonomy, $deleted_term, $object_ids ) {
|
||||
|
Loading…
Reference in New Issue
Block a user