*/ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } if ( ! class_exists( 'ShapedPlugin_Offer_Banner' ) ) { /** * The class for all admin offer banner. */ class ShapedPlugin_Offer_Banner { /** * The single instance of the class. * * @var self * @since */ private static $instance = null; /** * Class constructor. */ private function __construct() { add_action( 'admin_notices', array( $this, 'render_offer_banner' ) ); add_action( 'wp_ajax_shapedplugin_dismiss_offer_banner', array( $this, 'dismiss_offer_banner' ) ); } /** * Retrieves the singleton instance of the class. * * This method ensures that only one instance of the class is created (singleton pattern). * * @return self The singleton instance of the class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Retrieves the active offers. * * @return array The list of active offers. */ public function get_active_offers() { $now = time(); // Define offer durations. $offers = array( 'black_friday' => array( 'id' => 'black_friday_2025', 'start' => strtotime( '2025-11-18 00:00:00' ), 'end' => strtotime( '2025-12-14 23:59:59' ), 'image' => SP_EA_URL . 'admin/img/offer-banner/bfcm-offer-banner.svg', 'link' => 'https://easyaccordion.io/pricing/?campaign=ea&ref=423', ), 'new_year' => array( 'id' => 'new_year_2026', 'start' => strtotime( '2025-12-26 00:00:00' ), 'end' => strtotime( '2026-01-14 23:59:59' ), 'image' => SP_EA_URL . 'admin/img/offer-banner/new-year-offer-banner.svg', 'link' => 'https://easyaccordion.io/pricing/?campaign=ea&ref=423', ), ); $active_offers = array(); foreach ( $offers as $key => $offer ) { if ( $now >= $offer['start'] && $now <= $offer['end'] ) { $active_offers[ $key ] = $offer; } } return $active_offers; } /** * Renders the offer banner on the page. * * @return void */ public function render_offer_banner() { if ( ! current_user_can( 'manage_options' ) ) { return; } $active_offers = $this->get_active_offers(); if ( empty( $active_offers ) ) { return; } foreach ( $active_offers as $offer ) { $option_key = 'shapedplugin_offer_banner_dismissed_' . $offer['id']; // Check dismissed status. if ( get_option( $option_key ) ) { continue; } $nonce = wp_create_nonce( 'smart_tabs_offer_dismiss' ); ?>
ShapedPlugin Offer