Skip to content

Commit

Permalink
Fix: Return 404 for campaign pages when disabled on the campaign (#7716)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Waldstein <[email protected]>
  • Loading branch information
kjohnson and jonwaldstein authored Feb 21, 2025
1 parent 91aac39 commit 71e0a06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Campaigns/Actions/RedirectDisabledCampaignPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Give\Campaigns\Actions;

use Give\Campaigns\Models\CampaignPage;

/**
* @unreleased
*/
class RedirectDisabledCampaignPage
{
/**
* @unreleased
*/
public function __invoke()
{
if('give_campaign_page' !== get_post_type()) {
return;
}

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

if($campaignPage && !$campaignPage->campaign()->enableCampaignPage) {
global $wp_query;
$wp_query->set_404();
status_header(404);
}
}
}
1 change: 1 addition & 0 deletions src/Campaigns/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ private function replaceGiveFormsCptLabels()
private function setupCampaignPages()
{
Hooks::addAction('init', Actions\RegisterCampaignPagePostType::class);
Hooks::addAction('template_redirect', Actions\RedirectDisabledCampaignPage::class);
Hooks::addAction('enqueue_block_editor_assets', Actions\EnqueueCampaignPageEditorAssets::class);
Hooks::addAction('admin_action_edit_campaign_page', Actions\EditCampaignPageRedirect::class);
}
Expand Down

0 comments on commit 71e0a06

Please sign in to comment.