PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / trunk
Image Optimizer – Compress Images and Convert to WebP or AVIF vtrunk
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / modules / settings / banners / elementor-birthday-banner.php

elementor-birthday-banner.php in Image Optimizer – Compress Images and Convert to WebP or AVIF trunk, at modules/settings/banners/elementor-birthday-banner.php

152 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Settings\Banners;
4
5 use ImageOptimization\Modules\Core\Components\Pointers;
6 use Throwable;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Elementor_Birthday_Banner
14 */
15 class Elementor_Birthday_Banner {
16 const BANNER_POINTER_NAME = 'image_optimizer_birthday_sale_banner';
17 const POINTER_ACTION = 'image_optimizer_pointer_dismissed';
18 const POINTER_NONCE_KEY = 'image-optimization-pointer-dismissed';
19
20 public static function is_sale_time(): bool {
21 $sale_start_time = gmmktime( 9, 30, 0, 6, 15, 2026 );
22 $sale_end_time = gmmktime( 6, 59, 59, 6, 18, 2026 );
23
24 $now_time = gmdate( 'U' );
25
26 return $now_time >= $sale_start_time && $now_time <= $sale_end_time;
27 }
28
29 public static function user_viewed_banner(): bool {
30 return Pointers::is_dismissed( self::BANNER_POINTER_NAME );
31 }
32
33 /**
34 * Get banner markup
35 * @throws Throwable
36 */
37 public static function get_banner( string $link ) {
38 if ( ! self::is_sale_time() ) {
39 return;
40 }
41
42 if ( self::user_viewed_banner() ) {
43 return;
44 }
45
46 $img = plugins_url( '/images/elementor-birthday-banner.jpg', __FILE__ );
47 $url = admin_url( 'admin-ajax.php' );
48 $nonce = wp_create_nonce( self::POINTER_NONCE_KEY );
49 ?>
50 <div class="elementor-birthday-banner" role="region" aria-label="<?php esc_attr_e( 'Elementor birthday sale', 'image-optimization' ); ?>">
51 <div class="elementor-birthday-banner-container">
52 <p><span><?php esc_html_e( 'Celebrate Elementor’s 10th birthday', 'image-optimization' ); ?></span> | <?php esc_html_e( 'Up to 30% off', 'image-optimization' ); ?></p>
53 <a href="<?php echo esc_url( $link ); ?>" target="_blank"><?php esc_html_e( 'Get discounts', 'image-optimization' ); ?></a>
54 </div>
55 <button type="button" aria-label="<?php esc_attr_e( 'Dismiss', 'image-optimization' ); ?>">
56 <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
57 <path clip-rule="evenodd" fill-rule="evenodd" fill="#212121" d="M13.2803 1.28033C13.5732 0.987437 13.5732 0.512563 13.2803 0.21967C12.9874 -0.0732233 12.5126 -0.0732233 12.2197 0.21967L6.75 5.68934L1.28033 0.21967C0.987437 -0.0732233 0.512563 -0.0732233 0.21967 0.21967C-0.0732233 0.512563 -0.0732233 0.987437 0.21967 1.28033L5.68934 6.75L0.21967 12.2197C-0.0732233 12.5126 -0.0732233 12.9874 0.21967 13.2803C0.512563 13.5732 0.987437 13.5732 1.28033 13.2803L6.75 7.81066L12.2197 13.2803C12.5126 13.5732 12.9874 13.5732 13.2803 13.2803C13.5732 12.9874 13.5732 12.5126 13.2803 12.2197L7.81066 6.75L13.2803 1.28033Z"/>
58 </svg>
59 </button>
60 </div>
61 <style>
62 .elementor-birthday-banner {
63 position: relative;
64 min-height: 48px;
65 display: flex;
66 margin-inline-start: -20px;
67 margin-block-start: -48px;
68 z-index: 9999;
69 background-image: url('<?php echo esc_url( $img ); ?>');
70 background-size: cover;
71 background-position: center;
72 background-repeat: no-repeat;
73 }
74
75 .elementor-birthday-banner-container {
76 max-width: 1200px;
77 margin: 0 auto;
78 display: flex;
79 justify-content: center;
80 align-items: center;
81 gap: 20px;
82 }
83
84 .elementor-birthday-banner p {
85 margin: 0;
86 color: #2A0624;
87 font-size: 16px;
88 font-style: normal;
89 font-weight: 400;
90 font-feature-settings: 'liga' off, 'clig' off;
91 line-height: 1.4;
92 }
93
94 .elementor-birthday-banner p span {
95 font-weight: 700;
96 }
97
98 .elementor-birthday-banner a {
99 padding: 4px 16px;
100 border-radius: 6px;
101 background-color: #212121;
102 color: #fff;
103 font-size: 14px;
104 font-weight: 500;
105 font-feature-settings: 'liga' off, 'clig' off;
106 line-height: 1.4;
107 text-decoration: none;
108 text-align: center;
109 }
110
111 .elementor-birthday-banner button {
112 background: none;
113 border: none;
114 padding: 12px;
115 margin: 0 24px;
116 cursor: pointer;
117 float: inline-end;
118 line-height: 0;
119 }
120 </style>
121 <script>
122 document.addEventListener('DOMContentLoaded', function () {
123 const banner = document.querySelector('.elementor-birthday-banner');
124 const button = document.querySelector('.elementor-birthday-banner button');
125
126 const requestData = {
127 action: "<?php echo esc_js( self::POINTER_ACTION ); ?>",
128 nonce: "<?php echo esc_js( $nonce ); ?>",
129 data: {
130 pointer: "<?php echo esc_js( self::BANNER_POINTER_NAME ); ?>",
131 }
132 };
133
134 if (button) {
135 button.addEventListener('click', function () {
136 jQuery.ajax(
137 {
138 url: '<?php echo esc_js( $url ); ?>',
139 method: 'POST',
140 data: requestData,
141 success: () => banner.remove(),
142 error: (error) => console.error('Error:', error),
143 }
144 );
145 });
146 }
147 });
148 </script>
149 <?php
150 }
151 }
152