A negative term parent value should be sanitized to 0, not 1. Fix a regression in sanitize_term_field() caused by [26010].
props mattheu for initial patch. fixes #25852. git-svn-id: https://develop.svn.wordpress.org/trunk@26028 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2564c74a57
commit
fc8d09e2a6
@ -1710,8 +1710,11 @@ function sanitize_term($term, $taxonomy, $context = 'display') {
|
|||||||
*/
|
*/
|
||||||
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) {
|
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) {
|
||||||
$int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' );
|
$int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' );
|
||||||
if ( in_array( $field, $int_fields ) )
|
if ( in_array( $field, $int_fields ) ) {
|
||||||
$value = absint( $value );
|
$value = (int) $value;
|
||||||
|
if ( $value < 0 )
|
||||||
|
$value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ( 'raw' == $context )
|
if ( 'raw' == $context )
|
||||||
return $value;
|
return $value;
|
||||||
|
@ -433,6 +433,9 @@ class Tests_Term extends WP_UnitTestCase {
|
|||||||
unset( $GLOBALS['wp_taxonomies'][ $random_tax ] );
|
unset( $GLOBALS['wp_taxonomies'][ $random_tax ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 17646
|
||||||
|
*/
|
||||||
function test_get_object_terms_types() {
|
function test_get_object_terms_types() {
|
||||||
$post_id = $this->factory->post->create();
|
$post_id = $this->factory->post->create();
|
||||||
$term = wp_insert_term( 'one', $this->taxonomy );
|
$term = wp_insert_term( 'one', $this->taxonomy );
|
||||||
@ -447,6 +450,18 @@ class Tests_Term extends WP_UnitTestCase {
|
|||||||
$this->assertInternalType( 'int', $term, 'term' );
|
$this->assertInternalType( 'int', $term, 'term' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 25852
|
||||||
|
*/
|
||||||
|
function test_sanitize_term_field() {
|
||||||
|
$term = wp_insert_term( 'foo', $this->taxonomy );
|
||||||
|
|
||||||
|
$this->assertEquals( 0, sanitize_term_field( 'parent', 0, $term['term_id'], $this->taxonomy, 'raw' ) );
|
||||||
|
$this->assertEquals( 1, sanitize_term_field( 'parent', 1, $term['term_id'], $this->taxonomy, 'raw' ) );
|
||||||
|
$this->assertEquals( 0, sanitize_term_field( 'parent', -1, $term['term_id'], $this->taxonomy, 'raw' ) );
|
||||||
|
$this->assertEquals( 0, sanitize_term_field( 'parent', '', $term['term_id'], $this->taxonomy, 'raw' ) );
|
||||||
|
}
|
||||||
|
|
||||||
private function assertPostHasTerms( $post_id, $expected_term_ids, $taxonomy ) {
|
private function assertPostHasTerms( $post_id, $expected_term_ids, $taxonomy ) {
|
||||||
$assigned_term_ids = wp_get_object_terms( $post_id, $taxonomy, array(
|
$assigned_term_ids = wp_get_object_terms( $post_id, $taxonomy, array(
|
||||||
'fields' => 'ids'
|
'fields' => 'ids'
|
||||||
|
Loading…
Reference in New Issue
Block a user