[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 07:36:05 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 | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+---------------------
Comment (by Chouby):
Here is another test which is similar to the previous one but doesn't
involve a custom taxonomy on terms.
In this test a category is assigned to a second post when a category is
assigned to a first post in `wp_insert_post()`. The test passes in WP 5.5
and fails in WP 5.6-beta1:
{{{#!php
<?php
function
test_wp_set_object_terms_hooked_to_set_object_terms_in_wp_insert_post() {
$p1 = $this->factory->post->create();
$c1 = $this->factory->category->create();
$c2 = $this->factory->category->create();
add_action( 'set_object_terms', function() use ( $p1, $c1 ) {
static $avoid_recursion = false;
if ( ! $avoid_recursion ) {
$avoid_recursion = true;
wp_set_object_terms( $p1, $c1, 'category' );
}
$avoid_recursion = false;
} );
$p2 = $this->factory->post->create( array( 'post_category' =>
array( $c2 ) ) );
$term = get_term( $c1 );
$this->assertEquals( 1, $term->count ); // Check the term count,
fails in WP 5.6.
}
}}}
A variant of the test above uses the same category for the 2 posts:
{{{#!php
<?php
function
test_wp_set_object_terms_hooked_to_set_same_object_terms_in_wp_insert_post()
{
$p1 = $this->factory->post->create();
$c1 = $this->factory->category->create();
add_action( 'set_object_terms', function() use ( $p1, $c1 ) {
static $avoid_recursion = false;
if ( ! $avoid_recursion ) {
$avoid_recursion = true;
wp_set_object_terms( $p1, $c1, 'category' );
}
$avoid_recursion = false;
} );
$p2 = $this->factory->post->create( array( 'post_category' =>
array( $c1 ) ) );
$term = get_term( $c1 );
$this->assertEquals( 2, $term->count ); // Check the term count,
fails in WP 5.6.
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51630#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list