PluginProbe ʕ •ᴥ•ʔ
Essential Addons for Elementor – Popular Elementor Templates & Widgets / 6.2.3
Essential Addons for Elementor – Popular Elementor Templates & Widgets v6.2.3
6.6.9 6.6.8 6.6.7 6.6.6 6.6.5 6.6.4 6.6.3 5.7.3 5.7.4 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.15 5.8.16 5.8.18 5.8.2 5.8.3 5.8.4 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.10 5.9.11 5.9.12 5.9.13 5.9.14 5.9.15 5.9.16 5.9.17 5.9.18 5.9.19 5.9.2 5.9.20 5.9.21 5.9.22 5.9.23 5.9.24 5.9.25 5.9.26 5.9.27 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.14 6.0.15 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9 6.1.0 6.1.1 6.1.10 6.1.11 trunk 6.1.12 1.0.0 6.1.13 1.0.1 6.1.14 1.1.0 6.1.15 2.0 6.1.17 2.1 6.1.18 2.10.0 6.1.19 2.10.1 6.1.2 2.10.2 6.1.20 2.10.3 6.1.3 2.10.4 6.1.4 2.10.5 6.1.5 2.2.0 6.1.6 2.2.1 6.1.7 2.2.2 6.1.8 2.2.3 6.1.9 2.2.4 6.2.0 2.2.5 6.2.1 2.3.0 6.2.2 2.3.1 6.2.3 2.4.0 6.2.4 2.4.1 6.3.0 2.4.2 6.3.1 2.4.3 6.3.2 2.5.0 6.3.3 2.6.0 6.4.0 2.7.0 6.5.0 2.7.1 6.5.1 2.7.10 6.5.10 2.7.11 6.5.11 2.7.2 6.5.12 2.7.3 6.5.13 2.7.4 6.5.2 2.7.5 6.5.3 2.7.6 6.5.4 2.7.7 6.5.5 2.7.8 6.5.6 2.7.9 6.5.7 2.8.0 6.5.8 2.8.1 6.5.9 2.8.2 6.6.0 2.8.3 6.6.1 2.8.4 6.6.2 2.8.5 2.8.6 2.8.7 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.4.1 3.1.5 3.2.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.5.0 3.5.1 3.5.2 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 5.0.0 5.0.1 5.0.10 5.0.11 5.0.12 5.0.13 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.4.6 5.5.5 5.6.5 5.7.2
essential-addons-for-elementor-lite / vendor / priyomukul / wp-notice / src / Notices.php
essential-addons-for-elementor-lite / vendor / priyomukul / wp-notice / src Last commit date
Utils 2 years ago Dismiss.php 2 years ago Notice.php 2 years ago Notices.php 2 years ago
Notices.php
234 lines
1 <?php
2
3 namespace PriyoMukul\WPNotice;
4
5 use Exception;
6 use PriyoMukul\WPNotice\Utils\Base;
7 use PriyoMukul\WPNotice\Utils\CacheBank;
8 use PriyoMukul\WPNotice\Utils\Helper;
9
10
11 /**
12 * @property $notices []
13 * @property $queue []
14 * @property $id string
15 * @property $stylesheet_url string
16 */
17 #[\AllowDynamicProperties]
18 final class Notices extends Base {
19 use Helper;
20
21 const VERSION = '1.1.0';
22
23 private $version = '1.1.0';
24
25 public $system_id = 'wpnotice_system';
26 public $app = 'wpnotice';
27 private $storage = null;
28 private $scripts = null;
29
30 private $args;
31
32 /**
33 * A list of notice
34 * @var array
35 */
36 private $notices = [];
37
38 /**
39 * A list of notice based to timestamp (A Queue)
40 * @var false|mixed
41 */
42 private $queue;
43
44 /**
45 * @var CacheBank
46 */
47 private static $cache_bank;
48
49 /**
50 * @var bool
51 */
52 private $dev_mode = false;
53
54 /**
55 * Default notice system options
56 * @var array
57 */
58 private $options = [
59 'id' => '',
60 'stylesheet_url' => '',
61 'priority' => 1
62 ];
63
64 private $deprecated_options = [
65 'system_id' => 'id',
66 'app' => 'id',
67 'scripts' => 'stylesheet_url'
68 ];
69
70 private $default_options = [
71 'scripts_handle' => ''
72 ];
73
74 /**
75 * This method takes an array as argument.
76 *
77 * @template $args
78 *
79 * @param $args
80 *
81 * @throws Exception
82 */
83 public function __construct( $args ) {
84 self::$cache_bank = CacheBank::get_instance();
85
86 /**
87 * Check all the property is passed or not
88 */
89 if ( ! isset( $args['version'] ) && self::VERSION === '1.1.0' ) {
90 if ( ! is_array( $args ) ) {
91 $this->error( "Argument of " . __CLASS__ . " should be an array. " . gettype( $args ) . " given." );
92 }
93
94 if ( empty( $args ) ) {
95 $this->error( "Argument of " . __CLASS__ . " should not be an empty array." );
96 }
97
98 foreach ( $this->options as $key => $value ) {
99 if ( ! isset( $args[ $key ] ) ) {
100 $this->error( "Missing $key from argument list." );
101 }
102 }
103
104 $this->options = wp_parse_args( $args, $this->options );
105 $this->scripts = $this->stylesheet_url;
106 }
107
108 $this->system_id = ! empty( $args['id'] ) ? $args['id'] . '-notice-system' : 'wpnotice_system';
109 $this->app = ! empty( $args['id'] ) ? $args['id'] : 'wpnotice';
110 $this->dev_mode = ! empty( $args['dev_mode'] ) ? $args['dev_mode'] : $this->dev_mode;
111 $this->args = $args;
112
113 if ( ! empty( $args['styles'] ) ) {
114 $this->scripts = $args['styles'];
115 unset( $args['styles'] );
116 }
117
118 $this->queue = $this->storage()->get( '', [] );
119
120 self::$cache_bank->create_account( $this );
121 }
122
123 public function __get( $name ) {
124 if ( property_exists( $this, $name ) ) {
125 return $this->$name;
126 }
127
128 if ( ! empty( $this->options[ $name ] ) ) {
129 return $this->options[ $name ];
130 }
131
132 if ( isset( $this->deprecated_options[ $name ] ) && ! empty( $this->options[ $this->deprecated_options[ $name ] ] ) ) {
133 return $this->options[ $this->deprecated_options[ $name ] ];
134 }
135
136 if ( ! empty( $this->args[ $name ] ) ) {
137 return $this->args[ $name ];
138 }
139
140 return null;
141 }
142
143 public function storage() {
144 return $this->database( $this->args );
145 }
146
147 public function init() {
148 }
149
150 public function notices() {
151 wp_enqueue_style( $this->system_id, $this->scripts );
152
153 if ( ! $this->dev_mode ) {
154 /**
155 * @var Notice $notice
156 */
157 $notice = $this->current_notice();
158 if ( $notice ) {
159 $notice->display();
160 }
161 }
162
163 /**
164 * Print all notices while dev_mode is enabled.
165 */
166 $this->print_notices_for_dev_mode();
167 }
168
169 public function eligible_notices( $notices = [], $queue = [] ) {
170 $_sorted_queue = [];
171 $notices = empty( $notices ) ? $this->notices : $notices;
172 $queue = empty( $queue ) ? $this->queue : $queue;
173
174 if ( ! empty ( $queue ) ) {
175 array_walk( $queue, function ( $value, $key ) use ( &$_sorted_queue, $notices ) {
176 $notice = isset( $notices[ $key ] ) ? $notices[ $key ] : null;
177 if ( ! is_null( $notice ) ) {
178 if ( ! $notice->dismiss->is_dismissed() && ! $notice->is_expired() ) {
179 $_sorted_queue[ $notice->options( 'start' ) ] = $key;
180 }
181 }
182 } );
183 }
184
185 ksort( $_sorted_queue );
186
187 return $_sorted_queue;
188 }
189
190 public function scripts() {
191 if ( ! $this->dev_mode ) {
192 /**
193 * @var Notice $notice
194 */
195 $notice = $this->current_notice();
196
197 if ( $notice && $notice->show() ) {
198 $notice->dismiss->print_script();
199 }
200 }
201
202 /**
203 * Print scripts for all notices while dev_mode is enabled.
204 */
205 $this->print_notices_for_dev_mode( true );
206 }
207
208 public function add( $id, $content, $options = [] ) {
209 $this->notices[ $id ] = new Notice( $id, $content, $options, $this->queue, $this );
210
211 self::$cache_bank->deposit( $this->id, $id, $this->notices[ $id ] );
212 }
213
214 private function current_notice() {
215 $current_notice = current( $this->eligible_notices() );
216
217 return isset( $this->notices[ $current_notice ] ) ? $this->notices[ $current_notice ] : false;
218 }
219
220 private function print_notices_for_dev_mode( $scripts = false ) {
221 if ( $this->dev_mode ) {
222 /**
223 * @var Notice $notice
224 */
225 foreach ( $this->notices as $notice ) {
226 if ( $scripts ) {
227 $notice->dismiss->print_script();
228 } else {
229 $notice->display( true );
230 }
231 }
232 }
233 }
234 }