PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.5
Advanced Ads – Ad Manager & AdSense v2.0.5
2.0.25 2.0.24 2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / admin / includes / class-notices.php
advanced-ads / admin / includes Last commit date
ad-health-notices.php 1 year ago class-ad-network-ad-unit.php 1 year ago class-ad-network.php 1 year ago class-licenses.php 1 year ago class-notices.php 1 year ago class-overview-widgets.php 1 year ago notices.php 1 year ago
class-notices.php
558 lines
1 <?php // phpcs:ignore WordPress.Files.FileName
2 /**
3 * Container class for admin notices
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.x.x
8 */
9
10 use AdvancedAds\Abstracts\Ad;
11 use AdvancedAds\Utilities\WordPress;
12 use AdvancedAds\Utilities\Conditional;
13 use AdvancedAds\Framework\Utilities\Arr;
14
15 /**
16 * Container class for admin notices
17 *
18 * @package WordPress
19 * @subpackage Advanced Ads Plugin
20 */
21 class Advanced_Ads_Admin_Notices {
22
23 /**
24 * Maximum number of notices to show at once
25 */
26 const MAX_NOTICES = 2;
27
28 /**
29 * Options
30 *
31 * @var array
32 */
33 protected $options;
34
35 /**
36 * Notices to be displayed
37 *
38 * @var array
39 */
40 public $notices = [];
41
42 /**
43 * Advanced_Ads_Admin_Notices constructor to load notices
44 */
45 public function __construct() {
46 $this->load_notices();
47 }
48
49 /**
50 * Return an instance of this class.
51 *
52 * @return object A single instance of this class.
53 */
54 public static function get_instance() {
55 static $instance;
56
57 // if the single instance hasn't been set, set it now.
58 if ( null === $instance ) {
59 $instance = new self();
60 }
61
62 return $instance;
63 }
64
65 /**
66 * Determines if a notice can be displayed.
67 *
68 * @param string $notice The notice identifier.
69 *
70 * @return bool Returns true if the notice can be displayed, false otherwise.
71 */
72 public function can_display( $notice ) {
73 $options = $this->options();
74 $closed = $options['closed'] ?? [];
75
76 return ! array_key_exists( $notice, $closed );
77 }
78
79 /**
80 * Load admin notices
81 */
82 public function load_notices() {
83 $options = $this->options();
84 $plugin_options = Advanced_Ads::get_instance()->options();
85
86 // load notices from queue.
87 $this->notices = isset( $options['queue'] ) ? $options['queue'] : [];
88 $notices_before = $this->notices;
89
90 // check license notices.
91 $this->register_license_notices();
92
93 // check wizard notice.
94 $this->register_wizard_notice();
95
96 // check non org plugins update.
97 $this->check_non_org_plugins();
98
99 // don’t check non-critical notices if they are disabled.
100 if ( ! isset( $plugin_options['disable-notices'] ) ) {
101 // check other notices.
102 $this->check_notices();
103 }
104
105 // register notices in db so they get displayed until closed for good.
106 if ( $this->notices !== $notices_before ) {
107 $this->add_to_queue( $this->notices );
108 }
109 }
110
111 /**
112 * Check various notices conditions
113 */
114 public function check_notices() {
115 $internal_options = Advanced_Ads::get_instance()->internal_options();
116 $now = time();
117 $activation = ( isset( $internal_options['installed'] ) ) ? $internal_options['installed'] : $now; // activation time.
118
119 $options = $this->options();
120 $closed = isset( $options['closed'] ) ? $options['closed'] : [];
121 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
122 $paused = isset( $options['paused'] ) ? $options['paused'] : [];
123
124 // offer free add-ons if not yet subscribed.
125 if ( Conditional::user_can_subscribe( 'nl_free_addons' ) && ! in_array( 'nl_free_addons', $queue, true ) && ! isset( $closed['nl_free_addons'] ) ) {
126 // get number of ads.
127 if ( WordPress::get_count_ads() ) {
128 $this->notices[] = 'nl_free_addons';
129 }
130 }
131 $number_of_ads = 0;
132 // needed error handling due to a weird bug in the piklist plugin.
133 try {
134 $number_of_ads = WordPress::get_count_ads();
135 } catch ( Exception $e ) { // phpcs:ignore
136 // no need to catch anything since we just use TRY/CATCH to prevent an issue caused by another plugin.
137 }
138
139 // ask for a review after 2 days and when 3 ads were created and when not paused.
140 if (
141 ! in_array( 'review', $queue, true )
142 && ! isset( $closed['review'] )
143 && ( ! isset( $paused['review'] ) || $paused['review'] <= time() )
144 && 172800 < ( time() - $activation )
145 && 3 <= $number_of_ads
146 ) {
147 $this->notices[] = 'review';
148 } elseif ( in_array( 'review', $queue, true ) && 3 > $number_of_ads ) {
149 $review_key = array_search( 'review', $this->notices, true );
150 if ( false !== $review_key ) {
151 unset( $this->notices[ $review_key ] );
152 }
153 }
154 }
155
156 /**
157 * Register license key notices
158 */
159 public function register_license_notices() {
160
161 if ( ! Conditional::is_screen_advanced_ads() ) {
162 return;
163 }
164
165 $options = $this->options();
166 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
167 // check license keys.
168
169 if ( Advanced_Ads_Checks::licenses_invalid() ) {
170 if ( ! in_array( 'license_invalid', $queue, true ) ) {
171 $this->notices[] = 'license_invalid';
172 }
173 } else {
174 $this->remove_from_queue( 'license_invalid' );
175 }
176 }
177
178 /**
179 * Register wizard notice.
180 */
181 public function register_wizard_notice() {
182 if ( ! Conditional::is_screen_advanced_ads() ) {
183 return;
184 }
185
186 $options = $this->options();
187 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
188
189 if ( Advanced_Ads_Checks::can_launch_wizard() ) {
190 if ( ! in_array( 'monetize_wizard', $queue, true ) ) {
191 $this->notices[] = 'monetize_wizard';
192 }
193 } else {
194 $this->remove_from_queue( 'monetize_wizard' );
195 }
196 }
197
198 /**
199 * Check for updates of non wp.org plugins
200 */
201 public function check_non_org_plugins() {
202 if ( ! Conditional::is_screen_advanced_ads() ) {
203 return;
204 }
205
206 $addons = \AdvancedAds\Constants::ADDONS_NON_COMPATIBLE_VERSIONS;
207 $plugins = WordPress::get_wp_plugins();
208 $options = $this->options();
209 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
210 $closed = isset( $options['closed'] ) ? $options['closed'] : [];
211
212 foreach ( $addons as $version => $slug ) {
213 $addon = $plugins[ $slug ] ?? null;
214 if ( ! $addon ) {
215 continue;
216 }
217
218 $notice = $slug . '_upgrade';
219
220 if ( version_compare( $addon['version'], $version, '<=' ) ) {
221 if ( ! in_array( $notice, $queue, true ) && ! array_key_exists( $notice, $closed ) ) {
222 $this->notices[] = $notice;
223 }
224 } else {
225 $this->remove_from_queue( $notice );
226 }
227 }
228 }
229
230 /**
231 * Add update notices to the queue of all notices that still needs to be closed
232 *
233 * @param mixed $notices one or more notices to be added to the queue.
234 *
235 * @since 1.5.3
236 */
237 public function add_to_queue( $notices = 0 ) {
238 if ( ! $notices ) {
239 return;
240 }
241
242 // get queue from options.
243 $options = $this->options();
244 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
245
246 if ( is_array( $notices ) ) {
247 $queue = array_merge( $queue, $notices );
248 } else {
249 $queue[] = $notices;
250 }
251
252 // remove possible duplicated.
253 $queue = array_unique( $queue );
254
255 // update db.
256 $options['queue'] = $queue;
257 $this->update_options( $options );
258 }
259
260 /**
261 * Remove update notice from queue
262 * move notice into "closed"
263 *
264 * @param string $notice notice to be removed from the queue.
265 *
266 * @since 1.5.3
267 */
268 public function remove_from_queue( $notice ) {
269 if ( ! isset( $notice ) ) {
270 return;
271 }
272
273 // get queue from options.
274 $options = $this->options();
275 $options_before = $options;
276 if ( ! isset( $options['queue'] ) ) {
277 return;
278 }
279 $queue = (array) $options['queue'];
280 $closed = isset( $options['closed'] ) ? $options['closed'] : [];
281 $paused = isset( $options['paused'] ) ? $options['paused'] : [];
282
283 $key = array_search( $notice, $queue, true );
284 if ( false !== $key ) {
285 unset( $queue[ $key ] );
286 // close message with timestamp.
287 }
288 // don’t close again twice.
289 if ( ! isset( $closed[ $notice ] ) ) {
290 $closed[ $notice ] = time();
291 }
292 // remove from pause.
293 if ( isset( $paused[ $notice ] ) ) {
294 unset( $paused[ $notice ] );
295 }
296
297 // update db.
298 $options['queue'] = $queue;
299 $options['closed'] = $closed;
300 $options['paused'] = $paused;
301
302 // only update if changed.
303 if ( $options_before !== $options ) {
304 $this->update_options( $options );
305 // update already registered notices.
306 $this->load_notices();
307 }
308 }
309
310 /**
311 * Hide any notice for a given time
312 * move notice into "paused" with notice as key and timestamp as value
313 *
314 * @param string $notice notice to be paused.
315 */
316 public function hide_notice( $notice ) {
317 if ( ! isset( $notice ) ) {
318 return;
319 }
320
321 // get queue from options.
322 $options = $this->options();
323 $options_before = $options;
324 if ( ! isset( $options['queue'] ) ) {
325 return;
326 }
327 $queue = (array) $options['queue'];
328 $paused = isset( $options['paused'] ) ? $options['paused'] : [];
329
330 $key = array_search( $notice, $queue, true );
331 if ( false !== $key ) {
332 unset( $queue[ $key ] );
333 }
334 // close message with timestamp in 7 days
335 // don’t close again twice.
336 if ( ! isset( $paused[ $notice ] ) ) {
337 $paused[ $notice ] = time() + WEEK_IN_SECONDS;
338 }
339
340 // update db.
341 $options['queue'] = $queue;
342 $options['paused'] = $paused;
343
344 // only update if changed.
345 if ( $options_before !== $options ) {
346 $this->update_options( $options );
347 // update already registered notices.
348 $this->load_notices();
349 }
350 }
351
352 /**
353 * Display notices
354 */
355 public function display_notices() {
356 if ( wp_doing_ajax() ) {
357 return;
358 }
359
360 // register Black Friday 2023 deals.
361 if ( time() > 1700654400 &&
362 time() <= 1701172800 && Conditional::is_screen_advanced_ads() ) {
363 $options = $this->options();
364 $closed = isset( $options['closed'] ) ? $options['closed'] : [];
365
366 if ( ! isset( $closed['bfcm23'] ) ) {
367 $this->notices[] = 'bfcm23';
368 }
369 }
370
371 if ( [] === $this->notices ) {
372 return;
373 }
374
375 include_once ADVADS_ABSPATH . '/admin/includes/notices.php';
376
377 // Iterate through notices.
378 $count = 0;
379 foreach ( $this->notices as $_notice ) {
380
381 if ( isset( $advanced_ads_admin_notices[ $_notice ] ) ) {
382 $notice = $advanced_ads_admin_notices[ $_notice ];
383 $text = $advanced_ads_admin_notices[ $_notice ]['text'];
384 $type = isset( $advanced_ads_admin_notices[ $_notice ]['type'] ) ? $advanced_ads_admin_notices[ $_notice ]['type'] : '';
385 } else {
386 continue;
387 }
388
389 // don’t display non-global notices on other than plugin related pages.
390 if (
391 ( ! isset( $advanced_ads_admin_notices[ $_notice ]['global'] ) || ! $advanced_ads_admin_notices[ $_notice ]['global'] )
392 && ! Conditional::is_screen_advanced_ads()
393 ) {
394 continue;
395 }
396
397 // don't display license nag if ADVANCED_ADS_SUPPRESS_PLUGIN_ERROR_NOTICES is defined.
398 if ( defined( 'ADVANCED_ADS_SUPPRESS_PLUGIN_ERROR_NOTICES' ) && 'plugin_error' === $advanced_ads_admin_notices[ $_notice ]['type'] ) {
399 continue;
400 }
401
402 $hash = [
403 'info' => '/admin/views/notices/info.php',
404 'subscribe' => '/admin/views/notices/subscribe.php',
405 'plugin_error' => '/admin/views/notices/plugin_error.php',
406 'promo' => '/admin/views/notices/promo.php',
407 ];
408
409 $locate_tempalte = isset( $hash[ $type ] ) ? $hash[ $type ] : '/admin/views/notices/error.php';
410 include ADVADS_ABSPATH . $locate_tempalte;
411
412 // phpcs:disable
413 // if ( self::MAX_NOTICES === ++$count ) {
414 // break;
415 // }
416 // phpcs:enable
417 }
418 }
419
420 /**
421 * Return notices options
422 *
423 * @return array $options
424 */
425 public function options() {
426 if ( ! isset( $this->options ) ) {
427 $this->options = get_option( ADVADS_SLUG . '-notices', [] );
428 }
429
430 return $this->options;
431 }
432
433 /**
434 * Update notices options
435 *
436 * @param array $options new options.
437 */
438 public function update_options( array $options ) {
439 // do not allow to clear options.
440 if ( [] === $options ) {
441 return;
442 }
443
444 $this->options = $options;
445 update_option( ADVADS_SLUG . '-notices', $options );
446 }
447
448 /**
449 * Subscribe to newsletter and autoresponder
450 *
451 * @param string $notice slug of the subscription notice to send the correct reply.
452 *
453 * @return string
454 */
455 public function subscribe( $notice ) {
456 if ( ! isset( $notice ) ) {
457 return '';
458 }
459
460 $user = wp_get_current_user();
461
462 if ( '' === $user->user_email ) {
463 /* translators: %s: is a URL. */
464 return sprintf( __( 'You don’t seem to have an email address. Please use <a href="%s" target="_blank">this form</a> to sign up.', 'advanced-ads' ), 'http://eepurl.com/bk4z4P' );
465 }
466
467 $data = [
468 'email' => $user->user_email,
469 'notice' => $notice,
470 ];
471
472 $result = wp_remote_post(
473 'https://wpadvancedads.com/remote/subscribe.php?source=plugin',
474 [
475 'method' => 'POST',
476 'timeout' => 20,
477 'redirection' => 5,
478 'httpversion' => '1.1',
479 'blocking' => true,
480 'body' => $data,
481 ]
482 );
483
484 if ( is_wp_error( $result ) ) {
485 return __( 'How embarrassing. The email server seems to be down. Please try again later.', 'advanced-ads' );
486 }
487
488 // Mark as subscribed and move notice from queue.
489 $this->mark_as_subscribed( $notice );
490 $this->remove_from_queue( $notice );
491
492 /* translators: the first %s is an email address, the seconds %s is a URL. */
493 return sprintf( __( 'Please check your email (%1$s) for the confirmation message. If you didn’t receive one or want to use another email address then please use <a href="%2$s" target="_blank">this form</a> to sign up.', 'advanced-ads' ), $user->user_email, 'http://eepurl.com/bk4z4P' );
494 }
495
496 /**
497 * Update information that the current user is subscribed
498 *
499 * @param string $notice notice slug.
500 */
501 private function mark_as_subscribed( $notice ) {
502 // Early bail!!
503 if ( empty( $notice ) || ! Conditional::user_can_subscribe( $notice ) ) {
504 return;
505 }
506
507 $user_id = get_current_user_id();
508 $subscribed_notices = get_user_meta( $user_id, 'advanced-ads-subscribed', true );
509
510 // backward compatibility.
511 if ( ! is_array( $subscribed_notices ) ) {
512 $subscribed_notices = [];
513 }
514
515 $subscribed_notices[ $notice ] = true;
516
517 update_user_meta( $user_id, 'advanced-ads-subscribed', $subscribed_notices );
518 }
519
520 /**
521 * Check if a usesr can be subscribed to our newsletter
522 * check if is already subscribed or email is invalid
523 *
524 * @deprecated version 2.0 use Conditional::user_can_subscribe() instead
525 *
526 * @return bool true if user can subscribe
527 */
528 public function user_can_subscribe() {
529 _deprecated_function( __METHOD__, '2.0', '\AdvancedAds\Utilities\Conditional::user_can_subscribe()' );
530
531 return Conditional::user_can_subscribe( 'nl_first_steps' );
532 }
533
534 /**
535 * Add AdSense tutorial notice
536 *
537 * @param Ad $ad ad object.
538 */
539 public function adsense_tutorial( $ad ) {
540 $options = $this->options();
541 $_notice = 'nl_adsense';
542
543 if ( 'adsense' !== $ad->get_type() || isset( $options['closed'][ $_notice ] ) ) {
544 return;
545 }
546
547 include ADVADS_ABSPATH . '/admin/includes/notices.php';
548
549 if ( ! isset( $advanced_ads_admin_notices[ $_notice ] ) ) {
550 return;
551 }
552
553 $notice = $advanced_ads_admin_notices[ $_notice ];
554 $text = $notice['text'];
555 include ADVADS_ABSPATH . '/admin/views/notices/inline.php';
556 }
557 }
558