Skip to content

Conversation

@rbcorrales
Copy link
Member

All Submissions:

Changes proposed in this Pull Request:

Add support for overriding the current brand via URL parameter (?brand=brand-slug) and filters.

  • 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.

Rules:

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).
  1. 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.
  1. 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.
  1. Brand archives ignore overrides.
  2. Homepage ignores overrides.

How to test the changes in this Pull Request:

  • Posts (Single Brand)

    • Create a post (or edit an existing one) and assign it a single brand (e.g. brand‑a).
    • Visit the post's permalink (e.g. /my‑post) and verify that the post's brand (brand‑a) is used.
    • Then, append ?brand=brand‑b (or any other brand slug) to the URL and reload.
    • Verify that the post's brand (brand‑a) is still used (i.e. the override is ignored).
  • Posts (Multiple Brands)

    • Create (or edit) a post and assign it multiple brands (e.g. brand‑a and brand‑b). Optionally, set a primary brand.
    • Visit the post's permalink (e.g. /my‑multi‑brand‑post) and verify that (if a primary brand is set) that brand is used.
    • Append ?brand=brand‑a (or ?brand=brand‑b) and reload.
    • Verify that the override is used (if it's one of the post's brands).
    • Append ?brand=non‑existent‑brand and reload. Verify that if a primary brand is set the primary brand is used. Otherwise, the post should be neutral.
  • Author Archives

    • If the author has a primary brand set, visit the author's archive (e.g. /author/author‑name) and verify that the author's primary brand is used.
    • Append ?brand=brand‑a or any other brand slug that is not the primary for the author and reload.
    • Verify that the author's primary brand is still used (the override is ignored).
    • If the author does not have a primary brand, visit the author's archive and append ?brand=brand‑a or any other valid brand slug.
    • Verify that the override (brand‑a) is used.
  • Term Archives (Categories/Tags)

    • If your term (or an ancestor) has a primary brand set, visit the term's archive (e.g. /category/my‑cat) and verify that the primary brand (or ancestor's primary brand) is used.
    • Append ?brand=brand‑a or any other brand slug that is not the primary for the category and reload.
    • Verify that the primary brand (or ancestor's primary) is still used (the override is ignored).
    • If your term (and its ancestors) do not have a primary brand, visit the term's archive and append ?brand=brand‑a or any other valid brand slug.
    • Verify that the override (brand‑a) is used.
  • Brand Archives

    • Visit a brand archive (e.g. /brand‑a) and verify that the brand (brand‑a) is used.
    • Append ?brand=brand‑b (or any other brand slug) and reload.
    • Verify that the brand (brand‑a) is still used (the override is ignored).
  • Homepage

    • Visit the homepage (e.g. /) and verify that the page is neutral (no brand is used).
    • Append ?brand=brand‑a (or any other brand slug) and reload.
    • Verify that the homepage remains neutral (i.e. the override is ignored).
  • Custom Override (Filter)

    • Add a custom filter that hooks into the newspack_brand_override and verify that the filter's logic (for example, overriding with a different brand or returning null) is applied as expected.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

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.
@rbcorrales rbcorrales requested a review from a team as a code owner May 21, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants