feat: implement brand override backend logic#76
Open
rbcorrales wants to merge 2 commits intotrunkfrom
Open
Conversation
Add support for overriding the current brand via URL parameter (`?brand=brand-slug`) and filters.
Key changes:
- Add brand override check to the taxonomy class.
- Update brand resolution methods to accept optional brand override parameter.
- Add `newspack_brand_override` filter for custom override logic.
- Add extensive test coverage for brand override behavior across posts, author archives, term archives, brand archives, homepage and filter functionality.
The brand override system follows these rules:
1. Posts:
- If a post has a single brand, that brand is always used and overrides are ignored.
- If a post has multiple brands:
- If a valid override (via URL or filter) matches one of the post brands, it is used.
- If no valid override is present but a primary brand is set, the primary brand is used.
- If neither a valid override nor a primary brand is present, the post is neutral (no brand).
2. Author archives:
- If the author has a valid primary brand, that brand is always used and overrides are ignored.
- If the author has no primary brand, a valid override is used if present.
- If neither a primary brand nor a valid override is present, the page is neutral.
3. Term archives (categories/tags):
- If the term or any ancestor has a primary brand, that brand is used and overrides are ignored.
- If no primary brand is found in the term or ancestors, a valid override is used if present.
- If neither a primary brand nor a valid override is present, the page is neutral.
4. Brand archives ignore overrides.
5. Homepage ignores overrides.
adekbadek
approved these changes
Jun 24, 2025
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.
All Submissions:
Changes proposed in this Pull Request:
Add support for overriding the current brand via URL parameter (
?brand=brand-slug) and filters.newspack_brand_overridefilter for custom override logic.Rules:
The brand override system follows these rules:
How to test the changes in this Pull Request:
Posts (Single Brand)
brand‑a)./my‑post) and verify that the post's brand (brand‑a) is used.?brand=brand‑b(or any other brand slug) to the URL and reload.brand‑a) is still used (i.e. the override is ignored).Posts (Multiple Brands)
brand‑aandbrand‑b). Optionally, set a primary brand./my‑multi‑brand‑post) and verify that (if a primary brand is set) that brand is used.?brand=brand‑a(or?brand=brand‑b) and reload.?brand=non‑existent‑brandand reload. Verify that if a primary brand is set the primary brand is used. Otherwise, the post should be neutral.Author Archives
/author/author‑name) and verify that the author's primary brand is used.?brand=brand‑aor any other brand slug that is not the primary for the author and reload.?brand=brand‑aor any other valid brand slug.brand‑a) is used.Term Archives (Categories/Tags)
/category/my‑cat) and verify that the primary brand (or ancestor's primary brand) is used.?brand=brand‑aor any other brand slug that is not the primary for the category and reload.?brand=brand‑aor any other valid brand slug.brand‑a) is used.Brand Archives
/brand‑a) and verify that the brand (brand‑a) is used.?brand=brand‑b(or any other brand slug) and reload.brand‑a) is still used (the override is ignored).Homepage
/) and verify that the page is neutral (no brand is used).?brand=brand‑a(or any other brand slug) and reload.Custom Override (Filter)
newspack_brand_overrideand verify that the filter's logic (for example, overriding with a different brand or returning null) is applied as expected.Other information: