Skip to content

Commit

Permalink
ignore utility directories
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Mar 10, 2022
1 parent 08af4d0 commit 6d9825e
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions lib/compat/wordpress-6.0/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}
}
}

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 6d9825e

Please sign in to comment.