A2 Optimized WP - Version 2.1.3.10

Version Description

  • Add information related to A2 Optimized to the Site Health panel.
Download this release

Release Info

Developer a2hosting
Plugin Icon 128x128 A2 Optimized WP
Version 2.1.3.10
Comparing to
See all releases

Code changes from version 2.1.3.9 to 2.1.3.10

A2_Optimized_OptionsManager.php CHANGED
@@ -23,6 +23,7 @@ if (file_exists('/opt/a2-optimized/wordpress/Optimizations.php')) {
23
  require_once '/opt/a2-optimized/wordpress/Optimizations.php';
24
  }
25
  require_once 'A2_Optimized_Optimizations.php';
 
26
 
27
  class A2_Optimized_OptionsManager {
28
  public $plugin_dir;
@@ -835,6 +836,18 @@ class A2_Optimized_OptionsManager {
835
  $this->cache_settings_save();
836
  $this->settings_page_html();
837
  }
 
 
 
 
 
 
 
 
 
 
 
 
838
  if ($_GET['a2-page'] == 'dismiss_notice') {
839
  $allowed_notices = array(
840
  'a2_login_bookmark',
@@ -1007,6 +1020,8 @@ HTML;
1007
  $settingsGroup = get_class($this) . '-settings-group';
1008
  $description = $this->get_plugin_description();
1009
 
 
 
1010
  if ($this->is_a2()) {
1011
  $feedback = <<<HTML
1012
  <div style="margin:10px 0;" class="alert alert-success">
@@ -1872,6 +1887,145 @@ HTML;
1872
  $this->write_wp_config();
1873
  }
1874
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1875
 
1876
  /**
1877
  * Knowledge Base Searchbox HMTL
23
  require_once '/opt/a2-optimized/wordpress/Optimizations.php';
24
  }
25
  require_once 'A2_Optimized_Optimizations.php';
26
+ require_once 'A2_Optimized_SiteHealth.php';
27
 
28
  class A2_Optimized_OptionsManager {
29
  public $plugin_dir;
836
  $this->cache_settings_save();
837
  $this->settings_page_html();
838
  }
839
+ if ($_GET['a2-page'] == 'site_health') {
840
+ $this->site_health_page_html();
841
+ }
842
+ if ($_GET['a2-page'] == 'site_health_save') {
843
+ $this->site_health_save();
844
+ $this->site_health_page_html();
845
+ }
846
+ if ($_GET['a2-page'] == 'site_health_remove') {
847
+ $this->site_health_remove();
848
+ $this->site_health_page_html();
849
+ }
850
+
851
  if ($_GET['a2-page'] == 'dismiss_notice') {
852
  $allowed_notices = array(
853
  'a2_login_bookmark',
1020
  $settingsGroup = get_class($this) . '-settings-group';
1021
  $description = $this->get_plugin_description();
1022
 
1023
+
1024
+
1025
  if ($this->is_a2()) {
1026
  $feedback = <<<HTML
1027
  <div style="margin:10px 0;" class="alert alert-success">
1887
  $this->write_wp_config();
1888
  }
1889
  }
1890
+
1891
+ /**
1892
+ * Site Health View Page
1893
+ *
1894
+ */
1895
+ private function site_health_page_html() {
1896
+ $image_dir = plugins_url('/assets/images', __FILE__);
1897
+ if ( ! class_exists( 'WP_Debug_Data' ) ) {
1898
+ require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
1899
+ }
1900
+
1901
+ $saved_health_items = get_option('a2opt-sitehealth-results');
1902
+
1903
+ $current_site_health = null;
1904
+
1905
+ if (isset($_REQUEST['view_report'])) {
1906
+ foreach($saved_health_items as $date => $item){
1907
+ if(md5($date) == $_REQUEST['view_report']){
1908
+ $current_site_health = $item;
1909
+ $site_health_date = $date;
1910
+ };
1911
+ };
1912
+ }
1913
+ if(!$current_site_health){
1914
+ $WP_Debug_Data = new WP_Debug_Data();
1915
+ new A2_Optimized_SiteHealth;
1916
+ $info = $WP_Debug_Data::debug_data();
1917
+ $current_site_health = $WP_Debug_Data::format( $info, 'debug' );
1918
+ $site_health_date = date('Y-m-d H:i:s');
1919
+ }
1920
+
1921
+ ?>
1922
+ <section id="a2opt-content-general">
1923
+ <div class="wrap">
1924
+ <div>
1925
+ <div>
1926
+ <div>
1927
+ <div style="float:left;clear:both">
1928
+ <img src="<?php echo $image_dir; ?>/a2optimized.png" style="margin-top:20px" />
1929
+ </div>
1930
+ <div style="float:right;">
1931
+ </div>
1932
+ </div>
1933
+ <div style="clear:both;"></div>
1934
+ </div>
1935
+ </div>
1936
+ <div class="tab-content">
1937
+ <?php if (isset($_REQUEST['a2-page']) && $_REQUEST['a2-page'] == 'site_health_save') { ?>
1938
+ <div class="notice notice-success is-dismissible"><p>Site Health Record Saved</p></div>
1939
+ <?php } ?>
1940
+ <?php if (isset($_REQUEST['a2-page']) && $_REQUEST['a2-page'] == 'site_health_remove') { ?>
1941
+ <div class="notice notice-info is-dismissible"><p>Site Health Record Removed</p></div>
1942
+ <?php } ?>
1943
+ <?php if (isset($_REQUEST['view_report']) && isset($_REQUEST['a2-page'])) { ?>
1944
+ <h3>Site Health Results from <?php echo $site_health_date; ?></h3>
1945
+ <p><a href="admin.php?a2-page=site_health&page=A2_Optimized_Plugin_admin" class="button">Back</a></p>
1946
+ <p><a href="admin.php?a2-page=site_health_remove&page=A2_Optimized_Plugin_admin&remove_report=<?php echo md5($site_health_date); ?>" class="button">Remove Report</a></p>
1947
+ <?php } else { ?>
1948
+ <h3>Site Health Results</h3>
1949
+ <p><a href="admin.php?a2-page=site_health_save&page=A2_Optimized_Plugin_admin" class="button">Save current results</a> <a href="site-health.php?tab=debug" class="button">Back to Site Health</a></p>
1950
+ <?php }; ?>
1951
+ <?php if(count($saved_health_items) > 0){ ?>
1952
+ <p>
1953
+ <strong>Saved reports</strong>
1954
+ <ul>
1955
+ <?php foreach($saved_health_items as $date => $item){ ?>
1956
+ <li><a href="admin.php?a2-page=site_health&page=A2_Optimized_Plugin_admin&view_report=<?php echo md5($date); ?>"><?php echo $date; ?></a></li>
1957
+ <?php }; ?>
1958
+ </ul>
1959
+ </p>
1960
+ <?php }; ?>
1961
+ <div>
1962
+ <pre>
1963
+ <?php echo $current_site_health; ?>
1964
+ </pre>
1965
+ </div>
1966
+ </div>
1967
+
1968
+ </div>
1969
+
1970
+ <div style="clear:both;padding:10px;"></div>
1971
+ </section>
1972
+ <?php
1973
+ }
1974
+
1975
+ /**
1976
+ * Save Site Health Results
1977
+ *
1978
+ */
1979
+ private function site_health_save() {
1980
+ if (!current_user_can('manage_options')) {
1981
+ die('Cheating eh?');
1982
+ }
1983
+
1984
+ if ( ! class_exists( 'WP_Debug_Data' ) ) {
1985
+ require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
1986
+ }
1987
+
1988
+ $existing_health = get_option('a2opt-sitehealth-results');
1989
+
1990
+ if(!$existing_health){
1991
+ $existing_health = [];
1992
+ }
1993
+
1994
+ $WP_Debug_Data = new WP_Debug_Data();
1995
+ new A2_Optimized_SiteHealth;
1996
+ $info = $WP_Debug_Data::debug_data();
1997
+ $current_site_health = $WP_Debug_Data::format( $info, 'debug' );
1998
+
1999
+ $existing_health[date('Y-m-d H:i:s')] = $current_site_health;
2000
+
2001
+ update_option('a2opt-sitehealth-results', $existing_health);
2002
+ }
2003
+
2004
+ /**
2005
+ * Remove Site Health Results
2006
+ *
2007
+ */
2008
+ private function site_health_remove() {
2009
+ if (!current_user_can('manage_options')) {
2010
+ die('Cheating eh?');
2011
+ }
2012
+
2013
+ $existing_health = get_option('a2opt-sitehealth-results');
2014
+
2015
+ if(is_array($existing_health)){
2016
+ $index_to_remove = 0;
2017
+ foreach($existing_health as $date => $item){
2018
+ if(md5($date) == $_REQUEST['remove_report']){
2019
+ $index_to_remove = $date;
2020
+ }
2021
+ }
2022
+ if($index_to_remove !== 0){
2023
+ unset($existing_health[$index_to_remove]);
2024
+ update_option('a2opt-sitehealth-results', $existing_health);
2025
+ }
2026
+ }
2027
+
2028
+ }
2029
 
2030
  /**
2031
  * Knowledge Base Searchbox HMTL
A2_Optimized_Plugin.php CHANGED
@@ -308,6 +308,7 @@ HTML;
308
  add_filter("plugin_action_links_{$a2_plugin_basename}", array(&$this, 'plugin_settings_link'));
309
  register_setting( 'a2opt-cache', 'a2opt-cache', array( __CLASS__, 'validate_settings' ) );
310
  register_setting( 'a2opt-cache', 'a2_optimized_memcached_server', array( __CLASS__, 'validate_memcached' ));
 
311
  }
312
 
313
  if (get_option('A2_Optimized_Plugin_recaptcha', 0) == 1 && !is_admin()) {
308
  add_filter("plugin_action_links_{$a2_plugin_basename}", array(&$this, 'plugin_settings_link'));
309
  register_setting( 'a2opt-cache', 'a2opt-cache', array( __CLASS__, 'validate_settings' ) );
310
  register_setting( 'a2opt-cache', 'a2_optimized_memcached_server', array( __CLASS__, 'validate_memcached' ));
311
+ new A2_Optimized_SiteHealth;
312
  }
313
 
314
  if (get_option('A2_Optimized_Plugin_recaptcha', 0) == 1 && !is_admin()) {
A2_Optimized_SiteHealth.php ADDED
@@ -0,0 +1,753 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Site Health A2 Optimized Info.
4
+ */
5
+ class A2_Optimized_SiteHealth {
6
+ public function __construct() {
7
+ if ( ! $this->allow_load() ) {
8
+ return;
9
+ }
10
+ $this->hooks();
11
+ }
12
+
13
+ /**
14
+ * Indicate if Site Health is allowed to load.
15
+ *
16
+ * @return bool
17
+ */
18
+ private function allow_load() {
19
+ global $wp_version;
20
+
21
+ return version_compare( $wp_version, '5.2', '>=' );
22
+ }
23
+
24
+ /**
25
+ * Integration hooks.
26
+ */
27
+ protected function hooks() {
28
+ add_filter( 'debug_information', array( $this, 'add_debug_section' ) );
29
+ add_filter( 'site_status_tests', array( $this, 'add_site_status_items' ) );
30
+
31
+ add_action( 'site_health_tab_content', array( $this, 'add_button_to_site_health_info_tab' ) );
32
+ }
33
+
34
+
35
+ /**
36
+ * Add "Save" button to Debug tab
37
+ *
38
+ * @param array $tab Current tab being displayed within Site Health
39
+ *
40
+ * @return array Array with added A2 Optimized items.
41
+ */
42
+ public function add_button_to_site_health_info_tab( $tab ) {
43
+ // Do nothing if this is not the "debug" tab.
44
+ if ( 'debug' !== $tab ) {
45
+ return;
46
+ }
47
+ ?>
48
+ <div class='health-check-body health-check-debug-tab hide-if-no-js'>
49
+ <a href='admin.php?a2-page=site_health&page=A2_Optimized_Plugin_admin'><button class='button'>Save Report</button></a>
50
+ </div>
51
+ <?php
52
+ }
53
+
54
+ /**
55
+ * Add A2 Optimized items to main Status tab.
56
+ *
57
+ * @param array $tests Array of existing site health tests.
58
+ *
59
+ * @return array Array with added A2 Optimized items.
60
+ */
61
+ public function add_site_status_items($tests) {
62
+ if (php_sapi_name() == 'litespeed') {
63
+ // Litespeed server
64
+ $tests['direct']['a2_optimized_turbocache'] = array(
65
+ 'label' => 'TurboCache',
66
+ 'test' => array( $this, 'a2opt_turbocache_test' ),
67
+ );
68
+ }
69
+
70
+ $tests['direct']['a2_optimized_revisions'] = array(
71
+ 'label' => 'Large amount of revisions',
72
+ 'test' => array( $this, 'a2opt_revision_count_test' ),
73
+ );
74
+
75
+ $tests['direct']['a2_optimized_large_images'] = array(
76
+ 'label' => 'Large images in Media Library',
77
+ 'test' => array( $this, 'a2opt_large_image_test' ),
78
+ );
79
+
80
+ $tests['direct']['a2_optimized_blocking_search'] = array(
81
+ 'label' => 'Blocking search engines',
82
+ 'test' => array( $this, 'a2opt_block_search_test' ),
83
+ );
84
+
85
+ $tests['direct']['a2_optimized_caching'] = array(
86
+ 'label' => 'Caching enabled',
87
+ 'test' => array( $this, 'a2opt_cache_test' ),
88
+ );
89
+
90
+ $tests['direct']['a2_optimized_phpopcache'] = array(
91
+ 'label' => 'PHP OP Caching enabled',
92
+ 'test' => array( $this, 'a2opt_phpopcache_test' ),
93
+ );
94
+
95
+ $tests['direct']['a2_optimized_other_cache'] = array(
96
+ 'label' => 'Duplicate Caching plugins enabled',
97
+ 'test' => array( $this, 'a2opt_other_cache_test' ),
98
+ );
99
+
100
+ $tests['direct']['a2_optimized_php_memory'] = array(
101
+ 'label' => 'PHP has good memory limits',
102
+ 'test' => array( $this, 'a2opt_php_memory_test' ),
103
+ );
104
+
105
+ $tests['direct']['a2_optimized_object_cache'] = array(
106
+ 'label' => 'Using an object cache',
107
+ 'test' => array( $this, 'a2opt_object_cache_test' ),
108
+ );
109
+
110
+ if (is_plugin_active('woocommerce/woocommerce.php')) {
111
+ $tests['direct']['a2_optimized_cart_fragments'] = array(
112
+ 'label' => 'Dequeue WooCommerce Cart Fragments AJAX calls',
113
+ 'test' => array( $this, 'a2opt_cart_fragments_test' ),
114
+ );
115
+ }
116
+
117
+ $tests['direct']['a2_optimized_gzip_compression'] = array(
118
+ 'label' => 'Gzip Compression Enabled',
119
+ 'test' => array( $this, 'a2opt_gzip_test' ),
120
+ );
121
+
122
+ $tests['direct']['a2_optimized_block_xmlrpc'] = array(
123
+ 'label' => 'Block Unauthorized XML-RPC Requests',
124
+ 'test' => array( $this, 'a2opt_xml_rpc_test' ),
125
+ );
126
+
127
+ $tests['direct']['a2_optimized_disable_fileedit'] = array(
128
+ 'label' => 'Lock Editing of Plugins and Themes from the WP Admin',
129
+ 'test' => array( $this, 'a2opt_file_edit_test' ),
130
+ );
131
+
132
+ return $tests;
133
+ }
134
+
135
+ /**
136
+ * Check if TurboCache is enabled. This is a litespeed server
137
+ *
138
+ * @return array Array with added A2 Optimized items.
139
+ */
140
+ public function a2opt_turbocache_test() {
141
+ $result = array(
142
+ 'label' => __( 'TurboCache is enabled' ),
143
+ 'status' => 'good', // Default "passing" section
144
+ 'badge' => array(
145
+ 'label' => __( 'Performance' ),
146
+ 'color' => 'orange',
147
+ ),
148
+ 'description' => sprintf(
149
+ '<p>%s</p>',
150
+ __( 'Caching can help load your site more quickly for visitors.' )
151
+ ),
152
+ 'actions' => '',
153
+ 'test' => 'caching_plugin',
154
+ );
155
+
156
+ if (!is_plugin_active('litespeed-cache/litespeed-cache.php') || !get_option('litespeed.conf.cache')) {
157
+ $result['status'] = 'critical'; // "Critical" section
158
+ $result['label'] = __( 'TurboCache is available but not enabled' );
159
+ $result['description'] = sprintf(
160
+ '<p>%s</p>',
161
+ __( 'TurboCache is not currently enabled on your site. Caching can help load your site more quickly for visitors.' )
162
+ );
163
+ $result['actions'] .= sprintf(
164
+ '<p><a href="%s">%s</a></p>',
165
+ esc_url( admin_url( 'admin.php?page=litespeed-cache#cache' ) ),
166
+ __( 'Enable Caching' )
167
+ );
168
+ }
169
+
170
+ return $result;
171
+ }
172
+
173
+ /**
174
+ * Check if Revision count is too large
175
+ *
176
+ * @return array Array with added A2 Optimized items.
177
+ */
178
+ public function a2opt_revision_count_test() {
179
+ $result = array(
180
+ 'label' => __( 'Reasonable number of post revisions' ),
181
+ 'status' => 'good', // Default "passing" section
182
+ 'badge' => array(
183
+ 'label' => __( 'Performance' ),
184
+ 'color' => 'orange',
185
+ ),
186
+ 'description' => sprintf(
187
+ '<p>%s</p>',
188
+ __( 'Caching can help load your site more quickly for visitors.' )
189
+ ),
190
+ 'actions' => '',
191
+ 'test' => 'revision_count',
192
+ );
193
+
194
+ $args = array(
195
+ 'numberposts' => -1,
196
+ 'post_type' => 'revision'
197
+ );
198
+
199
+ $post_revisions = get_posts( $args );
200
+
201
+ if (count($post_revisions) > 1000) {
202
+ $result['status'] = 'recommended';
203
+ $result['label'] = __( 'Large number of post revisions in the WordPress database' );
204
+ $result['description'] = sprintf(
205
+ '<p>%s</p>',
206
+ __( "WordPress revisions can present a serious problem if you don't manage them properly. Essentially, the more pages and posts you add to your website, the more revisions it'll generate." )
207
+ );
208
+ }
209
+
210
+ return $result;
211
+ }
212
+
213
+ /**
214
+ * Check if large images are in the media library
215
+ *
216
+ * @return array Array with added A2 Optimized items.
217
+ */
218
+ public function a2opt_large_image_test() {
219
+ $result = array(
220
+ 'label' => __( 'Media library images are a reasonable size' ),
221
+ 'status' => 'good', // Default "passing" section
222
+ 'badge' => array(
223
+ 'label' => __( 'Performance' ),
224
+ 'color' => 'orange',
225
+ ),
226
+ 'description' => sprintf(
227
+ '<p>%s</p>',
228
+ __( 'Large images can lead to poor site performance' )
229
+ ),
230
+ 'actions' => '',
231
+ 'test' => 'large_images',
232
+ );
233
+
234
+ $large_image_count = 0;
235
+
236
+ $query_images_args = array(
237
+ 'post_type' => 'attachment',
238
+ 'post_mime_type' => 'image',
239
+ 'post_status' => 'inherit',
240
+ 'posts_per_page' => -1,
241
+ );
242
+
243
+ $query_images = new WP_Query( $query_images_args );
244
+
245
+ foreach ( $query_images->posts as $image ) {
246
+ $attachment_meta = wp_prepare_attachment_for_js($image->ID);
247
+
248
+ if ($attachment_meta['filesizeInBytes'] > 1000000) {
249
+ // Image is more than 1mb
250
+ $large_image_count++;
251
+ }
252
+ }
253
+
254
+ if ($large_image_count > 3) {
255
+ $result['status'] = 'recommended';
256
+ $result['label'] = ( $large_image_count . ' large images found in media library' );
257
+ $result['description'] = sprintf(
258
+ '<p>%s</p>',
259
+ __( 'Unoptimized images may slow down rendering of your site.' )
260
+ );
261
+ }
262
+
263
+ return $result;
264
+ }
265
+
266
+ /**
267
+ * Check if discourage search engines is enabled
268
+ *
269
+ * @return array Array with added A2 Optimized items.
270
+ */
271
+ public function a2opt_block_search_test() {
272
+ $result = array(
273
+ 'label' => __( 'Search engines are allowed' ),
274
+ 'status' => 'good', // Default "passing" section
275
+ 'badge' => array(
276
+ 'label' => __( 'Performance' ),
277
+ 'color' => 'orange',
278
+ ),
279
+ 'description' => sprintf(
280
+ '<p>%s</p>',
281
+ __( 'Your site is visable to search engines' )
282
+ ),
283
+ 'actions' => '',
284
+ 'test' => 'blocking_search',
285
+ );
286
+
287
+ if (get_option('blog_public') == 0) {
288
+ $result['status'] = 'critical';
289
+ $result['label'] = ( 'Search engine traffic is current blocked' );
290
+ $result['description'] = sprintf(
291
+ '<p>%s</p>',
292
+ __('Your site is currently disallowing traffic from search engines. This could lead to your site being de-indexed.')
293
+ );
294
+ }
295
+
296
+ return $result;
297
+ }
298
+
299
+ /**
300
+ * Check if caching is enabled
301
+ *
302
+ * @return array Array with added A2 Optimized items.
303
+ */
304
+ public function a2opt_cache_test() {
305
+ $result = array(
306
+ 'label' => __( 'Site Caching is enabled' ),
307
+ 'status' => 'good', // Default "passing" section
308
+ 'badge' => array(
309
+ 'label' => __( 'Performance' ),
310
+ 'color' => 'orange',
311
+ ),
312
+ 'description' => sprintf(
313
+ '<p>%s</p>',
314
+ __( 'Your site is cached and fast!' )
315
+ ),
316
+ 'actions' => '',
317
+ 'test' => 'caching_enabled',
318
+ );
319
+
320
+ if (!is_plugin_active('litespeed-cache/litespeed-cache.php') && get_option('a2_cache_enabled') != 1) {
321
+ $result['status'] = 'critical';
322
+ $result['label'] = ( 'Caching is disabled' );
323
+ $result['description'] = sprintf(
324
+ '<p>%s</p>',
325
+ __('Your site currently has caching disabled. This will lead to much slower page load times.')
326
+ );
327
+ $result['actions'] .= sprintf(
328
+ '<p><a href="%s">%s</a></p>',
329
+ esc_url( admin_url( 'admin.php?page=A2_Optimized_Plugin_admin' ) ),
330
+ __( 'Enable Caching' )
331
+ );
332
+ }
333
+
334
+ return $result;
335
+ }
336
+
337
+ /**
338
+ * Check if PHP OpCache is enabled
339
+ *
340
+ * @return array Array with added A2 Optimized items.
341
+ */
342
+ public function a2opt_phpopcache_test() {
343
+ $result = array(
344
+ 'label' => __( 'Site Caching is enabled' ),
345
+ 'status' => 'good', // Default "passing" section
346
+ 'badge' => array(
347
+ 'label' => __( 'Performance' ),
348
+ 'color' => 'orange',
349
+ ),
350
+ 'description' => sprintf(
351
+ '<p>%s</p>',
352
+ __( 'Your site is cached and fast!' )
353
+ ),
354
+ 'actions' => '',
355
+ 'test' => 'caching_enabled',
356
+ );
357
+
358
+ $opcache_status = opcache_get_status();
359
+
360
+ if (!is_array($opcache_status) || !$opcache_status['opcache_enabled']) {
361
+ $result['status'] = 'recommended';
362
+ $result['label'] = ( 'PHP OpCache is not available' );
363
+ $result['description'] = sprintf(
364
+ '<p>%s</p>',
365
+ __('Your PHP currently does not support OpCaching. This could lead to much slower site performance.')
366
+ );
367
+ }
368
+
369
+ return $result;
370
+ }
371
+
372
+ /**
373
+ * Check if other caching plugins are enabled
374
+ *
375
+ * @return array Array with added A2 Optimized items.
376
+ */
377
+ public function a2opt_other_cache_test() {
378
+ $result = array(
379
+ 'label' => __( 'No conflicting cache plugins detected' ),
380
+ 'status' => 'good', // Default "passing" section
381
+ 'badge' => array(
382
+ 'label' => __( 'Performance' ),
383
+ 'color' => 'orange',
384
+ ),
385
+ 'description' => sprintf(
386
+ '<p>%s</p>',
387
+ __( 'Your site is cached and fast!' )
388
+ ),
389
+ 'actions' => '',
390
+ 'test' => 'caching_enabled',
391
+ );
392
+
393
+ $active_plugins = get_option('active_plugins');
394
+
395
+ $incompatible_plugins = array(
396
+ 'wp-super-cache',
397
+ 'wp-fastest-cache',
398
+ 'wp-file-cache',
399
+ 'w3-total-cache',
400
+ 'sg-cachepress',
401
+ 'cache-enabler',
402
+ 'comet-cache',
403
+ 'wp-rocket',
404
+ 'surge'
405
+ );
406
+
407
+ $found_plugin = false;
408
+
409
+ foreach ($active_plugins as $active_plugin) {
410
+ $plugin_folder = explode('/', $active_plugin);
411
+ if (in_array($plugin_folder[0], $incompatible_plugins)) {
412
+ $found_plugin = true;
413
+ }
414
+ }
415
+
416
+ if ($found_plugin) {
417
+ $result['status'] = 'critical';
418
+ $result['label'] = ( 'Conflicting cache plugin detected' );
419
+ $result['description'] = sprintf(
420
+ '<p>%s</p>',
421
+ __('You have multiple caching plugins enabled. Please disable any that are not A2 Optimized or LiteSpeed Cache')
422
+ );
423
+ $result['actions'] .= sprintf(
424
+ '<p><a href="%s">%s</a></p>',
425
+ esc_url( admin_url( 'plugins.php' ) ),
426
+ __( 'Disable plugins' )
427
+ );
428
+ }
429
+
430
+ return $result;
431
+ }
432
+
433
+ /**
434
+ * Check PHP Memory limits
435
+ *
436
+ * @return array Array with added A2 Optimized items.
437
+ */
438
+ public function a2opt_php_memory_test() {
439
+ $result = array(
440
+ 'label' => __( 'PHP has good memory limits' ),
441
+ 'status' => 'good', // Default "passing" section
442
+ 'badge' => array(
443
+ 'label' => __( 'Performance' ),
444
+ 'color' => 'orange',
445
+ ),
446
+ 'description' => sprintf(
447
+ '<p>%s</p>',
448
+ __( 'PHP Memory is good' )
449
+ ),
450
+ 'actions' => '',
451
+ 'test' => 'php_memory',
452
+ );
453
+
454
+ if (ini_get('memory_limit') < 134217727) { // 128mb
455
+ $result['status'] = 'recommended';
456
+ $result['label'] = ( 'PHP Memory should be increased' );
457
+ $result['description'] = sprintf(
458
+ '<p>%s</p>',
459
+ __('You have less than 128mb of memory avilable to PHP. We recommend raising this to at least 128mb for best performance.')
460
+ );
461
+ }
462
+
463
+ return $result;
464
+ }
465
+
466
+ /**
467
+ * Check if using an object cache
468
+ *
469
+ * @return array Array with added A2 Optimized items.
470
+ */
471
+ public function a2opt_object_cache_test() {
472
+ $result = array(
473
+ 'label' => __( 'Using an object cache' ),
474
+ 'status' => 'good', // Default "passing" section
475
+ 'badge' => array(
476
+ 'label' => __( 'Performance' ),
477
+ 'color' => 'orange',
478
+ ),
479
+ 'description' => sprintf(
480
+ '<p>%s</p>',
481
+ __( 'Store frequently used database queries and WordPress objects in Memcached.' )
482
+ ),
483
+ 'actions' => '',
484
+ 'test' => 'object_cache',
485
+ );
486
+
487
+ if (!wp_using_ext_object_cache()) { // 128mb
488
+ $result['status'] = 'recommended';
489
+ $result['label'] = ( 'Start using an object cache' );
490
+ }
491
+
492
+ return $result;
493
+ }
494
+
495
+ /**
496
+ * Check number of unused plugins
497
+ *
498
+ * @return array Array with added A2 Optimized items.
499
+ */
500
+ public function a2opt_plugin_count_test() {
501
+ $result = array(
502
+ 'label' => __( 'Large number of unused plugins' ),
503
+ 'status' => 'good', // Default "passing" section
504
+ 'badge' => array(
505
+ 'label' => __( 'Performance' ),
506
+ 'color' => 'orange',
507
+ ),
508
+ 'description' => sprintf(
509
+ '<p>%s</p>',
510
+ __( 'Unused plugins could present a security issue.' )
511
+ ),
512
+ 'actions' => '',
513
+ 'test' => 'plugin_count',
514
+ );
515
+
516
+ $plugins = get_plugins();
517
+ $plugin_count = 0;
518
+
519
+ foreach ($plugins as $slug => $plugin) {
520
+ if (is_plugin_inactive($slug)) {
521
+ $plugin_count++;
522
+ }
523
+ }
524
+
525
+ if ($plugin_count > 4) {
526
+ $result['status'] = 'recommended';
527
+ $result['label'] = 'Remove unused plugins';
528
+ }
529
+
530
+ return $result;
531
+ }
532
+
533
+ /**
534
+ * Check number of unused themes
535
+ *
536
+ * @return array Array with added A2 Optimized items.
537
+ */
538
+ public function a2opt_theme_count_test() {
539
+ $result = array(
540
+ 'label' => __( 'Large number of unused themes' ),
541
+ 'status' => 'good', // Default "passing" section
542
+ 'badge' => array(
543
+ 'label' => __( 'Performance' ),
544
+ 'color' => 'orange',
545
+ ),
546
+ 'description' => sprintf(
547
+ '<p>%s</p>',
548
+ __( 'Unused themes could present a security issue.' )
549
+ ),
550
+ 'actions' => '',
551
+ 'test' => 'theme_count',
552
+ );
553
+
554
+ $themes = wp_get_themes();
555
+ $theme_count = 0;
556
+
557
+ foreach ($themes as $theme_name => $theme) {
558
+ if (substr($theme_name, 0, 6) != 'twenty') {
559
+ // We don't want default themes to count towards our warning total
560
+ $theme_count++;
561
+ }
562
+ }
563
+
564
+ if ($theme_count > 1) {
565
+ $result['status'] = 'recommended';
566
+ $result['label'] = 'Remove unused themes';
567
+ }
568
+
569
+ return $result;
570
+ }
571
+
572
+ /**
573
+ * Check if Cart Fragment AJAX calls are dequeued
574
+ *
575
+ * @return array Array with added A2 Optimized items.
576
+ */
577
+ public function a2opt_cart_fragments_test() {
578
+ $result = array(
579
+ 'label' => __( 'Dequeue WooCommerce Cart Fragments AJAX calls' ),
580
+ 'status' => 'good', // Default "passing" section
581
+ 'badge' => array(
582
+ 'label' => __( 'Performance' ),
583
+ 'color' => 'orange',
584
+ ),
585
+ 'description' => sprintf(
586
+ '<p>%s</p>',
587
+ __( 'Disable WooCommerce Cart Fragments on your homepage.' )
588
+ ),
589
+ 'actions' => '',
590
+ 'test' => 'cart_fragments',
591
+ );
592
+
593
+ if (!get_option('a2_wc_cart_fragments')) {
594
+ $result['status'] = 'recommended';
595
+ }
596
+
597
+ return $result;
598
+ }
599
+
600
+ /**
601
+ * Check if GZIP compression is enabled
602
+ *
603
+ * @return array Array with added A2 Optimized items.
604
+ */
605
+ public function a2opt_gzip_test() {
606
+ $result = array(
607
+ 'label' => __( 'Dequeue WooCommerce Cart Fragments AJAX calls' ),
608
+ 'status' => 'good', // Default "passing" section
609
+ 'badge' => array(
610
+ 'label' => __( 'Performance' ),
611
+ 'color' => 'orange',
612
+ ),
613
+ 'description' => sprintf(
614
+ '<p>%s</p>',
615
+ __( 'Disable WooCommerce Cart Fragments on your homepage.' )
616
+ ),
617
+ 'actions' => '',
618
+ 'test' => 'cart_fragments',
619
+ );
620
+
621
+ if (!A2_Optimized_Cache_Engine::$settings['compress_cache'] && !is_plugin_active('litespeed-cache/litespeed-cache.php')) {
622
+ $result['status'] = 'recommended';
623
+ }
624
+
625
+ return $result;
626
+ }
627
+
628
+ /**
629
+ * Check if XML-RPC requests are blocked
630
+ *
631
+ * @return array Array with added A2 Optimized items.
632
+ */
633
+ public function a2opt_xml_rpc_test() {
634
+ $result = array(
635
+ 'label' => __( 'Block Unauthorized XML-RPC Requests' ),
636
+ 'status' => 'good', // Default "passing" section
637
+ 'badge' => array(
638
+ 'label' => __( 'Performance' ),
639
+ 'color' => 'orange',
640
+ ),
641
+ 'description' => sprintf(
642
+ '<p>%s</p>',
643
+ __( 'Completely Disable XML-RPC services' )
644
+ ),
645
+ 'actions' => '',
646
+ 'test' => 'block_xmlrpc',
647
+ );
648
+
649
+ if (!get_option('a2_block_xmlrpc')) {
650
+ $result['status'] = 'recommended';
651
+ }
652
+
653
+ return $result;
654
+ }
655
+
656
+ /**
657
+ * Check if file editing is disabled
658
+ *
659
+ * @return array Array with added A2 Optimized items.
660
+ */
661
+ public function a2opt_file_edit_test() {
662
+ $result = array(
663
+ 'label' => __( 'Lock Editing of Plugins and Themes from the WP Admin' ),
664
+ 'status' => 'good', // Default "passing" section
665
+ 'badge' => array(
666
+ 'label' => __( 'Performance' ),
667
+ 'color' => 'orange',
668
+ ),
669
+ 'description' => sprintf(
670
+ '<p>%s</p>',
671
+ __( 'Prevents exploits that use the built in editing capabilities of the WP Admin' )
672
+ ),
673
+ 'actions' => '',
674
+ 'test' => 'file_edit',
675
+ );
676
+
677
+ if (!get_option('a2_optimized_lockdown')) {
678
+ $result['status'] = 'recommended';
679
+ }
680
+
681
+ return $result;
682
+ }
683
+
684
+ /**
685
+ * Add A2 Optimized section to Info tab.
686
+ *
687
+ * @param array $debug_info Array of all information.
688
+ *
689
+ * @return array Array with added A2 Optimized info section.
690
+ */
691
+ public function add_debug_section($debug_info) {
692
+ $a2_optimized = array(
693
+ 'label' => 'A2Optimized',
694
+ 'fields' => array(
695
+ 'version' => array(
696
+ 'label' => 'Version',
697
+ 'value' => A2OPT_FULL_VERSION,
698
+ ),
699
+ ),
700
+ );
701
+
702
+ /* MySQL Version */
703
+ global $wpdb;
704
+ $mysqlVersion = $wpdb->db_version();
705
+
706
+ $a2_optimized['fields']['mysql_version'] = array(
707
+ 'label' => 'MySQL Version',
708
+ 'value' => $mysqlVersion
709
+ );
710
+
711
+ /* PHP Version */
712
+ $a2_optimized['fields']['php_version'] = array(
713
+ 'label' => 'PHP Version',
714
+ 'value' => phpversion()
715
+ );
716
+
717
+ /* CPU Info */
718
+ $cpu_info = exec('cat /proc/cpuinfo | grep "model name\\|processor"');
719
+ $cpu_info = str_replace('model name', '', $cpu_info);
720
+ $cpu_info = str_replace('processor', '', $cpu_info);
721
+ $cpu_info = str_replace(':', '', $cpu_info);
722
+ $a2_optimized['fields']['cpu_info'] = array(
723
+ 'label' => 'CPU Info',
724
+ 'value' => $cpu_info
725
+ );
726
+
727
+ /* Webserver info */
728
+ $a2_optimized['fields']['http_server'] = array(
729
+ 'label' => 'Web Server',
730
+ 'value' => php_sapi_name()
731
+ );
732
+
733
+ /* PHP Memory Limit */
734
+ $a2_optimized['fields']['php_memory'] = array(
735
+ 'label' => 'PHP Memory Limit',
736
+ 'value' => ini_get('memory_limit')
737
+ );
738
+
739
+ /* Using Object Cache */
740
+ $object_cache = 'No';
741
+ if (wp_using_ext_object_cache()) {
742
+ $object_cache = 'Yes';
743
+ }
744
+ $a2_optimized['fields']['object_cache'] = array(
745
+ 'label' => 'Object Caching Enabled',
746
+ 'value' => $object_cache
747
+ );
748
+
749
+ $debug_info['a2-optimized-wp'] = $a2_optimized;
750
+
751
+ return $debug_info;
752
+ }
753
+ }
a2-optimized.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: A2 Optimized WP
4
  Plugin URI: https://wordpress.org/plugins/a2-optimized/
5
- Version: 2.1.3.9
6
  Author: A2 Hosting
7
  Author URI: https://www.a2hosting.com/
8
  Description: A2 Optimized - WordPress Optimization Plugin
@@ -25,9 +25,11 @@ require_once 'A2_Optimized_Server_Info.php';
25
  require_once 'A2_Optimized_Cache.php';
26
  require_once 'A2_Optimized_CacheEngine.php';
27
  require_once 'A2_Optimized_CacheDisk.php';
 
28
 
29
  //constants
30
  define( 'A2OPT_VERSION', '2.1' );
 
31
  define( 'A2OPT_MIN_PHP', '5.6' );
32
  define( 'A2OPT_MIN_WP', '5.1' );
33
  define( 'A2OPT_FILE', __FILE__ );
2
  /*
3
  Plugin Name: A2 Optimized WP
4
  Plugin URI: https://wordpress.org/plugins/a2-optimized/
5
+ Version: 2.1.3.10
6
  Author: A2 Hosting
7
  Author URI: https://www.a2hosting.com/
8
  Description: A2 Optimized - WordPress Optimization Plugin
25
  require_once 'A2_Optimized_Cache.php';
26
  require_once 'A2_Optimized_CacheEngine.php';
27
  require_once 'A2_Optimized_CacheDisk.php';
28
+ require_once 'A2_Optimized_SiteHealth.php';
29
 
30
  //constants
31
  define( 'A2OPT_VERSION', '2.1' );
32
+ define( 'A2OPT_FULL_VERSION', '2.1.3.10' );
33
  define( 'A2OPT_MIN_PHP', '5.6' );
34
  define( 'A2OPT_MIN_WP', '5.1' );
35
  define( 'A2OPT_FILE', __FILE__ );
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === A2 Optimized WP ===
2
  Contributors: A2BCool, a2hosting, dmatteson, sputala
3
- Tags: Speed, Optimize, Secure, Fast, W3 Total Cache, W3TC, Hosting
4
  Requires at least: 5.1
5
  Tested up to: 5.9
6
- Stable tag: 2.1.3.9
7
  Requires PHP: 5.6
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -123,6 +123,9 @@ Yes. A2 Optimized works on any host that supports WordPress; however, A2 Hostin
123
 
124
  == Changelog ==
125
 
 
 
 
126
  = 2.1.3.3 =
127
  * Patches a cross-site-scripting vulnerablity. This is a recommended upgrade.
128
 
1
  === A2 Optimized WP ===
2
  Contributors: A2BCool, a2hosting, dmatteson, sputala
3
+ Tags: Speed, Optimize, Secure, Fast, LiteSpeed, LSCache, A2, Hosting
4
  Requires at least: 5.1
5
  Tested up to: 5.9
6
+ Stable tag: 2.1.3.10
7
  Requires PHP: 5.6
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
123
 
124
  == Changelog ==
125
 
126
+ = 2.1.3.10 =
127
+ * Add information related to A2 Optimized to the Site Health panel.
128
+
129
  = 2.1.3.3 =
130
  * Patches a cross-site-scripting vulnerablity. This is a recommended upgrade.
131