WP Performance Score Booster - Version 1.3

Version Description

Download this release

Release Info

Developer dipakcg
Plugin Icon 128x128 WP Performance Score Booster
Version 1.3
Comparing to
See all releases

Code changes from version 1.2.2 to 1.3

Files changed (2) hide show
  1. readme.txt +5 -1
  2. wp-performance-score-booster.php +74 -32
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: performance, speed, time, query, strings, gzip, compression, caching, boos
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3S8BRPLWLNQ38
5
  Requires at least: 3.5
6
  Tested up to: 4.1
7
- Stable tag: 1.2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -42,6 +42,10 @@ Pretty much, yeah.
42
  1. Admin Settings
43
 
44
  == Changelog ==
 
 
 
 
45
  = 1.2.2, Dec 27, 2014 =
46
  * Added support for language translations
47
 
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3S8BRPLWLNQ38
5
  Requires at least: 3.5
6
  Tested up to: 4.1
7
+ Stable tag: 1.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
42
  1. Admin Settings
43
 
44
  == Changelog ==
45
+ = 1.3, Dec 29, 2014 =
46
+ * Fixed issues with htaccess custom rules overrides
47
+ * WP Performance Score Booster now adds rules to htaccess outside default WordPress block
48
+
49
  = 1.2.2, Dec 27, 2014 =
50
  * Added support for language translations
51
 
wp-performance-score-booster.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Performance Score Booster
4
  Plugin URI: https://github.com/dipakcg/wp-performance-score-booster
5
  Description: Speed-up page load times and improve website scores in services like PageSpeed, YSlow, Pingdom and GTmetrix.
6
- Version: 1.2.2
7
  Author: Dipak C. Gajjar
8
  Author URI: http://dipakgajjar.com
9
  Text Domain: wp-performance-score-booster
@@ -14,11 +14,12 @@ if (!defined('WPPSB_PLUGIN_VERSION')) {
14
  define('WPPSB_PLUGIN_VERSION', 'wppsb_plugin_version');
15
  }
16
  if (!defined('WPPSB_PLUGIN_VERSION_NUM')) {
17
- define('WPPSB_PLUGIN_VERSION_NUM', '1.2.2');
18
  }
19
  update_option(WPPSB_PLUGIN_VERSION, WPPSB_PLUGIN_VERSION_NUM);
20
 
21
  // Load plugin textdomain for language trnaslation
 
22
  function wppsb_load_plugin_textdomain() {
23
 
24
  $domain = 'wp-performance-score-booster';
@@ -51,10 +52,9 @@ function wppsb_remove_query_strings_emp( $src ) {
51
  }
52
 
53
  // Enable GZIP Compression
54
- function wppsb_enable_gzip_filter( $rules ) {
55
  $gzip_htaccess_content = <<<EOD
56
- \n## Added by WP Performance Score Booster ##
57
- ## BEGIN : Enable GZIP Compression (compress text, html, javascript, css, xml and so on) ##
58
  <IfModule mod_deflate.c>
59
  AddOutputFilterByType DEFLATE text/plain
60
  AddOutputFilterByType DEFLATE text/html
@@ -70,16 +70,15 @@ AddOutputFilterByType DEFLATE application/x-httpd-fastphp
70
  AddOutputFilterByType DEFLATE image/svg+xml
71
  SetOutputFilter DEFLATE
72
  </IfModule>
73
- ## END : Enable GZIP Compression ##\n\n
74
  EOD;
75
  return $gzip_htaccess_content . $rules;
76
  }
77
 
78
  // Enable expire caching
79
- function wppsb_expire_caching_filter( $rules ) {
80
  $expire_cache_htaccess_content = <<<EOD
81
- \n## Added by WP Performance Score Booster ##
82
- ## BEGIN : Expires Caching (Leverage Browser Caching) ##
83
  <IfModule mod_expires.c>
84
  ExpiresActive On
85
  ExpiresByType image/jpg "access 2 week"
@@ -93,26 +92,47 @@ ExpiresByType application/x-shockwave-flash "access 2 week"
93
  ExpiresByType image/x-icon "access 2 week"
94
  ExpiresDefault "access 2 week"
95
  </IfModule>
96
- ## END : Expires Caching (Leverage Browser Caching) ##\n\n
97
  EOD;
98
  return $expire_cache_htaccess_content . $rules;
99
  }
100
 
101
  // Set Vary: Accept-Encoding Header
102
- function wppsb_vary_accept_encoding_filter( $rules ) {
103
  $vary_accept_encoding_header = <<<EOD
104
- \n## Added by WP Performance Score Booster ##
105
- ## BEGIN : Vary: Accept-Encoding Header ##
106
  <IfModule mod_headers.c>
107
  <FilesMatch "\.(js|css|xml|gz)$">
108
  Header append Vary: Accept-Encoding
109
  </FilesMatch>
110
  </IfModule>
111
- ## END : Vary: Accept-Encoding Header ##\n\n
112
  EOD;
113
  return $vary_accept_encoding_header . $rules;
114
  }
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  // If 'Remove query strings" checkbox ticked, add filter otherwise remove filter
117
  if (get_option('wppsb_remove_query_strings') == 'on') {
118
  add_filter( 'script_loader_src', 'wppsb_remove_query_strings_q', 15, 1 );
@@ -164,25 +184,8 @@ function wppsb_admin_options() {
164
  update_option( $enable_gzip, $enable_gzip_val );
165
  update_option( $expire_caching, $expire_caching_val );
166
 
167
- // If 'Enable GZIP" checkbox ticked, add filter otherwise remove filter
168
- if ($enable_gzip_val == 'on') {
169
- add_filter('mod_rewrite_rules', 'wppsb_enable_gzip_filter');
170
- add_filter('mod_rewrite_rules', 'wppsb_vary_accept_encoding_filter');
171
- }
172
- else {
173
- remove_filter('mod_rewrite_rules', 'wppsb_enable_gzip_filter');
174
- remove_filter('mod_rewrite_rules', 'wppsb_vary_accept_encoding_filter');
175
- }
176
-
177
- // If 'Expire caching" checkbox ticked, add filter otherwise remove filter
178
- if ($expire_caching_val == 'on') {
179
- add_filter('mod_rewrite_rules', 'wppsb_expire_caching_filter');
180
- }
181
- else {
182
- remove_filter('mod_rewrite_rules', 'wppsb_expire_caching_filter');
183
- }
184
-
185
  flush_rewrite_rules();
 
186
 
187
  // Put the settings updated message on the screen
188
  ?>
@@ -232,6 +235,7 @@ function wppsb_admin_options() {
232
  add_action( 'admin_menu', 'wppsb_add_admin_menu' );
233
  function wppsb_add_admin_menu() {
234
  add_menu_page( __('WP Performance Score Booster Settings', 'wp-performance-score-booster'), __('WP Performance Score Booster', 'wp-performance-score-booster'), 'manage_options', 'wp-performance-score-booster', 'wppsb_admin_options', plugins_url('assets/images/wppsb-icon-24x24.png', __FILE__) );
 
235
  }
236
 
237
  // Add header
@@ -269,6 +273,7 @@ function wppsb_activate_plugin() {
269
  add_filter('mod_rewrite_rules', 'wppsb_expire_caching_filter');
270
 
271
  flush_rewrite_rules();
 
272
  }
273
  register_activation_hook( __FILE__, 'wppsb_activate_plugin' );
274
 
@@ -277,6 +282,43 @@ function wppsb_deactivate_plugin() {
277
  delete_option( 'wppsb_plugin_version' );
278
 
279
  flush_rewrite_rules();
 
280
  }
281
  register_deactivation_hook( __FILE__, 'wppsb_deactivate_plugin' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  ?>
3
  Plugin Name: WP Performance Score Booster
4
  Plugin URI: https://github.com/dipakcg/wp-performance-score-booster
5
  Description: Speed-up page load times and improve website scores in services like PageSpeed, YSlow, Pingdom and GTmetrix.
6
+ Version: 1.3
7
  Author: Dipak C. Gajjar
8
  Author URI: http://dipakgajjar.com
9
  Text Domain: wp-performance-score-booster
14
  define('WPPSB_PLUGIN_VERSION', 'wppsb_plugin_version');
15
  }
16
  if (!defined('WPPSB_PLUGIN_VERSION_NUM')) {
17
+ define('WPPSB_PLUGIN_VERSION_NUM', '1.3');
18
  }
19
  update_option(WPPSB_PLUGIN_VERSION, WPPSB_PLUGIN_VERSION_NUM);
20
 
21
  // Load plugin textdomain for language trnaslation
22
+ // load_plugin_textdomain( 'wp-performance-score-booster', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
23
  function wppsb_load_plugin_textdomain() {
24
 
25
  $domain = 'wp-performance-score-booster';
52
  }
53
 
54
  // Enable GZIP Compression
55
+ function wppsb_enable_gzip_filter( $rules = '' ) {
56
  $gzip_htaccess_content = <<<EOD
57
+ \n## BEGIN Enable GZIP Compression ##
 
58
  <IfModule mod_deflate.c>
59
  AddOutputFilterByType DEFLATE text/plain
60
  AddOutputFilterByType DEFLATE text/html
70
  AddOutputFilterByType DEFLATE image/svg+xml
71
  SetOutputFilter DEFLATE
72
  </IfModule>
73
+ ## END Enable GZIP Compression ##
74
  EOD;
75
  return $gzip_htaccess_content . $rules;
76
  }
77
 
78
  // Enable expire caching
79
+ function wppsb_expire_caching_filter( $rules = '' ) {
80
  $expire_cache_htaccess_content = <<<EOD
81
+ \n## BEGIN Expires Caching (Leverage Browser Caching) ##
 
82
  <IfModule mod_expires.c>
83
  ExpiresActive On
84
  ExpiresByType image/jpg "access 2 week"
92
  ExpiresByType image/x-icon "access 2 week"
93
  ExpiresDefault "access 2 week"
94
  </IfModule>
95
+ ## END Expires Caching (Leverage Browser Caching) ##
96
  EOD;
97
  return $expire_cache_htaccess_content . $rules;
98
  }
99
 
100
  // Set Vary: Accept-Encoding Header
101
+ function wppsb_vary_accept_encoding_filter( $rules = '' ) {
102
  $vary_accept_encoding_header = <<<EOD
103
+ \n## BEGIN Vary: Accept-Encoding Header ##
 
104
  <IfModule mod_headers.c>
105
  <FilesMatch "\.(js|css|xml|gz)$">
106
  Header append Vary: Accept-Encoding
107
  </FilesMatch>
108
  </IfModule>
109
+ ## END Vary: Accept-Encoding Header ##
110
  EOD;
111
  return $vary_accept_encoding_header . $rules;
112
  }
113
 
114
+ /* Plan to add in future releases */
115
+ // Defer parsing of java-script (to load at last)
116
+ /* function defer_parsing_of_js ( $src ) {
117
+ if ( FALSE === strpos( $src, '.js' ) )
118
+ return $src;
119
+ if ( strpos( $src, 'jquery.js' ) )
120
+ return $src;
121
+ return "$src' defer='defer";
122
+ }
123
+ add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 ); */
124
+
125
+ // Enqueue scripts in the footer to speed-up page load
126
+ /* function footer_enqueue_scripts() {
127
+ remove_action('wp_head', 'wp_print_scripts');
128
+ // remove_action('wp_head', 'wp_print_head_scripts', 9);
129
+ remove_action('wp_head', 'wp_enqueue_scripts', 1);
130
+ add_action('wp_footer', 'wp_print_scripts', 5);
131
+ // add_action('wp_footer', 'wp_print_head_scripts', 5);
132
+ add_action('wp_footer', 'wp_enqueue_scripts', 5);
133
+ }
134
+ add_action('after_setup_theme', 'footer_enqueue_scripts'); */
135
+
136
  // If 'Remove query strings" checkbox ticked, add filter otherwise remove filter
137
  if (get_option('wppsb_remove_query_strings') == 'on') {
138
  add_filter( 'script_loader_src', 'wppsb_remove_query_strings_q', 15, 1 );
184
  update_option( $enable_gzip, $enable_gzip_val );
185
  update_option( $expire_caching, $expire_caching_val );
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  flush_rewrite_rules();
188
+ wppsb_save_mod_rewrite_rules();
189
 
190
  // Put the settings updated message on the screen
191
  ?>
235
  add_action( 'admin_menu', 'wppsb_add_admin_menu' );
236
  function wppsb_add_admin_menu() {
237
  add_menu_page( __('WP Performance Score Booster Settings', 'wp-performance-score-booster'), __('WP Performance Score Booster', 'wp-performance-score-booster'), 'manage_options', 'wp-performance-score-booster', 'wppsb_admin_options', plugins_url('assets/images/wppsb-icon-24x24.png', __FILE__) );
238
+ // add_options_page( __('WP Performance Score Booster Settings', 'wp-performance-score-booster'), __('WP Performance Score Booster', 'wp-performance-score-booster'), 'manage_options', 'wp-performance-score-booster', 'wppsb_admin_options' );
239
  }
240
 
241
  // Add header
273
  add_filter('mod_rewrite_rules', 'wppsb_expire_caching_filter');
274
 
275
  flush_rewrite_rules();
276
+ wppsb_save_mod_rewrite_rules();
277
  }
278
  register_activation_hook( __FILE__, 'wppsb_activate_plugin' );
279
 
282
  delete_option( 'wppsb_plugin_version' );
283
 
284
  flush_rewrite_rules();
285
+ wppsb_save_mod_rewrite_rules();
286
  }
287
  register_deactivation_hook( __FILE__, 'wppsb_deactivate_plugin' );
288
+
289
+ // Special thanks to Marin Atanasov ( https://github.com/tyxla ) for contributing this awesome function.
290
+ // Updates the htaccess file with the current rules if it is writable.
291
+ function wppsb_save_mod_rewrite_rules() {
292
+ if ( is_multisite() )
293
+ return;
294
+ global $wp_rewrite;
295
+ $home_path = get_home_path();
296
+ $htaccess_file = $home_path.'.htaccess';
297
+ /*
298
+ * If the file doesn't already exist check for write access to the directory
299
+ * and whether we have some rules. Else check for write access to the file.
300
+ */
301
+ if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
302
+ if ( got_mod_rewrite() ) {
303
+ $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
304
+ // $remove_query_strings = 'wppsb_remove_query_strings';
305
+ $enable_gzip = 'wppsb_enable_gzip';
306
+ $expire_caching = 'wppsb_expire_caching';
307
+ // $remove_query_strings_val = get_option($remove_query_strings);
308
+ $enable_gzip_val = get_option($enable_gzip);
309
+ $expire_caching_val = get_option($expire_caching);
310
+ $rules = array();
311
+ if ($enable_gzip_val == 'on') {
312
+ $rules = array_merge($rules, explode("\n", wppsb_enable_gzip_filter()));
313
+ $rules = array_merge($rules, explode("\n", wppsb_vary_accept_encoding_filter()));
314
+ }
315
+ // If 'Expire caching" checkbox ticked, add filter otherwise remove filter
316
+ if ($expire_caching_val == 'on') {
317
+ $rules = array_merge($rules, explode("\n", wppsb_expire_caching_filter()));
318
+ }
319
+ return insert_with_markers( $htaccess_file, 'WP Performance Score Booster Settings', $rules );
320
+ }
321
+ }
322
+ return false;
323
+ }
324
  ?>