SG Optimizer - Version 5.7.14

Version Description

Download this release

Release Info

Developer sstoqnov
Plugin Icon 128x128 SG Optimizer
Version 5.7.14
Comparing to
See all releases

Code changes from version 5.7.13 to 5.7.14

core/Helper/Helper.php CHANGED
@@ -80,7 +80,9 @@ class Helper {
80
  // Init Cloudflare API.
81
  new Cloudflare();
82
 
 
83
  new Settings();
 
84
  }
85
 
86
  /**
80
  // Init Cloudflare API.
81
  new Cloudflare();
82
 
83
+ // Init Settings class.
84
  new Settings();
85
+
86
  }
87
 
88
  /**
core/Htaccess/Htaccess.php CHANGED
@@ -46,20 +46,25 @@ class Htaccess {
46
  */
47
  private $types = array(
48
  'gzip' => array(
49
- 'enabled' => '/\#\s+GZIP enabled by SG-Optimizer/si',
50
- 'disabled' => '/\#\s+GZIP enabled by SG-Optimizer(.+?)\#\s+END\s+GZIP\n/ims',
51
  'disable_all' => '/\#\s+GZIP enabled by SG-Optimizer(.+?)\#\s+END\s+GZIP\n|<IfModule mod_deflate\.c>(.*?\n)<\/IfModule>|# BEGIN WP Rocket(.*)# END WP Rocket/ims',
52
  ),
53
  'browser-caching' => array(
54
- 'enabled' => '/\#\s+Leverage Browser Caching by SG-Optimizer/si',
55
- 'disabled' => '/\#\s+Leverage Browser Caching by SG-Optimizer(.+?)\#\s+END\s+LBC\n/ims',
56
  'disable_all' => '/\#\s+Leverage Browser Caching by SG-Optimizer(.+?)\#\s+END\s+LBC\n|<IfModule mod_expires\.c>(.*?\n?)(<\/IfModule>\n\s)?<\/IfModule>/ims',
57
  ),
58
- 'ssl' => array(
59
  'enabled' => '/HTTPS forced by SG-Optimizer/si',
60
  'disabled' => '/\#\s+HTTPS\s+forced\s+by\s+SG-Optimizer(.+?)\#\s+END\s+HTTPS(\n)?/ims',
61
  'disable_all' => '/\#\s+HTTPS\s+forced\s+by\s+SG-Optimizer(.+?)\#\s+END\s+HTTPS(\n)?/ims',
62
  ),
 
 
 
 
 
63
  );
64
 
65
  /**
@@ -186,7 +191,7 @@ class Htaccess {
186
  }
187
 
188
  // Generate the new content of htaccess.
189
- $new_content = $new_rule . PHP_EOL . $content;
190
 
191
  // Return the result.
192
  return $this->lock_and_write( $new_content );
46
  */
47
  private $types = array(
48
  'gzip' => array(
49
+ 'enabled' => '/\#\s+GZIP enabled by SG-Optimizer/si',
50
+ 'disabled' => '/\#\s+GZIP enabled by SG-Optimizer(.+?)\#\s+END\s+GZIP\n/ims',
51
  'disable_all' => '/\#\s+GZIP enabled by SG-Optimizer(.+?)\#\s+END\s+GZIP\n|<IfModule mod_deflate\.c>(.*?\n)<\/IfModule>|# BEGIN WP Rocket(.*)# END WP Rocket/ims',
52
  ),
53
  'browser-caching' => array(
54
+ 'enabled' => '/\#\s+Leverage Browser Caching by SG-Optimizer/si',
55
+ 'disabled' => '/\#\s+Leverage Browser Caching by SG-Optimizer(.+?)\#\s+END\s+LBC\n/ims',
56
  'disable_all' => '/\#\s+Leverage Browser Caching by SG-Optimizer(.+?)\#\s+END\s+LBC\n|<IfModule mod_expires\.c>(.*?\n?)(<\/IfModule>\n\s)?<\/IfModule>/ims',
57
  ),
58
+ 'ssl' => array(
59
  'enabled' => '/HTTPS forced by SG-Optimizer/si',
60
  'disabled' => '/\#\s+HTTPS\s+forced\s+by\s+SG-Optimizer(.+?)\#\s+END\s+HTTPS(\n)?/ims',
61
  'disable_all' => '/\#\s+HTTPS\s+forced\s+by\s+SG-Optimizer(.+?)\#\s+END\s+HTTPS(\n)?/ims',
62
  ),
63
+ 'user-agent-vary' => array(
64
+ 'enabled' => '/\#\s+SGO Unset Vary/si',
65
+ 'disabled' => '/\#\s+SGO\s+Unset\s+Vary(.+?)\#\s+SGO\s+Unset\s+Vary\s+END(\n)?/ims',
66
+ 'disable_all' => '/\#\s+SGO\s+Unset\s+Vary(.+?)\#\s+SGO\s+Unset\s+Vary\s+END(\n)?/ims',
67
+ ),
68
  );
69
 
70
  /**
191
  }
192
 
193
  // Generate the new content of htaccess.
194
+ $new_content = ( 'user-agent-vary' === $type ) ? $content . PHP_EOL . $new_rule : $new_rule . PHP_EOL . $content;
195
 
196
  // Return the result.
197
  return $this->lock_and_write( $new_content );
core/Install_Service/Install_5_7_14.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace SiteGround_Optimizer\Install_Service;
3
+
4
+ use SiteGround_Optimizer\Htaccess\Htaccess;
5
+ use SiteGround_Optimizer\Options\Options;
6
+
7
+ class Install_5_7_14 extends Install {
8
+
9
+ /**
10
+ * The default install version. Overridden by the installation packages.
11
+ *
12
+ * @since 5.7.14
13
+ *
14
+ * @access protected
15
+ *
16
+ * @var string $version The install version.
17
+ */
18
+ protected static $version = '5.7.14';
19
+
20
+ /**
21
+ * Run the install procedure.
22
+ *
23
+ * @since 5.7.14
24
+ */
25
+ public function install() {
26
+ if (
27
+ ! Options::is_enabled( 'siteground_optimizer_user_agent_header' )
28
+ ) {
29
+ $htaccess = new Htaccess();
30
+ $htaccess->enable( 'user-agent-vary' );
31
+ }
32
+ }
33
+ }
core/Install_Service/Install_Service.php CHANGED
@@ -27,6 +27,7 @@ use SiteGround_Optimizer\Install_Service\Install_5_6_3;
27
  use SiteGround_Optimizer\Install_Service\Install_5_6_7;
28
  use SiteGround_Optimizer\Install_Service\Install_5_7_0;
29
  use SiteGround_Optimizer\Install_Service\Install_5_7_4;
 
30
  use SiteGround_Optimizer\Install_Service\Install_Cleanup;
31
  use SiteGround_Optimizer\Supercacher\Supercacher;
32
 
@@ -65,6 +66,7 @@ class Install_Service {
65
  new Install_5_6_7(),
66
  new Install_5_7_0(),
67
  new Install_5_7_4(),
 
68
  );
69
 
70
  add_action( 'upgrader_process_complete', array( $this, 'install' ) );
27
  use SiteGround_Optimizer\Install_Service\Install_5_6_7;
28
  use SiteGround_Optimizer\Install_Service\Install_5_7_0;
29
  use SiteGround_Optimizer\Install_Service\Install_5_7_4;
30
+ use SiteGround_Optimizer\Install_Service\Install_5_7_14;
31
  use SiteGround_Optimizer\Install_Service\Install_Cleanup;
32
  use SiteGround_Optimizer\Supercacher\Supercacher;
33
 
66
  new Install_5_6_7(),
67
  new Install_5_7_0(),
68
  new Install_5_7_4(),
69
+ new Install_5_7_14(),
70
  );
71
 
72
  add_action( 'upgrader_process_complete', array( $this, 'install' ) );
core/Options/Options.php CHANGED
@@ -1,36 +1,12 @@
1
  <?php
2
  namespace SiteGround_Optimizer\Options;
3
 
4
- use SiteGround_Optimizer\Htaccess\Htaccess;
5
  use SiteGround_Optimizer\Supercacher\Supercacher;
6
 
7
  /**
8
  * Handle PHP compatibility checks.
9
  */
10
  class Options {
11
-
12
- /**
13
- * The constructor.
14
- *
15
- * @since 5.0.0
16
- */
17
- public function __construct() {
18
- $this->htaccess_service = new Htaccess();
19
-
20
- add_filter(
21
- 'pre_update_option_siteground_optimizer_enable_gzip_compression',
22
- array( $this, 'toogle_gzip_comporession' ),
23
- 10,
24
- 2
25
- );
26
- add_filter(
27
- 'pre_update_option_siteground_optimizer_enable_browser_caching',
28
- array( $this, 'toogle_browser_caching' ),
29
- 10,
30
- 2
31
- );
32
- }
33
-
34
  /**
35
  * Check if a single boolean setting is enabled.
36
  *
@@ -190,46 +166,6 @@ class Options {
190
  return $result;
191
  }
192
 
193
- /**
194
- * Handle enable/disable gzip compression.
195
- *
196
- * @since 5.0.0
197
- *
198
- * @param mixed $value The new value.
199
- * @param mixed $old_value The old value.
200
- *
201
- * @return mixed The new or old value, depending of the result.
202
- */
203
- public function toogle_gzip_comporession( $value, $old_value ) {
204
- if ( 1 === $value ) {
205
- $result = $this->htaccess_service->enable( 'gzip' );
206
- } else {
207
- $result = $this->htaccess_service->disable( 'gzip' );
208
- }
209
-
210
- return true === $result ? $value : $old_value;
211
- }
212
-
213
- /**
214
- * Handle enable/disable browser caching.
215
- *
216
- * @since 5.0.0
217
- *
218
- * @param mixed $value The new value.
219
- * @param mixed $old_value The old value.
220
- *
221
- * @return mixed The new or old value, depending of the result.
222
- */
223
- public function toogle_browser_caching( $value, $old_value ) {
224
- if ( 1 === $value ) {
225
- $result = $this->htaccess_service->enable( 'browser-caching' );
226
- } else {
227
- $result = $this->htaccess_service->disable( 'browser-caching' );
228
- }
229
-
230
- return true === $result ? $value : $old_value;
231
- }
232
-
233
  /**
234
  * Checks if the `option_key` paramether exists in rest data.
235
  *
1
  <?php
2
  namespace SiteGround_Optimizer\Options;
3
 
 
4
  use SiteGround_Optimizer\Supercacher\Supercacher;
5
 
6
  /**
7
  * Handle PHP compatibility checks.
8
  */
9
  class Options {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  /**
11
  * Check if a single boolean setting is enabled.
12
  *
166
  return $result;
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  /**
170
  * Checks if the `option_key` paramether exists in rest data.
171
  *
core/Rest/Rest_Helper_Options.php CHANGED
@@ -5,6 +5,7 @@ use SiteGround_Optimizer\Options\Options;
5
  use SiteGround_Optimizer\Multisite\Multisite;
6
  use SiteGround_Optimizer\Front_End_Optimization\Front_End_Optimization;
7
  use SiteGround_Optimizer\Helper\Helper;
 
8
 
9
  /**
10
  * Rest Helper class that manages all of the front end optimisation.
@@ -14,8 +15,9 @@ class Rest_Helper_Options extends Rest_Helper {
14
  * The constructor.
15
  */
16
  public function __construct() {
17
- $this->options = new Options();
18
- $this->multisite = new Multisite();
 
19
  }
20
  /**
21
  * Checks if the option key exists.
@@ -30,6 +32,8 @@ class Rest_Helper_Options extends Rest_Helper {
30
  $is_network = $this->validate_and_get_option_value( $request, 'is_multisite', false );
31
  $result = $this->options->enable_option( $key, $is_network );
32
 
 
 
33
  // Enable the option.
34
  wp_send_json(
35
  array(
@@ -56,6 +60,8 @@ class Rest_Helper_Options extends Rest_Helper {
56
  $is_network = $this->validate_and_get_option_value( $request, 'is_multisite', false );
57
  $result = $this->options->disable_option( $key, $is_network );
58
 
 
 
59
  // Disable the option.
60
  return wp_send_json(
61
  array(
@@ -132,4 +138,44 @@ class Rest_Helper_Options extends Rest_Helper {
132
  // Send the options to react app.
133
  wp_send_json_success( $options );
134
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  }
5
  use SiteGround_Optimizer\Multisite\Multisite;
6
  use SiteGround_Optimizer\Front_End_Optimization\Front_End_Optimization;
7
  use SiteGround_Optimizer\Helper\Helper;
8
+ use SiteGround_Optimizer\Htaccess\Htaccess;
9
 
10
  /**
11
  * Rest Helper class that manages all of the front end optimisation.
15
  * The constructor.
16
  */
17
  public function __construct() {
18
+ $this->options = new Options();
19
+ $this->multisite = new Multisite();
20
+ $this->htaccess_service = new Htaccess();
21
  }
22
  /**
23
  * Checks if the option key exists.
32
  $is_network = $this->validate_and_get_option_value( $request, 'is_multisite', false );
33
  $result = $this->options->enable_option( $key, $is_network );
34
 
35
+ $this->maybe_change_htaccess_rules( $key, 1 );
36
+
37
  // Enable the option.
38
  wp_send_json(
39
  array(
60
  $is_network = $this->validate_and_get_option_value( $request, 'is_multisite', false );
61
  $result = $this->options->disable_option( $key, $is_network );
62
 
63
+ $this->maybe_change_htaccess_rules( $key, 0 );
64
+
65
  // Disable the option.
66
  return wp_send_json(
67
  array(
138
  // Send the options to react app.
139
  wp_send_json_success( $options );
140
  }
141
+
142
+ /**
143
+ * Check if we should add additional rules to the htaccess file.
144
+ *
145
+ * @since 5.7.14
146
+ *
147
+ * @param string $type The optimization type.
148
+ * @param int $value The optimization value.
149
+ */
150
+ public function maybe_change_htaccess_rules( $type, $value ) {
151
+ // Options mapping with the htaccess rules and methods.
152
+ $htaccess_options = array(
153
+ 'siteground_optimizer_enable_gzip_compression' => array(
154
+ 0 => 'disable',
155
+ 1 => 'enable',
156
+ 'rule' => 'gzip',
157
+ ),
158
+ 'siteground_optimizer_enable_browser_caching' => array(
159
+ 0 => 'disable',
160
+ 1 => 'enable',
161
+ 'rule' => 'browser-caching',
162
+ ),
163
+ 'siteground_optimizer_user_agent_header' => array(
164
+ 0 => 'enable',
165
+ 1 => 'disable',
166
+ 'rule' => 'user-agent-vary',
167
+ ),
168
+ );
169
+
170
+ // Bail if the option doesn't require additional htaccess rules to be added.
171
+ if ( ! array_key_exists( $type, $htaccess_options ) ) {
172
+ return;
173
+ }
174
+
175
+ // Call the htaccess method to add/remove the rules.
176
+ call_user_func_array(
177
+ array( $this->htaccess_service, $htaccess_options[ $type ][ $value ] ),
178
+ array( $htaccess_options[ $type ]['rule'] )
179
+ );
180
+ }
181
  }
readme.txt CHANGED
@@ -217,9 +217,12 @@ Our plugin uses a cookie in order to function properly. It does not store person
217
 
218
  == Changelog ==
219
 
 
 
 
220
  = Version 5.7.13 =
221
  * Add settings import/export cli command
222
- * Do not optimize xml sitemaps
223
  * Fix DNS Resolver fatal error for non existing hosts
224
  * Fix Cloudflare optimization for sites with custom wp-content dir
225
  * Improved Speed Test description for Webfonts optimization
217
 
218
  == Changelog ==
219
 
220
+ = Version 5.7.14 =
221
+ * Improved Vary:User-Agent handling
222
+
223
  = Version 5.7.13 =
224
  * Add settings import/export cli command
225
+ * Exclude XML sitemaps from optimizations
226
  * Fix DNS Resolver fatal error for non existing hosts
227
  * Fix Cloudflare optimization for sites with custom wp-content dir
228
  * Improved Speed Test description for Webfonts optimization
sg-cachepress.php CHANGED
@@ -10,7 +10,7 @@
10
  * Plugin Name: SG Optimizer
11
  * Plugin URI: https://siteground.com
12
  * Description: This plugin will link your WordPress application with all the performance optimizations provided by SiteGround
13
- * Version: 5.7.13
14
  * Author: SiteGround
15
  * Author URI: https://www.siteground.com
16
  * Text Domain: sg-cachepress
@@ -31,7 +31,7 @@ if ( ! defined( 'WPINC' ) ) {
31
 
32
  // Define version constant.
33
  if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
34
- define( __NAMESPACE__ . '\VERSION', '5.7.13' );
35
  }
36
 
37
  // Define slug constant.
10
  * Plugin Name: SG Optimizer
11
  * Plugin URI: https://siteground.com
12
  * Description: This plugin will link your WordPress application with all the performance optimizations provided by SiteGround
13
+ * Version: 5.7.14
14
  * Author: SiteGround
15
  * Author URI: https://www.siteground.com
16
  * Text Domain: sg-cachepress
31
 
32
  // Define version constant.
33
  if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
34
+ define( __NAMESPACE__ . '\VERSION', '5.7.14' );
35
  }
36
 
37
  // Define slug constant.
templates/user-agent-vary.tpl ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ # SGO Unset Vary
2
+ Header unset Vary
3
+ # SGO Unset Vary END