Ticket #40436: 40436.1.diff
File 40436.1.diff, 4.9 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-taxonomy.php
diff --git src/wp-includes/class-wp-taxonomy.php src/wp-includes/class-wp-taxonomy.php index 94353d8..1836f2a 100644
final class WP_Taxonomy { 152 152 public $cap; 153 153 154 154 /** 155 * Whether this taxonomy should remember the order in which terms are added to objects 156 * 157 * @var bool 158 */ 159 public $sort; 160 161 /** 155 162 * Rewrites information for this taxonomy. 156 163 * 157 164 * @since 4.7.0 … … final class WP_Taxonomy { 267 274 'meta_box_cb' => null, 268 275 'meta_box_sanitize_cb' => null, 269 276 'capabilities' => array(), 277 'sort' => false, 270 278 'rewrite' => true, 271 279 'query_var' => $this->name, 272 280 'update_count_callback' => '', -
src/wp-includes/class-wp-term-query.php
diff --git src/wp-includes/class-wp-term-query.php src/wp-includes/class-wp-term-query.php index b7c3b42..75b5566 100644
class WP_Term_Query { 232 232 $taxonomies = isset( $query['taxonomy'] ) ? (array) $query['taxonomy'] : null; 233 233 234 234 /** 235 * If all the requested taxonomies are sortable by term_order 236 * via the WP_Taxonomy::$sort flag we can set the default sort order 237 * to term_order. 238 */ 239 if ( is_array( $taxonomies ) ) { 240 $ts = array_map( 'get_taxonomy', $taxonomies ); 241 if ( count( array_filter( wp_list_pluck( $ts, 'sort' ) ) ) == count( $taxonomies ) ) { 242 if ( ( $t = get_taxonomy( $taxonomies[0] ) ) && $t->sort ) { 243 $this->query_var_defaults['orderby'] = 'term_order'; 244 } 245 } 246 } 247 248 /** 235 249 * Filters the terms query default arguments. 236 250 * 237 251 * Use {@see 'get_terms_args'} to filter the passed arguments. -
src/wp-includes/taxonomy.php
diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php index df828b0..7301c8e 100644
function is_taxonomy_hierarchical( $taxonomy ) { 377 377 * @type string $delete_terms Default 'manage_categories'. 378 378 * @type string $assign_terms Default 'edit_posts'. 379 379 * } 380 * @type bool $sort Whether this taxonomy should remember the order in which terms are 381 * added to objects. Default false. 380 382 * @type bool|array $rewrite { 381 383 * Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent 382 384 * rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys: … … function update_object_term_cache( $object_ids, $object_type ) { 3312 3314 3313 3315 $object_ids = array_map( 'intval', $object_ids ); 3314 3316 3317 $sorted_taxonomies = array(); 3315 3318 $taxonomies = get_object_taxonomies( $object_type ); 3316 3319 3320 /** 3321 * Split the sorted taxonomies out. They will 3322 * be ordered by term_order. 3323 */ 3324 foreach ( $taxonomies as $index => $taxonomy ) { 3325 if ( ( $t = get_taxonomy( $taxonomy ) ) && $t->sort ) { 3326 $sorted_taxonomies[] = $taxonomy; 3327 unset( $taxonomies[ $index ] ); 3328 } 3329 } 3330 3317 3331 $ids = array(); 3318 3332 foreach ( (array) $object_ids as $id ) { 3319 3333 foreach ( $taxonomies as $taxonomy ) { … … function update_object_term_cache( $object_ids, $object_type ) { 3336 3350 ) 3337 3351 ); 3338 3352 3353 $sorted_terms = wp_get_object_terms( 3354 $ids, $sorted_taxonomies, array( 3355 'fields' => 'all_with_object_id', 3356 'orderby' => 'term_order', 3357 'update_term_meta_cache' => false, 3358 ) 3359 ); 3360 3361 $terms = array_merge( $terms, $sorted_terms ); 3362 3339 3363 $object_terms = array(); 3340 3364 foreach ( (array) $terms as $term ) { 3341 3365 $object_terms[ $term->object_id ][ $term->taxonomy ][] = $term->term_id; -
tests/phpunit/tests/term/query.php
diff --git tests/phpunit/tests/term/query.php tests/phpunit/tests/term/query.php index b517417..440ba8f 100644
class Tests_Term_Query extends WP_UnitTestCase { 614 614 ); 615 615 $this->assertSame( array(), $q->terms ); 616 616 } 617 618 /** 619 * @ticket 40436 620 */ 621 public function test_taxonomy_sort_flag_orderby_term_order() { 622 $post_id = self::factory()->post->create(); 623 register_taxonomy( 'wptests_sort_tax', array( 'post' ), array( 'sort' => true, 'hierarchical' => false ) ); 624 625 $t = get_taxonomy( 'wptests_sort_tax' ); 626 $this->assertTrue( $t->sort ); 627 628 $terms = array( 'three', 'and', 'four', 'five' ); 629 wp_set_object_terms( $post_id, $terms, 'wptests_sort_tax' ); 630 631 // Make sure global term cache provides the correct order 632 update_object_term_cache( $post_id, 'post' ); 633 634 $q = new WP_Term_Query( 635 array( 636 'taxonomy' => 'wptests_sort_tax', 637 'object_ids' => $post_id, 638 ) 639 ); 640 $this->assertSame( $terms, wp_list_pluck( $q->terms, 'slug' ) ); 641 642 // Test metabox taxonomy (admin advanced edit) 643 $terms_to_edit = get_terms_to_edit( $post_id, 'wptests_sort_tax' ); 644 $this->assertEquals( implode( ',', $terms ), $terms_to_edit ); 645 } 617 646 }