Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Return 404 for campaign pages when disabled on the campaign #7716

Open
wants to merge 1 commit into
base: epic/campaigns
Choose a base branch
from

Conversation

kjohnson
Copy link
Member

@kjohnson kjohnson commented Feb 7, 2025

Resolves GIVE-2144

Description

This PR hooks into the page load to return a 404 for a Campaign Page when the campaign page feature is disabled on the campaign.

Testing Instructions

Create a Campaign and edit the Campaign Page. Then disable the campaign page feature and try to load the Campaign Page as a site visitor.

Pre-review Checklist

  • Acceptance criteria satisfied and marked in related issue
  • Relevant @unreleased tags included in DocBlocks
  • Includes unit tests
  • Reviewed by the designer (if follows a design)
  • Self Review of code and UX completed

@kjohnson kjohnson changed the base branch from develop to epic/campaigns February 7, 2025 18:03
@kjohnson kjohnson marked this pull request as ready for review February 7, 2025 18:04

$campaignPage = CampaignPage::find(get_the_ID());

if(!$campaignPage->campaign()->enableCampaignPage) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent a fatal error if $campaign is not found:

Suggested change
if(!$campaignPage->campaign()->enableCampaignPage) {
if($campaignPage && !$campaignPage->campaign()->enableCampaignPage) {

Comment on lines +27 to +28
get_template_part(404);
exit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get_template_part(404);
exit;

We can remove the exit statement so WP can still render a page, otherwise the website is unreachable.

Screenshot 2025-02-07 at 3 43 53 PM

vs

Screenshot 2025-02-07 at 3 44 07 PM

Also, it looks like we don't need the get_template_part either as WP must handle that up the chain via get_404_template()

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.

2 participants