forked from a2hosting/a2-optimized-wp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathA2_Optimized_Optimizations.php
723 lines (696 loc) · 36.5 KB
/
A2_Optimized_Optimizations.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
<?php
class A2_Optimized_Optimizations
{
private $thisclass;
public function __construct($thisclass)
{
$this->thisclass = $thisclass;
}
public function get_optimizations()
{
$public_opts = $this->get_public_optimizations();
$private_opts = $this->get_private_optimizations();
return array_merge($public_opts, $private_opts);
}
protected function get_public_optimizations()
{
$thisclass = $this->thisclass;
return array(
'page_cache' => array(
'slug' => 'page_cache',
'name' => 'Page Caching with W3 Total Cache',
'plugin' => 'W3 Total Cache',
'configured' => false,
'description' => 'Utilize W3 Total Cache to make the site faster by caching pages as static content. Cache: a copy of rendered dynamic pages will be saved by the server so that the next user does not need to wait for the server to generate another copy.',
'is_configured' => function (&$item) use (&$thisclass) {
$w3tc = $thisclass->get_w3tc_config();
if ($w3tc['pgcache.enabled']) {
$item['configured'] = true;
$permalink_structure = get_option('permalink_structure');
$vars = array();
if ($w3tc['pgcache.engine'] == 'apc') {
if ($permalink_structure == '') {
$vars['pgcache.engine'] = 'file';
} else {
$vars['pgcache.engine'] = 'file_generic';
}
} else {
if ($permalink_structure == '' && $w3tc['pgcache.engine'] != 'file') {
$vars['pgcache.engine'] = 'file';
} elseif ($permalink_structure != '' && $w3tc['pgcache.engine'] == 'file') {
$vars['pgcache.engine'] = 'file_generic';
}
}
if (count($vars) != 0) {
$thisclass->update_w3tc($vars);
}
$thisclass->set_install_status('page_cache', true);
} else {
$thisclass->set_install_status('page_cache', false);
}
},
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
'disable' => function () use (&$thisclass) {
$thisclass->disable_w3tc_page_cache();
},
'enable' => function () use (&$thisclass) {
$thisclass->enable_w3tc_page_cache();
}
),
'db_cache' => array(
'slug' => 'db_cache',
'name' => 'DB Caching with W3 Total Cache',
'plugin' => 'W3 Total Cache',
'configured' => false,
'description' => 'Speed up the site by storing the responses of common database queries in a cache.',
'is_configured' => function (&$item) use (&$thisclass) {
$w3tc = $thisclass->get_w3tc_config();
if ($w3tc['dbcache.enabled']) {
$vars = array();
$item['configured'] = true;
if (class_exists('W3_Config')) {
if (class_exists('WooCommerce')) {
if (array_search('_wc_session_', $w3tc['dbcache.reject.sql']) === false) {
$vars['dbcache.reject.sql'] = $w3tc['dbcache.reject.sql'];
$vars['dbcache.reject.sql'][] = '_wc_session_';
}
}
}
if (count($vars) != 0) {
$thisclass->update_w3tc($vars);
}
$thisclass->set_install_status('db_cache', true);
} else {
$thisclass->set_install_status('db_cache', false);
}
},
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
'disable' => function () use (&$thisclass) {
$thisclass->disable_w3tc_db_cache();
},
'enable' => function () use (&$thisclass) {
$thisclass->enable_w3tc_db_cache();
}
),
'object_cache' => array(
'slug' => 'object_cache',
'name' => 'Object Caching with W3 Total Cache',
'plugin' => 'W3 Total Cache',
'configured' => false,
'description' => 'Store a copy of widgets and menu bars in cache to reduce the time it takes to render pages.',
'is_configured' => function (&$item) use (&$thisclass) {
$w3tc = $thisclass->get_w3tc_config();
if ($w3tc['objectcache.enabled']) {
$item['configured'] = true;
$thisclass->set_install_status('object_cache', true);
} else {
$thisclass->set_install_status('object_cache', false);
}
},
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
'disable' => function () use (&$thisclass) {
$thisclass->disable_w3tc_object_cache();
},
'enable' => function () use (&$thisclass) {
$thisclass->enable_w3tc_object_cache();
}
),
'browser_cache' => array(
'slug' => 'browser_cache',
'name' => 'Browser Caching with W3 Total Cache',
'plugin' => 'W3 Total Cache',
'configured' => false,
'description' => '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.',
'is_configured' => function (&$item) use (&$thisclass) {
$w3tc = $thisclass->get_w3tc_config();
if ($w3tc['browsercache.enabled']) {
$item['configured'] = true;
$thisclass->set_install_status('browser_cache', true);
} else {
$thisclass->set_install_status('browser_cache', false);
}
},
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
'disable' => function () use (&$thisclass) {
$thisclass->disable_w3tc_browser_cache();
},
'enable' => function () use (&$thisclass) {
$thisclass->enable_w3tc_browser_cache();
}
),
'minify' => array(
'name' => 'Minify HTML Pages',
'slug' => 'minify',
'plugin' => 'W3 Total Cache',
'configured' => false,
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
'description' => 'Removes extra spaces,tabs and line breaks in the HTML to reduce the size of the files sent to the user.',
'is_configured' => function (&$item) use (&$thisclass) {
$w3tc = $thisclass->get_w3tc_config();
if ($w3tc['minify.enabled'] && $w3tc['minify.html.enable']) {
$item['configured'] = true;
$thisclass->set_install_status('minify-html', true);
} else {
$thisclass->set_install_status('minify-html', false);
}
},
'enable' => function () use (&$thisclass) {
$thisclass->enable_html_minify();
},
'disable' => function () use (&$thisclass) {
$thisclass->disable_html_minify();
}
),
'css_minify' => array(
'name' => 'Minify CSS Files',
'slug' => 'css_minify',
'plugin' => 'W3 Total Cache',
'configured' => false,
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
'description' => 'Makes your site faster by condensing css files into a single downloadable file and by removing extra space in CSS files to make them smaller.',
'is_configured' => function (&$item) use (&$thisclass) {
$w3tc = $thisclass->get_w3tc_config();
if ($w3tc['minify.css.enable']) {
$item['configured'] = true;
$thisclass->set_install_status('minify-css', true);
} else {
$thisclass->set_install_status('minify-css', false);
}
},
'enable' => function () use (&$thisclass) {
$thisclass->update_w3tc(array(
'minify.css.enable' => true,
'minify.enabled' => true,
'minify.auto' => 0,
'minify.engine' => 'file'
));
},
'disable' => function () use (&$thisclass) {
$thisclass->update_w3tc(array(
'minify.css.enable' => false,
'minify.auto' => 0
));
}
),
'js_minify' => array(
'name' => 'Minify JS Files',
'slug' => 'js_minify',
'plugin' => 'W3 Total Cache',
'configured' => false,
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
'description' => 'Makes your site faster by condensing JavaScript files into a single downloadable file and by removing extra space in JavaScript files to make them smaller.',
'is_configured' => function (&$item) use (&$thisclass) {
$w3tc = $thisclass->get_w3tc_config();
if ($w3tc['minify.js.enable']) {
$item['configured'] = true;
$thisclass->set_install_status('minify-js', true);
} else {
$thisclass->set_install_status('minify-js', false);
}
},
'enable' => function () use (&$thisclass) {
$thisclass->update_w3tc(array(
'minify.js.enable' => true,
'minify.enabled' => true,
'minify.auto' => 0,
'minify.engine' => 'file'
));
},
'disable' => function () use (&$thisclass) {
$thisclass->update_w3tc(array(
'minify.js.enable' => false,
'minify.auto' => 0
));
}
),
'gzip' => array(
'name' => 'Gzip Compression Enabled',
'slug' => 'gzip',
'plugin' => 'W3 Total Cache',
'configured' => false,
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
'description' => 'Makes your site significantly faster by compressing all text files to make them smaller.',
'is_configured' => function (&$item) use (&$thisclass) {
$w3tc = $thisclass->get_w3tc_config();
if ($w3tc['browsercache.other.compression']) {
$item['configured'] = true;
$thisclass->set_install_status('gzip', true);
} else {
$thisclass->set_install_status('gzip', false);
}
},
'enable' => function () use (&$thisclass) {
$thisclass->update_w3tc(array(
'browsercache.other.compression' => true,
'browsercache.html.compression' => true,
'browsercache.cssjs.compression' => true
));
},
'disable' => function () use (&$thisclass) {
$thisclass->update_w3tc(array(
'browsercache.other.compression' => false,
'browsercache.html.compression' => false,
'browsercache.cssjs.compression' => false
));
}
),
'htaccess' => array(
'name' => 'Deny Direct Access to Configuration Files and Comment Form',
'slug' => 'htaccess',
'plugin' => 'A2 Optimized',
'configured' => false,
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-the-a2-optimized-plugin',
'description' => 'Protects your configuration files by generating a Forbidden error to web users and bots when trying to access WordPress configuration files. <br> Also prevents POST requests to the site not originating from a user on the site. <br> <span class="danger" >note</span>: if you are using a plugin to allow remote posts and comments, disable this option.',
'is_configured' => function (&$item) use (&$thisclass) {
$htaccess = file_get_contents(ABSPATH . '.htaccess');
if (strpos($htaccess, "# BEGIN WordPress Hardening") === false) {
if ($thisclass->get_deny_direct() == true) {
$thisclass->set_deny_direct(false);
}
//make sure the basic a2-optimized rules are present
$thisclass->set_install_status('htaccess-deny-direct-access', false);
} else {
if ($thisclass->get_deny_direct() == false) {
$thisclass->set_deny_direct(true);
}
$item['configured'] = true;
$thisclass->set_install_status('htaccess-deny-direct-access', true);
}
},
'enable' => function () use (&$thisclass) {
$thisclass->set_deny_direct(true);
$thisclass->write_htaccess();
},
'disable' => function () use (&$thisclass) {
$thisclass->set_deny_direct(false);
$thisclass->write_htaccess();
}
),
'lock' => array(
'name' => 'Lock Editing of Plugins and Themes from the WP Admin',
'slug' => 'lock',
'plugin' => 'A2 Optimized',
'configured' => false,
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-the-a2-optimized-plugin',
'description' => 'Prevents exploits that use the built in editing capabilities of the WP Admin',
'is_configured' => function (&$item) use (&$thisclass) {
$wpconfig = file_get_contents(ABSPATH . 'wp-config.php');
if (strpos($wpconfig, "// BEGIN A2 CONFIG") === false) {
if ($thisclass->get_lockdown() == true) {
$thisclass->get_lockdown(false);
}
$thisclass->set_install_status('lock-editing', false);
} else {
if ($thisclass->get_lockdown() == false) {
$thisclass->set_lockdown(true);
}
$item['configured'] = true;
$thisclass->set_install_status('lock-editing', true);
}
},
'enable' => function () use (&$thisclass) {
$thisclass->set_lockdown(true);
$thisclass->write_wp_config();
},
'disable' => function () use (&$thisclass) {
$thisclass->set_lockdown(false);
$thisclass->write_wp_config();
}
),
'wp-login' => array(
'name' => 'Login URL Change',
'slug' => 'wp-login',
'premium' => true,
'plugin' => 'Rename wp-login.php',
'configured' => false,
'kb' => 'http://www.a2hosting.com/kb/security/application-security/wordpress-security#a-namemethodRenameLoginPageaMethod-3.3A-Change-the-WordPress-login-URL',
'description' => '
<p>Change the URL of your login page to make it harder for bots to find it to brute force attack.</p>
',
'is_configured' => function(){
return false;
}
),
'captcha' => array(
'name' => 'reCAPTCHA on comments and login',
'plugin' => 'reCAPTCHA',
'slug' => 'captcha',
'premium' => true,
'configured' => false,
'description' => 'Decreases spam and increases site security by adding a CAPTCHA to comment forms and the login screen. Without a CAPTCHA, bots will easily be able to post comments to you blog or brute force login to your admin panel.',
'is_configured' => function (){
return false;
}
),
'images' => array(
'name' => 'Compress Images on Upload',
'plugin' => 'EWWW Image Optimizer',
'slug' => 'images',
'premium' => true,
'configured' => false,
'description' => 'Makes your site faster by compressing images to make them smaller.',
'is_configured' => function () {
return false;
}
),
'turbo' => array(
'name' => 'Turbo Web Hosting',
'slug' => 'turbo',
'configured' => false,
'premium'=>true,
'description' => '
<ul>
<li>Turbo Web Hosting servers compile .htaccess files to make speed improvements. Any changes to .htaccess files are immediately re-compiled.</li>
<li>Turbo Web Hosting servers have their own PHP API that provides speed improvements over FastCGI and PHP-FPM (FastCGI Process Manager). </li>
<li>To serve static files, Turbo Web Hosting servers do not need to create a worker process as the user. Servers only create a worker process for PHP scripts, which results in faster performance.</li>
<li>PHP OpCode Caching is enabled by default. Accounts are allocated 256 MB of memory toward OpCode caching.</li>
<li>Turbo Web Hosting servers have a built-in caching engine for Full Page Cache and Edge Side Includes.</li>
</ul>
',
'is_configured' => function (){
return false;
}
),
'memcached' => array(
'name' => 'Memcached Database and Object Cache',
'slug' => 'memcached',
'configured' => false,
'premium'=>true,
'description' => '
<ul>
<li>Extremely fast and powerful caching system.</li>
<li>Store frequently used database queries and WordPress objects in Memcached.</li>
<li>Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.</li>
<li>Take advantage of A2 Hosting's one-click memcached configuration for WordPress.</li>
</ul>
',
'is_configured' => function (){
return false;
}
)
);
}
protected function get_private_optimizations()
{
if (class_exists("A2_Optimized_Private_Optimizations")) {
$a2opt_priv = new A2_Optimized_Private_Optimizations();
return $a2opt_priv->get_optimizations($this->thisclass);
} else {
return array();
}
}
public function get_advanced()
{
$public_opts = $this->get_public_advanced();
$private_opts = $this->get_private_advanced();
return array_merge($public_opts, $private_opts);
}
protected function get_public_advanced()
{
$thisclass = $this->thisclass;
return array(
'gtmetrix' => array(
'slug' => 'gtmetrix',
'name' => 'GTmetrix',
'plugin' => 'GTmetrix',
'plugin_slug' => 'gtmetrix-for-wordpress',
'file' => 'gtmetrix-for-wordpress/gtmetrix-for-wordpress.php',
'configured' => false,
'partially_configured' => false,
'required_options' => array('gfw_options' => array('authorized')),
'description' => '
<p>
Plugin that actively keeps track of your WP install and sends you alerts if your site falls below certain criteria.
The GTMetrix plugin requires an account with <a href="http://gtmetrix.com/" >gtmetrix.com</a>
</p>
<p>
<b>Use this plugin only if your site is experiencing issues with slow load times.</b><br><b style="color:red">The GTMetrix plugin will slow down your site.</b>
</p>
',
'not_configured_links' => array(),
'configured_links' => array(
'Configure GTmetrix' => 'admin.php?page=gfw_settings',
'GTmetrix Tests' => 'admin.php?page=gfw_tests',
),
'partially_configured_links' => array(
'Configure GTmetrix' => 'admin.php?page=gfw_settings',
'GTmetrix Tests' => 'admin.php?page=gfw_tests',
),
'partially_configured_message' => 'Click "Configure GTmetrix" to enter your GTmetrix Account Email and GTmetrix API Key.',
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix',
'is_configured' => function (&$item) use (&$thisclass) {
$gfw_options = get_option('gfw_options');
if (is_plugin_active($item['file']) && isset($gfw_options['authorized']) && $gfw_options['authorized'] == 1) {
$item['configured'] = true;
$thisclass->set_install_status('gtmetrix', true);
} elseif (is_plugin_active($item['file'])) {
$item['partially_configured'] = true;
} else {
$thisclass->set_install_status('gtmetrix', false);
}
},
'enable' => function ($slug) use (&$thisclass) {
$item = $thisclass->get_advanced_optimizations();
$item = $item[$slug];
if (!isset($thisclass->plugin_list[$item['file']])) {
$thisclass->install_plugin($item['plugin_slug']);
}
if (!is_plugin_active($item['file'])) {
$thisclass->activate_plugin($item['file']);
}
},
'disable' => function ($slug) use (&$thisclass) {
$item = $thisclass->get_advanced_optimizations();
$item = $item[$slug];
$thisclass->deactivate_plugin($item['file']);
}
),
'P3' => array(
'slug' => 'P3',
'name' => 'P3 (Plugin Performance Profiler)',
'description' => '
<p>See which plugins are slowing down your site.
This plugin creates a performance report for your site.</p>
<p>
<b>Use this plugin only if your site is experiencing issues with slow load times.</b><br><b style="color:red">The P3 plugin will slow down your site.</b>
</p>
',
'plugin' => 'P3 Profiler',
'plugin_slug' => 'p3-profiler',
'file' => 'p3-profiler/p3-profiler.php',
'configured' => false,
'configured_links' => array(
'Test Performance' => 'tools.php?page=p3-profiler',
),
'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/debugging-wordpress-with-p3-profiler',
'is_configured' => function (&$item) use (&$thisclass) {
if (is_plugin_active($item['file'])) {
$item['configured'] = true;
$thisclass->set_install_status('P3', true);
} else {
$thisclass->set_install_status('P3', false);
}
},
'enable' => function ($slug) use (&$thisclass) {
$item = $thisclass->get_advanced_optimizations();
$item = $item[$slug];
if (!isset($thisclass->plugin_list[$item['file']])) {
$thisclass->install_plugin($item['plugin_slug']);
}
if (!is_plugin_active($item['file'])) {
$thisclass->activate_plugin($item['file']);
}
},
'disable' => function ($slug) use (&$thisclass) {
$item = $thisclass->get_advanced_optimizations();
$item = $item[$slug];
$thisclass->deactivate_plugin($item['file']);
}
),
'clef' => array(
'slug' => 'clef',
'name' => 'Two-Factor Authentication with Clef',
'description' => '<p>Secure two-factor that people love to use: strong authentication without passwords or tokens; single sign on/off; magical user experience.</p>',
'plugin' => 'Clef',
'plugin_slug' => 'wpclef',
'file' => 'wpclef/wpclef.php',
'configured' => false,
'not_configured_links' => array(),
'configured_links' => array(
'Configure Clef' => 'admin.php?page=clef'
),
'partially_configured_links' => array(
'Configure Clef' => 'admin.php?page=clef'
),
'partially_configured_message' => 'Click "Configure Clef" to complete the configuration of Clef.',
//'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/adding-two-factor-authentication-with-clef',
'is_configured' => function (&$item) use (&$thisclass) {
$clef_options = get_option('wpclef');
if (is_plugin_active($item['file']) && isset($clef_options['clef_settings_app_id']) && isset($clef_options['clef_settings_app_secret'])) {
$item['configured'] = true;
$thisclass->set_install_status('clef', true);
} elseif (is_plugin_active($item['file'])) {
$item['partially_configured'] = true;
} else {
$thisclass->set_install_status('clef', false);
}
},
'enable' => function ($slug) use (&$thisclass) {
$item = $thisclass->get_advanced_optimizations();
$item = $item[$slug];
if (!isset($thisclass->plugin_list[$item['file']])) {
$thisclass->install_plugin($item['plugin_slug']);
}
if (!is_plugin_active($item['file'])) {
$thisclass->activate_plugin($item['file']);
}
},
'disable' => function ($slug) use (&$thisclass) {
$item = $thisclass->get_advanced_optimizations();
$item = $item[$slug];
$thisclass->deactivate_plugin($item['file']);
}
),
'cloudflare' => array(
'slug' => 'cloudflare',
'name' => 'CloudFlare',
'premium'=>true,
'description' => '
<p>
CloudFlare is a free global CDN and DNS provider that can speed up and protect any site online.
</p>
<dl style="padding-left:20px">
<dt>CloudFlare CDN</dt>
<dd>Distribute your content around the world so it's closer to your visitors (speeding up your site).</dd>
<dt>CloudFlare optimizer</dt>
<dd>Web pages with ad servers and third party widgets load snappy on both mobile and computers.</dd>
<dt>CloudFlare security</dt>
<dd>Protect your website from a range of online threats from spammers to SQL injection to DDOS.</dd>
<dt>CloudFlare analytics</dt>
<dd>Get insight into all of your website's traffic including threats and search engine crawlers.</dd>
</dl>
<div class="alert alert-info">
Host with A2 Hosting to take advantage of one click CloudFlare configuration.
</div>
',
'configured' => false,
'is_configured' => function(){
return false;
},
'not_configured_links' => array('Host with A2'=>'https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized')
)
);
}
protected function get_private_advanced()
{
if (class_exists("A2_Optimized_Private_Optimizations")) {
$a2opt_priv = new A2_Optimized_Private_Optimizations();
return $a2opt_priv->get_advanced($this->thisclass);
} else {
return array();
}
}
public function get_warnings()
{
$public_opts = $this->get_public_warnings();
$private_opts = $this->get_private_warnings();
return array_merge($public_opts, $private_opts);
}
protected function get_public_warnings()
{
return array(
'Bad WP Options' => array(
'posts_per_page' => array(
'title' => 'Recent Post Limit',
'description' => 'The number of recent posts per page is set greater than five. This could be slowing down page loads.',
'type' => 'numeric',
'threshold_type' => '>',
'threshold' => 5,
'config_url' => admin_url() . 'options-reading.php'
),
'posts_per_rss' => array(
'title' => 'RSS Post Limit',
'description' => 'The number of posts from external feeds is set greater than 5. This could be slowing down page loads.',
'type' => 'numeric',
'threshold_type' => '>',
'threshold' => 5,
'config_url' => admin_url() . 'options-reading.php'
),
'show_on_front' => array(
'title' => 'Recent Posts showing on home page',
'description' => 'Speed up your home page by selecting a static page to display.',
'type' => 'text',
'threshold_type' => '=',
'threshold' => 'posts',
'config_url' => admin_url() . 'options-reading.php'
),
'permalink_structure' => array(
'title' => 'Permalink Structure',
'description' => 'To fully optimize page caching with "Disk Enhanced" mode:<br>you must set a permalink structure other than "Default".',
'type' => 'text',
'threshold_type' => '=',
'threshold' => '',
'config_url' => admin_url() . 'options-permalink.php'
)
),
'Advanced Warnings' => array(
'themes' => array(
'is_warning' => function () {
$themes = wp_get_themes();
switch (count($themes)) {
case 1:
return false;
case 2:
$theme = wp_get_theme();
if ($theme->get('Template') != '') {
return false;
}
}
return true;
},
'title' => 'Unused Themes',
'description' => 'One or more unused themes are installed. Unused themes should be deleted. For more information read the Wordpress.org Codex on <a target="_blank" href="http://codex.wordpress.org/WordPress_Housekeeping#Theme_Housekeeping">WordPress Housekeeping</a>',
'config_url' => admin_url() . 'themes.php'
),
'a2_hosting' => array(
'title' => 'Not Hosted with A2 Hosting',
'description' => 'Get faster page load times and more optimizations when you <a href="https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized" target="_blank">host with A2 Hosting</a>.',
'is_warning' => function () {
if(is_dir("/opt/a2-optimized"))
return false;
return true;
},
'config_url' => "https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized"
)
),
'Bad Plugins' => array(
'wp-super-cache',
'wp-file-cache',
'wordfence',
'wp-db-backup',
//'WP DB Manager',
//'BackupWordPress',
//'Broken Link Checker',
//'MyReviewPlugin',
//'LinkMan',
//'Google XML Sitemaps',
//'Fuzzy SEO Booster',
//'Tweet Blender',
//'Dynamic Related Posts',
//'SEO Auto Links & Related Posts',
//'Yet Another Related Posts Plugin',
//'Similar Posts',
//'Contextual Related Posts',
)
);
}
protected function get_private_warnings()
{
if (class_exists("A2_Optimized_Private_Optimizations")) {
$a2opt_priv = new A2_Optimized_Private_Optimizations();
return $a2opt_priv->get_warnings($this->thisclass);
} else {
return array();
}
}
}