PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.6.0
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.6.0
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 / sale-banner.php

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

142 lines 4.2 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 * Sale_Banner
14 */
15 class Sale_Banner {
16 const BANNER_POINTER_NAME = 'image_optimizer_sale_bf_2024_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( 13, 0, 0, 11, 26, 2024 );
22 $sale_end_time = gmmktime( 9, 59, 0, 12, 4, 2024 );
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() || self::user_viewed_banner() ) {
39 return;
40 }
41 $img = plugins_url( '/images/bf-banner-io-2024.jpg', __FILE__ );
42 $url = admin_url( 'admin-ajax.php' );
43 $nonce = wp_create_nonce( self::POINTER_NONCE_KEY );
44
45 ?>
46 <div class="elementor-black-friday-banner">
47 <div class="elementor-black-friday-banner-container">
48 <img src="<?php echo esc_url( $img ); ?>" alt="Black Friday banner image">
49 <a href="<?php echo esc_url( $link ); ?>" target="_blank">
50 Claim discount
51 </a>
52 <button>
53 <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
54 <path fill-rule="evenodd" clip-rule="evenodd" 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" fill="white"/>
55 </svg>
56 </button>
57 </div>
58 </div>
59 <style>
60 .elementor-black-friday-banner {
61 overflow: hidden;
62 margin-left: -20px;
63 background: #000;
64 }
65 .elementor-black-friday-banner-container {
66 position: relative;
67 max-width: 1200px;
68 margin: 0 auto;
69 display: flex;
70 justify-content: end;
71 align-items: center;
72 height: 80px;
73 }
74 .elementor-black-friday-banner img {
75 position: absolute;
76 left: 0;
77 top: 50%;
78 transform: translateY(-50%);
79 width: 100%;
80 }
81 .elementor-black-friday-banner a {
82 position: relative;
83 display: inline-block;
84 padding: 12px 24px;
85 font-size: 18px;
86 color: #000;
87 background-color: #FF7BE5;
88 text-decoration: none;
89 z-index: 2;
90 }
91 .elementor-black-friday-banner button {
92 position: relative;
93 border: none;
94 background: none;
95 padding: 12px;
96 margin: 0 24px;
97 cursor: pointer;
98 z-index: 2;
99 }
100 @media (max-width: 768px) {
101 .elementor-black-friday-banner a {
102 padding: 6px 12px;
103 font-size: 14px;
104 }
105 .elementor-black-friday-banner button {
106 margin: 0 12px;
107 }
108 }
109 </style>
110 <script>
111 document.addEventListener('DOMContentLoaded', function () {
112 const banner = document.querySelector('.elementor-black-friday-banner');
113 const button = document.querySelector('.elementor-black-friday-banner button');
114
115 const requestData = {
116 action: "<?php echo esc_js( self::POINTER_ACTION ); ?>",
117 nonce: "<?php echo esc_js( $nonce ); ?>",
118 data: {
119 pointer: "<?php echo esc_js( self::BANNER_POINTER_NAME ); ?>",
120 }
121 };
122
123 if (button) {
124 button.addEventListener('click', function () {
125 jQuery.ajax(
126 {
127 url: '<?php echo esc_js( $url ); ?>',
128 method: 'POST',
129 data: requestData,
130 success: () => banner.remove(),
131 error: (error) => console.error('Error:', error),
132 }
133 );
134 });
135 }
136 });
137
138 </script>
139 <?php
140 }
141 }
142