[wp-trac] [WordPress Trac] #51630: Partial term counts: `_wp_prevent_term_counting()` breaks term counting for terms created on actions.

WordPress Trac noreply at wordpress.org
Mon Oct 26 02:14:43 UTC 2020


#51630: Partial term counts: `_wp_prevent_term_counting()` breaks term counting for
terms created on actions.
---------------------------+------------------------------------------
 Reporter:  peterwilsoncc  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  5.6
Component:  General        |    Version:  trunk
 Severity:  normal         |   Keywords:  needs-patch needs-unit-tests
  Focuses:                 |
---------------------------+------------------------------------------
 `_wp_prevent_term_counting()` added in #40351 breaks term counting when
 terms are applied to any object apart from the original post during the
 `wp_insert_post()` workflow.

 An example may be a term is created and applied to another post, term,
 comment or user.

 In this unit test a tag is created by `wp_insert_post()` which in turn
 applies a term to another object. This test passes with WordPress 5.5 but
 fails with 5.6 beta 1:

 {{{#!php
 <?php
 function
 test_wp_set_object_terms_hooked_to_create_term_in_wp_insert_post() {
         $args['update_count_callback'] = '_update_generic_term_count';
         register_taxonomy( 'term_taxonomy', 'term', $args );

         add_action( 'create_term', function( $term_id, $tt_id, $taxonomy )
 {
                 if ( 'post_tag' === $taxonomy ) {
                         $term = wp_insert_term( uniqid(), 'term_taxonomy'
 );
                         $lang = $term['term_id'];
                         wp_set_object_terms( $term_id, $lang,
 'term_taxonomy' );
                 }
         }, 10, 3 );

         $post_id = $this->factory->post->create( array( 'tags_input' =>
 array( 'my_tag' ) ) );
         $tags = wp_get_post_tags( $post_id );
         $tag = reset( $tags );
         $terms = wp_get_object_terms( $tag->term_id, 'term_taxonomy' );
         $this->assertCount( 1, $terms ); // Check that a term has been
 assigned to the tag.
         $term = reset( $terms );
         $this->assertEquals( 1, $term->count ); // Check the term count,
 fails in WP 5.6.
 }
 }}}


 Reported by and example test provided by @Chouby on earlier ticket
 ticket:40351#comment:42

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51630>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list