PluginProbe
WP Coder – Insert & Manage Code Snippets / 3.2.1
WP Coder – Insert & Manage Code Snippets v3.2.1
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
wp-coder / classes / Optimization / CSSMinifier.php

CSSMinifier.php in WP Coder – Insert & Manage Code Snippets 3.2.1, at classes/Optimization/CSSMinifier.php

19 lines 553 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPCoder\Optimization;
4
5 // Exit if accessed directly.
6 defined( 'ABSPATH' ) || exit;
7
8 class CSSMinifier {
9
10 public static function minify($css): string {
11 $css = preg_replace('/\/\*(.*?)\*\//s', '', $css); // Remove comments
12 $css = preg_replace('/\s+/', ' ', $css); // Remove whitespace
13 $css = preg_replace('/;\s*/', ';', $css); // Remove spaces after semicolons
14 $css = preg_replace('/: /', ':', $css); // Remove spaces after colons
15 $css = preg_replace('/\s{2,}/', ' ', $css); // Remove multiple spaces
16 return trim($css);
17 }
18
19 }