-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix: Term counts should not be recalculated when a post transitions between statuses that are not counted #8970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
src/wp-includes/post.php
Outdated
// Do not calculate if both statuses are same. | ||
if ( $new_status === $old_status ) { | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to not recalculate when both status are same, Based on
wordpress-develop/src/wp-includes/ms-blogs.php
Lines 911 to 924 in 6ac0efd
function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) { | |
if ( $new_status === $old_status ) { | |
return; | |
} | |
if ( 'post' !== get_post_type( $post ) ) { | |
return; | |
} | |
if ( 'publish' !== $new_status && 'publish' !== $old_status ) { | |
return; | |
} | |
update_posts_count(); |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
The implementation for filter is missing. |
Yes, Thanks for the note, I am adding the implementation for the same. |
…_term_count_statuses`
Hi @mukeshpanchal27, I have implemented the fix to respect the filter, Let me know if that is correct approach or need to update with some other logic. Thank You, |
Let's add unit tests that validate the updated functionality. |
Hi @mukeshpanchal27, I reviewed this and looked into how we can accommodate the suggested test. However, it seems that the existing tests already cover the intended functionality: The tests in this file already handle the scenario: https://github.com/WordPress/wordpress-develop/blob/trunk/tests/phpunit/tests/term/termCounts.php For example, we've added a check to ensure that if both the old and new statuses are the same, the term count remains unchanged. This specific case is already covered here:
The data provider for that test includes conditions where both statuses are the same, which ensures no change in the term count unless one of the statuses is publish. Additionally, we already have a test for the update_post_term_count_statuses filter, which covers scenarios where a custom status is added:
So I am not sure if we should proceed to add the test, because I do not see any test specific to this function Let me know if we need to add a specific test for this? Thank You, |
Trac ticket: https://core.trac.wordpress.org/ticket/63562
_update_term_count_on_transition_post_status
which is hooked totransition_post_status
action, and added condition to only recalculate when the new status or old status is publish.This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.