Fix: Clear unmapped attribute banner when attribute is deleted #3674
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.
Description
This PR fixes a bug where the unmapped attribute banner would persist after an attribute was deleted. Previously, when a user created a new attribute that didn't map to a Meta catalog field, a banner would be displayed. However, if the user then deleted that attribute, the banner would continue to display for up to 30 minutes (the transient timeout period) due to cached data not being cleared.
The fix implements a defensive programming approach by validating the attribute's existence at display time rather than trying to catch deletion events. This ensures the banner automatically disappears when the tracked attribute no longer exists, regardless of how it was deleted.
Related Issue: Fixes banner persistence after attribute deletion
Type of change
Checklist
Changelog entry
Fix: Unmapped attribute banner no longer persists after attribute deletion
Test Plan
Reproduction Steps (Before Fix)
Expected Result: Banner should not be visible after the attribute is deleted
Actual Result (Before Fix): Banner persists for up to 30 minutes ❌
Verification Steps (After Fix)
Additional Test Scenarios
Technical Details
The fix adds validation in
display_unmapped_attribute_banner()to check if the tracked attribute still exists before displaying the banner. If the attribute has been deleted, the transients are cleared and the banner is not shown.Key Changes:
attribute_exists()method that checks both taxonomy existence and WooCommerce attribute registrationdisplay_unmapped_attribute_banner()that clears stale transients when attribute is deletedScreenshots
Before
The banner persists even after the attribute "Test Attribute" has been deleted:
![Banner persists after deletion - shows stale banner for deleted attribute]
After
The banner automatically disappears when the attribute is deleted:
![Banner clears after deletion - no banner shown after attribute deletion]