From e0251ee5d75decc223f38a741a4e8104b64d2e16 Mon Sep 17 00:00:00 2001
From: Joshua Dinh <75056371+JoshuaHungDinh@users.noreply.github.com>
Date: Tue, 20 Aug 2024 05:57:51 -0700
Subject: [PATCH] Refactor: remove StellarBanner (#7472)
---
.../InPluginUpsells/SaleBanners.php | 53 -------
.../InPluginUpsells/StellarSaleBanners.php | 143 ------------------
src/Promotions/ServiceProvider.php | 11 --
3 files changed, 207 deletions(-)
delete mode 100644 src/Promotions/InPluginUpsells/StellarSaleBanners.php
diff --git a/src/Promotions/InPluginUpsells/SaleBanners.php b/src/Promotions/InPluginUpsells/SaleBanners.php
index 1a08f9bcb7..dc1be766b0 100644
--- a/src/Promotions/InPluginUpsells/SaleBanners.php
+++ b/src/Promotions/InPluginUpsells/SaleBanners.php
@@ -242,59 +242,6 @@ public static function getDataByPricingPlan(array $data): string
return $data['default'];
}
- /**
- * @since 3.13.0
- *
- * This method cycles through the visible banners, selecting the next banner in the list
- * on each call. If no banners are visible, or if the session index is not set, it returns
- * all visible banners.
- */
- public function alternateVisibleBanners(): array
- {
- $visibleBanners = $this->getVisibleBanners();
- $bannerCount = count($visibleBanners);
-
- if ($bannerCount > 0) {
- $currentIndex = $_SESSION['banner_index'] ?? 0;
-
- $selectedBanner = $visibleBanners[$currentIndex];
-
- $currentIndex = ($currentIndex + 1) % $bannerCount;
-
- $_SESSION['banner_index'] = $currentIndex;
-
- if( !$selectedBanner){
- $this->destroySession();
- return $visibleBanners;
- }
-
- return [$selectedBanner];
- }
-
- return $visibleBanners;
- }
-
- /**
- * @since 3.13.0
- */
- public function startSession(): void
- {
- if (!session_id()) {
- session_start();
- }
- }
-
- /**
- * @since 3.13.0
- */
- public function destroySession(): void
- {
- if (session_id()) {
- session_destroy();
- }
- }
-
-
/**
* @since 3.13.0
*/
diff --git a/src/Promotions/InPluginUpsells/StellarSaleBanners.php b/src/Promotions/InPluginUpsells/StellarSaleBanners.php
deleted file mode 100644
index 9ddf392324..0000000000
--- a/src/Promotions/InPluginUpsells/StellarSaleBanners.php
+++ /dev/null
@@ -1,143 +0,0 @@
- 'bfgt2024-give',
- 'mainHeader' => self::getDataByPricingPlan([
- 'Pro' => __('Make it stellar.', 'give'),
- 'default' => __('Make it yours.', 'give'),
- ]),
- 'subHeader' => self::getDataByPricingPlan([
- 'Basic' => __('Save 40% on the GiveWP Plus Plan.', 'give'),
- 'Plus' => __('Save 40% on the GiveWP Pro Plan.', 'give'),
- 'Pro' => __('Save 40% on all StellarWP products.', 'give'),
- 'default' => __('Save 40% on the GiveWP Plus Plan.', 'give'),
- ]),
- 'actionText' => __('Shop Now', 'give'),
- 'actionURL' => self::getDataByPricingPlan([
- 'Basic' => 'https://go.givewp.com/plusplan',
- 'Plus' => 'https://go.givewp.com/pro',
- 'Pro' => 'https://go.givewp.com/stellarsale',
- 'default' => 'https://go.givewp.com/plusplan',
- ]),
- 'secondaryActionText' => __('View all StellarWP Deals', 'give'),
- 'secondaryActionURL' => 'https://go.givewp.com/stellarsale',
- 'content' => self::getDataByPricingPlan([
- 'Pro' => sprintf(__('Take %s off all brands during the annual Stellar Sale. Now through July 30.', 'give'),
- '40%'),
- 'default' => sprintf(__('Take %s off all StellarWP brands during the annual Stellar Sale. Now through July 30.', 'give'),
- '40%'),
- ]),
- 'startDate' => '2024-07-23 00:00',
- 'endDate' => '2024-07-30 23:59',
- ],
- ];
-
- foreach($this->getAddonBanners() as $addonBanner){
- $banners[] = $addonBanner;
- }
-
- return $banners;
- }
-
- /**
- * @since 3.13.0
- */
- public function getP2PBanners(): array
- {
- return [
- [
- 'id' => 'bfgt2024-p2p',
- 'mainHeader' => __('Make it yours.', 'give'),
- 'subHeader' => __('Save 40% on Peer-to-Peer Fundraising.', 'give'),
- 'actionText' => __('Shop Now', 'give'),
- 'actionURL' => self::getDataByPricingPlan([
- 'Basic' => 'https://go.givewp.com/p2p',
- 'Plus' => 'https://go.givewp.com/p2ppro',
- 'default' => 'https://go.givewp.com/p2p',
- ]),
- 'secondaryActionText' => __('View all StellarWP Deals', 'give'),
- 'secondaryActionURL' => 'https://go.givewp.com/stellarsale',
- 'content' => self::getDataByPricingPlan([
- 'Basic' => __('Open up your donation forms to your supporters during the annual Stellar Sale. Now through July 30.', 'give'),
- 'Plus' => __('Upgrade to the Pro Plan and get Peer-to-Peer Fundraising during the annual Stellar Sale. Now through July 30.', 'give'),
- 'Pro' => __('Upgrade to the Pro Plan and get Peer-to-Peer Fundraising during the annual Stellar Sale. Now through July 30.', 'give'),
- 'default' => __('Open up your donation forms to your supporters during the annual Stellar Sale. Now through July 30.', 'give'),
- ]),
- 'startDate' => '2024-07-23 00:00',
- 'endDate' => '2024-07-30 23:59',
- ],
- ];
- }
-
- /**
- * @since 3.13.0
- */
- public function getAddonBanners(): array
- {
- if(self::getUserPricingPlan() === 'Pro') {
- return [];
- }
-
- $addonBanners = [];
-
- if(!defined('GIVE_P2P_VERSION')) {
- $addonBanners = $this->getP2PBanners();
- }
-
- return $addonBanners;
- }
-
- /**
- * @since 3.13.0
- */
- public function loadScripts(): void
- {
- wp_enqueue_style(
- 'give-in-plugin-upsells-stellar-sales-banner',
- GIVE_PLUGIN_URL . 'assets/dist/css/admin-stellarwp-sales-banner.css',
- [],
- GIVE_VERSION
- );
-
- wp_enqueue_style('givewp-admin-fonts');
- }
-
- /**
- * @since 3.13.0
- */
- public function render(): void
- {
- $banners = $this->alternateVisibleBanners();
-
- if (!empty($banners)) {
- include __DIR__ . '/resources/views/stellarwp-sale-banner.php';
- }
- }
-
- /**
- * @since 3.13.0
- */
- public static function isShowing(): bool
- {
- $saleBanners = new self();
- $page = $_GET['page'] ?? [];
- $validPages = ['give-donors', 'give-payment-history', 'give-reports'];
-
- return isset($_GET['post_type']) && $_GET['post_type'] === 'give_forms' &&
- in_array($page, $validPages, true) &&
- !empty($saleBanners->getBanners());
- }
-}
diff --git a/src/Promotions/ServiceProvider.php b/src/Promotions/ServiceProvider.php
index 1f19ed2503..eac4aba17e 100644
--- a/src/Promotions/ServiceProvider.php
+++ b/src/Promotions/ServiceProvider.php
@@ -57,17 +57,6 @@ private function bootPluginUpsells()
Hooks::addAction('admin_enqueue_scripts', AddonsAdminPage::class, 'loadScripts');
}
- if (SaleBanners::isShowing()) {
- Hooks::addAction('admin_notices', SaleBanners::class, 'render');
- Hooks::addAction('admin_enqueue_scripts', SaleBanners::class, 'loadScripts');
- }
-
- if (StellarSaleBanners::isShowing()) {
- Hooks::addAction('admin_init', SaleBanners::class, 'startSession');
- Hooks::addAction('admin_notices', StellarSaleBanners::class, 'render');
- Hooks::addAction('admin_enqueue_scripts', StellarSaleBanners::class, 'loadScripts');
- }
-
if (ReportsWidgetBanner::isShowing()) {
Hooks::addAction('admin_enqueue_scripts', ReportsWidgetBanner::class, 'loadScripts');
}