Add CacheInvalidationTrait for hook registration - #461
Conversation
There was a problem hiding this comment.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Post Status Transition Parameters Not Handled ▹ view |
Files scanned
| File Path | Reviewed |
|---|---|
| nuclear-engagement/inc/Traits/CacheInvalidationTrait.php | ✅ |
| nuclear-engagement/inc/Core/InventoryCache.php | ✅ |
| nuclear-engagement/inc/Services/PostsQueryService.php | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
| 'deleted_post', | ||
| 'trashed_post', | ||
| 'untrashed_post', | ||
| 'transition_post_status', |
There was a problem hiding this comment.
Post Status Transition Parameters Not Handled 
Tell me more
What is the issue?
The 'transition_post_status' hook callback doesn't account for the specific parameters passed by WordPress (new status, old status, post object), which are needed to make informed cache invalidation decisions.
Why this matters
Without handling the specific status transition parameters, the cache might be invalidated unnecessarily, such as when transitioning to 'draft' or other non-public statuses.
Suggested change ∙ Feature Preview
Modify the trait to allow for specific parameter handling in the callback:
protected static function register_cache_invalidation_hooks( callable $callback, callable $transition_callback = null ): void {
// ... other hooks ...
add_action( 'transition_post_status', $transition_callback ?? $callback, 999, 3 );
// ... remaining hooks ...
}Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
Summary
CacheInvalidationTraitto consolidate cache invalidation hooksInventoryCacheandPostsQueryServiceTesting
composer lint(fails: command not found)composer test(fails: command not found)https://chatgpt.com/codex/tasks/task_e_685e4174b1b88327bda915bcc8f455c5
Description by Korbit AI
What change is being made?
Add a
CacheInvalidationTraitto centralize and simplify the registration of hooks for cache invalidation across classes, applying it to bothInventoryCacheandPostsQueryService.Why are these changes being made?
The changes aim to reduce code duplication and improve maintainability by introducing a reusable trait that handles hook registration for cache invalidation, simplifying hook management in both the
InventoryCacheandPostsQueryService. This approach provides a cleaner and more consistent method to handle cache invalidation triggers.