Check and Enable GZIP compression - Version 1.0.1

Version Description

  • Added a fix for the htaccess rules
Download this release

Release Info

Developer Richards Toolbox
Plugin Icon Check and Enable GZIP compression
Version 1.0.1
Comparing to
See all releases

Code changes from version 1.0 to 1.0.1

Files changed (3) hide show
  1. class.richards-toolbox.php +8 -0
  2. readme.txt +3 -0
  3. richards-toolbox.php +44 -2
class.richards-toolbox.php CHANGED
@@ -8,10 +8,18 @@ class Richards_Toolbox {
8
 
9
  function enableGZIPCompression() {
10
  update_option( 'richards-toolbox-gzip-enabled', 1 );
 
 
 
 
 
11
  }
12
 
13
  function disableGZIPCompression() {
 
14
  update_option( 'richards-toolbox-gzip-enabled', 0 );
 
 
15
  }
16
  function isApache() {
17
  return strtolower($_SERVER['SERVER_SOFTWARE']) == 'apache';
8
 
9
  function enableGZIPCompression() {
10
  update_option( 'richards-toolbox-gzip-enabled', 1 );
11
+ if(@$_GET['apache'] == '1') {
12
+ update_option( 'richards-toolbox-htaccess-enabled', 1 );
13
+ add_filter('mod_rewrite_rules', 'richards_toolbox_addHtaccessContent');
14
+ save_mod_rewrite_rules();
15
+ }
16
  }
17
 
18
  function disableGZIPCompression() {
19
+ update_option( 'richards-toolbox-htaccess-enabled', 0 );
20
  update_option( 'richards-toolbox-gzip-enabled', 0 );
21
+ remove_filter('mod_rewrite_rules', 'richards_toolbox_addHtaccessContent');
22
+ save_mod_rewrite_rules();
23
  }
24
  function isApache() {
25
  return strtolower($_SERVER['SERVER_SOFTWARE']) == 'apache';
readme.txt CHANGED
@@ -57,6 +57,9 @@ Just about all the large websites worldwide use GZIP compression. For and actual
57
 
58
  == Changelog ==
59
 
 
 
 
60
  = 1.0 =
61
  * Plugin is mature enough for v1.0 ;)
62
  * Better explanation of the preview mode
57
 
58
  == Changelog ==
59
 
60
+ = 1.0.1 =
61
+ * Added a fix for the htaccess rules
62
+
63
  = 1.0 =
64
  * Plugin is mature enough for v1.0 ;)
65
  * Better explanation of the preview mode
richards-toolbox.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://checkgzipcompression.com
5
  Description: This handy tool checks if you have GZIP compression enabled, and makes it possible to turn on GZIP compression. Every time you run this check, your domain name will be sent to http://checkgzipcompression.com. We won�t sent any other private information.
6
  Author: Richard's Toolbox
7
  Text Domain: richards-toolbox
8
- Version: 1.0
9
  Author URI: http://richardstoolbox.com
10
  */
11
 
@@ -71,9 +71,51 @@ function gzip_compression_page() {
71
  }
72
 
73
  //check gzip compression
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  add_action( 'after_setup_theme', 'check_richards_toolbox_gzip' );
75
  function check_richards_toolbox_gzip() {
76
- if( (get_option('richards-toolbox-gzip-enabled') || isset($_GET['preview-gzip'])) && !is_admin() ) {
77
  ob_start("ob_gzhandler");
78
  }
79
  }
5
  Description: This handy tool checks if you have GZIP compression enabled, and makes it possible to turn on GZIP compression. Every time you run this check, your domain name will be sent to http://checkgzipcompression.com. We won�t sent any other private information.
6
  Author: Richard's Toolbox
7
  Text Domain: richards-toolbox
8
+ Version: 1.0.1
9
  Author URI: http://richardstoolbox.com
10
  */
11
 
71
  }
72
 
73
  //check gzip compression
74
+ add_action( 'wp_loaded', 'check_richards_toolbox_htaccess');
75
+ function check_richards_toolbox_htaccess() {
76
+ if(get_option('richards-toolbox-htaccess-enabled')) {
77
+ add_filter('mod_rewrite_rules', 'richards_toolbox_addHtaccessContent');
78
+ }
79
+ }
80
+
81
+ function richards_toolbox_addHtaccessContent($rules) {
82
+ $my_content = '
83
+ # BEGIN GZIP COMPRESSION BY RICHARD\'S TOOLBOX
84
+ <IfModule mod_deflate.c>
85
+ #add content typing
86
+ AddType application/x-gzip .gz .tgz
87
+ AddEncoding x-gzip .gz .tgz
88
+
89
+ # Insert filters
90
+ AddOutputFilterByType DEFLATE text/plain
91
+ AddOutputFilterByType DEFLATE text/html
92
+ AddOutputFilterByType DEFLATE text/xml
93
+ AddOutputFilterByType DEFLATE text/css
94
+ AddOutputFilterByType DEFLATE application/xml
95
+ AddOutputFilterByType DEFLATE application/xhtml+xml
96
+ AddOutputFilterByType DEFLATE application/rss+xml
97
+ AddOutputFilterByType DEFLATE application/javascript
98
+ AddOutputFilterByType DEFLATE application/x-javascript
99
+ AddOutputFilterByType DEFLATE application/x-httpd-php
100
+ AddOutputFilterByType DEFLATE application/x-httpd-fastphp
101
+ AddOutputFilterByType DEFLATE image/svg+xml
102
+
103
+ # Drop problematic browsers
104
+ BrowserMatch ^Mozilla/4 gzip-only-text/html
105
+ BrowserMatch ^Mozilla/4\.0[678] no-gzip
106
+ BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
107
+
108
+ # Make sure proxies don\'t deliver the wrong content
109
+ Header append Vary User-Agent env=!dont-vary
110
+ </IfModule>
111
+ # END GZIP COMPRESSION
112
+ ';
113
+ return $my_content . $rules;
114
+ }
115
+
116
  add_action( 'after_setup_theme', 'check_richards_toolbox_gzip' );
117
  function check_richards_toolbox_gzip() {
118
+ if((!get_option('richards-toolbox-htaccess-enabled') && get_option('richards-toolbox-gzip-enabled') || isset($_GET['preview-gzip'])) && !is_admin() ) {
119
  ob_start("ob_gzhandler");
120
  }
121
  }