You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Posts, Post Types: Don't unnecessarily recount terms when a post transitions between statuses that don't require them to be recounted.
This accounts for transitions where:
* Both the old and new statuses are not included in term counts.
* Both the old and new statuses are included in term counts.
This results in term counts only being recalculated when a post transitions between a counted and an uncounted status.
If the terms of the post are changed then the term recounting is still handled by `wp_update_term_count()` inside `wp_set_object_terms()`.
Props hbhalodia, johnbillion, peterwilsoncc, mukesh27.
Fixes #63562
git-svn-id: https://develop.svn.wordpress.org/trunk@60510 602fd350-edb4-49c9-b593-d223f7449a82
// Change something about the post but not its status.
157
161
wp_update_post(
@@ -161,10 +165,149 @@ public function test_term_count_is_not_recalculated_when_status_does_not_change(
161
165
)
162
166
);
163
167
164
-
$this->assertSame( 0, did_action( 'edited_term_taxonomy') - $edited_term_taxonomy_count, 'Term taxonomy count should not be recalculated when post status does not change.' );
168
+
$this->assertSame( 0, $action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should not be recalculated when post status does not change.' );
165
169
$this->assertTermCount( 2, self::$term_id );
166
170
}
167
171
172
+
/**
173
+
* Test that the term count is not recalculated when both the old and new status are included in term counts.
174
+
*
175
+
* This accounts for a transition such as draft -> pending.
// Change the post to another status that is not included in term counts.
236
+
wp_update_post(
237
+
array(
238
+
'ID' => self::$post_id,
239
+
'post_status' => 'pending',
240
+
)
241
+
);
242
+
243
+
$this->assertSame( 0, $action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should not be recalculated when neither new nor old post status is included in term counts.' );
244
+
$this->assertTermCount( 0, self::$term_id, 'Term count should remain unchanged when transitioning between post statuses that are not counted.' );
245
+
}
246
+
247
+
/**
248
+
* Test to ensure that the `update_post_term_count_statuses` filter is respected.
// Change the post to another status that is included in term counts for one of its two taxonomies.
299
+
wp_update_post(
300
+
array(
301
+
'ID' => self::$post_id,
302
+
'post_status' => 'pending',
303
+
)
304
+
);
305
+
306
+
$this->assertSame( 1, $action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should respect the statuses returned by the update_post_term_count_statuses filter.' );
307
+
$this->assertTermCount( 0, self::$term_id, 'Term count for the default taxonomy should remain zero since "pending" is not included in its countable statuses.' );
308
+
$this->assertTermCount( 1, $custom_term_id, 'Term count for the custom taxonomy should be updated to 1 because the "pending" status is included via the update_post_term_count_statuses filter.' );
0 commit comments