-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* StagON Name: HTML Minifier | ||
* StagON Text Domain: html-minifier | ||
* StagON URI: https://stagphp.io | ||
* StagON Description: This StagON minifies the HTML output | ||
* Version: 1.0 | ||
* Author: StagPHP | ||
* License: GPL3 | ||
* License URI: https://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
|
||
function sanitize_output($buffer) { | ||
$search = array( | ||
'/\>[^\S ]+/s', // strip white spaces after tags, except space | ||
'/[^\S ]+\</s', // strip white spaces before tags, except space | ||
'/(\s)+/s', // shorten multiple whitespace sequences | ||
'/<!--(.|\s)*?-->/' // Remove HTML comments | ||
); | ||
|
||
$replace = array( | ||
'>', | ||
'<', | ||
'\\1', | ||
'' | ||
); | ||
|
||
$buffer = preg_replace($search, $replace, $buffer); | ||
|
||
return $buffer; | ||
} | ||
|
||
function minified_output(){ | ||
echo sanitize_output(ob_get_clean()); | ||
} | ||
|
||
stag_add_action('processed', 'minified_output', TRUE); |