Ticket #36949: 36949.2.diff
File 36949.2.diff, 5.0 KB (added by , 6 years ago) |
---|
-
src/wp-includes/class-wp-term-query.php
204 204 'parent' => '', 205 205 'childless' => false, 206 206 'cache_domain' => 'core', 207 'cached_results' => true, 207 208 'update_term_meta_cache' => true, 208 209 'meta_query' => '', 209 210 'meta_key' => '', … … 676 677 $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request ); 677 678 $last_changed = wp_cache_get_last_changed( 'terms' ); 678 679 $cache_key = "get_terms:$key:$last_changed"; 679 $cache = wp_cache_get( $cache_key, 'terms' ); 680 $cache = false; 681 if ( $args['cached_results'] ) { 682 $cache = wp_cache_get( $cache_key, 'terms' ); 683 } 680 684 if ( false !== $cache ) { 681 685 if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) { 682 686 $cache = $this->populate_terms( $cache ); -
src/wp-includes/taxonomy.php
1354 1354 * 1355 1355 * @since 3.0.0 1356 1356 * 1357 * @global wpdb $wpdb WordPress database abstraction object.1358 1357 * 1359 1358 * @param int|string $term The term to check. Accepts term ID, slug, or name. 1360 1359 * @param string $taxonomy The taxonomy name to use … … 1365 1364 * is specified and the pairing exists. 1366 1365 */ 1367 1366 function term_exists( $term, $taxonomy = '', $parent = null ) { 1368 global $wpdb;1369 1370 $select = "SELECT term_id FROM $wpdb->terms as t WHERE ";1371 $tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE ";1372 1373 1367 if ( is_int( $term ) ) { 1374 1368 if ( 0 == $term ) { 1375 1369 return 0; 1376 1370 } 1377 $where = 't.term_id = %d'; 1371 $_term = get_term( $term, $taxonomy ); 1372 if ( is_wp_error( $_term ) || is_null( $_term ) ) { 1373 return null; 1374 } 1378 1375 if ( ! empty( $taxonomy ) ) { 1379 return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . ' AND tt.taxonomy = %s', $term, $taxonomy ), ARRAY_A ); 1380 } else { 1381 return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) ); 1376 return array( 1377 'term_id' => (string) $_term->term_id, 1378 'term_taxonomy_id' => (string) $_term->term_taxonomy_id, 1379 ); 1382 1380 } 1381 return (string) $_term->term_id; 1383 1382 } 1384 1383 1385 1384 $term = trim( wp_unslash( $term ) ); 1386 $slug = sanitize_title( $term ); 1385 if ( empty( $term ) ) { 1386 return null; 1387 } 1387 1388 1388 $where = 't.slug = %s'; 1389 $else_where = 't.name = %s'; 1390 $where_fields = array( $slug ); 1391 $else_where_fields = array( $term ); 1392 $orderby = 'ORDER BY t.term_id ASC'; 1393 $limit = 'LIMIT 1'; 1389 $defaults = array( 1390 'get' => 'all', 1391 'hide_empty' => false, 1392 'number' => 1, 1393 'update_term_meta_cache' => false, 1394 'orderby' => 'term_id', 1395 'suppress_filter' => true, 1396 'cached_results' => false, 1397 ); 1398 1399 if ( is_numeric( $parent ) ) { 1400 $defaults['parent'] = (int) $parent; 1401 } 1394 1402 if ( ! empty( $taxonomy ) ) { 1395 if ( is_numeric( $parent ) ) { 1396 $parent = (int) $parent; 1397 $where_fields[] = $parent; 1398 $else_where_fields[] = $parent; 1399 $where .= ' AND tt.parent = %d'; 1400 $else_where .= ' AND tt.parent = %d'; 1403 $defaults['taxonomy'] = $taxonomy; 1404 } 1405 $args = wp_parse_args( array( 'slug' => $term ), $defaults ); 1406 $terms = get_terms( $args ); 1407 if ( empty( $terms ) || is_wp_error( $terms ) ) { 1408 $args = wp_parse_args( array( 'name' => $term ), $defaults ); 1409 $terms = get_terms( $args ); 1410 if ( empty( $terms ) || is_wp_error( $terms ) ) { 1411 return null; 1401 1412 } 1402 1403 $where_fields[] = $taxonomy;1404 $else_where_fields[] = $taxonomy;1405 1406 if ( $result = $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields ), ARRAY_A ) ) {1407 return $result;1408 }1409 1410 return $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields ), ARRAY_A );1411 1413 } 1414 $_term = array_shift( $terms ); 1412 1415 1413 if ( $result = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields ) ) ) { 1414 return $result; 1416 if ( ! empty( $taxonomy ) ) { 1417 return array( 1418 'term_id' => (string) $_term->term_id, 1419 'term_taxonomy_id' => (string) $_term->term_taxonomy_id, 1420 ); 1415 1421 } 1416 1422 1417 return $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields ) );1423 return (string) $_term->term_id; 1418 1424 } 1419 1425 1420 1426 /**