Make WordPress Core

Ticket #36949: 36949.diff

File 36949.diff, 6.0 KB (added by spacedmonkey, 6 years ago)
  • src/wp-includes/class-wp-term-query.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    253253                        $query['child_of'] = false;
    254254                }
    255255
     256                // If importing, change cache domain, so all calls are uncached.
     257                if ( defined( 'WP_IMPORTING' ) ) {
     258                        $query['cache_domain'] = microtime( true );
     259                }
     260
    256261                if ( 'all' == $query['get'] ) {
    257262                        $query['childless']    = false;
    258263                        $query['child_of']     = 0;
  • src/wp-includes/taxonomy.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    13541354 *
    13551355 * @since 3.0.0
    13561356 *
    1357  * @global wpdb $wpdb WordPress database abstraction object.
    13581357 *
    13591358 * @param int|string $term     The term to check. Accepts term ID, slug, or name.
    13601359 * @param string     $taxonomy The taxonomy name to use
     
    13651364 *               is specified and the pairing exists.
    13661365 */
    13671366function 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 
    13731367        if ( is_int( $term ) ) {
    13741368                if ( 0 == $term ) {
    13751369                        return 0;
    13761370                }
    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                }
    13781375                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                        );
    13821380                }
     1381                return (string) $_term->term_id;
    13831382        }
    13841383
    13851384        $term = trim( wp_unslash( $term ) );
    1386         $slug = sanitize_title( $term );
     1385        if ( empty( $term ) ) {
     1386                return null;
     1387        }
    13871388
    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        );
     1397
     1398        if ( is_numeric( $parent ) ) {
     1399                $defaults['parent'] = (int) $parent;
     1400        }
    13941401        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';
    1401                 }
    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;
     1402                $defaults['taxonomy'] = $taxonomy;
     1403        }
     1404        $args  = wp_parse_args( array( 'slug' => $term ), $defaults );
     1405        $terms = get_terms( $args );
     1406        if ( empty( $terms ) || is_wp_error( $terms ) ) {
     1407                $args  = wp_parse_args( array( 'name' => $term ), $defaults );
     1408                $terms = get_terms( $args );
     1409                if ( empty( $terms ) || is_wp_error( $terms ) ) {
     1410                        return null;
    14081411                }
    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 );
    14111412        }
     1413        $_term = array_shift( $terms );
    14121414
    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;
     1415        if ( ! empty( $taxonomy ) ) {
     1416                return array(
     1417                        'term_id'          => (string) $_term->term_id,
     1418                        'term_taxonomy_id' => (string) $_term->term_taxonomy_id,
     1419                );
    14151420        }
    14161421
    1417         return $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields ) );
     1422        return (string) $_term->term_id;
    14181423}
    14191424
    14201425/**
  • tests/phpunit/tests/term/getTerm.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    3131                        array( '%d' )
    3232                );
    3333
     34                clean_term_cache( $t1['term_id'], 'wptests_tax' );
     35
    3436                return array(
    3537                        array(
    3638                                'term_id'          => $t1['term_id'],
  • tests/phpunit/tests/term/wpGetObjectTerms.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    447447                $wpdb->update( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => 100006 ), array( 'term_taxonomy_id' => $term_2->term_taxonomy_id ) );
    448448                $wpdb->update( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => 100005 ), array( 'term_taxonomy_id' => $term_3->term_taxonomy_id ) );
    449449
     450                // After update, clear caches.
     451                clean_term_cache( array( $term_1->term_id, $term_2->term_id, $term_3->term_id ), $this->taxonomy );
     452
    450453                $set = wp_set_object_terms( $p, array( $t1, $t2, $t3 ), $this->taxonomy );
    451454
    452455                $found = wp_get_object_terms(