ReportsWidgetBanner.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Promotions\ReportsWidgetBanner; |
| 4 | |
| 5 | use Give\Promotions\InPluginUpsells\SaleBanners; |
| 6 | |
| 7 | /** |
| 8 | * @since 3.13.0 |
| 9 | */ |
| 10 | class ReportsWidgetBanner extends SaleBanners |
| 11 | { |
| 12 | |
| 13 | /** |
| 14 | @since 3.13.0 |
| 15 | */ |
| 16 | public function getBanners(): array |
| 17 | { |
| 18 | return [ |
| 19 | [ |
| 20 | 'id' => 'bfgt2024-reports-widget', |
| 21 | 'header' => __('Make it yours. Save 40% on all GiveWP products.', 'give'), |
| 22 | 'actionText' => __('Shop Now', 'give'), |
| 23 | 'actionUrl' => 'https://go.givewp.com/40sale24', |
| 24 | 'startDate' => '2024-07-23 00:00', |
| 25 | 'endDate' => '2024-07-30 23:59', |
| 26 | ], |
| 27 | ]; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @since 3.13.0 |
| 32 | */ |
| 33 | public function loadScripts(): void |
| 34 | { |
| 35 | wp_enqueue_script( |
| 36 | 'give-in-plugin-upsells-sale-banners', |
| 37 | GIVE_PLUGIN_URL . 'assets/dist/js/admin-upsell-sale-banner.js', |
| 38 | [], |
| 39 | GIVE_VERSION, |
| 40 | true |
| 41 | ); |
| 42 | |
| 43 | wp_localize_script( |
| 44 | 'give-in-plugin-upsells-sale-banners', |
| 45 | 'giveReportsWidget', |
| 46 | [ |
| 47 | 'apiRoot' => esc_url_raw(rest_url('give-api/v2/sale-banner')), |
| 48 | 'apiNonce' => wp_create_nonce('wp_rest'), |
| 49 | 'banner' => $this->getVisibleBanners()[0], |
| 50 | ] |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @since 3.13.0 |
| 56 | */ |
| 57 | public static function isShowing(): bool |
| 58 | { |
| 59 | $hasBanners = !empty((new ReportsWidgetBanner)->getVisibleBanners()); |
| 60 | $isDashboardWidgetPage = admin_url() . 'index.php' === get_site_url() . $_SERVER['REQUEST_URI']; |
| 61 | |
| 62 | return $hasBanners && $isDashboardWidgetPage; |
| 63 | } |
| 64 | } |
| 65 |