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
Taxonomy: Add update_term_count action that fires when term counts are updated.
This allows plugins to run custom queries only when a term count is actually updated and not on every update of terms or posts.
Follow-up to [60365], [60510].
Props leonidasmilossis, peterwilsoncc, mukesh27, rollybueno, SergeyBiryukov.
Fixes #63904.
git-svn-id: https://develop.svn.wordpress.org/trunk@60711 602fd350-edb4-49c9-b593-d223f7449a82
// Change something about the post but not its status.
161
166
wp_update_post(
@@ -165,7 +170,8 @@ public function test_term_count_is_not_recalculated_when_status_does_not_change(
165
170
)
166
171
);
167
172
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.' );
173
+
$this->assertSame( 0, $edited_term_taxonomy_action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should not be recalculated when post status does not change.' );
174
+
$this->assertSame( 0, $update_term_count_action->get_call_count() - $update_term_count_action_count, 'The `update_term_count` action should not run when term taxonomy count is not recalculated.' );
169
175
$this->assertTermCount( 2, self::$term_id );
170
176
}
171
177
@@ -177,9 +183,13 @@ public function test_term_count_is_not_recalculated_when_status_does_not_change(
// Register a custom status that is included in term counts.
185
195
register_post_status(
@@ -206,7 +216,8 @@ static function ( $status ) {
206
216
)
207
217
);
208
218
209
-
$this->assertSame( 0, $action->get_call_count(), 'Term taxonomy count should not be recalculated both statuses are included in term counts.' );
219
+
$this->assertSame( 0, $edited_term_taxonomy_action->get_call_count(), 'Term taxonomy count should not be recalculated when both statuses are included in term counts.' );
220
+
$this->assertSame( 0, $update_term_count_action->get_call_count(), 'The `update_term_count` action should not run when term taxonomy count is not recalculated.' );
210
221
$this->assertTermCount( 1, self::$term_id, 'Term count should remain unchanged when transitioning between post statuses that are counted.' );
211
222
}
212
223
@@ -218,9 +229,13 @@ static function ( $status ) {
// Change the post to another status that is not included in term counts.
236
252
wp_update_post(
@@ -240,7 +256,8 @@ public function test_term_count_is_not_recalculated_when_neither_status_is_count
240
256
)
241
257
);
242
258
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.' );
259
+
$this->assertSame( 0, $edited_term_taxonomy_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.' );
260
+
$this->assertSame( 0, $update_term_count_action->get_call_count() - $update_term_count_action_count, 'The `update_term_count` action should not run when term taxonomy count is not recalculated.' );
244
261
$this->assertTermCount( 0, self::$term_id, 'Term count should remain unchanged when transitioning between post statuses that are not counted.' );
245
262
}
246
263
@@ -250,9 +267,13 @@ public function test_term_count_is_not_recalculated_when_neither_status_is_count
// Change the post to another status that is included in term counts for one of its two taxonomies.
299
321
wp_update_post(
@@ -303,7 +325,8 @@ static function ( array $statuses, WP_Taxonomy $taxonomy ) use ( $custom_taxonom
303
325
)
304
326
);
305
327
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.' );
328
+
$this->assertSame( 1, $edited_term_taxonomy_action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should respect the statuses returned by the update_post_term_count_statuses filter.' );
329
+
$this->assertSame( 1, $update_term_count_action->get_call_count() - $update_term_count_action_count, 'The `update_term_count` action should run when term taxonomy count is recalculated.' );
307
330
$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
331
$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