PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.24
Advanced Ads – Ad Manager & AdSense v2.0.24
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 4 weeks ago class-ad-network-ad-unit.php 5 months ago class-ad-network.php 1 year ago class-licenses.php 3 months ago class-notices.php 5 months ago class-overview-widgets.php 1 year ago class-plugins-screen-updates.php 2 months ago notices.php 5 months ago
class-notices.php
591 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 2025 deals.
361 if ( time() > 1764025200 &&
362 time() <= 1764630000 ) {
363 $options = $this->options();
364 $closed = isset( $options['closed'] ) ? $options['closed'] : [];
365
366 if ( ! isset( $closed['bfcm25'] ) ) {
367 $this->notices[] = 'bfcm25';
368 }
369 }
370
371 if ( [] === $this->notices ) {
372 return;
373 }
374
375 include_once ADVADS_ABSPATH . '/admin/includes/notices.php';
376
377 // Register Conflict Plugins notice
378 $this->register_plugin_conflict_notices($plugin_conflicts);
379
380 // Iterate through notices.
381 $count = 0;
382 foreach ( $this->notices as $_notice ) {
383
384 if ( isset( $advanced_ads_admin_notices[ $_notice ] ) ) {
385 $notice = $advanced_ads_admin_notices[ $_notice ];
386 $text = $advanced_ads_admin_notices[ $_notice ]['text'];
387 $type = isset( $advanced_ads_admin_notices[ $_notice ]['type'] ) ? $advanced_ads_admin_notices[ $_notice ]['type'] : '';
388 } else {
389 continue;
390 }
391
392 // don’t display non-global notices on other than plugin related pages.
393 if (
394 ( ! isset( $advanced_ads_admin_notices[ $_notice ]['global'] ) || ! $advanced_ads_admin_notices[ $_notice ]['global'] )
395 && ! Conditional::is_screen_advanced_ads()
396 ) {
397 continue;
398 }
399
400 // don't display license nag if ADVANCED_ADS_SUPPRESS_PLUGIN_ERROR_NOTICES is defined.
401 if ( defined( 'ADVANCED_ADS_SUPPRESS_PLUGIN_ERROR_NOTICES' ) && 'plugin_error' === $advanced_ads_admin_notices[ $_notice ]['type'] ) {
402 continue;
403 }
404
405 $hash = [
406 'info' => '/admin/views/notices/info.php',
407 'subscribe' => '/admin/views/notices/subscribe.php',
408 'plugin_error' => '/admin/views/notices/plugin_error.php',
409 'promo' => '/admin/views/notices/promo.php',
410 ];
411
412 $locate_tempalte = isset( $hash[ $type ] ) ? $hash[ $type ] : '/admin/views/notices/error.php';
413 include ADVADS_ABSPATH . $locate_tempalte;
414
415 // phpcs:disable
416 // if ( self::MAX_NOTICES === ++$count ) {
417 // break;
418 // }
419 // phpcs:enable
420 }
421 }
422
423 /**
424 * Return notices options
425 *
426 * @return array $options
427 */
428 public function options() {
429 if ( ! isset( $this->options ) ) {
430 $this->options = get_option( ADVADS_SLUG . '-notices', [] );
431 }
432
433 return $this->options;
434 }
435
436 /**
437 * Update notices options
438 *
439 * @param array $options new options.
440 */
441 public function update_options( array $options ) {
442 // do not allow to clear options.
443 if ( [] === $options ) {
444 return;
445 }
446
447 $this->options = $options;
448 update_option( ADVADS_SLUG . '-notices', $options );
449 }
450
451 /**
452 * Subscribe to newsletter and autoresponder
453 *
454 * @param string $notice slug of the subscription notice to send the correct reply.
455 *
456 * @return string
457 */
458 public function subscribe( $notice ) {
459 if ( ! isset( $notice ) ) {
460 return '';
461 }
462
463 $user = wp_get_current_user();
464
465 if ( '' === $user->user_email ) {
466 /* translators: %s: is a URL. */
467 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' );
468 }
469
470 $data = [
471 'email' => $user->user_email,
472 'notice' => $notice,
473 ];
474
475 $result = wp_remote_post(
476 'https://wpadvancedads.com/remote/subscribe.php?source=plugin',
477 [
478 'method' => 'POST',
479 'timeout' => 20,
480 'redirection' => 5,
481 'httpversion' => '1.1',
482 'blocking' => true,
483 'body' => $data,
484 ]
485 );
486
487 if ( is_wp_error( $result ) ) {
488 return __( 'How embarrassing. The email server seems to be down. Please try again later.', 'advanced-ads' );
489 }
490
491 // Mark as subscribed and move notice from queue.
492 $this->mark_as_subscribed( $notice );
493 $this->remove_from_queue( $notice );
494
495 /* translators: the first %s is an email address, the seconds %s is a URL. */
496 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' );
497 }
498
499 /**
500 * Update information that the current user is subscribed
501 *
502 * @param string $notice notice slug.
503 */
504 private function mark_as_subscribed( $notice ) {
505 // Early bail!!
506 if ( empty( $notice ) || ! Conditional::user_can_subscribe( $notice ) ) {
507 return;
508 }
509
510 $user_id = get_current_user_id();
511 $subscribed_notices = get_user_meta( $user_id, 'advanced-ads-subscribed', true );
512
513 // backward compatibility.
514 if ( ! is_array( $subscribed_notices ) ) {
515 $subscribed_notices = [];
516 }
517
518 $subscribed_notices[ $notice ] = true;
519
520 update_user_meta( $user_id, 'advanced-ads-subscribed', $subscribed_notices );
521 }
522
523 /**
524 * Check if a usesr can be subscribed to our newsletter
525 * check if is already subscribed or email is invalid
526 *
527 * @deprecated version 2.0 use Conditional::user_can_subscribe() instead
528 *
529 * @return bool true if user can subscribe
530 */
531 public function user_can_subscribe() {
532 _deprecated_function( __METHOD__, '2.0', '\AdvancedAds\Utilities\Conditional::user_can_subscribe()' );
533
534 return Conditional::user_can_subscribe( 'nl_first_steps' );
535 }
536
537 /**
538 * Add AdSense tutorial notice
539 *
540 * @param Ad $ad ad object.
541 */
542 public function adsense_tutorial( $ad ) {
543 $options = $this->options();
544 $_notice = 'nl_adsense';
545
546 if ( 'adsense' !== $ad->get_type() || isset( $options['closed'][ $_notice ] ) ) {
547 return;
548 }
549
550 include ADVADS_ABSPATH . '/admin/includes/notices.php';
551
552 if ( ! isset( $advanced_ads_admin_notices[ $_notice ] ) ) {
553 return;
554 }
555
556 $notice = $advanced_ads_admin_notices[ $_notice ];
557 $text = $notice['text'];
558 include ADVADS_ABSPATH . '/admin/views/notices/inline.php';
559 }
560
561
562
563 /**
564 * Register plugin conflict notices already defined in notices.php
565 */
566 public function register_plugin_conflict_notices($plugin_conflicts) {
567
568 // Early Bail !
569 if (empty($plugin_conflicts)) {
570 return;
571 }
572
573 $options = $this->options();
574 $queue = $options['queue'] ?? [];
575 $closed = $options['closed'] ?? [];
576
577
578 foreach($plugin_conflicts as $slug => $name){
579 $noticeId = str_replace(' ', '_', strtolower($name));
580 $notice_id = sanitize_title( $noticeId ) . '_active';
581 if ( ! is_plugin_active( $slug ) ) {
582 continue;
583 }
584 if ( ! in_array( $notice_id, $queue, true ) && ! isset( $closed[ $notice_id ] ) ) {
585 $this->notices[] = $notice_id;
586 }
587 }
588 }
589
590 }
591