Avoid database error when `include` or `exclude` is not really a `term_id`. Adds more unit tests.
Props kovshenin. Fixes #11823. git-svn-id: https://develop.svn.wordpress.org/trunk@25257 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4286692d7d
commit
e8c7634e79
|
@ -1310,9 +1310,10 @@ function get_terms($taxonomies, $args = '') {
|
||||||
$inclusions = implode( ',', wp_parse_id_list( $include ) );
|
$inclusions = implode( ',', wp_parse_id_list( $include ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $inclusions ) )
|
if ( ! empty( $inclusions ) ) {
|
||||||
$inclusions = ' AND t.term_id IN ( ' . $inclusions . ' )';
|
$inclusions = ' AND t.term_id IN ( ' . $inclusions . ' )';
|
||||||
$where .= $inclusions;
|
$where .= $inclusions;
|
||||||
|
}
|
||||||
|
|
||||||
$exclusions = '';
|
$exclusions = '';
|
||||||
if ( ! empty( $exclude_tree ) ) {
|
if ( ! empty( $exclude_tree ) ) {
|
||||||
|
@ -1339,6 +1340,8 @@ function get_terms($taxonomies, $args = '') {
|
||||||
$exclusions = ' AND t.term_id NOT IN (' . $exclusions . ')';
|
$exclusions = ' AND t.term_id NOT IN (' . $exclusions . ')';
|
||||||
|
|
||||||
$exclusions = apply_filters( 'list_terms_exclusions', $exclusions, $args );
|
$exclusions = apply_filters( 'list_terms_exclusions', $exclusions, $args );
|
||||||
|
|
||||||
|
if ( ! empty( $exclusions ) )
|
||||||
$where .= $exclusions;
|
$where .= $exclusions;
|
||||||
|
|
||||||
if ( !empty($slug) ) {
|
if ( !empty($slug) ) {
|
||||||
|
|
|
@ -121,10 +121,11 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ti
|
* @ticket 11823
|
||||||
* cket 11823
|
|
||||||
*/
|
*/
|
||||||
function test_get_terms_include_exclude() {
|
function test_get_terms_include_exclude() {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
$term_id1 = $this->factory->tag->create();
|
$term_id1 = $this->factory->tag->create();
|
||||||
$term_id2 = $this->factory->tag->create();
|
$term_id2 = $this->factory->tag->create();
|
||||||
$inc_terms = get_terms( 'post_tag', array(
|
$inc_terms = get_terms( 'post_tag', array(
|
||||||
|
@ -138,6 +139,16 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||||
'hide_empty' => false
|
'hide_empty' => false
|
||||||
) );
|
) );
|
||||||
$this->assertEquals( array(), wp_list_pluck( $exc_terms, 'term_id' ) );
|
$this->assertEquals( array(), wp_list_pluck( $exc_terms, 'term_id' ) );
|
||||||
|
|
||||||
|
// These should not generate query errors.
|
||||||
|
get_terms( 'post_tag', array( 'exclude' => array( 0 ), 'hide_empty' => false ) );
|
||||||
|
$this->assertEmpty( $wpdb->last_error );
|
||||||
|
|
||||||
|
get_terms( 'post_tag', array( 'exclude' => array( 'unexpected-string' ), 'hide_empty' => false ) );
|
||||||
|
$this->assertEmpty( $wpdb->last_error );
|
||||||
|
|
||||||
|
get_terms( 'post_tag', array( 'include' => array( 'unexpected-string' ), 'hide_empty' => false ) );
|
||||||
|
$this->assertEmpty( $wpdb->last_error );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue