forked from a2hosting/a2-optimized-wp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
A2_Optimized_OptionsManager.php
1627 lines (1345 loc) · 56.5 KB
/
A2_Optimized_OptionsManager.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
<?php
if(is_admin()){
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
class A2_Plugin_Installer_Skin Extends Plugin_Installer_Skin{
public function feedback($type){}
public function error($error){}
}
}
if (file_exists("/opt/a2-optimized/wordpress/Optimizations.php")) {
require_once "/opt/a2-optimized/wordpress/Optimizations.php";
}
require_once 'A2_Optimized_Optimizations.php';
class A2_Optimized_OptionsManager {
public $plugin_dir;
private $optimizations;
private $advanced_optimizations;
private $advanced_optimization_status;
private $optimization_count;
private $advanced_optimization_count;
private $plugin_list;
private $install_status;
public function set_w3tc_defaults()
{
$vars = $this->get_w3tc_defaults();
if (!class_exists('W3_ConfigData')) {
$this->enable_w3_total_cache();
}
$config_writer = new W3_ConfigWriter(0, false);
foreach ($vars as $name => $val) {
$config_writer->set($name, $val);
}
$config_writer->set('common.instance_id', mt_rand());
$config_writer->save();
$this->refresh_w3tc();
}
public function get_w3tc_defaults()
{
return array(
'pgcache.check.domain' => true,
'pgcache.prime.post.enabled' => true,
'pgcache.reject.logged' => true,
'pgcache.reject.request_head' => true,
'pgcache.purge.front_page' => true,
'pgcache.purge.home' => true,
'pgcache.purge.post' => true,
'pgcache.purge.comments' => true,
'pgcache.purge.author' => true,
'pgcache.purge.terms' => true,
'pgcache.purge.archive.daily' => true,
'pgcache.purge.archive.monthly' => true,
'pgcache.purge.archive.yearly' => true,
'pgcache.purge.feed.blog' => true,
'pgcache.purge.feed.comments' => true,
'pgcache.purge.feed.author' => true,
'pgcache.purge.feed.terms' => true,
'pgcache.cache.feed' => true,
'pgcache.debug' => false,
'pgcache.purge.postpages_limit' => 0,//purge all pages that list posts
'pgcache.purge.feed.types' => array(
0 => 'rdf',
1 => 'rss',
2 => 'rss2',
3 => 'atom'
),
'minify.debug' => false,
'dbcache.debug' => false,
'objectcache.debug' => false,
'mobile.enabled' => true,
'minify.auto' => false,
'minify.html.engine' => 'html',
'minify.html.inline.css' => true,
'minify.html.inline.js' => true,
'minify.js.engine' => 'js',
'minify.css.engine' => 'css',
'minify.js.header.embed_type' => 'nb-js',
'minify.js.body.embed_type' => 'nb-js',
'minify.js.footer.embed_type' => 'nb-js',
'minify.lifetime' => 14400,
'minify.file.gc' => 144000,
'dbcache.lifetime' => 3600,
'dbcache.file.gc' => 7200,
'objectcache.lifetime' => 3600,
'objectcache.file.gc' => 7200,
'browsercache.cssjs.last_modified' => true,
'browsercache.cssjs.compression' => true,
'browsercache.cssjs.expires' => true,
'browsercache.cssjs.lifetime' => 31536000,
'browsercache.cssjs.nocookies' => false,
'browsercache.cssjs.cache.control' => true,
'browsercache.cssjs.cache.policy' => 'cache_maxage',
'browsercache.cssjs.etag' => true,
'browsercache.cssjs.w3tc' => true,
'browsercache.cssjs.replace' => true,
'browsercache.html.compression' => true,
'browsercache.html.last_modified' => true,
'browsercache.html.expires' => true,
'browsercache.html.lifetime' => 30,
'browsercache.html.cache.control' => true,
'browsercache.html.cache.policy' => 'cache_maxage',
'browsercache.html.etag' => true,
'browsercache.html.w3tc' => true,
'browsercache.html.replace' => true,
'browsercache.other.last_modified' => true,
'browsercache.other.compression' => true,
'browsercache.other.expires' => true,
'browsercache.other.lifetime' => 31536000,
'browsercache.other.nocookies' => false,
'browsercache.other.cache.control' => true,
'browsercache.other.cache.policy' => 'cache_maxage',
'browsercache.other.etag' => true,
'browsercache.other.w3tc' => true,
'browsercache.other.replace' => true,
'config.check' => true,
'varnish.enabled' => false
);
}
public function enable_w3_total_cache()
{
$file = 'w3-total-cache/w3-total-cache.php';
$slug = 'w3-total-cache';
if (!class_exists('W3_ConfigWriter')) {
$plugins = $this->get_plugins();
if (isset($plugins[$file])) {
activate_plugin($file);
} else {
$this->install_plugin($slug);
$this->activate_plugin($file);
$this->hit_the_w3tc_page();
}
}
}
public function get_plugins()
{
if (isset($this->plugin_list)) {
return $this->plugin_list;
} else {
return get_plugins();
}
}
public function install_plugin($slug, $activate = false)
{
require_once ABSPATH . 'wp-admin/includes/plugin.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$api = plugins_api('plugin_information', array('slug' => $slug));
$found = false;
$plugins = $this->get_plugins();
foreach ($plugins as $file => $plugin) {
if ($plugin['Name'] == $api->name) {
$found = true;
}
}
if (!$found) {
ob_start();
$upgrader = new Plugin_Upgrader(new A2_Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api')));
$upgrader->install($api->download_link);
ob_end_clean();
$this->plugin_list = get_plugins();
}
if ($activate) {
$plugins = $this->get_plugins();
foreach ($plugins as $file => $plugin) {
if ($plugin['Name'] == $api->name) {
$this->activate_plugin($file);
}
}
}
$this->clear_w3_total_cache();
}
public function activate_plugin($file)
{
require_once ABSPATH . 'wp-admin/includes/plugin.php';
activate_plugin($file);
$this->clear_w3_total_cache();
}
public function clear_w3_total_cache()
{
if (is_plugin_active('w3-total-cache/w3-total-cache.php')) {
//TODO: add clear cache
}
}
public function hit_the_w3tc_page()
{
$cookie = "";
foreach ($_COOKIE as $name => $val) {
$cookie .= "{$name}={$val};";
}
rtrim($cookie, ';');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, get_admin_url() . 'admin.php?page=w3tc_general&nonce=' . wp_create_nonce('w3tc'));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_REFERER, get_admin_url());
$result = curl_exec($ch);
curl_close($ch);
}
public function refresh_w3tc()
{
$this->hit_the_w3tc_page();
}
public function get_w3tc_config(){
if(class_exists('W3_ConfigData')){
$config_writer = new W3_ConfigWriter(0,false);
return W3_ConfigData::get_array_from_file($config_writer->get_config_filename());
}
else{
return false;
}
}
public function enable_w3tc_cache(){
$permalink_structure = get_option('permalink_structure');
$vars = array();
if($permalink_structure == ''){
$vars['pgcache.engine']='file';
}
else{
$vars['pgcache.engine']='file_generic';
}
$vars['dbcache.engine'] = 'file';
$vars['objectcache.engine'] = 'file';
$vars['objectcache.enabled'] = true;
$vars['dbcache.enabled'] = true;
$vars['pgcache.enabled'] = true;
$vars['browsercache.enabled'] = true;
$this->update_w3tc($vars);
}
public function enable_w3tc_page_cache(){
$permalink_structure = get_option('permalink_structure');
$vars = array();
if($permalink_structure == ''){
$vars['pgcache.engine']='file';
}
else{
$vars['pgcache.engine']='file_generic';
}
$vars['pgcache.enabled'] = true;
$this->update_w3tc($vars);
}
public function enable_w3tc_db_cache(){
$permalink_structure = get_option('permalink_structure');
$vars = array();
$vars['dbcache.engine'] = 'file';
$vars['dbcache.enabled'] = true;
$this->update_w3tc($vars);
}
public function enable_w3tc_object_cache(){
$permalink_structure = get_option('permalink_structure');
$vars = array();
$vars['objectcache.engine'] = 'file';
$vars['objectcache.enabled'] = true;
$this->update_w3tc($vars);
}
public function enable_w3tc_browser_cache(){
$permalink_structure = get_option('permalink_structure');
$vars = array();
$vars['browsercache.enabled'] = true;
$this->update_w3tc($vars);
}
public function update_w3tc($vars)
{
$vars = array_merge($this->get_w3tc_defaults(), $vars);
if (!class_exists('W3_ConfigData')) {
$this->enable_w3_total_cache();
}
$config_writer = new W3_ConfigWriter(0, false);
foreach ($vars as $name => $val) {
$config_writer->set($name, $val);
}
$config_writer->set('common.instance_id', mt_rand());
$config_writer->save();
$this->refresh_w3tc();
}
public function disable_w3tc_cache()
{
$this->update_w3tc(array(
'pgcache.enabled' => false,
'dbcache.enabled' => false,
'objectcache.enabled' => false,
'browsercache.enabled' => false,
));
}
public function disable_w3tc_page_cache(){
$vars = array();
$vars['pgcache.enabled'] = false;
$this->update_w3tc($vars);
}
public function disable_w3tc_db_cache(){
$vars = array();
$vars['dbcache.enabled'] = false;
$this->update_w3tc($vars);
}
public function disable_w3tc_object_cache(){
$vars = array();
$vars['objectcache.enabled'] = false;
$this->update_w3tc($vars);
}
public function disable_w3tc_browser_cache(){
$vars = array();
$vars['browsercache.enabled'] = false;
$this->update_w3tc($vars);
}
public function disable_html_minify()
{
$this->update_w3tc(array(
'minify.html.enable' => false,
'minify.html.enabled' => false,
'minify.auto' => false
));
}
public function enable_html_minify()
{
$this->update_w3tc(array(
'minify.html.enable' => true,
'minify.enabled' => true,
'minify.auto' => false,
'minify.engine' => 'file'
));
}
public function curl_save_w3tc($cookie, $url)
{
$post = "w3tc_save_options=Save all settings&_wpnonce=" . wp_create_nonce('w3tc') . "&_wp_http_referer=%2Fwp-admin%2Fadmin.php%3Fpage%3Dw3tc_general%26&w3tc_note%3Dconfig_save";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, get_admin_url() . $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_REFERER, get_admin_url() . $url);
//curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$head = curl_exec($ch);
curl_close($ch);
}
public function get_optimizations()
{
return $this->optimizations;
}
/**
* Creates HTML for the Administration page to set options for this plugin.
* Override this method to create a customized page.
* @return void
*/
public function settingsPage()
{
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access A2 Optimized.', 'a2-optimized'));
}
$thisclass = $this;
$optimization_count = 0;
$this->get_plugin_status();
$thisdir = rtrim(__DIR__, "/");
wp_enqueue_style('bootstrap', plugins_url('/assets/bootstrap/css/bootstrap.css',__FILE__));
wp_enqueue_style('bootstrap-theme', plugins_url('/assets/bootstrap/css/bootstrap-theme.css',__FILE__));
wp_enqueue_script('bootstrap-theme', plugins_url('/assets/bootstrap/js/bootstrap.js',__FILE__), array('jquery'));
$image_dir = plugins_url('/assets/images',__FILE__);
do_action('a2_notices');
$ini_error_reporting = ini_get('error_reporting');
//ini_set('error_reporting',0);
$this->optimization_status = "";
$optionMetaData = $this->getOptionMetaData();
$csrf_token = 0;
/*$kbpage = $this->curl('https://www.a2hosting.com/kb');
if (preg_match('/name="csrf_token" value="([a-z0-9]{40})"/', $kbpage, $csrf_match)) {
$csrf_token = $csrf_match[1];
}*/
$optimization_status = "";
foreach ($this->advanced_optimizations as $shortname => &$item) {
$this->advanced_optimization_status .= $this->get_optimization_status($item);
if ($item['configured']) {
$this->advanced_optimization_count++;
}
}
$this->optimization_count = 0;
foreach ($this->optimizations as $shortname => &$item) {
$this->optimization_status .= $this->get_optimization_status($item);
if ($item['configured']) {
$this->optimization_count++;
}
}
if ($this->optimization_count == count($this->optimizations)) {
$optimization_alert = '<div class="alert alert-success">Your site has been fully optimized!</div>';
} elseif (!$this->optimizations['page_cache']['configured']) {
$optimization_alert = '<div class="alert alert-danger">Your site is NOT optimized!</div>';
} elseif ($this->optimization_count > 5) {
$optimization_alert = '<div class="alert alert-success">Your site has been partially optimized!</div>';
} elseif ($this->optimization_count > 2) {
$optimization_alert = '<div class="alert alert-danger">Your site is barely optimized!</div>';
} else {
$optimization_alert = '<div class="alert alert-danger">Your site is NOT optimized!</div>';
}
$optimization_number = count($this->optimizations);
$optimization_circle = "";
if ($optimization_number > 0) {
$optimization_circle = <<<HTML
<span class="badge badge-success">{$this->optimization_count}/{$optimization_number}</span>
HTML;
}
$kb_search_box = <<<HTML
<div class='big-search' style="margin-top:34px" >
<div class='kb-search' >
<form method="post" action="https://www.a2hosting.com/" target="_blank" >
<div class='hiddenFields'>
<input type="hidden" name="ACT" value="25" />
<input type="hidden" name="RP" value="kb/results" />
<input type="hidden" name="site_id" value="1" />
<input type="hidden" name="csrf_token" value="{$csrf_token}" />
</div>
<input type="text" id="kb-search-request" name="keywords" placeholder="Search The A2 Knowledge Base">
<button class='btn btn-success' type='submit'>Search</button>
<div id='honeypot'><input type='text' class='input'></div>
</form>
</div>
</div>
HTML;
list($warnings, $num_warnings) = $this->warnings();
$advanced_circle = "";
$warning_circle = "";
if ($num_warnings > 0) {
$warning_circle = <<<HTML
<span class="badge badge-warning">{$num_warnings}</span>
HTML;
}
$settingsGroup = get_class($this) . '-settings-group';
$description = $this->get_plugin_description();
echo <<<HTML
<section id="content-general">
<div class="wrap">
<div>
<div>
<div>
<div style="float:left;clear:both">
<img src="{$image_dir}/a2optimized.png" style="margin-top:20px" />
</div>
<div style="float:right;">
{$kb_search_box}
</div>
</div>
<div style="clear:both;"></div>
</div>
<div >
<div style="margin:20px 0;">
{$optimization_alert}
</div>
</div>
</div>
<ul class="nav nav-tabs" roll="tablist">
<li role="tab" aria-controls="optimization-status" id="li-optimization-status" ><a onclick='document.location.hash="#optimization-status-tab"' href="#optimization-status" data-toggle="tab">Optimization Status {$optimization_circle}</a></li>
<li role="tab" aria-controls="optimization-warnings" id="li-optimization-warnings" ><a onclick='document.location.hash="#optimization-warnings-tab"' href="#optimization-warnings" data-toggle="tab">Warnings {$warning_circle}</a></li>
<li role="tab" aria-controls="optimization-advanced" id="li-optimization-advanced" ><a onclick='document.location.hash="#optimization-advanced-tab"' href="#optimization-advanced" data-toggle="tab">Advanced Optimizations {$advanced_circle}</a></li>
<li role="tab" aria-controls="optimization-about" id="li-optimization-about" ><a onclick='document.location.hash="#optimization-about-tab"' href="#optimization-about" data-toggle="tab">About A2 Optimized</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" aria-labelledby="li-optimization-status" id="optimization-status" class="tab-pane">
<h3>Optimization Status</h3>
<div >
{$this->optimization_status}
</div>
</div>
<div role="tabpanel" aria-labelledby="li-optimization-warnings" id="optimization-warnings" class="tab-pane">
<h3>Warnings</h3>
{$warnings}
</div>
<div role="tabpanel" aria-labelledby="li-optimization-advanced" id="optimization-advanced" class="tab-pane">
<h3>Advanced Optimizations</h3>
{$this->advanced_optimization_status}
</div>
<div role="tabpanel" aria-labelledby="li-optimization-about" id="optimization-about" class="tab-pane">
<div style="margin:20px 0;">
<h3>About A2 Optimized</h3>
<ul style="list-style-type: disc;list-style-position: inside">
<li>A2 Optimized was developed by A2 Hosting to make it faster and easier to configure the caching of all aspects of a WordPress site.</li>
<li>This free plugin comes with many of the popular Optimizations that come with WordPress hosted at A2 Hosting.</li>
<li>To get the full advantage of A2 Optimized, try hosting your site at <a href='https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized' target='_blank'>A2 Hosting</a></li>
</ul>
</div>
<div style="margin:20px 0;">
<h3>Free Optimizations</h3>
<dt>Page Caching with W3 Total Cache</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Page Caching stores full copies of pages on the disk so that php code and database queries can be skipped by the web server.</li>
</ul>
</dd>
<dt>DB Caching with W3 Total Cache</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Database cache stores copies of common database queries on disk or in memcory to speed up page rendering.</li>
</ul>
</dd>
<dt>Object Caching with W3 Total Cache</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Object Caching stores commonly used elements such as menus / widgets and forms on disk or in memory to speed up page rendering.</li>
</ul>
</dd>
<dt>Browser Caching with W3 Total Cache</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Add Rules to the web server to tell the browser to store a copy of static files to reduce the load time pages requested after the first page is loaded.</li>
</ul>
</dd>
<dt>Minify HTML Pages</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Auto Configure W3 Total Cache to remove excess white space and comments from html pages to compress their size.</li>
<li>This provides for minor imporvements in page load time.</li>
</ul>
</dd>
<dt>Minify CSS Files</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Auto Configure W3 Total Cache to condense CSS files into non human-readable compressed files.</li>
<li>Combines multiple css files into a single download.</li>
<li>Can provide significant speed imporvements for page loads.</li>
</ul>
</dd>
<dt>Minify JS Files</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Auto Configure W3 Total Cache to condense JavaScript files into non human-readable compressed files.</li>
<li>Combines multiple js files into a single download.</li>
<li>Can provide significant speed imporvements for page loads.</li>
</ul>
</dd>
<dt>Gzip Compression Enabled</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Turns on gzip compression using W3 Total Cache.</li>
<li>Ensures that files are compressed before transfering them.</li>
<li>Can provide significant speed imporvements for page loads.</li>
<li>Reduces bandwidth required to serve web pages.</li>
</ul>
</dd>
<dt>Deny Direct Access to Configuration Files and Comment Form</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Enables WordPress hardening rules in .htaccess to prevent browser access to certain files.</li>
<li>Prevents bots from submitting to comment forms.</li>
<li>Turn this off if you use systems that post to the comment form without visiting the page.</li>
</ul>
</dd>
<dt>Lock Editing of Plugins and Themes from the WP Admin</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Turns off the file editor in the wp-admin.</li>
<li>Prevents plugins and themes from being tampered with from the wp-admin.</li>
</ul>
</dd>
</div>
<div style="margin:20px 0;">
<h3>A2 Hosting Exclusive Optimizations</h3>
<p>
These one-click optimizations are only available while hosted at A2 Hosting.
</p>
<dt>Login URL Change</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Move the login page from the default wp-login.php to a random URL.</li>
<li>Prevents bots from automatically brute-force attacking wp-login.php</li>
</ul>
</dd>
<dt>reCAPTCHA on comments and login</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>provides google reCAPTCHA on both the Login form and comments.</li>
<li>Prevents bots from automatically brute-force attacking wp-login.php</li>
<li>Prevents bots from automatically spamming comments.</li>
</ul>
</dd>
<dt>Compress Images on Upload</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Enables and configures EWWW Image Optimizer.</li>
<li>Compresses images that are uploaded to save bandwidth.</li>
<li>Improves page load times: especially on sites with many images.</li>
</ul>
</dd>
<dt>Turbo Web Hosting</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Take advantage of A2 Hosting's Turbo Web Hosting platform.</li>
<li>Faster serving of static files.</li>
<li>Pre-compiled .htaccess files on the web server for imporved performance.</li>
<li>PHP OpCode cache enabled by default</li>
<li>Custom php engine that is faster than Fast-CGI and FPM</li>
</ul>
</dd>
<dt>Memcached Database and Object Cache</dt>
<dd>
<ul style="list-style-type: disc;list-style-position: inside">
<li>Database and Object cache in memory instead of on disk.</li>
<li>Secure and Faster Memcached using Unix socket files.</li>
<li>Significant improvement in page load times, especially on pages that can not use full page cache such as wp-admin</li>
</ul>
</dd>
</div>
</div>
</div>
<div style="margin:10px 0;" class="alert alert-success">
We want to hear from you! Please share your thoughts and feedback in our <a href="https://my.a2hosting.com/a2-suggestion-box.php" target="_blank">Suggestion Box!</a>
</div>
</div>
<div style="clear:both;padding:10px;"></div>
</section>
<script>
if(document.location.hash != ""){
switch(document.location.hash.replace("#","")){
case 'optimization-status-tab':
document.getElementById("li-optimization-status").setAttribute("class","active");
document.getElementById("optimization-status").setAttribute("class","tab-pane active");
break;
case 'optimization-warnings-tab':
document.getElementById("li-optimization-warnings").setAttribute("class","active");
document.getElementById("optimization-warnings").setAttribute("class","tab-pane active");
break;
case "optimization-plugins-tab":
document.getElementById("li-optimization-plugins").setAttribute("class","active");
document.getElementById("optimization-plugins").setAttribute("class","tab-pane active");
break;
case "optimization-advanced-tab":
document.getElementById("li-optimization-advanced").setAttribute("class","active");
document.getElementById("optimization-advanced").setAttribute("class","tab-pane active");
break;
case "optimization-about-tab":
document.getElementById("li-optimization-about").setAttribute("class","active");
document.getElementById("optimization-about").setAttribute("class","tab-pane active");
break;
default:
document.getElementById("li-optimization-status").setAttribute("class","active");
document.getElementById("optimization-status").setAttribute("class","tab-pane active");
}
}
else{
document.getElementById("li-optimization-status").setAttribute("class","active");
document.getElementById("optimization-status").setAttribute("class","tab-pane active");
}
</script>
HTML;
ini_set('error_reporting', $ini_error_reporting);
}
public function get_plugin_status()
{
$thisclass = $this;
$opts = new A2_Optimized_Optimizations($thisclass);
$this->advanced_optimizations = $opts->get_advanced();
$this->optimizations = $opts->get_optimizations();
$this->plugin_list = get_plugins();
if (isset($_GET['activate'])) {
foreach ($this->plugin_list as $file => $plugin) {
if ($_GET['activate'] == $plugin['Name']) {
$this->activate_plugin($file);
}
}
}
if (isset($_GET['hide_login_url'])) {
$this->addOption('hide_login_url', true);
}
if (isset($_GET['deactivate'])) {
foreach ($this->plugin_list as $file => $plugin) {
if ($_GET['deactivate'] == $plugin['Name']) {
$this->deactivate_plugin($file);
}
}
}
if (isset($_GET['delete'])) {
foreach ($this->plugin_list as $file => $plugin) {
if ($_GET['delete'] == $plugin['Name']) {
$this->uninstall_plugin($file);
}
}
}
if (isset($_GET['disable_optimization'])) {
$hash = "";
if (isset($this->optimizations[$_GET['disable_optimization']])) {
$this->optimizations[$_GET['disable_optimization']]['disable']($_GET['disable_optimization']);
}
if (isset($this->advanced_optimizations[$_GET['disable_optimization']])) {
$this->advanced_optimizations[$_GET['disable_optimization']]['disable']($_GET['disable_optimization']);
$hash = "#optimization-advanced-tab";
}
echo <<<JAVASCRIPT
<script type="text/javascript">
window.location = 'admin.php?page=A2_Optimized_Plugin_admin{$hash}';
</script>
JAVASCRIPT;
exit();
}
if (isset($_GET['enable_optimization'])) {
$hash = "";
if (isset($this->optimizations[$_GET['enable_optimization']])) {
$this->optimizations[$_GET['enable_optimization']]['enable']($_GET['enable_optimization']);
}
if (isset($this->advanced_optimizations[$_GET['enable_optimization']])) {
$this->advanced_optimizations[$_GET['enable_optimization']]['enable']($_GET['enable_optimization']);
$hash = "#optimization-advanced-tab";
}
echo <<<JAVASCRIPT
<script type="text/javascript">
window.location = 'admin.php?page=A2_Optimized_Plugin_admin{$hash}';
</script>
JAVASCRIPT;
exit();
}
ini_set('disable_functions', '');
require_once ABSPATH . 'wp-admin/includes/plugin.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$plugins_url = plugins_url();
$plugins_url = explode('/', $plugins_url);
array_shift($plugins_url);
array_shift($plugins_url);
array_shift($plugins_url);
$this->plugin_dir = ABSPATH . implode('/', $plugins_url);
$this->plugins_url = plugins_url();
validate_active_plugins();
$this->set_install_status('plugins', $this->plugin_list);
}
/**
* A wrapper function delegating to WP add_option() but it prefixes the input $optionName
* to enforce "scoping" the options in the WP options table thereby avoiding name conflicts
* @param $optionName string defined in settings.php and set as keys of $this->optionMetaData
* @param $value mixed the new value
* @return null from delegated call to delete_option()
*/
public function addOption($optionName, $value)
{
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
return add_option($prefixedOptionName, $value);
}
/**
* Get the prefixed version input $name suitable for storing in WP options
* Idempotent: if $optionName is already prefixed, it is not prefixed again, it is returned without change
* @param $name string option name to prefix. Defined in settings.php and set as keys of $this->optionMetaData
* @return string
*/
public function prefix($name)
{
$optionNamePrefix = $this->getOptionNamePrefix();
if (strpos($name, $optionNamePrefix) === 0) { // 0 but not false
return $name; // already prefixed
}
return $optionNamePrefix . $name;
}
public function getOptionNamePrefix()
{
return get_class($this) . '_';
}
public function deactivate_plugin($file)
{
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if (is_plugin_active($file)) {
deactivate_plugins($file);
$this->clear_w3_total_cache();
}
}
public function uninstall_plugin($file, $delete = true)
{
require_once ABSPATH . 'wp-admin/includes/plugin.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$this->deactivate_plugin($file);
uninstall_plugin($file);
if ($delete) {
delete_plugins(array($file));
}
unset($this->plugin_list[$file]);
$this->clear_w3_total_cache();
}
public function set_install_status($name, $value)
{
if (!isset($this->install_status)) {
$this->install_status = new StdClass;
}
$this->install_status->{$name} = $value;
}
/**
* Define your options meta data here as an array, where each element in the array
* @return array of key=>display-name and/or key=>array(display-name, choice1, choice2, ...)
* key: an option name for the key (this name will be given a prefix when stored in
* the database to ensure it does not conflict with other plugin options)
* value: can be one of two things:
* (1) string display name for displaying the name of the option to the user on a web page
* (2) array where the first element is a display name (as above) and the rest of
* the elements are choices of values that the user can select
* e.g.
* array(
* 'item' => 'Item:', // key => display-name
* 'rating' => array( // key => array ( display-name, choice1, choice2, ...)
* 'CanDoOperationX' => array('Can do Operation X', 'Administrator', 'Editor', 'Author', 'Contributor', 'Subscriber'),
* 'Rating:', 'Excellent', 'Good', 'Fair', 'Poor')
*/
public function getOptionMetaData()
{
return array();
}
private function curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
/*public function get_litespeed(){
return get_option('a2_optimized_litespeed');
}*/
/*public function set_litespeed($litespeed = true){
update_option('a2_optimized_litespeed',$litespeed);
}*/
function get_optimization_status(&$item)
{
if ($item != null) {
$settings_slug = $this->getSettingsSlug();
if (isset($item['is_configured'])) {
$item['is_configured']($item);
}
$active_color = 'danger';
$active_text = 'Not Activated';
$glyph = 'exclamation-sign';
$links = array();
if ($item['configured']) {
$active_color = 'success';
$active_text = 'Configured';
$glyph = 'ok';