A2 Optimized WP - Version 2.1.4.6

Version Description

  • Better compatibility with LiteSpeed Cache
Download this release

Release Info

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

Code changes from version 2.1.4.5.3 to 2.1.4.6

Files changed (3) hide show
  1. A2_Optimized_Plugin.php +28 -9
  2. a2-optimized.php +107 -102
  3. readme.txt +4 -1
A2_Optimized_Plugin.php CHANGED
@@ -14,8 +14,8 @@ if (! defined('WPINC')) {
14
  include_once('A2_Optimized_OptionsManager.php');
15
 
16
  class A2_Optimized_Plugin extends A2_Optimized_OptionsManager {
17
- const optionInstalled = '_installed';
18
- const optionVersion = '_version';
19
  private $config_pages = [
20
  'w3tc_dashboard',
21
  'w3tc_general',
@@ -32,7 +32,16 @@ class A2_Optimized_Plugin extends A2_Optimized_OptionsManager {
32
  'w3tc_extensions',
33
  'w3tc_install',
34
  'w3tc_about',
35
- 'w3tc_faq'
 
 
 
 
 
 
 
 
 
36
  ];
37
 
38
  //list of plugins that may conflict, displays a notice on installation of these plugins
@@ -309,15 +318,16 @@ HTML;
309
  add_action('wp_dashboard_setup', [&$this, 'dashboard_widget']);
310
  $a2_plugin_basename = plugin_basename($GLOBALS['A2_Plugin_Dir'] . '/a2-optimized.php');
311
  add_filter("plugin_action_links_{$a2_plugin_basename}", [&$this, 'plugin_settings_link']);
312
- register_setting( 'a2opt-cache', 'a2opt-cache', [ 'A2_Optimized_Cache', 'validate_settings' ] );
313
- register_setting( 'a2opt-cache', 'a2_optimized_objectcache_type');
314
- register_setting( 'a2opt-cache', 'a2_optimized_memcached_server', ['A2_Optimized_Cache', 'validate_object_cache' ]);
315
- register_setting( 'a2opt-cache', 'a2_optimized_redis_server', ['A2_Optimized_Cache', 'validate_object_cache' ]);
316
- new A2_Optimized_SiteHealth;
317
  register_setting('a2opt-cache', 'a2_db_optimizations', ['A2_Optimized_DBOptimizations', 'validate_db_optimization_settings']);
 
318
  }
319
 
320
- new A2_Optimized_DBOptimizations;
321
 
322
  if (get_option('A2_Optimized_Plugin_recaptcha', 0) == 1 && !is_admin()) {
323
  add_action('woocommerce_login_form', [&$this, 'login_captcha']);
@@ -332,6 +342,15 @@ HTML;
332
  }
333
  }
334
 
 
 
 
 
 
 
 
 
 
335
  public function plugin_settings_link($links) {
336
  $settings_link = '<a href="admin.php?page=A2_Optimized_Plugin_admin">Settings</a>';
337
  array_unshift($links, $settings_link);
14
  include_once('A2_Optimized_OptionsManager.php');
15
 
16
  class A2_Optimized_Plugin extends A2_Optimized_OptionsManager {
17
+ public const optionInstalled = '_installed';
18
+ public const optionVersion = '_version';
19
  private $config_pages = [
20
  'w3tc_dashboard',
21
  'w3tc_general',
32
  'w3tc_extensions',
33
  'w3tc_install',
34
  'w3tc_about',
35
+ 'w3tc_faq',
36
+ 'litespeed',
37
+ 'litespeed-general',
38
+ 'litespeed-cache',
39
+ 'litespeed-cdn',
40
+ 'litespeed-img_optm',
41
+ 'litespeed-page_optm',
42
+ 'litespeed-db_optm',
43
+ 'litespeed-crawler',
44
+ 'litespeed-toolbox'
45
  ];
46
 
47
  //list of plugins that may conflict, displays a notice on installation of these plugins
318
  add_action('wp_dashboard_setup', [&$this, 'dashboard_widget']);
319
  $a2_plugin_basename = plugin_basename($GLOBALS['A2_Plugin_Dir'] . '/a2-optimized.php');
320
  add_filter("plugin_action_links_{$a2_plugin_basename}", [&$this, 'plugin_settings_link']);
321
+ register_setting('a2opt-cache', 'a2opt-cache', [ 'A2_Optimized_Cache', 'validate_settings' ]);
322
+ register_setting('a2opt-cache', 'a2_optimized_objectcache_type');
323
+ register_setting('a2opt-cache', 'a2_optimized_memcached_server', ['A2_Optimized_Cache', 'validate_object_cache' ]);
324
+ register_setting('a2opt-cache', 'a2_optimized_redis_server', ['A2_Optimized_Cache', 'validate_object_cache' ]);
325
+ new A2_Optimized_SiteHealth();
326
  register_setting('a2opt-cache', 'a2_db_optimizations', ['A2_Optimized_DBOptimizations', 'validate_db_optimization_settings']);
327
+ add_action('admin_menu', [&$this, 'remove_admin_menu_items'], 999);
328
  }
329
 
330
+ new A2_Optimized_DBOptimizations();
331
 
332
  if (get_option('A2_Optimized_Plugin_recaptcha', 0) == 1 && !is_admin()) {
333
  add_action('woocommerce_login_form', [&$this, 'login_captcha']);
342
  }
343
  }
344
 
345
+ public function remove_admin_menu_items() {
346
+ if (isset($_GET) && isset($_GET['page'])) {
347
+ if (!in_array($_GET['page'], $this->config_pages)) {
348
+ // Only show the Litespeed Cache menu if the user has directly navigated to it
349
+ remove_menu_page('litespeed');
350
+ }
351
+ }
352
+ }
353
+
354
  public function plugin_settings_link($links) {
355
  $settings_link = '<a href="admin.php?page=A2_Optimized_Plugin_admin">Settings</a>';
356
  array_unshift($links, $settings_link);
a2-optimized.php CHANGED
@@ -1,18 +1,18 @@
1
  <?php
2
  /*
3
- Plugin Name: A2 Optimized WP
4
- Plugin URI: https://wordpress.org/plugins/a2-optimized/
5
- Version: 2.1.4.5.3
6
- Author: A2 Hosting
7
- Author URI: https://www.a2hosting.com/
8
- Description: A2 Optimized - WordPress Optimization Plugin
9
- Text Domain: a2-optimized
10
- License: GPLv3
11
  */
12
 
13
  // Prevent direct access to this file
14
- if ( ! defined( 'WPINC' ) ) {
15
- die;
16
  }
17
 
18
  //////////////////////////////////
@@ -29,105 +29,110 @@ require_once 'A2_Optimized_SiteHealth.php';
29
  require_once 'A2_Optimized_DB_Optimizations.php';
30
 
31
  //constants
32
- define( 'A2OPT_VERSION', '2.1' );
33
- define( 'A2OPT_FULL_VERSION', '2.1.4.5' );
34
- define( 'A2OPT_MIN_PHP', '5.6' );
35
- define( 'A2OPT_MIN_WP', '5.1' );
36
- define( 'A2OPT_FILE', __FILE__ );
37
- define( 'A2OPT_BASE', plugin_basename( __FILE__ ) );
38
- define( 'A2OPT_DIR', __DIR__ );
39
-
40
- class A2_Optimized {
41
- public function __construct() {
42
- if (version_compare(PHP_VERSION, A2OPT_MIN_PHP) < 0) {
43
- add_action('admin_notices', [&$this,'A2_Optimized_noticePhpVersionWrong']);
44
-
45
- return;
46
- }
47
-
48
- $GLOBALS['A2_Plugin_Dir'] = dirname(__FILE__);
49
-
50
- $a2Plugin = new A2_Optimized_Plugin();
51
-
52
- // Install the plugin
53
- if (!$a2Plugin->isInstalled()) {
54
- $a2Plugin->install();
55
- } else {
56
- // Perform any version-upgrade activities prior to activation (e.g. database changes)
57
- $a2Plugin->upgrade();
58
- }
59
-
60
- // Add callbacks to hooks
61
- $a2Plugin->addActionsAndFilters();
62
-
63
- // Register the Plugin Activation Hook
64
- register_activation_hook(__FILE__, [&$a2Plugin, 'activate']);
65
-
66
- // Register the Plugin Deactivation Hook
67
- register_deactivation_hook(__FILE__, [&$a2Plugin, 'deactivate']);
68
- }
69
-
70
- public function A2_Optimized_noticePhpVersionWrong() {
71
- echo '<div class="notice notice-warning fade is-dismissible">' .
72
- __('Error: plugin "A2 Optimized" requires a newer version of PHP to be running.', 'a2-optimized') .
73
- '<br/>' . __('Minimal version of PHP required: ', 'a2-optimized') . '<strong>' . A2OPT_MIN_PHP . '</strong>' .
74
- '<br/>' . __('Your site is running PHP version: ', 'a2-optimized') . '<strong>' . phpversion() . '</strong>' .
75
- '<br />' . __(' To learn how to change the version of php running on your site') . ' <a target="_blank" href="http://www.a2hosting.com/kb/cpanel/cpanel-software-and-services/php-version">' . __('read this Knowledge Base Article') . '</a>.' .
76
- '</div>';
77
- }
78
-
79
- // add plugin upgrade notification
80
- public static function showUpgradeNotification($currentPluginMetadata) {
81
- // Notice Transient
82
- $upgrade_notices = get_transient('a2_opt_ug_notes');
83
- if (!$upgrade_notices) {
84
- $response = wp_remote_get( 'https://wp-plugins.a2hosting.com/wp-json/wp/v2/update_notice?notice_plugin=2' );
85
- if ( is_array( $response ) ) {
86
- $upgrade_notices = [];
87
- $body = json_decode($response['body']); // use the content
88
- foreach ($body as $item) {
89
- $upgrade_notices[$item->title->rendered] = 'Version ' . $item->title->rendered . ': ' . strip_tags($item->content->rendered);
90
- }
91
- set_transient('a2_opt_ug_notes', $upgrade_notices, 3600 * 12);
92
- } else {
93
- return;
94
- }
95
- }
96
-
97
- foreach ($upgrade_notices as $ver => $notice) {
98
- if (version_compare($currentPluginMetadata['Version'], $ver) < 0) {
99
- echo '</div><p style="background-color: #d54e21; padding: 10px; color: #f9f9f9; margin-top: 10px" class="update-message notice inline notice-warning notice-alt"><strong>Important Upgrade Notice:</strong><br />';
100
- echo esc_html($notice), '</p><div>';
101
-
102
- break;
103
- }
104
- }
105
- }
106
-
107
- // Remove WooCommerce AJAX calls from homepage if user has selected
108
- public static function dequeue_woocommerce_cart_fragments() {
109
- if (is_front_page() && get_option('a2_wc_cart_fragments')) {
110
- wp_dequeue_script('wc-cart-fragments');
111
- }
112
- }
 
 
 
 
 
113
  }
114
 
115
  if (get_option('a2_cache_enabled') == 1) {
116
- if(is_plugin_active('litespeed-cache/litespeed-cache.php')){
117
- A2_Optimized_Cache_Disk::clean();
118
- update_option('a2_cache_enabled', 0);
119
- } else {
120
- add_action( 'plugins_loaded', [ 'A2_Optimized_Cache', 'init' ] );
121
- }
122
  }
123
- register_deactivation_hook( __FILE__, [ 'A2_Optimized_Cache', 'on_deactivation' ] );
124
- register_uninstall_hook( __FILE__, [ 'A2_Optimized_Cache', 'on_uninstall' ] );
125
 
126
  $a2opt_class = new A2_Optimized();
127
  add_action('in_plugin_update_message-a2-optimized-wp/a2-optimized.php', [ 'A2_Optimized','showUpgradeNotification'], 10, 2);
128
- add_action( 'wp_enqueue_scripts', ['A2_Optimized', 'dequeue_woocommerce_cart_fragments'], 11, 2);
129
 
130
  // load WP-CLI command
131
- if ( defined( 'WP_CLI' ) && WP_CLI && class_exists( 'WP_CLI' ) ) {
132
- require_once A2OPT_DIR . '/A2_Optimized_CLI.php';
133
  }
1
  <?php
2
  /*
3
+ Plugin Name: A2 Optimized WP
4
+ Plugin URI: https://wordpress.org/plugins/a2-optimized/
5
+ Version: 2.1.4.6
6
+ Author: A2 Hosting
7
+ Author URI: https://www.a2hosting.com/
8
+ Description: A2 Optimized - WordPress Optimization Plugin
9
+ Text Domain: a2-optimized
10
+ License: GPLv3
11
  */
12
 
13
  // Prevent direct access to this file
14
+ if (! defined('WPINC')) {
15
+ die;
16
  }
17
 
18
  //////////////////////////////////
29
  require_once 'A2_Optimized_DB_Optimizations.php';
30
 
31
  //constants
32
+ define('A2OPT_VERSION', '2.1');
33
+ define('A2OPT_FULL_VERSION', '2.1.4.6');
34
+ define('A2OPT_MIN_PHP', '5.6');
35
+ define('A2OPT_MIN_WP', '5.1');
36
+ define('A2OPT_FILE', __FILE__);
37
+ define('A2OPT_BASE', plugin_basename(__FILE__));
38
+ define('A2OPT_DIR', __DIR__);
39
+
40
+ class A2_Optimized
41
+ {
42
+ public function __construct()
43
+ {
44
+ if (version_compare(PHP_VERSION, A2OPT_MIN_PHP) < 0) {
45
+ add_action('admin_notices', [&$this,'A2_Optimized_noticePhpVersionWrong']);
46
+
47
+ return;
48
+ }
49
+
50
+ $GLOBALS['A2_Plugin_Dir'] = dirname(__FILE__);
51
+
52
+ $a2Plugin = new A2_Optimized_Plugin();
53
+
54
+ // Install the plugin
55
+ if (!$a2Plugin->isInstalled()) {
56
+ $a2Plugin->install();
57
+ } else {
58
+ // Perform any version-upgrade activities prior to activation (e.g. database changes)
59
+ $a2Plugin->upgrade();
60
+ }
61
+
62
+ // Add callbacks to hooks
63
+ $a2Plugin->addActionsAndFilters();
64
+
65
+ // Register the Plugin Activation Hook
66
+ register_activation_hook(__FILE__, [&$a2Plugin, 'activate']);
67
+
68
+ // Register the Plugin Deactivation Hook
69
+ register_deactivation_hook(__FILE__, [&$a2Plugin, 'deactivate']);
70
+ }
71
+
72
+ public function A2_Optimized_noticePhpVersionWrong()
73
+ {
74
+ echo '<div class="notice notice-warning fade is-dismissible">' .
75
+ __('Error: plugin "A2 Optimized" requires a newer version of PHP to be running.', 'a2-optimized') .
76
+ '<br/>' . __('Minimal version of PHP required: ', 'a2-optimized') . '<strong>' . A2OPT_MIN_PHP . '</strong>' .
77
+ '<br/>' . __('Your site is running PHP version: ', 'a2-optimized') . '<strong>' . phpversion() . '</strong>' .
78
+ '<br />' . __(' To learn how to change the version of php running on your site') . ' <a target="_blank" href="http://www.a2hosting.com/kb/cpanel/cpanel-software-and-services/php-version">' . __('read this Knowledge Base Article') . '</a>.' .
79
+ '</div>';
80
+ }
81
+
82
+ // add plugin upgrade notification
83
+ public static function showUpgradeNotification($currentPluginMetadata)
84
+ {
85
+ // Notice Transient
86
+ $upgrade_notices = get_transient('a2_opt_ug_notes');
87
+ if (!$upgrade_notices) {
88
+ $response = wp_remote_get('https://wp-plugins.a2hosting.com/wp-json/wp/v2/update_notice?notice_plugin=2');
89
+ if (is_array($response)) {
90
+ $upgrade_notices = [];
91
+ $body = json_decode($response['body']); // use the content
92
+ foreach ($body as $item) {
93
+ $upgrade_notices[$item->title->rendered] = 'Version ' . $item->title->rendered . ': ' . strip_tags($item->content->rendered);
94
+ }
95
+ set_transient('a2_opt_ug_notes', $upgrade_notices, 3600 * 12);
96
+ } else {
97
+ return;
98
+ }
99
+ }
100
+
101
+ foreach ($upgrade_notices as $ver => $notice) {
102
+ if (version_compare($currentPluginMetadata['Version'], $ver) < 0) {
103
+ echo '</div><p style="background-color: #d54e21; padding: 10px; color: #f9f9f9; margin-top: 10px" class="update-message notice inline notice-warning notice-alt"><strong>Important Upgrade Notice:</strong><br />';
104
+ echo esc_html($notice), '</p><div>';
105
+
106
+ break;
107
+ }
108
+ }
109
+ }
110
+
111
+ // Remove WooCommerce AJAX calls from homepage if user has selected
112
+ public static function dequeue_woocommerce_cart_fragments()
113
+ {
114
+ if (is_front_page() && get_option('a2_wc_cart_fragments')) {
115
+ wp_dequeue_script('wc-cart-fragments');
116
+ }
117
+ }
118
  }
119
 
120
  if (get_option('a2_cache_enabled') == 1) {
121
+ if (is_plugin_active('litespeed-cache/litespeed-cache.php')) {
122
+ A2_Optimized_Cache_Disk::clean();
123
+ update_option('a2_cache_enabled', 0);
124
+ } else {
125
+ add_action('plugins_loaded', [ 'A2_Optimized_Cache', 'init' ]);
126
+ }
127
  }
128
+ register_deactivation_hook(__FILE__, [ 'A2_Optimized_Cache', 'on_deactivation' ]);
129
+ register_uninstall_hook(__FILE__, [ 'A2_Optimized_Cache', 'on_uninstall' ]);
130
 
131
  $a2opt_class = new A2_Optimized();
132
  add_action('in_plugin_update_message-a2-optimized-wp/a2-optimized.php', [ 'A2_Optimized','showUpgradeNotification'], 10, 2);
133
+ add_action('wp_enqueue_scripts', ['A2_Optimized', 'dequeue_woocommerce_cart_fragments'], 11, 2);
134
 
135
  // load WP-CLI command
136
+ if (defined('WP_CLI') && WP_CLI && class_exists('WP_CLI')) {
137
+ require_once A2OPT_DIR . '/A2_Optimized_CLI.php';
138
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ 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: 6.0
6
- Stable tag: 2.1.4.5.3
7
  Requires PHP: 5.6
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -133,6 +133,9 @@ Yes. A2 Optimized works on any host that supports WordPress; however, A2 Hostin
133
 
134
  == Changelog ==
135
 
 
 
 
136
  = 2.1.4.5.1 =
137
  * Optimize database tables was not being called correctly in some cases.
138
 
3
  Tags: Speed, Optimize, Secure, Fast, LiteSpeed, LSCache, A2, Hosting
4
  Requires at least: 5.1
5
  Tested up to: 6.0
6
+ Stable tag: 2.1.4.6
7
  Requires PHP: 5.6
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
133
 
134
  == Changelog ==
135
 
136
+ = 2.1.4.6 =
137
+ * Better compatibility with LiteSpeed Cache
138
+
139
  = 2.1.4.5.1 =
140
  * Optimize database tables was not being called correctly in some cases.
141