-
Notifications
You must be signed in to change notification settings - Fork 0
/
html-markup-indenter.php
49 lines (42 loc) · 1.37 KB
/
html-markup-indenter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
Plugin Name: HTML Markup Indenter
Plugin URI: https://github.com/CreunaFI/html-markup-indenter
Description: Indents the HTML markup output by WordPress
Version: 2.0.1
Author: Johannes Siipola
Author URI: https://siipo.la
*/
defined('ABSPATH') or die();
require 'library/dindent/src/Indenter.php';
// Thanks to
// https://stackoverflow.com/questions/772510/wordpress-filter-to-modify-final-html-output/22818089#22818089
add_action('plugins_loaded', function () {
ob_start();
});
add_action('shutdown', function () {
if (extension_loaded('mbstring') && html_markup_indenter_is_html() && !is_user_logged_in()) {
$final = '';
$levels = ob_get_level();
for ($i = 0; $i < $levels; $i++) {
$final = $final . ob_get_clean();
}
$indenter = new \Gajus\Dindent\Indenter();
echo $indenter->indent($final);
}
}, 0);
function html_markup_indenter_is_html() {
foreach (headers_list() as $header) {
if (strpos($header, "Content-Type: text/html") !== false) {
return true;
}
}
return false;
}
add_action('admin_notices', function() {
if (!extension_loaded('mbstring')) {
echo '<div class="notice notice-warning"><p>';
echo __("Mbstring PHP extension is not loaded. HTML Markup Indenter has been disabled.", 'html-markup-indenter');
echo '</p></div>';
}
});