C:\xampp\htdocs\landing\wp-content\plugins\hummingbird-performance\admin\class-notices.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
<?php
/**
 * Notices class.
 *
 * @package Hummingbird
 */

namespace Hummingbird\Admin;

use 
Hummingbird\Core\Settings;
use 
Hummingbird\Core\Utils;
use 
WPMUDEV_Dashboard;

if ( ! 
defined'ABSPATH' ) ) {
    exit;
}

/**
 * Class Notices
 */
class Notices {

    
/**
     * In order to avoid duplicated notices,
     * we save notices IDs here
     *
     * @var    array $displayed_notices
     * @access protected
     */
    
protected static $displayed_notices = array();

    
/**
     * Instance of class.
     *
     * @since  1.7.0
     * @access private
     * @var    $instance
     */
    
private static $instance null;

    
/**
     * Return the plugin instance.
     *
     * @since 1.7.0
     * @return Notices
     */
    
public static function get_instance() {
        if ( ! 
self::$instance ) {
            
self::$instance = new self();
        }

        return 
self::$instance;
    }

    
/**
     * Notices constructor.
     */
    
public function __construct() {
        
$dismiss = isset( $_GET['wphb-dismiss'] ) ? sanitize_text_field$_GET['wphb-dismiss'] ) : false;
        if ( 
$dismiss ) {
            
$this->dismiss$dismiss );
        }

        if ( ! 
function_exists'get_plugins' ) ) {
            include_once 
ABSPATH 'wp-admin/includes/plugin.php';
        }

        
// Only show notices to users who can do something about it (update, for example).
        
$cap is_multisite() ? 'manage_network_plugins' 'update_plugins';
        if ( ! 
current_user_can$cap ) ) {
            return;
        }

        
// This will show notice on both multisite and single site.
        
add_action'admin_notices', array( $this'clear_cache' ) );
        
add_action'network_admin_notices', array( $this'clear_cache' ) );

        if ( 
is_multisite() ) {
            
add_action'network_admin_notices', array( $this'upgrade_to_pro' ) );
            
add_action'network_admin_notices', array( $this'free_version_deactivated' ) );
            
add_action'network_admin_notices', array( $this'free_version_rate' ) );
            
add_action'network_admin_notices', array( $this'plugin_compat_check' ) );
        } else {
            
add_action'admin_notices', array( $this'upgrade_to_pro' ) );
            
add_action'admin_notices', array( $this'free_version_deactivated' ) );
            
add_action'admin_notices', array( $this'free_version_rate' ) );
            
add_action'admin_notices', array( $this'plugin_compat_check' ) );
        }

        
add_action'upgrader_process_complete', array( $this'plugin_changed' ) );
        
add_action'activated_plugin', array( $this'plugin_changed' ) );
        
add_action'deactivated_plugin', array( $this'plugin_changed' ) );
        
add_action'after_switch_theme', array( $this'plugin_changed' ) );
    }

    
/**
     * Clear the notice blocker on plugin activate/deactivate.
     *
     * @since 1.7.0
     * @used-by activated_plugin action
     * @used-by deactivated_plugin action
     */
    
public function plugin_changed() {
        
$detection Settings::get_setting'detection''page_cache' );

        
// Do nothing selected in settings.
        
if ( 'none' === $detection ) {
            return;
        }

        
// Show notice.
        
if ( 'manual' === $detection ) {
            
update_option'wphb-notice-cache-cleaned-show''yes' );
            return;
        }

        
// Auto clear cache, don't show any notice.
        
if ( 'auto' === $detection ) {
            
$modules = array( 'page_cache''minify' );
            foreach ( 
$modules as $mod ) {
                
$module Utils::get_module$mod );
                if ( ! 
$module->is_active() ) {
                    continue;
                }

                
// Make sure no settings are cleared during auto page cache purge.
                
if ( 'minify' === $mod ) {
                    
$module->clear_cachefalse );
                } else {
                    
$module->clear_cache();
                }
            }
        }
    }

    
/**
     * Display notice HTML code.
     *
     * @since  1.7.0
     * @access private
     * @param  string $id             Accepted: upgrade-to-pro, free-deactivated, free-rated, plugin-compat.
     * @param  string $message        Notice message.
     * @param  bool   $additional     Additional content that goes after the message text.
     * @param  bool   $only_hb_pages  Show message only on Hummingbird pages.
     */
    
private function show_notice$id ''$message ''$additional false$only_hb_pages false ) {
        
// Only run on HB pages.
        
if ( $only_hb_pages && ! preg_match'/^(toplevel|hummingbird)(-pro)*_page_wphb/'get_current_screen()->id ) ) {
            return;
        }

        
$dismiss_url wp_nonce_urladd_query_arg'wphb-dismiss'$id ), 'wphb-dismiss-notice' );
        
?>
        <div class="notice-info notice wphb-notice">
            <a class="wphb-dismiss" href="<?php echo esc_url$dismiss_url ); ?>">
                <span class="dashicons dashicons-dismiss"></span>
                <span class="screen-reader-text">
                    <?php esc_html_e'Dismiss this notice.''wphb' ); ?>
                </span>
            </a>
            <?php echo wp_kses_post$message ); ?>
            <?php if ( $additional ) : ?>
                <p>
                    <?php echo wp_kses_post$additional ); ?>
                </p>
            <?php endif; ?>
        </div>
        <style>
            .wphb-notice .wphb-dismiss {
                color: #aaaaaa;
                float: right;
                padding: 15px;
                position: absolute;
                right: 1px;
                text-decoration: none;
                top: 0;
            }
            body:not(.wpmud) .wphb-notice .wphb-dismiss {
                position: relative;
                padding: 10px 0;
            }
        </style>
        <?php
    
}

    
/**
     * Check if a notice has been dismissed by the current user.
     *
     * Will accept: 'user' for user options, 'option' for site wide options and
     *              'site' for sub site options.
     *
     * @since  1.7.0 changed to private
     * @access private
     * @param  string $notice  Notice.
     * @param  string $mode    Default: 'user'.
     * @return mixed
     */
    
private function is_dismissed$notice$mode 'user' ) {
        if ( 
'user' === $mode ) {
            return 
get_user_metaget_current_user_id(), 'wphb-' $notice '-dismissed' );
        }

        if ( 
'option' === $mode ) {
            return 
'yes' !== get_option'wphb-notice-' $notice '-show' );
        }

        return 
false;
    }

    
/**
     * Dismiss a notice.
     *
     * @since  1.7.0 changed to private
     * @access private
     * @param  string $notice  Notice.
     */
    
private function dismiss$notice ) {
        
check_admin_referer'wphb-dismiss-notice' );

        
$user_notices = array(
            
'upgrade-to-pro',
            
'plugin-compat',
        );

        
$options_notices = array(
            
'free-deactivated',
            
'free-rated',
            
'cache-cleaned',
        );

        if ( 
in_array$notice$user_noticestrue ) ) {
            
update_user_metaget_current_user_id(), 'wphb-' $notice '-dismissed'true );
        } elseif ( 
in_array$notice$options_noticestrue ) ) {
            
delete_option'wphb-notice-' $notice '-show' );
        }

        
$redirect remove_query_arg( array( 'wphb-dismiss''_wpnonce' ) );
        
wp_safe_redirect$redirect );
        exit;
    }

    
/**
     * Show top floating notice (SUI style).
     *
     * @since 2.6.0
     *
     * @param string $message  The notice text.
     * @param string $type     Notice type.
     */
    
public function show_floating$message$type 'success' ) {
        
?>
        <script>
            document.addEventListener( 'DOMContentLoaded', function () {
                WPHB_Admin.notices.show(
                    "<?php echo wp_kses_post$message ); ?>",
                    "<?php echo esc_attr$type ); ?>"
                );
            } );
        </script>
        <?php
    
}

    
/**
     * Show inline notice (SUI style).
     *
     * @since 2.6.0
     *
     * @param string $message  The notice text.
     * @param string $class    Class for the notice wrapper.
     * @param mixed  ...$data  Variable list of addition text.
     */
    
public function show_inline$message$class 'success', ...$data ) {
        if ( 
'sui-upsell-notice' === $class ) {
            
$this->show_inline_upsell$message, ...$data );
            return;
        }
        
?>
        <div class="sui-notice sui-notice-<?php echo esc_attr$class ); ?>">
            <div class="sui-notice-content">
                <div class="sui-notice-message">
                    <i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
                    <p><?php echo wp_kses_post$message ); ?></p>
                    <?php foreach ( $data as $p ) : ?>
                        <?php if ( ! empty( $p ) ) : ?>
                            <?php echo '<p>' wp_kses_post$p ) . '</p>'?>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php
    
}

    
/**
     * Show inline upsell notice (SUI style).
     *
     * This is an upsell implementation of an upsell notice to show with an image on the left side.
     * Can be triggered by calling show_inline() with a 'sui-upsell-notice' $class as an argument.
     *
     * @since 2.6.0
     *
     * @param string $message  The notice text.
     * @param mixed  ...$data  Variable list of addition text.
     */
    
private function show_inline_upsell$message, ...$data ) {
        
?>
        <div class="sui-upsell-notice">
            <p>
                <?php echo wp_kses_post$message ); ?>
                <?php foreach ( $data as $p ) : ?>
                    <?php echo wp_kses_post$p ); ?>
                <?php endforeach; ?>
            </p>
        </div>
        <?php
    
}

    
/**
     * Check if the notice can be displayed.
     *
     * @since 2.6.0  Refactored from show().
     *
     * @param string $id  Unique identifier for the notice.
     *
     * @return bool
     */
    
public function can_show_notice$id ) {
        
// Is already dismissed ?
        
if ( $this->is_dismissed$id'option' ) ) {
            return 
false;
        }

        if ( 
in_array$idself::$displayed_noticestrue ) ) {
            return 
false;
        }

        
self::$displayed_notices[] = $id;

        return 
true;
    }

    
/**
     * Show inline dismissible notice (SUI style).
     *
     * @since 2.6.0  Refactored from show().
     *
     * @param string $id       Unique identifier for the notice.
     * @param string $message  The notice text.
     * @param string $class    Class for the notice wrapper.
     */
    
public function show_inline_dismissible$id$message$class 'sui-notice-error' ) {
        if ( ! 
current_user_canUtils::get_admin_capability() ) ) {
            return;
        }

        
// Is already dismissed ?
        
if ( $this->is_dismissed$id'option' ) ) {
            return;
        }

        if ( 
in_array$idself::$displayed_noticestrue ) ) {
            return;
        }

        
self::$displayed_notices[] = $id;
        
?>
        <div class="sui-notice <?php echo esc_attr$class ); ?>" id="<?php echo esc_attr$id ); ?>" role="alert" style="display: block">
            <div class="sui-notice-content">
                <div class="sui-notice-message">
                    <i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
                    <p><?php echo wp_kses_post$message ); ?></p>
                    <p>
                        <a role="button" href="#" style="color: #888;text-transform: uppercase" onclick="WPHB_Admin.notices.dismiss( this )">
                            <?php esc_html_e'Dismiss''wphb' ); ?>
                        </a>
                    </p>
                </div>
            </div>
        </div>
        <?php
    
}

    
/**
     * *************************
     * NOTICES
     ***************************/

    /**
     * Available notices.
     *
     * @see Notices::upgrade_to_pro()
     * @see Notices::free_version_deactivated()
     * @see Notices::free_version_rate()
     */

    /**
     * Show Upgrade to Pro notice
     *
     * User is authenticated into WPMU DEV but it has free version installed
     */
    
public function upgrade_to_pro() {
        if ( 
$this->is_dismissed'upgrade-to-pro' ) ) {
            return;
        }

        if ( ! 
class_exists'WPMUDEV_Dashboard' ) ) {
            return;
        }

        
$dashboard WPMUDEV_Dashboard::instance();
        if ( ! 
is_object$dashboard ) ) {
            return;
        }

        if ( 
defined'WPHB_WPORG' ) && WPHB_WPORG && Utils::is_member() ) {
            
$url WPMUDEV_Dashboard::$ui->page_urls->plugins_url;
            
/* translators: %s: Upgrade URL */
            
$message sprintf__'Awww yeah! You’ve got access to Hummingbird Pro! Let’s upgrade your free version so you can start using premium features. <a href="%s">Upgrade</a>''wphb' ), esc_url$url ) );
            
$message '<p>' $message '</p>';
            
$this->show_notice'upgrade-to-pro'$messagefalsetrue );
        }
    }

    
/**
     * Notice displayed when the free version is deactivated because the pro one was already active
     */
    
public function free_version_deactivated() {
        if ( ! 
file_existsWP_PLUGIN_DIR '/hummingbird-performance/wp-hummingbird.php' ) ) {
            return;
        }

        
// If the Pro version files are not there, or plugin is not active - bail.
        
if ( ! file_existsWP_PLUGIN_DIR '/wp-hummingbird/wp-hummingbird.php' ) || ! is_plugin_active'wp-hummingbird/wp-hummingbird.php' ) ) {
            
// Probably a stored notice from a previous install - remove the notice.
            
delete_site_option'wphb-notice-free-deactivated-show' );
            return;
        }

        if ( 
$this->is_dismissed'free-deactivated''option' ) ) {
            return;
        }

        
$text '<p>' __'We noticed you’re running both the free and pro versions of Hummingbird. No biggie! We’ve deactivated the free version for you. Enjoy the pro features!''wphb' ) . '</p>';
        
$this->show_notice(
            
'free-deactivated',
            
$text
        
);
    }

    
/**
     * Offer the user to submit a review for the free version of the plugin.
     *
     * @since 1.5.4
     */
    
public function free_version_rate() {
        if ( 
Utils::is_member() ) {
            return;
        }

        if ( 
$this->is_dismissed'free-rated''option' ) ) {
            return;
        }

        
// Show only if at least 7 days have past after installation of the free version.
        
$free_installation get_site_option'wphb-free-install-date' );
        if ( ( 
current_time'timestamp' ) - (int) $free_installation ) < 604800 ) {
            return;
        }

        
$text            '<p>' esc_html__"We've spent countless hours developing Hummingbird and making it free for you to use. We would really appreciate it if you dropped us a quick rating!"'wphb' ) . '</p>';
        
$additional_text '<p><a href="https://wordpress.org/support/plugin/hummingbird-performance/reviews/" class="sui-button sui-button-blue" target="_blank">' __'Rate Hummingbird''wphb' ) . '</a></p>';
        
$this->show_notice(
            
'free-rated',
            
$text,
            
$additional_text
        
);
    }

    
/**
     * Show clear cache notice.
     *
     * @since 1.7.0
     */
    
public function clear_cache() {
        if ( 
$this->is_dismissed'cache-cleaned''option' ) ) {
            return;
        }

        
// Only show if minification or page cache is enabled.
        
$minify_active  Utils::get_module'minify' )->is_active();
        
$caching_active Utils::get_module'page_cache' )->is_active();

        
// If both modules disabled - don't show notice.
        
if ( ! $minify_active && ! $caching_active ) {
            return;
        }

        
$text       __"We've noticed you've made changes to your website. We recommend you clear Hummingbird's page cache to avoid any issues."'wphb' );
        
$additional '';

        if ( 
$minify_active ) {
            
// Add new files link.
            
$recheck_file_url add_query_arg(
                array(
                    
'recheck-files' => 'true',
                ),
                
Utils::get_admin_menu_url'minification' )
            );

            
$text __(
                
"We've noticed you've made changes to your website. If you’ve installed new plugins or themes,
            we recommend you re-check Hummingbird's Asset Optimization configuration to ensure those new files are added
            correctly."
,
                
'wphb'
            
);

            
$additional .= '<a href="' esc_url$recheck_file_url ) . '" class="button button-primary" style="margin-right:10px">' __'Re-check Asset Optimization''wphb' ) . '</a>';
        }

        
$additional .= '<a href="#" id="wp-admin-notice-wphb-clear-cache" class="button">' __'Clear Cache''wphb' ) . '</a>';
        if ( 
$caching_active ) {
            
$adjust_settings_url Utils::get_admin_menu_url'caching' ) . '&view=settings';
            if ( ! 
is_multisite() || ( is_multisite() && is_network_admin() ) ) {
                
$additional .= '<a href="' esc_url$adjust_settings_url ) . '" style="color:#888;margin-left:10px;text-decoration:none">' __'Adjust notification settings''wphb' ) . '</a>';
            }
        }

        
$text '<p>' $text '</p>';
        
$this->show_notice(
            
'cache-cleaned',
            
$text,
            
$additional
        
);
    }

    
/**
     * Generates text for the admin notice with a list of incompatible plugins
     *
     * @param array $incompat_plugins List of incompatible plugins if any.
     *
     * @return string Text message to be displayed
     */
    
public static function plugin_incompat_message$incompat_plugins ) {

        
$text '<p>' esc_html__'You have multiple WordPress performance plugins installed. This may cause unpredictable behavior and can even break your site. For best results, use only one performance plugin at a time. ''wphb' );

        if ( 
count$incompat_plugins ) > ) {
            
$text .= esc_html__'These plugins may cause issues with Hummingbird:''wphb' ) . '</p>';

            
$text .= '<ul id="wphb-incompat-plugin-list">';

            foreach ( 
$incompat_plugins as $plugin_k => $plugin ) {
                
$text .= "<li><strong>$plugin</strong></li>";
            }

            
$text .= '</ul>';
        } else {
            
$text .= sprintf/* translators: %s - plugin name */
                
esc_html__'%s plugin may cause issues with Hummingbird.''wphb' ),
                
'<strong>' $incompat_pluginskey$incompat_plugins ) ] . '</strong>'
            
) . '</p>';
        }

        return 
$text;
    }

    
/**
     * Display a admin notice if any of the incompatible plugin is installed.
     */
    
public function plugin_compat_check() {
        if ( 
$this->is_dismissed'plugin-compat' ) ) {
            return;
        }

        
$incompat_plugins Utils::get_incompat_plugin_list();

        if ( 
count$incompat_plugins ) <= ) {
            return;
        }

        
$text $this->plugin_incompat_message$incompat_plugins );

        
// CTA.
        
if ( is_multisite() && current_user_can'manage_network_plugins' ) ) {
            
$plugins_url network_admin_url'plugins.php' );
        } else {
            
$plugins_url admin_url'plugins.php' );
        }

        
$dismiss_url wp_nonce_urladd_query_arg'wphb-dismiss''plugin-compat' ), 'wphb-dismiss-notice' );

        
$additional  '<a href="' esc_url$plugins_url ) . '" id="wphb-manage-plugins" class="button button-primary">' esc_html__'Manage plugins''wphb' ) . '</a>';
        
$additional .= '<a role="button" href="' esc_url$dismiss_url ) . '" class="wphb-dismiss-cta">' esc_html__'Dismiss''wphb' ) . '</a>';

        
$this->show_notice'plugin-compat'$text$additionaltrue );
    }

}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586