| @@ -1,0 +1,73 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Admin; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +use ABlocks\Helper; | |
| 9 | + | |
| 10 | +class Notice { | |
| 11 | + public static function init() { | |
| 12 | + $self = new self(); | |
| 13 | + add_action( 'admin_notices', array( $self, 'admin_offer_notice' ) ); | |
| 14 | + add_action( 'admin_init', array( $self, 'dismiss_admin_offer_notice' ) ); | |
| 15 | + } | |
| 16 | + | |
| 17 | + public function admin_offer_notice() { | |
| 18 | + // Check if dismissed | |
| 19 | + if ( ! $this->has_upgrade_to_pro_notice() || get_user_meta( get_current_user_id(), 'ablocks_dismiss_offer_notice', true ) ) { | |
| 20 | + return; | |
| 21 | + } | |
| 22 | + | |
| 23 | + // Build dismissal URL (adds parameter to current page) | |
| 24 | + $dismiss_url = add_query_arg( | |
| 25 | + array( 'ablocks_dismiss_offer_notice' => '1' ), | |
| 26 | + esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) | |
| 27 | + ); | |
| 28 | + | |
| 29 | + ?> | |
| 30 | + <div class="notice notice-info ablocks-offer-notice" style="position: relative; display: flex; column-gap: 24px; padding: 24px; border-left-color: #13191b;"> | |
| 31 | + <div class="ablocks-offer-notice__thumbnail"> | |
| 32 | + <img src="<?php echo esc_url( ABLOCKS_ASSETS_URL . 'images/logo-shape.svg' ); ?>" alt="logo" style="width: 100px;" /> | |
| 33 | + </div> | |
| 34 | + <div> | |
| 35 | + <h2>Upgrade to aBlocks Pro Today!</h2> | |
| 36 | + <p>🔥 1 Site Only <strong>$29 LTD</strong> | <strong>$129 Unlimited</strong> LTD </p> | |
| 37 | + <p>Apply Code: <code>SpecialDeal</code> to Upgrade Now</p> | |
| 38 | + <p>Ends Sept 29</p> | |
| 39 | + <a class="button button-primary" href="https://ablocks.pro/pricing/" target="_blank" style="background: #13191b; color: #fff;">Get The Deal</a> | |
| 40 | + <a href="<?php echo esc_url( $dismiss_url ); ?>" style="position: absolute; top: 10px; right: 10px;"> | |
| 41 | + <?php esc_html_e( 'Dismiss', 'ablocks' ); ?> | |
| 42 | + </a> | |
| 43 | + </div> | |
| 44 | + </div> | |
| 45 | + <?php | |
| 46 | + } | |
| 47 | + | |
| 48 | + public function dismiss_admin_offer_notice() { | |
| 49 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 50 | + if ( isset( $_GET['ablocks_dismiss_offer_notice'] ) && $_GET['ablocks_dismiss_offer_notice'] == '1' ) { | |
| 51 | + update_user_meta( get_current_user_id(), 'ablocks_dismiss_offer_notice', 1 ); | |
| 52 | + | |
| 53 | + // Redirect to remove query param | |
| 54 | + wp_redirect( remove_query_arg( 'ablocks_dismiss_offer_notice' ) ); | |
| 55 | + exit; | |
| 56 | + } | |
| 57 | + } | |
| 58 | + | |
| 59 | + public static function has_upgrade_to_pro_notice() { | |
| 60 | + if ( Helper::is_active_ablocks_pro() ) { | |
| 61 | + return false; | |
| 62 | + } | |
| 63 | + | |
| 64 | + $saved_time = get_option( 'ablocks_first_install_time' ); | |
| 65 | + $three_days_ago = Helper::get_time() - ( 150 * DAY_IN_SECONDS ); | |
| 66 | + | |
| 67 | + if ( $saved_time < $three_days_ago ) { | |
| 68 | + return true; | |
| 69 | + } | |
| 70 | + | |
| 71 | + return false; | |
| 72 | + } | |
| 73 | +} | |