Conversation
The Quick Edit feature for custom statuses was displaying stale data after updates. Whilst the update persisted correctly to the database, the AJAX response returned outdated information, requiring a page refresh to see the changes. The root cause was premature cache invalidation. The internal cache was being cleared at the start of update_custom_status(), but subsequent calls to get_default_custom_status() during slug validation repopulated it with stale data before wp_update_term() executed. This meant get_custom_status_by() returned cached data instead of the freshly updated term. Moving the cache reset to immediately after wp_update_term() ensures the cache contains only fresh data when retrieving the updated status. This matches the pattern used successfully in the Editorial Metadata module. Fixes #657
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change addresses a visual update bug in the Custom Status Quick Edit functionality where the status row would display stale data after updates, requiring a manual page refresh to see the correct name.
The Problem
When editing a custom status name through Quick Edit, the update operation would save correctly to the database (verified by page refresh), but the table row rendered from the AJAX response would display the old name rather than the newly updated one. This created a confusing user experience where changes appeared not to take effect until the page was manually refreshed.
The underlying issue was a timing problem in the cache management within
update_custom_status(). The function cleared the internalcustom_statuses_cacheat the start of its execution. However, during the update logic—specifically when the slug needed to be updated as part of a name change—calls toget_default_custom_status()would repopulate this cache with stale data from the database. This repopulation occurred beforewp_update_term()had written the new values. Consequently, when the function returned the updated status viaget_custom_status_by(), it was serving cached data that reflected the pre-update state.The Solution
The fix moves the cache reset to occur after
wp_update_term()has completed but before fetching the updated term data. This ensures that whenget_custom_status_by()retrieves the status object to return in the AJAX response, it's working with fresh data that reflects the update that was just written to the database.This approach mirrors the pattern already successfully employed in the Editorial Metadata module, which handles similar update operations without cache-related issues.
Testing
To verify the fix:
Fixes #657