| 1 |
<?php |
| 2 |
namespace Kibo\PhastPlugins\PhastPress\Compat; |
| 3 |
|
| 4 |
class Slimstat { |
| 5 |
public function setup() { |
| 6 |
// Don't delay Slimstat Analytics. |
| 7 |
add_filter('wp_print_scripts', function () { |
| 8 |
if (!wp_script_is('wp_slimstat')) { |
| 9 |
return; |
| 10 |
} |
| 11 |
|
| 12 |
// Don't defer the tracker script. |
| 13 |
add_filter('script_loader_tag', function ($tag, $handle, $src) { |
| 14 |
if ($handle !== 'wp_slimstat') { |
| 15 |
return $tag; |
| 16 |
} |
| 17 |
return preg_replace('~<script\b~', '$0 data-phast-no-defer async', $tag); |
| 18 |
}, 10, 3); |
| 19 |
|
| 20 |
// Don't defer the inline parameters script. |
| 21 |
ob_start(function ($chunk) { |
| 22 |
return preg_replace('~(<script\b)([^>]*>\s*(/\*.*?\*/)?\s*var\s+SlimStatParams\s*=)~', '$1 data-phast-no-defer$2', $chunk); |
| 23 |
}, 8192); |
| 24 |
}); |
| 25 |
} |
| 26 |
} |
| 27 |
|