From 6265e317ec6761bdb049c3694654b89c4f9475b7 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 23 Feb 2023 00:50:11 +0700 Subject: [PATCH 1/2] remove white spaces from theme slugs --- admin/class-create-block-theme-admin.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/admin/class-create-block-theme-admin.php b/admin/class-create-block-theme-admin.php index 605c90e6..cbde3637 100644 --- a/admin/class-create-block-theme-admin.php +++ b/admin/class-create-block-theme-admin.php @@ -469,6 +469,7 @@ function get_theme_slug( $new_theme_name ) { $old_slug = wp_get_theme()->get( 'TextDomain' ); $new_slug = sanitize_title( $new_theme_name ); + $new_slug = preg_replace('/\s+/', '', $new_slug); // Remove spaces if( ! str_contains( $old_slug , '-') && str_contains( $new_slug, '-' ) ) { return str_replace( '-', '', $new_slug ); @@ -494,7 +495,6 @@ function filter_theme_template( $template, $export_type, $path, $old_slug, $new_ return false; } - $template->content = _remove_theme_attribute_in_block_template_content( $template->content ); // NOTE: Dashes are encoded as \u002d in the content that we get (noteably in things like css variables used in templates) // This replaces that with dashes again. We should consider decoding the entire string but that is proving difficult. @@ -644,7 +644,8 @@ function make_html_media_local ( $html ) { if ( $style ) { preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $style, $match); $urls = $match[0]; - foreach ( $urls as $url ) { + $template_content = $template->content; + foreach ( $urls as $url ) { if ( $this->is_absolute_url( $url ) ) { $html = str_replace( $url, $this->make_relative_media_url( $url ), $html ); } @@ -704,15 +705,6 @@ function make_mediatext_block_local ( $block ) { return $block; } - function add_theme_attr_to_template_part_block ( $block ) { - // The template parts included in the patterns need to indicate the theme they belong to - if ( 'core/template-part' === $block[ 'blockName' ] ) { - $block['attrs']['theme'] = ( $_POST['theme']['type'] === "export" || $_POST['theme']['type'] === "save" ) - ? strtolower( wp_get_theme()->get( 'Name' ) ) - : $_POST['theme']['name']; - } - return $block; - } function make_media_blocks_local ( $nested_blocks ) { $new_blocks = []; @@ -729,9 +721,6 @@ function make_media_blocks_local ( $nested_blocks ) { case 'core/media-text': $block = $this->make_mediatext_block_local( $block ); break; - case 'core/template-part': - $block = $this->add_theme_attr_to_template_part_block( $block ); - break; } // recursive call for inner blocks if ( !empty ( $block['innerBlocks'] ) ) { From 6e1a9aee0021d8f854941e47980172f70167860a Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 23 Feb 2023 00:54:38 +0700 Subject: [PATCH 2/2] remove unused variable --- admin/class-create-block-theme-admin.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/admin/class-create-block-theme-admin.php b/admin/class-create-block-theme-admin.php index cbde3637..48eb9ef3 100644 --- a/admin/class-create-block-theme-admin.php +++ b/admin/class-create-block-theme-admin.php @@ -644,8 +644,7 @@ function make_html_media_local ( $html ) { if ( $style ) { preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $style, $match); $urls = $match[0]; - $template_content = $template->content; - foreach ( $urls as $url ) { + foreach ( $urls as $url ) { if ( $this->is_absolute_url( $url ) ) { $html = str_replace( $url, $this->make_relative_media_url( $url ), $html ); }