Changeset 47557 for trunk/src/wp-includes/taxonomy.php
- Timestamp:
- 04/09/2020 03:41:04 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r47550 r47557 2469 2469 2470 2470 $term_info = term_exists( $term, $taxonomy ); 2471 2471 2472 if ( ! $term_info ) { 2472 2473 // Skip if a non-existent term ID is passed. … … 2474 2475 continue; 2475 2476 } 2477 2476 2478 $term_info = wp_insert_term( $term, $taxonomy ); 2477 2479 } 2480 2478 2481 if ( is_wp_error( $term_info ) ) { 2479 2482 return $term_info; 2480 2483 } 2484 2481 2485 $term_ids[] = $term_info['term_id']; 2482 2486 $tt_id = $term_info['term_taxonomy_id']; … … 2498 2502 */ 2499 2503 do_action( 'add_term_relationship', $object_id, $tt_id, $taxonomy ); 2504 2500 2505 $wpdb->insert( 2501 2506 $wpdb->term_relationships, … … 2517 2522 */ 2518 2523 do_action( 'added_term_relationship', $object_id, $tt_id, $taxonomy ); 2524 2519 2525 $new_tt_ids[] = $tt_id; 2520 2526 } … … 2540 2546 2541 2547 $t = get_taxonomy( $taxonomy ); 2548 2542 2549 if ( ! $append && isset( $t->sort ) && $t->sort ) { 2543 $values = array(); 2544 $term_order = 0; 2550 $values = array(); 2551 $term_order = 0; 2552 2545 2553 $final_tt_ids = wp_get_object_terms( 2546 2554 $object_id, … … 2551 2559 ) 2552 2560 ); 2561 2553 2562 foreach ( $tt_ids as $tt_id ) { 2554 if ( in_array( $tt_id, $final_tt_ids) ) {2563 if ( in_array( (int) $tt_id, $final_tt_ids, true ) ) { 2555 2564 $values[] = $wpdb->prepare( '(%d, %d, %d)', $object_id, $tt_id, ++$term_order ); 2556 2565 } 2557 2566 } 2567 2558 2568 if ( $values ) { 2559 2569 if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . ' ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)' ) ) { … … 2579 2589 */ 2580 2590 do_action( 'set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ); 2591 2581 2592 return $tt_ids; 2582 2593 } … … 3617 3628 $object_types = esc_sql( $tax_obj->object_type ); 3618 3629 $results = $wpdb->get_results( "SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode( ',', array_keys( $term_ids ) ) . ") AND post_type IN ('" . implode( "', '", $object_types ) . "') AND post_status = 'publish'" ); 3630 3619 3631 foreach ( $results as $row ) { 3620 $id = $term_ids[ $row->term_taxonomy_id ]; 3632 $id = $term_ids[ $row->term_taxonomy_id ]; 3633 3621 3634 $term_items[ $id ][ $row->object_id ] = isset( $term_items[ $id ][ $row->object_id ] ) ? ++$term_items[ $id ][ $row->object_id ] : 1; 3622 3635 } … … 3628 3641 while ( ! empty( $terms_by_id[ $child ] ) && $parent = $terms_by_id[ $child ]->parent ) { 3629 3642 $ancestors[] = $child; 3643 3630 3644 if ( ! empty( $term_items[ $term_id ] ) ) { 3631 3645 foreach ( $term_items[ $term_id ] as $item_id => $touches ) { … … 3633 3647 } 3634 3648 } 3649 3635 3650 $child = $parent; 3636 3651 3637 if ( in_array( $parent, $ancestors ) ) {3652 if ( in_array( $parent, $ancestors, true ) ) { 3638 3653 break; 3639 3654 } … … 4523 4538 if ( 'taxonomy' === $resource_type ) { 4524 4539 $term = get_term( $object_id, $object_type ); 4525 while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {4540 while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors, true ) ) { 4526 4541 $ancestors[] = (int) $term->parent; 4527 4542 $term = get_term( $term->parent, $object_type );
Note: See TracChangeset
for help on using the changeset viewer.