PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.8
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.8
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / admin / views / notices / offer-banner.php

offer-banner.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at admin/views/notices/offer-banner.php

165 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin offer banner.
4 *
5 * @since 2.2.3
6 * @version 2.2.3
7 *
8 * @package Smart_Post_Show
9 * @subpackage Smart_Post_Show/admin/views/notices
10 * @author ShapedPlugin<[email protected]>
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 if ( ! class_exists( 'ShapedPlugin_Offer_Banner' ) ) {
18 /**
19 * The admin review notice.
20 */
21 class ShapedPlugin_Offer_Banner {
22
23 /**
24 * The single instance of the class.
25 *
26 * @var self
27 * @since
28 */
29 private static $instance = null;
30
31 /**
32 * Class constructor.
33 */
34 private function __construct() {
35 add_action( 'admin_notices', array( $this, 'render_offer_banner' ) );
36 add_action( 'wp_ajax_shapedplugin_dismiss_offer_banner', array( $this, 'dismiss_offer_banner' ) );
37 }
38
39 /**
40 * Retrieves the singleton instance of the class.
41 *
42 * This method ensures that only one instance of the class is created (singleton pattern).
43 *
44 * @return self The singleton instance of the class.
45 */
46 public static function instance() {
47 if ( null === self::$instance ) {
48 self::$instance = new self();
49 }
50
51 return self::$instance;
52 }
53
54 /**
55 * Retrieves the active offers.
56 *
57 * @return array The list of active offers.
58 */
59 public function get_active_offers() {
60 $now = time();
61
62 // Define offer durations.
63 $offers = array(
64 'black_friday' => array(
65 'id' => 'black_friday_2025',
66 'start' => strtotime( '2025-11-18 00:00:00' ),
67 'end' => strtotime( '2025-12-14 23:59:59' ),
68 'image' => SP_PC_URL . 'admin/assets/img/offer-banner/bfcm-offer-banner.svg',
69 'link' => 'https://wpsmartpost.com/pricing/?campaign=spost&ref=423',
70 ),
71 'new_year' => array(
72 'id' => 'new_year_2026',
73 'start' => strtotime( '2025-12-26 00:00:00' ),
74 'end' => strtotime( '2026-01-14 23:59:59' ),
75 'image' => SP_PC_URL . 'admin/assets/img/offer-banner/new-year-offer-banner.svg', // Will be replaced by actual new year banner.
76 'link' => 'https://wpsmartpost.com/pricing/?campaign=spost&ref=423',
77 ),
78 );
79
80 $active_offers = array();
81
82 foreach ( $offers as $key => $offer ) {
83 if ( $now >= $offer['start'] && $now <= $offer['end'] ) {
84 $active_offers[ $key ] = $offer;
85 }
86 }
87
88 return $active_offers;
89 }
90
91 /**
92 * Renders the offer banner on the page.
93 *
94 * @return void
95 */
96 public function render_offer_banner() {
97 if ( ! current_user_can( 'manage_options' ) ) {
98 return;
99 }
100
101 $active_offers = $this->get_active_offers();
102
103 if ( empty( $active_offers ) ) {
104 return;
105 }
106
107 foreach ( $active_offers as $offer ) {
108 $option_key = 'shapedplugin_offer_banner_dismissed_' . $offer['id'];
109
110 // Check dismissed status.
111 if ( get_option( $option_key ) ) {
112 continue;
113 }
114
115 $nonce = wp_create_nonce( 'smart_tabs_offer_dismiss' );
116 ?>
117 <div id="shapedplugin-offer-banner" class="notice notice-info is-dismissible">
118 <a href="<?php echo esc_url( $offer['link'] ); ?>" target="_blank">
119 <img src="<?php echo esc_url( $offer['image'] ); ?>" alt="ShapedPlugin Offer" style="width:100%;height:auto;">
120 </a>
121
122 <button type="button"
123 class="notice-dismiss shapedplugin-offer-banner-dismiss"
124 data-offer-id="<?php echo esc_attr( $offer['id'] ); ?>"
125 data-nonce="<?php echo esc_attr( $nonce ); ?>">
126 </button>
127 </div>
128 <?php
129 }
130 ?>
131 <script type="text/javascript">
132 (function($){
133 $(document).on('click', '#shapedplugin-offer-banner .notice-dismiss', function(e){
134 e.preventDefault();
135 const nonce = $(this).data('nonce');
136 const offerID = $(this).data('offer-id')
137 $.post(ajaxurl, {
138 action: 'shapedplugin_dismiss_offer_banner',
139 offer_id: offerID,
140 nonce: nonce
141 });
142 $('#shapedplugin-offer-banner').fadeOut(300);
143 });
144 })(jQuery);
145 </script>
146 <?php
147 }
148
149 /**
150 * Handles the AJAX request to dismiss the offer banner.
151 *
152 * @return void
153 */
154 public function dismiss_offer_banner() {
155 check_ajax_referer( 'smart_tabs_offer_dismiss', 'nonce' );
156 $offer_id = isset( $_POST['offer_id'] ) ? sanitize_text_field( wp_unslash( $_POST['offer_id'] ) ) : '';
157
158 update_option( 'shapedplugin_offer_banner_dismissed_' . $offer_id, true );
159
160 wp_send_json_success();
161 }
162 }
163
164 ShapedPlugin_Offer_Banner::instance();
165 }