PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.25
Advanced Ads – Ad Manager & AdSense v2.0.25
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 2 days ago class-ad-network-ad-unit.php 5 months ago class-ad-network.php 1 year ago class-licenses.php 2 days ago class-notices.php 2 days ago class-overview-widgets.php 2 days ago class-plugins-screen-updates.php 3 months ago notices.php 2 days ago
class-notices.php
592 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\Addons;
12 use AdvancedAds\Utilities\WordPress;
13 use AdvancedAds\Utilities\Conditional;
14 use AdvancedAds\Framework\Utilities\Arr;
15
16 /**
17 * Container class for admin notices
18 *
19 * @package WordPress
20 * @subpackage Advanced Ads Plugin
21 */
22 class Advanced_Ads_Admin_Notices {
23
24 /**
25 * Maximum number of notices to show at once
26 */
27 const MAX_NOTICES = 2;
28
29 /**
30 * Options
31 *
32 * @var array
33 */
34 protected $options;
35
36 /**
37 * Notices to be displayed
38 *
39 * @var array
40 */
41 public $notices = [];
42
43 /**
44 * Advanced_Ads_Admin_Notices constructor to load notices
45 */
46 public function __construct() {
47 $this->load_notices();
48 }
49
50 /**
51 * Return an instance of this class.
52 *
53 * @return object A single instance of this class.
54 */
55 public static function get_instance() {
56 static $instance;
57
58 // if the single instance hasn't been set, set it now.
59 if ( null === $instance ) {
60 $instance = new self();
61 }
62
63 return $instance;
64 }
65
66 /**
67 * Determines if a notice can be displayed.
68 *
69 * @param string $notice The notice identifier.
70 *
71 * @return bool Returns true if the notice can be displayed, false otherwise.
72 */
73 public function can_display( $notice ) {
74 $options = $this->options();
75 $closed = $options['closed'] ?? [];
76
77 return ! array_key_exists( $notice, $closed );
78 }
79
80 /**
81 * Load admin notices
82 */
83 public function load_notices() {
84 $options = $this->options();
85 $plugin_options = Advanced_Ads::get_instance()->options();
86
87 // load notices from queue.
88 $this->notices = isset( $options['queue'] ) ? $options['queue'] : [];
89 $notices_before = $this->notices;
90
91 // check license notices.
92 $this->register_license_notices();
93
94 // check wizard notice.
95 $this->register_wizard_notice();
96
97 // check non org plugins update.
98 $this->check_non_org_plugins();
99
100 // don’t check non-critical notices if they are disabled.
101 if ( ! isset( $plugin_options['disable-notices'] ) ) {
102 // check other notices.
103 $this->check_notices();
104 }
105
106 // register notices in db so they get displayed until closed for good.
107 if ( $this->notices !== $notices_before ) {
108 $this->add_to_queue( $this->notices );
109 }
110 }
111
112 /**
113 * Check various notices conditions
114 */
115 public function check_notices() {
116 $internal_options = Advanced_Ads::get_instance()->internal_options();
117 $now = time();
118 $activation = ( isset( $internal_options['installed'] ) ) ? $internal_options['installed'] : $now; // activation time.
119
120 $options = $this->options();
121 $closed = isset( $options['closed'] ) ? $options['closed'] : [];
122 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
123 $paused = isset( $options['paused'] ) ? $options['paused'] : [];
124
125 // offer free add-ons if not yet subscribed.
126 if ( Conditional::user_can_subscribe( 'nl_free_addons' ) && ! in_array( 'nl_free_addons', $queue, true ) && ! isset( $closed['nl_free_addons'] ) ) {
127 // get number of ads.
128 if ( WordPress::get_count_ads() ) {
129 $this->notices[] = 'nl_free_addons';
130 }
131 }
132 $number_of_ads = 0;
133 // needed error handling due to a weird bug in the piklist plugin.
134 try {
135 $number_of_ads = WordPress::get_count_ads();
136 } catch ( Exception $e ) { // phpcs:ignore
137 // no need to catch anything since we just use TRY/CATCH to prevent an issue caused by another plugin.
138 }
139
140 // ask for a review after 2 days and when 3 ads were created and when not paused.
141 if (
142 ! in_array( 'review', $queue, true )
143 && ! isset( $closed['review'] )
144 && ( ! isset( $paused['review'] ) || $paused['review'] <= time() )
145 && 172800 < ( time() - $activation )
146 && 3 <= $number_of_ads
147 ) {
148 $this->notices[] = 'review';
149 } elseif ( in_array( 'review', $queue, true ) && 3 > $number_of_ads ) {
150 $review_key = array_search( 'review', $this->notices, true );
151 if ( false !== $review_key ) {
152 unset( $this->notices[ $review_key ] );
153 }
154 }
155 }
156
157 /**
158 * Register license key notices
159 */
160 public function register_license_notices() {
161
162 if ( ! Conditional::is_screen_advanced_ads() ) {
163 return;
164 }
165
166 $options = $this->options();
167 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
168 // check license keys.
169
170 if ( Advanced_Ads_Checks::licenses_invalid() ) {
171 if ( ! in_array( 'license_invalid', $queue, true ) ) {
172 $this->notices[] = 'license_invalid';
173 }
174 } else {
175 $this->remove_from_queue( 'license_invalid' );
176 }
177 }
178
179 /**
180 * Register wizard notice.
181 */
182 public function register_wizard_notice() {
183 if ( ! Conditional::is_screen_advanced_ads() ) {
184 return;
185 }
186
187 $options = $this->options();
188 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
189
190 if ( Advanced_Ads_Checks::can_launch_wizard() ) {
191 if ( ! in_array( 'monetize_wizard', $queue, true ) ) {
192 $this->notices[] = 'monetize_wizard';
193 }
194 } else {
195 $this->remove_from_queue( 'monetize_wizard' );
196 }
197 }
198
199 /**
200 * Check for updates of non wp.org plugins
201 */
202 public function check_non_org_plugins() {
203 if ( ! Conditional::is_screen_advanced_ads() ) {
204 return;
205 }
206
207 $addons = \AdvancedAds\Constants::ADDONS_NON_COMPATIBLE_VERSIONS;
208 $plugins = Addons::get_plugins_by_text_domain( true );
209 $options = $this->options();
210 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
211 $closed = isset( $options['closed'] ) ? $options['closed'] : [];
212
213 foreach ( $addons as $version => $slug ) {
214 $addon = $plugins[ $slug ] ?? null;
215 if ( ! $addon ) {
216 continue;
217 }
218
219 $notice = $slug . '_upgrade';
220
221 if ( version_compare( $addon['version'], $version, '<=' ) ) {
222 if ( ! in_array( $notice, $queue, true ) && ! array_key_exists( $notice, $closed ) ) {
223 $this->notices[] = $notice;
224 }
225 } else {
226 $this->remove_from_queue( $notice );
227 }
228 }
229 }
230
231 /**
232 * Add update notices to the queue of all notices that still needs to be closed
233 *
234 * @param mixed $notices one or more notices to be added to the queue.
235 *
236 * @since 1.5.3
237 */
238 public function add_to_queue( $notices = 0 ) {
239 if ( ! $notices ) {
240 return;
241 }
242
243 // get queue from options.
244 $options = $this->options();
245 $queue = isset( $options['queue'] ) ? $options['queue'] : [];
246
247 if ( is_array( $notices ) ) {
248 $queue = array_merge( $queue, $notices );
249 } else {
250 $queue[] = $notices;
251 }
252
253 // remove possible duplicated.
254 $queue = array_unique( $queue );
255
256 // update db.
257 $options['queue'] = $queue;
258 $this->update_options( $options );
259 }
260
261 /**
262 * Remove update notice from queue
263 * move notice into "closed"
264 *
265 * @param string $notice notice to be removed from the queue.
266 *
267 * @since 1.5.3
268 */
269 public function remove_from_queue( $notice ) {
270 if ( ! isset( $notice ) ) {
271 return;
272 }
273
274 // get queue from options.
275 $options = $this->options();
276 $options_before = $options;
277 if ( ! isset( $options['queue'] ) ) {
278 return;
279 }
280 $queue = (array) $options['queue'];
281 $closed = isset( $options['closed'] ) ? $options['closed'] : [];
282 $paused = isset( $options['paused'] ) ? $options['paused'] : [];
283
284 $key = array_search( $notice, $queue, true );
285 if ( false !== $key ) {
286 unset( $queue[ $key ] );
287 // close message with timestamp.
288 }
289 // don’t close again twice.
290 if ( ! isset( $closed[ $notice ] ) ) {
291 $closed[ $notice ] = time();
292 }
293 // remove from pause.
294 if ( isset( $paused[ $notice ] ) ) {
295 unset( $paused[ $notice ] );
296 }
297
298 // update db.
299 $options['queue'] = $queue;
300 $options['closed'] = $closed;
301 $options['paused'] = $paused;
302
303 // only update if changed.
304 if ( $options_before !== $options ) {
305 $this->update_options( $options );
306 // update already registered notices.
307 $this->load_notices();
308 }
309 }
310
311 /**
312 * Hide any notice for a given time
313 * move notice into "paused" with notice as key and timestamp as value
314 *
315 * @param string $notice notice to be paused.
316 */
317 public function hide_notice( $notice ) {
318 if ( ! isset( $notice ) ) {
319 return;
320 }
321
322 // get queue from options.
323 $options = $this->options();
324 $options_before = $options;
325 if ( ! isset( $options['queue'] ) ) {
326 return;
327 }
328 $queue = (array) $options['queue'];
329 $paused = isset( $options['paused'] ) ? $options['paused'] : [];
330
331 $key = array_search( $notice, $queue, true );
332 if ( false !== $key ) {
333 unset( $queue[ $key ] );
334 }
335 // close message with timestamp in 7 days
336 // don’t close again twice.
337 if ( ! isset( $paused[ $notice ] ) ) {
338 $paused[ $notice ] = time() + WEEK_IN_SECONDS;
339 }
340
341 // update db.
342 $options['queue'] = $queue;
343 $options['paused'] = $paused;
344
345 // only update if changed.
346 if ( $options_before !== $options ) {
347 $this->update_options( $options );
348 // update already registered notices.
349 $this->load_notices();
350 }
351 }
352
353 /**
354 * Display notices
355 */
356 public function display_notices() {
357 if ( wp_doing_ajax() ) {
358 return;
359 }
360
361 // register Black Friday 2025 deals.
362 if ( time() > 1764025200 &&
363 time() <= 1764630000 ) {
364 $options = $this->options();
365 $closed = isset( $options['closed'] ) ? $options['closed'] : [];
366
367 if ( ! isset( $closed['bfcm25'] ) ) {
368 $this->notices[] = 'bfcm25';
369 }
370 }
371
372 if ( [] === $this->notices ) {
373 return;
374 }
375
376 include_once ADVADS_ABSPATH . '/admin/includes/notices.php';
377
378 // Register Conflict Plugins notice
379 $this->register_plugin_conflict_notices($plugin_conflicts);
380
381 // Iterate through notices.
382 $count = 0;
383 foreach ( $this->notices as $_notice ) {
384
385 if ( isset( $advanced_ads_admin_notices[ $_notice ] ) ) {
386 $notice = $advanced_ads_admin_notices[ $_notice ];
387 $text = $advanced_ads_admin_notices[ $_notice ]['text'];
388 $type = isset( $advanced_ads_admin_notices[ $_notice ]['type'] ) ? $advanced_ads_admin_notices[ $_notice ]['type'] : '';
389 } else {
390 continue;
391 }
392
393 // don’t display non-global notices on other than plugin related pages.
394 if (
395 ( ! isset( $advanced_ads_admin_notices[ $_notice ]['global'] ) || ! $advanced_ads_admin_notices[ $_notice ]['global'] )
396 && ! Conditional::is_screen_advanced_ads()
397 ) {
398 continue;
399 }
400
401 // don't display license nag if ADVANCED_ADS_SUPPRESS_PLUGIN_ERROR_NOTICES is defined.
402 if ( defined( 'ADVANCED_ADS_SUPPRESS_PLUGIN_ERROR_NOTICES' ) && 'plugin_error' === $advanced_ads_admin_notices[ $_notice ]['type'] ) {
403 continue;
404 }
405
406 $hash = [
407 'info' => '/admin/views/notices/info.php',
408 'subscribe' => '/admin/views/notices/subscribe.php',
409 'plugin_error' => '/admin/views/notices/plugin_error.php',
410 'promo' => '/admin/views/notices/promo.php',
411 ];
412
413 $locate_tempalte = isset( $hash[ $type ] ) ? $hash[ $type ] : '/admin/views/notices/error.php';
414 include ADVADS_ABSPATH . $locate_tempalte;
415
416 // phpcs:disable
417 // if ( self::MAX_NOTICES === ++$count ) {
418 // break;
419 // }
420 // phpcs:enable
421 }
422 }
423
424 /**
425 * Return notices options
426 *
427 * @return array $options
428 */
429 public function options() {
430 if ( ! isset( $this->options ) ) {
431 $this->options = get_option( ADVADS_SLUG . '-notices', [] );
432 }
433
434 return $this->options;
435 }
436
437 /**
438 * Update notices options
439 *
440 * @param array $options new options.
441 */
442 public function update_options( array $options ) {
443 // do not allow to clear options.
444 if ( [] === $options ) {
445 return;
446 }
447
448 $this->options = $options;
449 update_option( ADVADS_SLUG . '-notices', $options );
450 }
451
452 /**
453 * Subscribe to newsletter and autoresponder
454 *
455 * @param string $notice slug of the subscription notice to send the correct reply.
456 *
457 * @return string
458 */
459 public function subscribe( $notice ) {
460 if ( ! isset( $notice ) ) {
461 return '';
462 }
463
464 $user = wp_get_current_user();
465
466 if ( '' === $user->user_email ) {
467 /* translators: %s: is a URL. */
468 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' );
469 }
470
471 $data = [
472 'email' => $user->user_email,
473 'notice' => $notice,
474 ];
475
476 $result = wp_remote_post(
477 'https://wpadvancedads.com/remote/subscribe.php?source=plugin',
478 [
479 'method' => 'POST',
480 'timeout' => 20,
481 'redirection' => 5,
482 'httpversion' => '1.1',
483 'blocking' => true,
484 'body' => $data,
485 ]
486 );
487
488 if ( is_wp_error( $result ) ) {
489 return __( 'How embarrassing. The email server seems to be down. Please try again later.', 'advanced-ads' );
490 }
491
492 // Mark as subscribed and move notice from queue.
493 $this->mark_as_subscribed( $notice );
494 $this->remove_from_queue( $notice );
495
496 /* translators: the first %s is an email address, the seconds %s is a URL. */
497 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' );
498 }
499
500 /**
501 * Update information that the current user is subscribed
502 *
503 * @param string $notice notice slug.
504 */
505 private function mark_as_subscribed( $notice ) {
506 // Early bail!!
507 if ( empty( $notice ) || ! Conditional::user_can_subscribe( $notice ) ) {
508 return;
509 }
510
511 $user_id = get_current_user_id();
512 $subscribed_notices = get_user_meta( $user_id, 'advanced-ads-subscribed', true );
513
514 // backward compatibility.
515 if ( ! is_array( $subscribed_notices ) ) {
516 $subscribed_notices = [];
517 }
518
519 $subscribed_notices[ $notice ] = true;
520
521 update_user_meta( $user_id, 'advanced-ads-subscribed', $subscribed_notices );
522 }
523
524 /**
525 * Check if a usesr can be subscribed to our newsletter
526 * check if is already subscribed or email is invalid
527 *
528 * @deprecated version 2.0 use Conditional::user_can_subscribe() instead
529 *
530 * @return bool true if user can subscribe
531 */
532 public function user_can_subscribe() {
533 _deprecated_function( __METHOD__, '2.0', '\AdvancedAds\Utilities\Conditional::user_can_subscribe()' );
534
535 return Conditional::user_can_subscribe( 'nl_first_steps' );
536 }
537
538 /**
539 * Add AdSense tutorial notice
540 *
541 * @param Ad $ad ad object.
542 */
543 public function adsense_tutorial( $ad ) {
544 $options = $this->options();
545 $_notice = 'nl_adsense';
546
547 if ( 'adsense' !== $ad->get_type() || isset( $options['closed'][ $_notice ] ) ) {
548 return;
549 }
550
551 include ADVADS_ABSPATH . '/admin/includes/notices.php';
552
553 if ( ! isset( $advanced_ads_admin_notices[ $_notice ] ) ) {
554 return;
555 }
556
557 $notice = $advanced_ads_admin_notices[ $_notice ];
558 $text = $notice['text'];
559 include ADVADS_ABSPATH . '/admin/views/notices/inline.php';
560 }
561
562
563
564 /**
565 * Register plugin conflict notices already defined in notices.php
566 */
567 public function register_plugin_conflict_notices($plugin_conflicts) {
568
569 // Early Bail !
570 if (empty($plugin_conflicts)) {
571 return;
572 }
573
574 $options = $this->options();
575 $queue = $options['queue'] ?? [];
576 $closed = $options['closed'] ?? [];
577
578
579 foreach($plugin_conflicts as $slug => $name){
580 $noticeId = str_replace(' ', '_', strtolower($name));
581 $notice_id = sanitize_title( $noticeId ) . '_active';
582 if ( ! is_plugin_active( $slug ) ) {
583 continue;
584 }
585 if ( ! in_array( $notice_id, $queue, true ) && ! isset( $closed[ $notice_id ] ) ) {
586 $this->notices[] = $notice_id;
587 }
588 }
589 }
590
591 }
592