Version Description
- Plugin is mature enough for v1.0 ;)
- Better explanation of the preview mode
- Following Wordpress guidelines, you can now compress your site using the ob_gzhandler handler or using the .htaccess method (if youre on an Apache host).
- Numerous small bugfixes
Download this release
Release Info
Developer | Richards Toolbox |
Plugin | Check and Enable GZIP compression |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- class.richards-toolbox.php +19 -0
- gzip-page.php +55 -0
- readme.txt +71 -0
- richards-toolbox.php +80 -0
class.richards-toolbox.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Richards_Toolbox {
|
4 |
+
function checkGZIPCompression($url) {
|
5 |
+
$result = file_get_contents('http://checkgzipcompression.com/js/checkgzip.json?url=' . $url);
|
6 |
+
return json_decode($result);
|
7 |
+
}
|
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';
|
18 |
+
}
|
19 |
+
}
|
gzip-page.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
//enable or disable
|
3 |
+
if(isset($_GET['enable-gzip']) && $_GET['enable-gzip'] == 1) {
|
4 |
+
$tb->enableGZIPCompression();
|
5 |
+
$gzipCheck->result->gzipenabled = 1;
|
6 |
+
$gzipCheck->result->summary = 'GZIP is enabled. Enjoy!';
|
7 |
+
|
8 |
+
} elseif(isset($_GET['disable-gzip']) && $_GET['disable-gzip']) {
|
9 |
+
$tb->disableGZIPCompression();
|
10 |
+
$gzipCheck->result->gzipenabled = 0;
|
11 |
+
$gzipCheck->result->summary = 'GZIP is disabled.';
|
12 |
+
}
|
13 |
+
?>
|
14 |
+
|
15 |
+
<div class="wrap">
|
16 |
+
<?php if(!$gzipCheck->error) : ?>
|
17 |
+
<h2><?php echo $gzipCheck->result->gzipenabled ? "You're blessed! It's GZIP Enabled.": "GZIP is not enabled :("; ?></h2>
|
18 |
+
<p><?php echo $gzipCheck->result->summary; ?></p>
|
19 |
+
<?php if( $gzipCheck->result->gzipenabled != 1 && $canEnableCheck->result->gzipenabled == 1) : ?>
|
20 |
+
<p>We can enable GZIP compression for you (and save <?php echo $canEnableCheck->result->percentagesaved ?>% bandwidth), but encourage you to first check the site in our preview mode. Click the link below to check if your website still works when enabling GZIP Compression.<br>
|
21 |
+
<br>
|
22 |
+
<a href="<?php echo get_site_url(); ?>?preview-gzip=1" target=_blank>Open my site in preview mode (temporarily enable GZIP Compression)</a>
|
23 |
+
</p>
|
24 |
+
<form method=GET action="">
|
25 |
+
<p class="submit">
|
26 |
+
<b>Did you check preview mode? Now you can enable gzip compression!</b>
|
27 |
+
<br /><br />
|
28 |
+
|
29 |
+
<input type="hidden" name="enable-gzip" value="1" />
|
30 |
+
<input type="hidden" name="page" value="richards-toolbox-gzip" />
|
31 |
+
<?php if($tb->isApache()) : ?>
|
32 |
+
<input type="checkbox" name="apache" value="1" checked=true /> Also enable for CSS, HTML, Javascript, XML and SVG.<br><br>
|
33 |
+
<?php endif; ?>
|
34 |
+
<input type="submit" name="submit" id="submit" class="button button-primary" value="Enable GZIP Compression">
|
35 |
+
</a>
|
36 |
+
|
37 |
+
</p>
|
38 |
+
</form>
|
39 |
+
<?php endif;
|
40 |
+
if($gzipCheck->result->gzipenabled == 1 && get_option('richards-toolbox-gzip-enabled')) : ?>
|
41 |
+
<p class="submit">
|
42 |
+
<a href="?page=richards-toolbox-gzip&disable-gzip=1">
|
43 |
+
<input type="submit" name="submit" id="submit" class="button button-primary" value="Disable GZIP
|
44 |
+
Compression">
|
45 |
+
</a>
|
46 |
+
</p>
|
47 |
+
<?php endif; ?>
|
48 |
+
<?php else:
|
49 |
+
?>
|
50 |
+
<h2>GZIP check</h2>
|
51 |
+
<p>Oops! Something went wrong :( It could be that you are on a local development environment, or that we couldn't contact <a href="http://checkgzipcompression.com">checkgzipcompression.com</a></a></p>
|
52 |
+
<p>We checked the url: <?php echo "<a href='$siteUrl'>$siteUrl</a>"; ?></p>
|
53 |
+
<?php endif; ?>
|
54 |
+
<p><br><br><em>Powered by <a href="http://richardstoolbox.com/" target=_blank>richardstoolbox.com</a> & The Marketing Gang</em></p>
|
55 |
+
</div>
|
readme.txt
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Plugin Name ===
|
2 |
+
Contributors: Richards Toolbox, ericmulder
|
3 |
+
Donate link: http://richardstoolbox.com/
|
4 |
+
Tags: gzip, compression, compressed, speed, cache,http, loading, performance, server
|
5 |
+
Requires at least: 3.0.1
|
6 |
+
Tested up to: 4.3.1
|
7 |
+
Stable tag: trunk
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
This handy tool checks if you have GZIP compression enabled, and makes it possible to turn on GZIP compression.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
GZIP compression is bundling (zipping) pages on a web server before the page is sent to the visitor.
|
16 |
+
This saves bandwidth and therefore increases the loading speed of the page significantly.
|
17 |
+
The visitors' web browser then automatically unzips the pages. This compressing and unzipping only takes a fraction of a second.
|
18 |
+
|
19 |
+
This plugin checks if your Wordpress site has GZIP compression enabled. Every time you run this check, your domain name will be sent to http://checkgzipcompression.com. We won’t sent any other private information.
|
20 |
+
|
21 |
+
== Installation ==
|
22 |
+
|
23 |
+
1. Upload `check-and-enable-gzip-compression.zip` to the `/wp-content/plugins/` directory
|
24 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
25 |
+
1. The plugin will let you know it GZIP is enabled,
|
26 |
+
1. When GZIP is not enabled, you can enabled it via the tools menu.
|
27 |
+
|
28 |
+
== Frequently Asked Questions ==
|
29 |
+
|
30 |
+
= What is GZIP compression? =
|
31 |
+
|
32 |
+
GZIP compression is bundling (zipping) pages on a web server before the page is sent to the visitor.
|
33 |
+
This saves bandwidth and therefore increases the loading speed of the page significantly.
|
34 |
+
The visitors' web browser then automatically unzips the pages. This compressing and unzipping only takes a fraction of a second.
|
35 |
+
|
36 |
+
GZIP compression is recommended for all types of text files such as:
|
37 |
+
- HTML (.html) but also all types of dynamic HTML (such as extension .php, .aspx)
|
38 |
+
- Textfiles (extension .txt)
|
39 |
+
- CSS and Javascript (extensie .css and .js)
|
40 |
+
- Webservices, such as WSDL, REST and JSON
|
41 |
+
|
42 |
+
GZIP compression is not recommended for non-text files, such as graphical files and .zip files because it hardly saves space and can therefore increase the loading time.
|
43 |
+
|
44 |
+
= Why is GZIP compression important? =
|
45 |
+
|
46 |
+
GZIP compression saves 50% to 80% bandwidth and will therefore significantly increase the website's loading speed.
|
47 |
+
The textfiles are compressed (zipped) on the web server after which the visitor's web browser will automatically unzip the files. This compressing and unzipping only takes a fraction of a second without the end user noticing.
|
48 |
+
|
49 |
+
Just about all the large websites worldwide use GZIP compression. For and actual overview of GZIP usage nowadays please check our [statistics page](http://checkgzipcompression.com/stats/).
|
50 |
+
|
51 |
+
== Screenshots ==
|
52 |
+
|
53 |
+
1. When enabled the plugin will tell you if GZIP is enabled.
|
54 |
+
2. The detail page will show you details about the GZIP compression state. And will make it possible to enable GZIP compression.
|
55 |
+
3. When GZIP compression is enabled, the plugin will tell you so.
|
56 |
+
4. You’ll receive an alert when GZIP is enabled.
|
57 |
+
|
58 |
+
== Changelog ==
|
59 |
+
|
60 |
+
= 1.0 =
|
61 |
+
* Plugin is mature enough for v1.0 ;)
|
62 |
+
* Better explanation of the preview mode
|
63 |
+
* Following Wordpress guidelines, you can now compress your site using the ‘ob_gzhandler’ handler or using the .htaccess method (if you’re on an Apache host).
|
64 |
+
* Numerous small bugfixes
|
65 |
+
|
66 |
+
= 0.2 =
|
67 |
+
* Added preview modus for testing
|
68 |
+
* If enabled, only front-end is GZIP compressed, not admin area
|
69 |
+
|
70 |
+
= 0.1 =
|
71 |
+
* First version of the plugin.
|
richards-toolbox.php
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Check and Enable GZIP compression
|
4 |
+
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 |
+
|
12 |
+
/*
|
13 |
+
* Now we set that function up to execute when the admin_notices action is called
|
14 |
+
*/
|
15 |
+
add_action( 'admin_notices', 'richard_toolbox_notices' );
|
16 |
+
function richard_toolbox_notices() {
|
17 |
+
global $current_user;
|
18 |
+
$user_id = $current_user->ID;
|
19 |
+
$hideError = get_user_meta($user_id, 'rt_gzip_error_ignore', true);
|
20 |
+
$hideSuccess = get_user_meta($user_id, 'rt_gzip_success_ignore', true);
|
21 |
+
if(!$hideError || !$hideSuccess) {
|
22 |
+
require_once(dirname(__FILE__) . '/class.richards-toolbox.php');
|
23 |
+
$tb = new Richards_Toolbox();
|
24 |
+
$siteUrl = get_site_url();
|
25 |
+
$gzipCheck = $tb->checkGZIPCompression($siteUrl);
|
26 |
+
if(!$gzipCheck->result->gzipenabled && !$gzipCheck->error && !$hideError) {
|
27 |
+
echo '<div class="error"><p><strong>GZIP compression is disabled. Please go to the <a href="'.admin_url('tools.php?page=richards-toolbox-gzip').'">plugin admin page</a> to enable GZIP compression and make your site '.$gzipCheck->result->percentagesaved.'% smaller!</strong> | <a href="'.admin_url('tools.php?page=richards-toolbox-gzip&rt_gzip_error_ignore').'">Remove alert</a></p></div>';
|
28 |
+
} elseif($gzipCheck->result->gzipenabled && !$gzipCheck->error && !$hideSuccess) {
|
29 |
+
echo '<div class="updated"><p><strong>GZIP compression is enabled. Good job!</strong> | <a href="'.$siteUrl.'/wp-admin/tools.php?page=richards-toolbox-gzip&rt_gzip_success_ignore">Remove alert</a></p></div>';
|
30 |
+
}
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
add_action('admin_init', 'rt_gzip_ignore');
|
35 |
+
function rt_gzip_ignore() {
|
36 |
+
global $current_user;
|
37 |
+
$user_id = $current_user->ID;
|
38 |
+
/* If user clicks to ignore the notice, add that to their user meta */
|
39 |
+
if ( isset($_GET['rt_gzip_success_ignore']) ) {
|
40 |
+
add_user_meta($user_id, 'rt_gzip_success_ignore', 'true', true);
|
41 |
+
}
|
42 |
+
|
43 |
+
if ( isset($_GET['rt_gzip_error_ignore']) ) {
|
44 |
+
add_user_meta($user_id, 'rt_gzip_error_ignore', 'true', true);
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
// Add extra page in tools
|
52 |
+
/** Step 2 (from text above). */
|
53 |
+
add_action( 'admin_menu', 'toolbox_plugin_menu' );
|
54 |
+
|
55 |
+
/** Step 1. */
|
56 |
+
function toolbox_plugin_menu() {
|
57 |
+
add_management_page( __('GZIP Compression','richards-toolbox'), __('GZIP Compression','richards-toolbox'), 'manage_options', 'richards-toolbox-gzip', 'gzip_compression_page' );
|
58 |
+
}
|
59 |
+
|
60 |
+
/** Step 3. */
|
61 |
+
function gzip_compression_page() {
|
62 |
+
if ( !current_user_can( 'manage_options' ) ) {
|
63 |
+
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
|
64 |
+
}
|
65 |
+
require_once(dirname(__FILE__) . '/class.richards-toolbox.php');
|
66 |
+
$tb = new Richards_Toolbox();
|
67 |
+
$siteUrl = get_site_url();
|
68 |
+
$gzipCheck = $tb->checkGZIPCompression($siteUrl);
|
69 |
+
$canEnableCheck = $tb->checkGZIPCompression(urlencode($siteUrl . '?preview-gzip=1'));
|
70 |
+
require(dirname(__FILE__) . '/gzip-page.php');
|
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 |
+
}
|
80 |
+
?>
|