C:\xampp\htdocs\landing\wp-content\plugins\hummingbird-performance\core\modules\class-advanced.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
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
<?php
/**
 * Class Advanced
 *
 * Implements various advanced features of the plugin: removing query strings from static resources,
 * removing the emojis file from rendering on the pages, prefetching dns queries.
 *
 * @since 1.8
 * @package Hummingbird\Core\Modules
 */

namespace Hummingbird\Core\Modules;

use 
Hummingbird\Core\Module;
use 
Hummingbird\Core\Settings;
use 
Hummingbird\Core\Traits\Module as ModuleContract;
use 
Hummingbird\Core\Utils;
use 
stdClass;

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

/**
 * Class Advanced
 */
class Advanced extends Module {

    use 
ModuleContract;

    
/**
     * Initializes the module. Always executed even if the module is deactivated.
     *
     * Do not use __construct in subclasses, use init() instead
     */
    
public function init() {
        
$options $this->get_options();

        
// See if we need to fetch the network value for query strings option.
        
if ( ( $options['query_strings_global'] || $options['emoji_global'] ) && is_multisite() ) {
            
$network_options get_blog_optionget_main_site_id(), 'wphb_settings' );

            if ( 
$options['query_strings_global'] && isset( $network_options['advanced'] ) && isset( $network_options['advanced']['query_string'] ) ) {
                
$options['query_string'] = $network_options['advanced']['query_string'];
            }
            if ( 
$options['emoji_global'] && isset( $network_options['advanced'] ) && isset( $network_options['advanced']['emoji'] ) ) {
                
$options['emoji'] = $network_options['advanced']['emoji'];
            }
        }

        
// Remove emoji.
        
if ( $options['emoji'] ) {
            
// Remove styles/scripts.
            
$this->remove_emoji();
            
// Remove dns prefetch.
            
add_filter'emoji_svg_url''__return_false' );
            
// Remove from TinyMCE.
            
add_filter'tiny_mce_plugins', array( $this'remove_emoji_tinymce' ) );
        }

        
// Process HB cleanup task.
        
add_action'wphb_hummingbird_cleanup', array( $this'hb_cleanup_cron' ) );

        
// Ajax handler to return the comment template.
        
add_action'wp_ajax_get_comments_template', array( $this'comment_template' ) );
        
add_action'wp_ajax_nopriv_get_comments_template', array( $this'comment_template' ) );

        if ( isset( 
$options['lazy_load'] ) && $options['lazy_load']['enabled'] ) {
            
/* Divi Compatibility  */
            
add_filter'et_builder_load_requests', array( $this'add_divi_support' ) );
            
add_action'wp_enqueue_scripts', array( $this'enqueue_global' ) );
        }
        
add_filter'paginate_links', array( $this'strip_params' ) );

        
// Everything else is only for frontend.
        
if ( is_admin() ) {
            return;
        }

        
// Disable WooCommerce cart fragments.
        
add_action'wp_enqueue_scripts', array( $this'remove_cart_fragments' ), 11 );

        
// Remove query strings from static resources (only on front-end).
        
if ( $options['query_string'] ) {
            
add_filter'script_loader_src', array( $this'remove_query_strings' ), 15);
            
add_filter'style_loader_src', array( $this'remove_query_strings' ), 15);
        }

        
// DNS prefetch.
        
add_filter'wp_resource_hints', array( $this'prefetch_dns' ), 10);

        
// Filter comment template if lazy load is enabled.
        
if ( isset( $options['lazy_load'] ) && $options['lazy_load']['enabled'] ) {
            
add_filter'comments_template', array( $this'filter_comments_template' ), 100 );
        }
    }

    
/**
     * *************************
     * Remove query strings from static assets.
     ***************************/

    /**
     * Parse the src of script/style tags to remove the version query string.
     *
     * @param string $src  Script loader source path.
     *
     * @return string
     */
    
public function remove_query_strings$src ) {
        
$parts preg_split'/\?ver|\?timestamp/'$src );
        return 
$parts[0];
    }

    
/**
     * *************************
     * Remove Emoji.
     ***************************/

    /**
     * Remove Emoji scripts from WordPress.
     */
    
public function remove_emoji() {
        
remove_action'wp_head''print_emoji_detection_script');
        
remove_action'admin_print_scripts''print_emoji_detection_script' );
        
remove_action'wp_print_styles''print_emoji_styles' );
        
remove_action'admin_print_styles''print_emoji_styles' );
        
remove_filter'the_content_feed''wp_staticize_emoji' );
        
remove_filter'comment_text_rss''wp_staticize_emoji' );
        
remove_filter'wp_mail''wp_staticize_emoji_for_email' );
    }

    
/**
     * Remove Emoji icons from TinyMCE.
     *
     * @param array $plugins  An array of default TinyMCE plugins.
     *
     * @return array
     */
    
public function remove_emoji_tinymce$plugins ) {
        if ( 
is_array$plugins ) ) {
            return 
array_diff$plugins, array( 'wpemoji' ) );
        }

        return array();
    }

    
/**
     * *************************
     * Prefetch DNS.
     ***************************/

    /**
     * Prefetch DNS. Minimum required WordPress version is 4.6.
     *
     * @param array  $hints          URLs to print for resource hints.
     * @param string $relation_type  The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'.
     *
     * @see https://make.wordpress.org/core/2016/07/06/resource-hints-in-4-6/
     *
     * @return array
     */
    
public function prefetch_dns$hints$relation_type ) {
        
$urls Settings::get_setting'prefetch''advanced' );

        
// If not urls set, return default WP hints array.
        
if ( ! is_array$urls ) || empty( $urls ) ) {
            return 
$hints;
        }

        
$urls array_map'esc_url'$urls );

        if ( 
'dns-prefetch' === $relation_type ) {
            foreach ( 
$urls as $url ) {
                
$hints[] = $url;
            }
        }

        return 
$hints;
    }

    
/**
     * Optimize WooCommerce cart fragments.
     *
     * @since 2.2.0
     */
    
public function remove_cart_fragments() {
        
$options $this->get_options();

        if ( ! isset( 
$options['cart_fragments'] ) || ! $options['cart_fragments'] ) {
            return;
        }

        if ( ! 
function_exists'is_woocommerce' ) ) {
            return;
        }

        if ( 
'all' === $options['cart_fragments'] || ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) ) {
            
wp_dequeue_script'wc-cart-fragments' );
        }
    }

    
/**
     * *************************
     * Database cleanup.
     ***************************/

    /**
     * Get default fields for database cleanup.
     *
     * @return array
     */
    
public static function get_db_fields() {
        return array(
            
'revisions'          => array(
                
'title'   => __'Post Revisions''wphb' ),
                
'tooltip' => __"Historic versions of your posts and pages. If you don't need to revert to older versions, delete these entries"'wphb' ),
            ),
            
'drafts'             => array(
                
'title'   => __'Draft Posts''wphb' ),
                
'tooltip' => __'Auto-saved versions of your posts and pages. If you don’t use drafts you can safely delete these entries''wphb' ),
            ),
            
'trash'              => array(
                
'title'   => __'Trashed Posts''wphb' ),
                
'tooltip' => __"Posts or pages you've marked as trash but haven't permanently deleted yet"'wphb' ),
            ),
            
'spam'               => array(
                
'title'   => __'Spam Comments''wphb' ),
                
'tooltip' => __"Comments marked as spam that haven't been deleted yet"'wphb' ),
            ),
            
'trash_comment'      => array(
                
'title'   => __'Trashed Comments''wphb' ),
                
'tooltip' => __"Comments you've marked as trash but haven't permanently deleted yet"'wphb' ),
            ),
            
'expired_transients' => array(
                
'title'   => __'Expired Transients''wphb' ),
                
'tooltip' => __'Cached data that themes and plugins have stored, except these ones have expired and can be deleted''wphb' ),
            ),
            
'transients'         => array(
                
'title'   => __'All Transients''wphb' ),
                
'tooltip' => __'Cached data that themes and plugins have stored, but may still be in use. Note: the next page to load could take a bit longer due to WordPress regenerating transients.''wphb' ),
            ),
        );
    }

    
/**
     * Get data from the database.
     *
     * @param string $type Accepts: 'revisions', 'drafts', 'trash', 'spam', 'trash_comment',
     *                     'expired_transients', 'transients', 'all'.
     *
     * @return int|array|stdClass
     */
    
public static function get_db_count$type 'all' ) {
        global 
$wpdb;

        
$count wp_cache_get"wphb_db_optimization:{$type});

        if ( 
false === $count ) {
            switch ( 
$type ) {
                case 
'revisions':
                    
$count $wpdb->get_var"SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'revision' AND post_status = 'inherit'" ); // Db call ok.
                    
break;
                case 
'drafts':
                    
$count $wpdb->get_var"SELECT COUNT(*) FROM {$wpdb->posts} WHERE ( post_status = 'draft' OR post_status = 'auto-draft' ) AND ( post_type = 'page' OR post_type = 'post' )" ); // Db call ok.
                    
break;
                case 
'trash':
                    
$count $wpdb->get_var"SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = 'trash'" ); // Db call ok.
                    
break;
                case 
'spam':
                    
$count $wpdb->get_var"SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_approved = 'spam'" ); // Db call ok.
                    
break;
                case 
'trash_comment':
                    
$count $wpdb->get_var"SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_approved = 'trash'" ); // Db call ok.
                    
break;
                case 
'expired_transients':
                    
$count $wpdb->get_var"SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_timeout\__%%' AND option_value < UNIX_TIMESTAMP()" ); // Db call ok.
                    
break;
                case 
'transients':
                    
$count $wpdb->get_var"SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name LIKE '%_transient_%'" ); // Db call ok.
                    
break;
                case 
'all':
                default:
                    
$count $wpdb->get_row(
                        
"
                    SELECT revisions, drafts, trash, spam, trash_comment, expired_transients, transients,
                           sum(revisions+drafts+trash+spam+trash_comment+expired_transients+transients) AS total
                    FROM (
                      (SELECT
                        COUNT(CASE WHEN post_type = 'revision' AND post_status = 'inherit' THEN 1 ELSE NULL END) AS revisions,
                        COUNT(CASE WHEN ( post_status = 'draft' OR post_status = 'auto-draft' ) AND ( post_type = 'page' OR post_type = 'post' ) THEN 1 ELSE NULL END) AS drafts,
                        COUNT(CASE WHEN post_status = 'trash' THEN 1 ELSE NULL END) AS trash
                      FROM 
{$wpdb->posts}) as posts,
                      (SELECT
                        COUNT(CASE WHEN comment_approved = 'spam' THEN 1 ELSE NULL END) AS spam,
                        COUNT(CASE WHEN comment_approved = 'trash' THEN 1 ELSE NULL END) AS trash_comment
                      FROM 
{$wpdb->comments}) as comments,
                      (SELECT
                        COUNT(CASE WHEN option_name LIKE '\_transient\_timeout\__%%' AND option_value < UNIX_TIMESTAMP() THEN 1 ELSE NULL END ) AS expired_transients,
                        COUNT(CASE WHEN option_name LIKE '%_transient_%' THEN 1 ELSE NULL END) AS transients
                      FROM 
{$wpdb->options}) as options
                    )"
                    
); // Db call ok.
                    
break;
            }

            
wp_cache_set"wphb_db_optimization:{$type}"$count );
        }

        return 
$count;
    }

    
/**
     * Delete database rows.
     *
     * @since 1.8
     *
     * @param string $type Accepts: 'revisions', 'drafts', 'trash', 'spam', 'trash_comment',
     *                     'expired_transients', 'transients', 'all'.
     *
     * @return array|bool
     */
    
public function delete_db_data$type ) {
        global 
$wpdb;

        
$sql = array(
            
'revisions'          => "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'revision' AND post_status = 'inherit'",
            
'drafts'             => "SELECT ID FROM {$wpdb->posts} WHERE ( post_status = 'draft' OR post_status = 'auto-draft' ) AND ( post_type = 'page' OR post_type = 'post' )",
            
'trash'              => "SELECT ID FROM {$wpdb->posts} WHERE post_status = 'trash'",
            
'spam'               => "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_approved = 'spam'",
            
'trash_comment'      => "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_approved = 'trash'",
            
'expired_transients' => "SELECT option_name FROM {$wpdb->options}
                                            WHERE option_name LIKE '\_transient\_timeout\__%%' AND option_value < UNIX_TIMESTAMP()"
,
            
'transients'         => "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%_transient_%'",
        );

        if ( ! isset( 
$sql$type ] ) && 'all' !== $type ) {
            return 
false;
        }

        if ( 
'all' === $type ) {
            
$items 0;
            foreach ( 
$sql as $type => $query ) {
                
$items $items $this->delete$query$type );
            }
        } else {
            
$items $this->delete$sql$type ], $type );
        }

        
wp_cache_delete"wphb_db_optimization:{$type});

        
/**
         * Fires after the database cleanup task.
         *
         * @since 1.9.2
         *
         * @param string $type   Data type that was cleared from the database. Can return following values: all,
         *                       revisions, drafts, trash, spam, trash_comment, expired_transients, transients.
         * @param int    $items  Number of items that was cleared from the database for the selected data type.
         */
        
do_action'wphb_delete_db_data'$type$items );

        return array(
            
'items' => $items,
            
'left'  => self::get_db_count'all' ), // Check for any non-deleted items.
        
);
    }

    
/**
     * Delete items from the database using a provided query and item type.
     *
     * @since 1.8
     *
     * @access private
     * @param  string $sql   SQL query to fetch items.
     * @param  string $type  Type of item to fetch.
     *
     * @return int
     */
    
private function delete$sql$type ) {
        global 
$wpdb;

        
wp_cache_flush();
        
$entries $wpdb->get_col$sql ); // Db call ok; no-cache oka.

        
if ( 'revisions' === $type || 'drafts' === $type || 'trash' === $type ) {
            
$func 'wp_delete_post';
        } elseif ( 
'spam' === $type || 'trash_comment' === $type ) {
            
$func 'wp_delete_comment';
        } elseif ( 
'expired_transients' === $type && function_exists'delete_expired_transients' ) ) {
            
delete_expired_transients();
            return 
count$entries );
        } else {
            
$func 'delete_option';
        }

        
$items 0;
        foreach ( 
$entries as $entry ) {
            if ( 
'delete_option' === $func ) {
                
// No option to force delete in delete_option function.
                
$del call_user_func$func$entry );
            } else {
                
// Force delete entries (without moving to trash).
                
$del call_user_func$func$entrytrue );
            }

            if ( 
null !== $del && ! is_wp_error$del ) ) {
                
$items++;
            }
        }

        return 
$items;
    }

    
/**
     * *************************
     * HB cleanup.
     ***************************/

    /**
     * Cleanup cron task.
     *
     * @since 1.8.1
     */
    
public function hb_cleanup_cron() {
        global 
$wpdb;

        
// Select 100 entries.
        
$entries $wpdb->get_col"SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wphb_minify_group' LIMIT 0, 100" ); // db call ok; no-cache ok.

        // Delete them properly.
        
foreach ( $entries as $entry ) {
            if ( 
get_post$entry ) && 'wphb_minify_group' === get_post_type$entry ) ) {
                
wp_delete_post$entrytrue );
            }
        }

        
// Reschedule another batch if any entries left.
        
$count $wpdb->get_var"SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'wphb_minify_group'" ); // db call ok; no-cache ok.

        
if ( < (int) $count ) {
            
wp_schedule_single_eventtime(), 'wphb_hummingbird_cleanup' );
        } else {
            
wp_clear_scheduled_hook'wphb_hummingbird_cleanup' );
        }

        return 
true;
    }

    
/**
     * *************************
     * System Information.
     ***************************/

    /**
     * Get PHP information for System Information.
     *
     * @since 1.8.2
     *
     * @return array
     */
    
public static function get_php_info() {
        
$php_info = array();
        
$php_vars = array(
            
'max_execution_time',
            
'open_basedir',
            
'memory_limit',
            
'upload_max_filesize',
            
'post_max_size',
            
'display_errors',
            
'log_errors',
            
'track_errors',
            
'session.auto_start',
            
'session.cache_expire',
            
'session.cache_limiter',
            
'session.cookie_domain',
            
'session.cookie_httponly',
            
'session.cookie_lifetime',
            
'session.cookie_path',
            
'session.cookie_secure',
            
'session.gc_divisor',
            
'session.gc_maxlifetime',
            
'session.gc_probability',
            
'session.referer_check',
            
'session.save_handler',
            
'session.save_path',
            
'session.serialize_handler',
            
'session.use_cookies',
            
'session.use_only_cookies',
        );

        
$php_info__'Version''wphb' ) ] = phpversion();
        foreach ( 
$php_vars as $setting ) {
            
$php_info$setting ] = ini_get$setting );
        }
        
$levels          = array();
        
$error_reporting error_reporting();

        
$extension_constants = array(
            
'E_ERROR',
            
'E_WARNING',
            
'E_PARSE',
            
'E_NOTICE',
            
'E_CORE_ERROR',
            
'E_CORE_WARNING',
            
'E_COMPILE_ERROR',
            
'E_COMPILE_WARNING',
            
'E_USER_ERROR',
            
'E_USER_WARNING',
            
'E_USER_NOTICE',
            
'E_STRICT',
            
'E_RECOVERABLE_ERROR',
            
'E_DEPRECATED',
            
'E_USER_DEPRECATED',
            
'E_ALL',
        );

        foreach ( 
$extension_constants as $level ) {
            if ( 
defined$level ) ) {
                
$c constant$level );
                if ( 
$error_reporting $c ) {
                    
$levels$c ] = $level;
                }
            }
        }
        
$php_info__'Error Reporting''wphb' ) ] = implode'<br>'$levels );
        
$extensions                                  get_loaded_extensions();
        
natcasesort$extensions );
        
$php_info__'Extensions''wphb' ) ] = implode'<br>'$extensions );

        return 
$php_info;
    }

    
/**
     * Get Database information for System Information.
     *
     * @since 1.8.2
     *
     * @return array
     */
    
public static function get_db_info() {
        global 
$wpdb;
        
$dump_mysql = array();
        
$mysql_vars = array(
            
'key_buffer_size'    => true,   // Key cache size limit.
            
'max_allowed_packet' => false,  // Individual query size limit.
            
'max_connections'    => false,  // Max number of client connections.
            
'query_cache_limit'  => true,   // Individual query cache size limit.
            
'query_cache_size'   => true,   // Total cache size limit.
            
'query_cache_type'   => 'ON',   // Query cache on or off.
        
);
        
$extra_info = array();
        
$variables  $wpdb->get_results"SHOW VARIABLES WHERE Variable_name IN ( '" implode"', '"array_keys$mysql_vars ) ) . "' )" ); // db call ok; no-cache ok.

        
$dbh $wpdb->dbh;
        if ( 
is_resource$dbh ) ) {
            
$driver  'mysql';
            
$version function_exists'mysqli_get_server_info' ) ? mysqli_get_server_info$dbh ) : mysql_get_server_info$dbh );
        } elseif ( 
is_object$dbh ) ) {
            
$driver get_class$dbh );
            if ( 
method_exists$dbh'db_version' ) ) {
                
$version $dbh->db_version();
            } elseif ( isset( 
$dbh->server_info ) ) {
                
$version $dbh->server_info;
            } elseif ( isset( 
$dbh->server_version ) ) {
                
$version $dbh->server_version;
            } else {
                
$version __'Unknown''wphb' );
            }
            if ( isset( 
$dbh->client_info ) ) {
                
$extra_info['Driver version'] = $dbh->client_info;
            }
            if ( isset( 
$dbh->host_info ) ) {
                
$extra_info['Connection info'] = $dbh->host_info;
            }
        } else {
            
$version $driver __'Unknown''wphb' );
        }
        
$extra_info['Database']     = $wpdb->dbname;
        
$extra_info['Charset']      = $wpdb->charset;
        
$extra_info['Collate']      = $wpdb->collate;
        
$extra_info['Table Prefix'] = $wpdb->prefix;

        
$dump_mysql['Server Version'] = $version;
        
$dump_mysql['Driver']         = $driver;
        foreach ( 
$extra_info as $key => $val ) {
            
$dump_mysql$key ] = $val;
        }
        foreach ( 
$mysql_vars as $key => $val ) {
            
$dump_mysql$key ] = $val;
        }
        foreach ( 
$variables as $item ) {
            if ( 
is_numeric$item->Value ) && ( $item->Value >= ( 1024 1024 ) ) ) {
                
$val size_format$item->Value );
            }
            
$dump_mysql$item->Variable_name ] = $val;
        }

        return 
$dump_mysql;
    }

    
/**
     * Get WordPress Installation information for System Information.
     *
     * @since 1.8.2
     *
     * @return array
     */
    
public static function get_wp_info() {
        global 
$wp_version;
        
$dump_wp                      = array();
        
$wp_consts                    = array(
            
'ABSPATH',
            
'WP_CONTENT_DIR',
            
'WP_PLUGIN_DIR',
            
'WPINC',
            
'WP_LANG_DIR',
            
'UPLOADBLOGSDIR',
            
'UPLOADS',
            
'WP_TEMP_DIR',
            
'SUNRISE',
            
'WP_ALLOW_MULTISITE',
            
'MULTISITE',
            
'SUBDOMAIN_INSTALL',
            
'DOMAIN_CURRENT_SITE',
            
'PATH_CURRENT_SITE',
            
'SITE_ID_CURRENT_SITE',
            
'BLOGID_CURRENT_SITE',
            
'BLOG_ID_CURRENT_SITE',
            
'COOKIE_DOMAIN',
            
'COOKIEPATH',
            
'SITECOOKIEPATH',
            
'DISABLE_WP_CRON',
            
'ALTERNATE_WP_CRON',
            
'DISALLOW_FILE_MODS',
            
'WP_HTTP_BLOCK_EXTERNAL',
            
'WP_ACCESSIBLE_HOSTS',
            
'WP_DEBUG',
            
'WP_DEBUG_LOG',
            
'WP_DEBUG_DISPLAY',
            
'ERRORLOGFILE',
            
'SCRIPT_DEBUG',
            
'WP_LANG',
            
'WP_MAX_MEMORY_LIMIT',
            
'WP_MEMORY_LIMIT',
            
'WPMU_ACCEL_REDIRECT',
            
'WPMU_SENDFILE',
        );
        
$dump_wp['WordPress Version'] = $wp_version;
        foreach ( 
$wp_consts as $const ) {
            
$dump_wp$const ] = self::format_constant$const );
        }

        return 
$dump_wp;
    }


    
/**
     * Get server information for System Information.
     *
     * @since 1.8.2
     *
     * @return array
     */
    
public static function get_server_info() {
        
$dump_server = array();
        
$server      explode' 'wp_unslash$_SERVER['SERVER_SOFTWARE'] ) ); // Input var ok.
        
$server      explode'/'reset$server ) );

        if ( isset( 
$server[1] ) ) {
            
$server_version $server[1];
        } else {
            
$server_version 'Unknown';
        }

        
$dump_server__'Software Name''wphb' ) ]     = $server[0];
        
$dump_server__'Software Version''wphb' ) ]  = $server_version;
        
$dump_server__'Server IP''wphb' ) ]         = @$_SERVER['SERVER_ADDR'];
        
$dump_server__'Server Hostname''wphb' ) ]   = @$_SERVER['SERVER_NAME'];
        
$dump_server__'Server Admin''wphb' ) ]      = @$_SERVER['SERVER_ADMIN'];
        
$dump_server__'Server local time''wphb' ) ] = date'Y-m-d H:i:s (\U\T\C P)' );
        
$dump_server__'Operating System''wphb' ) ]  = @php_uname's' );
        
$dump_server__'OS Hostname''wphb' ) ]       = @php_uname'n' );
        
$dump_server__'OS Version''wphb' ) ]        = @php_uname'v' );

        return 
$dump_server;
    }

    
/**
     * Helper function.
     *
     * @since 1.8.2
     *
     * @param string $constant  Name of a PHP const.
     *
     * @return string
     */
    
private static function format_constant$constant ) {
        if ( ! 
defined$constant ) ) {
            return 
'<em>' __'undefined''wphb' ) . '</em>';
        }

        
$val constant$constant );
        if ( ! 
is_bool$val ) ) {
            return 
$val;
        } elseif ( ! 
$val ) {
            return 
__'FALSE''wphb' );
        } else {
            return 
__'TRUE''wphb' );
        }
    }

    
/**
     * Get database data and index sizes.
     *
     * @since 2.7.0
     *
     * @return array
     */
    
public function get_db_size() {
        global 
$wpdb;

        if ( ! 
defined'DB_NAME' ) ) {
            return array(
                
'data_size'  => 0,
                
'index_size' => 0,
            );
        }

        
$table_info $wpdb->get_row(
            
$wpdb->prepare(
                
"SELECT SUM( DATA_LENGTH ) as data, SUM( INDEX_LENGTH ) as 'index'
                       FROM information_schema.TABLES
                       WHERE TABLE_SCHEMA = %s AND TABLE_NAME LIKE %s;"
,
                
DB_NAME,
                
$wpdb->get_blog_prefixget_current_blog_id() ) . '%'
            
)
        ); 
// DB call ok; no-cache ok.

        
return array(
            
'data_size'  => Utils::format_bytes$table_info->data ),
            
'index_size' => Utils::format_bytes$table_info->index ),
        );
    }

    
/**
     * Get orphaned mata rows from `wp_postmeta` that, most likely, belong to Asset Optimization, but
     * do not have a registered `wphb_minify_group` in the `wp_postmeta` table.
     *
     * @since 2.7.0
     *
     * @return int
     */
    
public function get_orphaned_ao() {
        
$count wp_cache_get'wphb_ao_meta_fields' );

        if ( 
false === $count ) {
            global 
$wpdb;

            
$table  $wpdb->get_blog_prefixget_current_blog_id() ) . 'postmeta';
            
$search implode"', '"Minify::get_postmeta_fields() );

            
$results $wpdb->get_row(
            
"SELECT COUNT( post_id ) as posts FROM {$table} WHERE meta_key IN ('{$search}');"
            
); // Db call ok.

            
$count $results->posts;
            unset( 
$results );
        }

        
wp_cache_set'wphb_ao_meta_fields'$count );

        return 
$count;
    }

    
/**
     * Pluck all orphaned meta fields that belong to Hummingbird.
     *
     * Difference from above method, it will only include actual orphaned data, while with the method
     * above, we need to subtract the number of valid assets.
     *
     * @since 2.7.0
     *
     * @return int.
     */
    
public function get_orphaned_ao_complex() {
        
$count wp_cache_get'wphb_ao_orphaned_data' );

        if ( 
false === $count ) {
            global 
$wpdb;

            
$search_fields   implode"', '"Minify::get_postmeta_fields() );
            
$database_prefix $wpdb->get_blog_prefixget_current_blog_id() );
            
$posts_table     $database_prefix 'posts';
            
$post_meta_table $database_prefix 'postmeta';

            
$count $wpdb->get_var(
                
"SELECT COUNT( post_id ) FROM {$post_meta_table} A
                LEFT JOIN 
{$posts_table} B
                ON A.post_id = B.ID
                WHERE A.meta_key IN ('
{$search_fields}')
                AND B.ID IS NULL"
            
); // Db call ok.
        
}

        
wp_cache_set'wphb_ao_orphaned_data'$count );

        return 
$count;
    }

    
/**
     * Clear out a set number of orphaned asset optimization data.
     *
     * @since 2.7.0
     *
     * @param int $rows  Number of rows to clear.
     */
    
public function purge_orphaned_step$rows ) {
        global 
$wpdb;

        
$search_fields   implode"', '"Minify::get_postmeta_fields() );
        
$database_prefix $wpdb->get_blog_prefixget_current_blog_id() );
        
$posts_table     $database_prefix 'posts';
        
$post_meta_table $database_prefix 'postmeta';

        
$items $wpdb->get_col(
            
$wpdb->prepare(
                
"SELECT meta_id FROM {$post_meta_table} A
                LEFT JOIN 
{$posts_table} B
                ON A.post_id = B.ID
                WHERE A.meta_key IN ('
{$search_fields}')
                AND B.ID IS NULL LIMIT %d"
,
                
$rows
            
)
        ); 
// Db call ok.

        
$ids implode','array_map'intval'$items ) );
        
$wpdb->query"DELETE FROM {$post_meta_table} WHERE meta_id IN($ids)" );

        
// Remove count cache.
        
wp_cache_delete'wphb_ao_meta_fields' );

        
/** This might be a better alternative - just try to force purge everything.
        $sql = "DELETE A FROM {$post_meta_table} AS A
                LEFT JOIN {$posts_table} AS B ON A.post_id = B.ID
                WHERE A.meta_key IN ('{$search_fields}')
                AND B.ID IS NULL;";
        */
    
}

    
/**
     * *************************
     * Comment lazy loading.
     ***************************/

    /**
     * Enqueue lazy load scripts on single page/post.
     *
     * @since 2.5.0
     */
    
public function enqueue_global() {
        
$lazy_load_comment_js is_singular();
        
$lazy_load_comment_js apply_filters'wphb_lazy_load_comment_js'$lazy_load_comment_js );
        
// Do not load sitewide.
        
if ( ! $lazy_load_comment_js ) {
            return;
        }

        
wp_enqueue_script(
            
'wphb-lazy-load',
            
WPHB_DIR_URL 'admin/assets/js/wphb-lazy-load.min.js',
            array(),
            
WPHB_VERSION,
            
true
        
);

        
wp_localize_script(
            
'wphb-lazy-load',
            
'wphbGlobal',
            array(
                
'ajaxurl' => admin_url'admin-ajax.php' ),
            )
        );
    }

    
/**
     * Checks for the user agent to validate if the visitor is a bot
     *
     * @since 2.5.0
     *
     * @return bool
     */
    
public function visitor_is_a_bot() {
        
/* No User agent, Or the useragent string matches the basic pattern */
        
if ( ! isset( $_SERVER['HTTP_USER_AGENT'] ) || preg_match'/bot|crawl|slurp|spider/i'sanitize_keywp_unslash$_SERVER['HTTP_USER_AGENT'] ) ) ) ) {
            return 
true;
        }

        return 
false;
    }

    
/**
     * Validates if we should be lazy loading comments or not
     *
     * @since 2.5.0
     *
     * @param array $options plugin settings.
     *
     * @return bool True|False
     */
    
public function should_lazy_load$options ) {
        global 
$wp_query;

        
$lazy_load true;

        if ( 
$this->visitor_is_a_bot() ) {
            
$lazy_load false;
        }

        
$comment_count get_comments_number();

        if ( ! 
$comment_count ) {
            
// If there are no comments.
            
$lazy_load false;
        } elseif ( (int) 
$options['lazy_load']['threshold'] > $comment_count ) {
            
// if threshold is lower than total comment count.
            
$lazy_load false;
        } elseif ( ! empty( 
$wp_query->comment_count ) && (int) $options['lazy_load']['threshold'] > $wp_query->comment_count ) {
            
// If there is a comment pagination, and the comment_count for the page < threshold.
            
$lazy_load false;
        }

        return 
$lazy_load;
    }

    
/**
     * Filters the default comment template to Lazy Load markup ( Button or a Scroll div )
     *
     * @since 2.5.0
     *
     * @param string $template Current comment template.
     *
     * @return string HTML markup for the button or a div used to load comments template on scroll
     */
    
public function filter_comments_template$template ) {
        
$options $this->get_options();

        
$should_lazy_load $this->should_lazy_load$options );

        
/* Return the original template if we should not lazy load */
        
if ( ! apply_filters'wphb_should_lazy_load_comment'$should_lazy_load ) ) {
            return 
$template;
        }

        
/* Set "separate-comments" transient if not set already */
        
if ( false === get_transient'wphb-separate-comments' ) ) {
            global 
$wp_query;

            
// Check if separate comments is set.
            
$separate_comments = ! empty( $wp_query ) && ! empty( $wp_query->comments_by_type ) ? 0;

            
set_transient'wphb-separate-comments'$separate_comments60 );
        }

        
set_query_var'lazy_load_settings'$options['lazy_load'] );

        return 
WPHB_DIR_PATH 'core/views/comment-template.php';
    }

    
/**
     * Strip parameters.
     *
     * @since 2.5.0
     *
     * @param string $link  URL.
     *
     * @return bool|string
     */
    
public function strip_params$link ) {
        if ( ! isset( 
$_GET['action'] ) || 'get_comments_template' !== sanitize_keywp_unslash$_GET['action'] ) ) ) {
            return 
$link;
        }

        return 
remove_query_arg( array( 'action''id''_nonce' ), $link );
    }

    
/**
     * Ajax handler to load the actual comment template on front-end.
     *
     * @since 2.5.0
     */
    
public function comment_template() {
        if ( empty( 
$_GET['_nonce'] ) || ! wp_verify_noncewp_unslash$_GET['_nonce'] ), 'comments_template' ) ) {
            
$message '<div class="wphb-lazy-load-error sui-error">' esc_html__'We could not validate the request, try reloading the page.''wphb' ) . '</div>';
            
wp_send_json_error( array( 'content' => $message ) );
        }

        
/* Return an error if post id isn't set */
        
if ( empty( $_GET['id'] ) ) {
            
$message '<div class="wphb-lazy-load-error sui-error">' esc_html__'Something went wrong. Try reloading the page to see if the comments load for you.''wphb' ) . '</div>';
            
wp_send_json_error( array( 'content' => $message ) );
        }

        
$cpage_num = ! empty( $_GET['cpage_num'] ) ? absint$_GET['cpage_num'] ) : '';

        
$separate_comments get_transient'wphb-separate-comments' );

        
/* Remove our comment template filter to be able to get the original content */
        
remove_filter'comments_template', array( $this'filter_comments_template' ), 100 );

        
/**
         * Allow plugin/themes to hook-in, to enable support for loading custom comments template over AJAX
         */
        
do_action'wphb_ajax_get_comments_template' );

        
query_posts( array( 'p' => absint$_GET['id'] ) ) );

        
/* Restore original Post Data */
        
wp_reset_postdata();
        if ( 
have_posts() ) {
            
the_post();

            
// Workaround :( .
            
$orig_uri               $_SERVER['REQUEST_URI'];
            
$_SERVER['REQUEST_URI'] = get_the_permalinkget_the_ID() );
            if ( ! empty( 
$cpage_num ) ) {
                
set_query_var'cpage'$cpage_num );
                
/**
                 * Override page_comments decision set from discussion settings page.
                 * By default comment pagination is ignored when page_comments is false.
                 * See in function comments_template() in wp-includes/comment-template.php
                 * We need it always true to get comments for specific cpage.
                 */
                
add_filter'option_page_comments', array( $this'filter_option_page_comments' ), 100 );

                
/**
                 * As we override page_comments decision, function comments_template() calculate max_num_comment_pages and set to wp_query
                 * Theme comment template tries to generate comment pagination by
                 * using the_comments_pagination/get_the_comments_pagination function
                 * This function needs comment page count. If comment page count is more than 1 , it generates pagination
                 * get_comment_pages_count() function usages max_num_comment_pages
                 * We don't want to show pagination, We will reset max_num_comment_pages value to 1 so that get_comment_pages_count retuns 1
                 * comments_template function usages a filter for comments_template file.
                 * We will use this filter to reset wp_query->max_num_comment_pages.
                 */
                
add_filter'comments_template', array( $this'reset_wp_query_max_num_comment_pages' ), );

                
/**
                 * Override comment_order decision set from discussion settings page.
                 * When default_comments_page value is 'newest' we want comment_order 'desc'.
                 * When default_comments_page value is 'oldest' we want comment_order 'asc'.
                 */
                
add_filter'option_comment_order', array( $this'filter_option_comment_order' ), 100 );

            }
            
ob_start();

            
comments_template''$separate_comments );
            
$content ob_get_contents();

            
ob_end_clean();
            
$_SERVER['REQUEST_URI'] = $orig_uri;
        }

        if ( ! empty( 
$content ) ) {
            
wp_send_json_success( array( 'content' => $content ) );
        }

        die();
    }

    
/**
     * Add Lazy load action to the list of supported ajax action in Divi theme comment template.
     *
     * @since 2.5.0
     *
     * @return array
     */
    
public function add_divi_support() {
        return array( 
'action' => array( 'get_comments_template' ) );
    }

    
/**
     * Set page_comments option true.
     *
     * Return TRUE only one time when the filter option_page_comments called in
     * function comments_template() in wp-includes/comment-template.php
     *
     * @since 2.5.0
     *
     * @param mixed $value  Value.
     *
     * @return bool|mixed
     */
    
public function filter_option_page_comments$value ) {
        static 
$n;

        if ( ! empty( 
$n ) ) {
            return 
$value;
        }

        
$n 1;

        return 
true;
    }

    
/**
     * This is a fake callback function for comments_template filter
     * We will not change $template value
     * We will change max_num_comment_pages var from $wp_query object
     *
     * @since 2.5.0
     *
     * @param string $template The path to the theme template file.
     *
     * @return string
     */
    
public function reset_wp_query_max_num_comment_pages$template ) {
        global 
$wp_query;
        
$wp_query->max_num_comment_pages 1;
        return 
$template;
    }

    
/**
     * Filter comment_order option value.
     * When default_comments_page value is 'newest' we want comment_order 'desc'.
     * When default_comments_page value is 'oldest' we want comment_order 'asc'.
     *
     * @since 2.5.0
     *
     * @param string $order  Order type.
     *
     * @return string
     */
    
public function filter_option_comment_order$order ) {
        
$dcp get_option'default_comments_page' );
        return ( 
'newest' === $dcp ) ? 'desc' 'asc';
    }

}
x

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