Endpoints
3 years ago
resources
2 years ago
AddonsAdminPage.php
3 years ago
AddonsRepository.php
4 years ago
LegacyFormEditor.php
3 years ago
PaymentGateways.php
3 years ago
SaleBanners.php
3 years ago
SummerSalesBanner.php
2 years ago
SummerSalesBanner.php
157 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Promotions\InPluginUpsells; |
| 4 | |
| 5 | /** |
| 6 | * @unrleased |
| 7 | */ |
| 8 | class SummerSalesBanner extends SaleBanners |
| 9 | { |
| 10 | /** |
| 11 | * @unrleased |
| 12 | */ |
| 13 | public function getBanners(): array |
| 14 | { |
| 15 | $commonBannerInfo = [ |
| 16 | 'accessibleLabel' => __('Save 30% on all GiveWP Pricing Plans.', 'give'), |
| 17 | 'leadHeader' => __('Make it yours.', 'give'), |
| 18 | 'contentText' => __( |
| 19 | 'Purchase any StellarWP product during the sale and get 100% off WP Business Reviews and take 40% off all other brands.', |
| 20 | 'give' |
| 21 | ), |
| 22 | 'actionText' => __('Shop Now', 'give'), |
| 23 | 'alternateActionText' => __('View all StellarWP Deals', 'give'), |
| 24 | 'alternateActionURL' => 'https://go.givewp.com/ss23stellar', |
| 25 | 'startDate' => '2023-07-24 00:00', |
| 26 | 'endDate' => '2023-07-31 23:59', |
| 27 | ]; |
| 28 | |
| 29 | $hasValidLicenses = self::hasValidLicenses(); |
| 30 | |
| 31 | if ($hasValidLicenses) { |
| 32 | return [ |
| 33 | array_merge($commonBannerInfo, [ |
| 34 | 'id' => 'bfgt2023stellar', |
| 35 | 'leadText' => __('Save 30% on all StellarWP products.', 'give'), |
| 36 | 'actionURL' => 'https://go.givewp.com/ss23stellar', |
| 37 | ]), |
| 38 | ]; |
| 39 | } |
| 40 | |
| 41 | return [ |
| 42 | array_merge($commonBannerInfo, [ |
| 43 | 'id' => 'bfgt2023givewp', |
| 44 | 'leadText' => __('Save 30% on all GiveWP Pricing Plans.', 'give'), |
| 45 | 'actionURL' => 'https://go.givewp.com/ss23give', |
| 46 | |
| 47 | ]), |
| 48 | ]; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | /** |
| 53 | * @unrleased |
| 54 | */ |
| 55 | public function loadScripts() |
| 56 | { |
| 57 | wp_enqueue_script( |
| 58 | 'give-in-plugin-upsells-sale-banners', |
| 59 | GIVE_PLUGIN_URL . 'assets/dist/js/admin-upsell-sale-banner.js', |
| 60 | [], |
| 61 | GIVE_VERSION, |
| 62 | true |
| 63 | ); |
| 64 | |
| 65 | wp_localize_script( |
| 66 | 'give-in-plugin-upsells-sale-banners', |
| 67 | 'GiveSaleBanners', |
| 68 | [ |
| 69 | 'apiRoot' => esc_url_raw(rest_url('give-api/v2/sale-banner')), |
| 70 | 'apiNonce' => wp_create_nonce('wp_rest'), |
| 71 | ] |
| 72 | ); |
| 73 | |
| 74 | wp_enqueue_style( |
| 75 | 'give-in-plugin-upsells-summer-sales-banner', |
| 76 | GIVE_PLUGIN_URL . 'assets/dist/css/admin-summer-sales-banner.css', |
| 77 | [], |
| 78 | GIVE_VERSION |
| 79 | ); |
| 80 | |
| 81 | wp_enqueue_style('givewp-admin-fonts'); |
| 82 | |
| 83 | wp_enqueue_style( |
| 84 | 'Inconsolpata', |
| 85 | 'https://fonts.googleapis.com/css2?family=Inconsolata&display=swap', |
| 86 | [], |
| 87 | '1.0', |
| 88 | 'all' |
| 89 | ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @since 2.31.0 |
| 94 | */ |
| 95 | public function render() |
| 96 | { |
| 97 | $banner = $this->getVisibleBanners(); |
| 98 | |
| 99 | if ( ! empty($banner)) { |
| 100 | include __DIR__ . '/resources/views/summer-sales-banner.php'; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | |
| 105 | /** |
| 106 | * @since 2.31.0 |
| 107 | */ |
| 108 | public static function isShowing(): bool |
| 109 | { |
| 110 | global $pagenow; |
| 111 | |
| 112 | return $pagenow === 'plugins.php'; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @since 2.31.0 |
| 117 | */ |
| 118 | public static function hasValidLicenses(): bool |
| 119 | { |
| 120 | $requiredPluginSlugs = [ |
| 121 | 'recurring' => 'give-recurring', |
| 122 | 'form_field_manager' => 'give-form-field-manager', |
| 123 | 'fee_recovery' => 'give-fee-recovery', |
| 124 | 'manual_donations' => 'give-manual-donations', |
| 125 | 'peer_to_peer' => 'give-peer-to-peer', |
| 126 | ]; |
| 127 | |
| 128 | $licensedPluginSlugs = self::getLicensedPluginSlugs(); |
| 129 | |
| 130 | sort($requiredPluginSlugs); |
| 131 | sort($licensedPluginSlugs); |
| 132 | |
| 133 | return $requiredPluginSlugs == $licensedPluginSlugs; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @since 2.31.0 |
| 138 | */ |
| 139 | public static function getLicensedPluginSlugs(): array |
| 140 | { |
| 141 | $pluginSlugs = []; |
| 142 | $licenses = get_option("give_licenses", []); |
| 143 | |
| 144 | foreach ($licenses as $license) { |
| 145 | if (isset($license['is_all_access_pass']) && $license['is_all_access_pass'] && ! empty($license['download'])) { |
| 146 | $slugs = array_column($license['download'], 'plugin_slug'); |
| 147 | $pluginSlugs = array_merge($pluginSlugs, $slugs); |
| 148 | } else { |
| 149 | $pluginSlugs[] = $license['plugin_slug']; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return $pluginSlugs; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 |