From e306ef1c8d1dd7cb3637aaeb5b6c2aba35c7331e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 23 Feb 2025 20:19:47 -0800 Subject: [PATCH 1/7] Add path data for TT5 theme stylesheet --- src/wp-content/themes/twentytwentyfive/functions.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wp-content/themes/twentytwentyfive/functions.php b/src/wp-content/themes/twentytwentyfive/functions.php index ddb42a89f2b46..1ff1934c374ed 100644 --- a/src/wp-content/themes/twentytwentyfive/functions.php +++ b/src/wp-content/themes/twentytwentyfive/functions.php @@ -55,6 +55,11 @@ function twentytwentyfive_enqueue_styles() { array(), wp_get_theme()->get( 'Version' ) ); + wp_style_add_data( + 'twentytwentyfive-style', + 'path', + get_parent_theme_file_path( 'style.css' ) + ); } endif; add_action( 'wp_enqueue_scripts', 'twentytwentyfive_enqueue_styles' ); From c9702207dea9bdf3019ad256b3e79769dcd1bb8f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 23 Feb 2025 20:20:09 -0800 Subject: [PATCH 2/7] Try minifying theme stylesheet at runtime --- .../themes/twentytwentyfive/functions.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/wp-content/themes/twentytwentyfive/functions.php b/src/wp-content/themes/twentytwentyfive/functions.php index 1ff1934c374ed..8ff845bf96c27 100644 --- a/src/wp-content/themes/twentytwentyfive/functions.php +++ b/src/wp-content/themes/twentytwentyfive/functions.php @@ -64,6 +64,58 @@ function twentytwentyfive_enqueue_styles() { endif; add_action( 'wp_enqueue_scripts', 'twentytwentyfive_enqueue_styles' ); +if ( ! function_exists( 'twentytwentyfive_get_theme_style_css' ) ) : + /** + * Gets the CSS from the theme stylesheet without comments. + * + * @since Twenty Twenty-Five n.e.x.t + * + * @return string + */ + function twentytwentyfive_get_theme_style_css(): string { + static $css = null; + if ( null !== $css ) { + return $css; + } + $css = file_get_contents( get_parent_theme_file_path( 'style.css' ) ); // 2,505 bytes before minification + if ( ! SCRIPT_DEBUG ) { + // Strip out CSS comments, collapse whitespace, and remove unneeded spaces in this specific CSS file. + // This works for TT5's theme CSS, but it is not a complete solution applicable to any stylesheet. + // For a general solution, a proper CSS tokenizer should be used. Alternatively, the CSS should go a build step so that there is a style.min.css minified version available! + $css = trim( preg_replace( '#/\*.*?\*/\s*#s', '', $css ) ); + $css = preg_replace( '/\s+/', ' ', $css ); + $css = preg_replace( '/(?<=[{};:,+]) | (?=[{};:,!+])/', '', $css ); + $css = str_replace( ';}', '}', $css ); + // 586 bytes after minification + } + return $css; + } + + add_filter( + 'pre_wp_filesize', + static function ( $size, $path ) { + if ( get_parent_theme_file_path( 'style.css' ) === $path ) { + $size = strlen( twentytwentyfive_get_theme_style_css() ); + } + return $size; + }, + 10, + 2 + ); + + add_action( + 'wp_head', + static function () { + $style = wp_styles()->query( 'twentytwentyfive-style' ); + + if ( $style && $style->src === false ) { + $style->extra['after'][0] = twentytwentyfive_get_theme_style_css(); + } + }, + 2 + ); +endif; + // Registers custom block styles. if ( ! function_exists( 'twentytwentyfive_block_styles' ) ) : /** From a04081284fd8907cb7a60012f19b37604d5c2875 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 23 Feb 2025 20:20:15 -0800 Subject: [PATCH 3/7] Revert "Try minifying theme stylesheet at runtime" This reverts commit c9702207dea9bdf3019ad256b3e79769dcd1bb8f. --- .../themes/twentytwentyfive/functions.php | 52 ------------------- 1 file changed, 52 deletions(-) diff --git a/src/wp-content/themes/twentytwentyfive/functions.php b/src/wp-content/themes/twentytwentyfive/functions.php index 8ff845bf96c27..1ff1934c374ed 100644 --- a/src/wp-content/themes/twentytwentyfive/functions.php +++ b/src/wp-content/themes/twentytwentyfive/functions.php @@ -64,58 +64,6 @@ function twentytwentyfive_enqueue_styles() { endif; add_action( 'wp_enqueue_scripts', 'twentytwentyfive_enqueue_styles' ); -if ( ! function_exists( 'twentytwentyfive_get_theme_style_css' ) ) : - /** - * Gets the CSS from the theme stylesheet without comments. - * - * @since Twenty Twenty-Five n.e.x.t - * - * @return string - */ - function twentytwentyfive_get_theme_style_css(): string { - static $css = null; - if ( null !== $css ) { - return $css; - } - $css = file_get_contents( get_parent_theme_file_path( 'style.css' ) ); // 2,505 bytes before minification - if ( ! SCRIPT_DEBUG ) { - // Strip out CSS comments, collapse whitespace, and remove unneeded spaces in this specific CSS file. - // This works for TT5's theme CSS, but it is not a complete solution applicable to any stylesheet. - // For a general solution, a proper CSS tokenizer should be used. Alternatively, the CSS should go a build step so that there is a style.min.css minified version available! - $css = trim( preg_replace( '#/\*.*?\*/\s*#s', '', $css ) ); - $css = preg_replace( '/\s+/', ' ', $css ); - $css = preg_replace( '/(?<=[{};:,+]) | (?=[{};:,!+])/', '', $css ); - $css = str_replace( ';}', '}', $css ); - // 586 bytes after minification - } - return $css; - } - - add_filter( - 'pre_wp_filesize', - static function ( $size, $path ) { - if ( get_parent_theme_file_path( 'style.css' ) === $path ) { - $size = strlen( twentytwentyfive_get_theme_style_css() ); - } - return $size; - }, - 10, - 2 - ); - - add_action( - 'wp_head', - static function () { - $style = wp_styles()->query( 'twentytwentyfive-style' ); - - if ( $style && $style->src === false ) { - $style->extra['after'][0] = twentytwentyfive_get_theme_style_css(); - } - }, - 2 - ); -endif; - // Registers custom block styles. if ( ! function_exists( 'twentytwentyfive_block_styles' ) ) : /** From 41c9e75dc30d6ddfdeb25d1a38a4679916fabfba Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 23 Feb 2025 21:07:34 -0800 Subject: [PATCH 4/7] Minify T25 style.css as part of core build --- .gitignore | 1 + Gruntfile.js | 3 ++- src/wp-content/themes/twentytwentyfive/functions.php | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 648c711b21f26..8ab4cc7090050 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ wp-tests-config.php /src/wp-includes/blocks/**/*.css /src/wp-includes/blocks/**/*.js /src/wp-includes/blocks/**/*.js.map +/src/wp-content/themes/twentytwentyfive/style.min.css /packagehash.txt /artifacts /setup.log diff --git a/Gruntfile.js b/Gruntfile.js index 09ce2317e2b51..74eb8790b21aa 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -545,7 +545,8 @@ module.exports = function(grunt) { 'wp-admin/css/*.css', '!wp-admin/css/wp-admin*.css', 'wp-includes/css/*.css', - 'wp-includes/js/mediaelement/wp-mediaelement.css' + 'wp-includes/js/mediaelement/wp-mediaelement.css', + 'wp-content/themes/twentytwentyfive/style.css' ] }, rtl: { diff --git a/src/wp-content/themes/twentytwentyfive/functions.php b/src/wp-content/themes/twentytwentyfive/functions.php index 1ff1934c374ed..616624bc260e0 100644 --- a/src/wp-content/themes/twentytwentyfive/functions.php +++ b/src/wp-content/themes/twentytwentyfive/functions.php @@ -49,16 +49,17 @@ function twentytwentyfive_editor_style() { * @return void */ function twentytwentyfive_enqueue_styles() { + $file = 'style' . ( SCRIPT_DEBUG ? '.css' : '.min.css' ); wp_enqueue_style( 'twentytwentyfive-style', - get_parent_theme_file_uri( 'style.css' ), + get_parent_theme_file_uri( $file ), array(), wp_get_theme()->get( 'Version' ) ); wp_style_add_data( 'twentytwentyfive-style', 'path', - get_parent_theme_file_path( 'style.css' ) + get_parent_theme_file_path( $file ) ); } endif; From 65f353cd762c9f0d44aaf2afbbefcb26636883d1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 24 Feb 2025 15:15:18 -0800 Subject: [PATCH 5/7] Add path data to T22 stylesheet and minify --- Gruntfile.js | 1 + .../themes/twentytwentytwo/functions.php | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 74eb8790b21aa..b96ccc64b3f66 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -546,6 +546,7 @@ module.exports = function(grunt) { '!wp-admin/css/wp-admin*.css', 'wp-includes/css/*.css', 'wp-includes/js/mediaelement/wp-mediaelement.css', + 'wp-content/themes/twentytwentytwo/style.css', 'wp-content/themes/twentytwentyfive/style.css' ] }, diff --git a/src/wp-content/themes/twentytwentytwo/functions.php b/src/wp-content/themes/twentytwentytwo/functions.php index 8f93dcfc5f53c..17f4e48a54a2d 100644 --- a/src/wp-content/themes/twentytwentytwo/functions.php +++ b/src/wp-content/themes/twentytwentytwo/functions.php @@ -45,15 +45,19 @@ function twentytwentytwo_styles() { $theme_version = wp_get_theme()->get( 'Version' ); $version_string = is_string( $theme_version ) ? $theme_version : false; - wp_register_style( + + $file = 'style' . ( SCRIPT_DEBUG ? '.css' : '.min.css' ); + wp_enqueue_style( 'twentytwentytwo-style', - get_template_directory_uri() . '/style.css', + get_parent_theme_file_uri( $file ), array(), $version_string ); - - // Enqueue theme stylesheet. - wp_enqueue_style( 'twentytwentytwo-style' ); + wp_style_add_data( + 'twentytwentytwo-style', + 'path', + get_parent_theme_file_path( $file ) + ); } endif; From 7b87a85d98e37b9b60b69d587e50534e0aa98a1e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 24 Feb 2025 15:34:02 -0800 Subject: [PATCH 6/7] Add T22 and T25 minified CSS to gitignore Co-authored-by: Stephen A. Bernhardt --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8ab4cc7090050..d7e870c0faa0a 100644 --- a/.gitignore +++ b/.gitignore @@ -39,7 +39,6 @@ wp-tests-config.php /src/wp-includes/blocks/**/*.css /src/wp-includes/blocks/**/*.js /src/wp-includes/blocks/**/*.js.map -/src/wp-content/themes/twentytwentyfive/style.min.css /packagehash.txt /artifacts /setup.log @@ -89,6 +88,10 @@ wp-tests-config.php /src/wp-content/themes/twentytwentyone/node_modules /src/wp-content/themes/twentytwenty/node_modules +# Minified files in bundled themes +/src/wp-content/themes/twentytwentytwo/*.min.css +/src/wp-content/themes/twentytwentyfive/*.min.css + # Operating system specific files .DS_Store From d836dcb30927e4fe85fd7701930b6a1ed261dea3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 14 Oct 2025 23:12:57 -0700 Subject: [PATCH 7/7] Remove redundant changes after b56b386 --- .gitignore | 4 ---- Gruntfile.js | 4 +--- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 5c1dd82835844..58af6fe2fc10d 100644 --- a/.gitignore +++ b/.gitignore @@ -95,10 +95,6 @@ wp-tests-config.php /src/wp-content/themes/twentytwentytwo/*.min.css /src/wp-content/themes/twentytwentyfive/*.min.css -# Minified files in bundled themes -/src/wp-content/themes/twentytwentytwo/*.min.css -/src/wp-content/themes/twentytwentyfive/*.min.css - # Operating system specific files .DS_Store diff --git a/Gruntfile.js b/Gruntfile.js index 82f2a0967bfe7..216dbfae64945 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -545,9 +545,7 @@ module.exports = function(grunt) { 'wp-admin/css/*.css', '!wp-admin/css/wp-admin*.css', 'wp-includes/css/*.css', - 'wp-includes/js/mediaelement/wp-mediaelement.css', - 'wp-content/themes/twentytwentytwo/style.css', - 'wp-content/themes/twentytwentyfive/style.css' + 'wp-includes/js/mediaelement/wp-mediaelement.css' ] }, rtl: {