Created
October 25, 2016 09:42
-
-
Save Digiover/cac8ea983856dd07b476ca915138146c to your computer and use it in GitHub Desktop.
Diff for cache_enabler_disk.class.php to add wp_is_mobile() support to KeyCDN's Cache Enabler plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- cache_enabler_disk.class.php.org 2016-09-26 07:24:22.000000000 +0200 | |
+++ cache_enabler_disk.class.php 2016-10-24 16:33:54.145108306 +0200 | |
@@ -24,7 +24,9 @@ | |
*/ | |
const FILE_HTML = 'index.html'; | |
+ const FILE_HTML_MOBILE = 'index-mobile.html'; | |
const FILE_GZIP = 'index.html.gz'; | |
+ const FILE_GZIP_MOBILE = 'index-mobile.html.gz'; | |
const FILE_WEBP_HTML = 'index-webp.html'; | |
const FILE_WEBP_GZIP = 'index-webp.html.gz'; | |
@@ -169,7 +171,9 @@ | |
); | |
@unlink($path.self::FILE_HTML); | |
+ @unlink($path.self::FILE_HTML_MOBILE); | |
@unlink($path.self::FILE_GZIP); | |
+ @unlink($path.self::FILE_GZIP_MOBILE); | |
@unlink($path.self::FILE_WEBP_HTML); | |
@unlink($path.self::FILE_WEBP_GZIP); | |
} | |
@@ -218,15 +222,29 @@ | |
} | |
// check encoding and deliver gzip file if support | |
- if ( $http_accept_encoding && ( strpos($http_accept_encoding, 'gzip') !== false ) && is_readable( self::_file_gzip() ) ) { | |
- header('Content-Encoding: gzip'); | |
- readfile( self::_file_gzip() ); | |
- exit; | |
+ if ( $http_accept_encoding && ( strpos($http_accept_encoding, 'gzip') !== false ) && is_readable( self::_file_gzip() ) ) { | |
+ if ( wp_is_mobile() ) { | |
+ header('Content-Encoding: gzip'); | |
+ readfile( self::_file_gzip_mobile() ); | |
+ exit; | |
+ } | |
+ else { | |
+ header('Content-Encoding: gzip'); | |
+ readfile( self::_file_gzip() ); | |
+ exit; | |
+ } | |
} | |
// deliver cached file (default) | |
- readfile( self::_file_html() ); | |
- exit; | |
+ if ( wp_is_mobile() ) { | |
+ readfile( self::_file_mobile_html() ); | |
+ exit; | |
+ } | |
+ else { | |
+ readfile( self::_file_html() ); | |
+ exit; | |
+ } | |
+ | |
} | |
@@ -273,14 +291,25 @@ | |
// cache enabler options | |
$options = Cache_Enabler::$options; | |
- // create files | |
- self::_create_file( self::_file_html(), $data.$cache_signature." (html) -->" ); | |
- | |
- // create pre-compressed file | |
- if ($options['compress']) { | |
- self::_create_file( self::_file_gzip(), gzencode($data.$cache_signature." (html gzip) -->", 9) ); | |
+ if ( wp_is_mobile() ) { | |
+ // create files | |
+ if ($options['compress']) { | |
+ self::_create_file( self::_file_gzip_mobile(), gzencode($data.$cache_signature." (html mobile gzip) -->", 9) ); | |
+ } | |
+ else { | |
+ self::_create_file( self::_file_mobile_html(), $data.$cache_signature." (html mobile) -->" ); | |
+ } | |
+ } | |
+ else { | |
+ // create files | |
+ // create pre-compressed file | |
+ if ($options['compress']) { | |
+ self::_create_file( self::_file_gzip(), gzencode($data.$cache_signature." (html gzip) -->", 9) ); | |
+ } | |
+ else { | |
+ self::_create_file( self::_file_html(), $data.$cache_signature." (html) -->" ); | |
+ } | |
} | |
- | |
// create webp supported files | |
if ($options['webp']) { | |
// magic regex rule | |
@@ -458,7 +487,6 @@ | |
return trailingslashit($path); | |
} | |
- | |
/** | |
* get file path | |
* | |
@@ -472,6 +500,19 @@ | |
return self::_file_path(). self::FILE_HTML; | |
} | |
+ /** | |
+ * get mobile file path | |
+ * | |
+ * @since 1.0.0 | |
+ * @change 1.0.7 | |
+ * | |
+ * @return string path to the mobile html file | |
+ */ | |
+ | |
+ private static function _file_mobile_html() { | |
+ return self::_file_path(). self::FILE_HTML_MOBILE; | |
+ } | |
+ | |
/** | |
* get gzip file path | |
@@ -486,6 +527,18 @@ | |
return self::_file_path(). self::FILE_GZIP; | |
} | |
+ /** | |
+ * get gzip file path | |
+ * | |
+ * @since 1.0.1 | |
+ * @change 1.0.7 | |
+ * | |
+ * @return string path to the gzipped mobile html file | |
+ */ | |
+ | |
+ private static function _file_gzip_mobile() { | |
+ return self::_file_path(). self::FILE_GZIP_MOBILE; | |
+ } | |
/** | |
* get webp file path | |
@@ -638,3 +691,4 @@ | |
} | |
} | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference for this gist: https://wordpress.org/support/topic/mobile-device-support-2/