diff --git a/assets/boilerplate/functions.php b/assets/boilerplate/functions.php new file mode 100644 index 00000000..ec2bcf29 --- /dev/null +++ b/assets/boilerplate/functions.php @@ -0,0 +1,55 @@ +get( 'Version' ) + ); + } + add_action( 'wp_enqueue_scripts', 'theme_enqueue_style' ); +} + +if ( ! function_exists( 'theme_enqueue_editor_style' ) ) { + /** + * Enqueue the theme's main stylesheet in the block editor. + * + * This function enqueues the `style.css` file in the block editor to ensure + * that the editor styles match the frontend styles. It uses the + * `add_editor_style` function which is specifically designed for this purpose. + * + * Usage: Hooked into 'after_setup_theme'. + * + * @since 1.0.0 + * + * @see https://developer.wordpress.org/reference/functions/add_editor_style/ + * + * @return void + */ + function theme_enqueue_editor_style() { + add_editor_style( 'style.css' ); + } + add_action( 'after_setup_theme', 'theme_enqueue_editor_style' ); +} diff --git a/includes/create-theme/theme-create.php b/includes/create-theme/theme-create.php index 736f0b1b..d467c5d8 100644 --- a/includes/create-theme/theme-create.php +++ b/includes/create-theme/theme-create.php @@ -124,6 +124,13 @@ public static function create_blank_theme( $theme, $screenshot ) { } } + // Ensure functions.php is present to enqueue style.css + $functions_src = $source . DIRECTORY_SEPARATOR . 'functions.php'; + $functions_dest = $blank_theme_path . DIRECTORY_SEPARATOR . 'functions.php'; + if ( file_exists( $functions_src ) ) { + copy( $functions_src, $functions_dest ); + } + // Overwrite default screenshot if one is provided. if ( static::is_valid_screenshot( $screenshot ) ) { file_put_contents(