From 1b0240858ff0589c3b65688b74efc1198b7c2446 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Thu, 10 Mar 2022 12:24:45 +0000 Subject: [PATCH] ignore utility directories --- .../wordpress-6.0/block-template-utils.php | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/compat/wordpress-6.0/block-template-utils.php b/lib/compat/wordpress-6.0/block-template-utils.php index 0979a9e16c099..eb578ecd1d3cc 100644 --- a/lib/compat/wordpress-6.0/block-template-utils.php +++ b/lib/compat/wordpress-6.0/block-template-utils.php @@ -7,6 +7,23 @@ * @package gutenberg */ +/** + * Filters theme directories that should be ignored during export. + * + * @since 6.0.0 + * @return Bool Whether this file is in an ignored directory. + */ +function gutenberg_directory_ignored( $path ) { + $directories_to_ignore = array( '.git', 'node_modules', 'vendor' ); + foreach( $directories_to_ignore as $directory ) { + if ( strpos( $path, $directory ) === 0 ) { + return true; + } + } + + return false; +} + /** * Creates an export of the current templates and * template parts from the site editor at the @@ -46,14 +63,16 @@ function gutenberg_generate_block_templates_export_file() { ); // Make a copy of the current theme. - foreach ($theme_files as $name => $file ) { + foreach ( $theme_files as $name => $file ) { // Skip directories as they are added automatically. if ( ! $file->isDir() ) { // Get real and relative path for current file. $file_path = wp_normalize_path( $file->getRealPath() ); - $relative_path = substr( $file_path, strlen( $theme_path) + 1 ); + $relative_path = substr( $file_path, strlen( $theme_path ) + 1 ); - $zip->addFile( $file_path, $theme_name . '/' . $relative_path ); + if ( ! gutenberg_directory_ignored( $relative_path ) ) { + $zip->addFile( $file_path, $theme_name . '/' . $relative_path ); + } } } @@ -86,16 +105,6 @@ function gutenberg_generate_block_templates_export_file() { wp_json_encode( $tree->get_data(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); - $zip->addFile( - wp_normalize_path( get_stylesheet_directory() ) . '/index.php', - 'theme/index.php' - ); - - $zip->addFile( - wp_normalize_path( get_stylesheet_directory() ) . '/style.css', - 'theme/style.css' - ); - // Save changes to the zip file. $zip->close();