From 5f6de3dae619bad2e7dd4602e35c713cb74fb955 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Mon, 3 Apr 2023 15:12:16 -0300 Subject: [PATCH 1/5] fixing textdaomin and template settings of generated themes --- admin/class-create-block-theme-admin.php | 27 ++++++++++++++++++------ admin/create-theme/theme-styles.php | 3 ++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/admin/class-create-block-theme-admin.php b/admin/class-create-block-theme-admin.php index 1348415a..3f91353f 100644 --- a/admin/class-create-block-theme-admin.php +++ b/admin/class-create-block-theme-admin.php @@ -95,6 +95,8 @@ function export_child_theme( $theme ) { * Create a sibling theme of the activated theme */ function create_sibling_theme( $theme, $screenshot ) { + $theme_slug = Theme_Utils::get_theme_slug( $theme['name'] ); + // Sanitize inputs. $theme['name'] = sanitize_text_field( $theme['name'] ); $theme['description'] = sanitize_text_field( $theme['description'] ); @@ -102,8 +104,9 @@ function create_sibling_theme( $theme, $screenshot ) { $theme['author'] = sanitize_text_field( $theme['author'] ); $theme['author_uri'] = sanitize_text_field( $theme['author_uri'] ); $theme['tags_custom'] = sanitize_text_field( $theme['tags_custom'] ); - $theme['slug'] = Theme_Utils::get_theme_slug( $theme['name'] ); + $theme['slug'] = $theme_slug; $theme['template'] = wp_get_theme()->get( 'Template' ); + $theme['text_domain'] = $theme_slug; // Create ZIP file in the temporary directory. $filename = tempnam( get_temp_dir(), $theme['slug'] ); @@ -152,6 +155,8 @@ function create_sibling_theme( $theme, $screenshot ) { * Clone the activated theme to create a new theme */ function clone_theme( $theme, $screenshot ) { + $theme_slug = Theme_Utils::get_theme_slug( $theme['name'] ); + // Sanitize inputs. $theme['name'] = sanitize_text_field( $theme['name'] ); $theme['description'] = sanitize_text_field( $theme['description'] ); @@ -159,9 +164,10 @@ function clone_theme( $theme, $screenshot ) { $theme['author'] = sanitize_text_field( $theme['author'] ); $theme['author_uri'] = sanitize_text_field( $theme['author_uri'] ); $theme['tags_custom'] = sanitize_text_field( $theme['tags_custom'] ); - $theme['slug'] = Theme_Utils::get_theme_slug( $theme['name'] ); - $theme['template'] = wp_get_theme()->get( 'Template' ); + $theme['slug'] = $theme_slug; + $theme['template'] = ''; $theme['original_theme'] = wp_get_theme()->get( 'Name' ); + $theme['text_domain'] = $theme_slug; // Use previous theme's tags if custom tags are empty. if ( empty( $theme['tags_custom'] ) ) { @@ -236,6 +242,10 @@ public function register_theme_export() { * Create a child theme of the activated theme */ function create_child_theme( $theme, $screenshot ) { + + $parent_theme_slug = Theme_Utils::get_theme_slug( wp_get_theme()->get( 'Name' ) ); + $child_theme_slug = Theme_Utils::get_theme_slug( $theme['name'] ); + // Sanitize inputs. $theme['name'] = sanitize_text_field( $theme['name'] ); $theme['description'] = sanitize_text_field( $theme['description'] ); @@ -243,8 +253,10 @@ function create_child_theme( $theme, $screenshot ) { $theme['author'] = sanitize_text_field( $theme['author'] ); $theme['author_uri'] = sanitize_text_field( $theme['author_uri'] ); $theme['tags_custom'] = sanitize_text_field( $theme['tags_custom'] ); - $theme['slug'] = Theme_Utils::get_theme_slug( $theme['name'] ); - $theme['template'] = wp_get_theme()->get( 'TextDomain' ); + + $theme['text_domain'] = $child_theme_slug; + $theme['template'] = $parent_theme_slug; + $theme['slug'] = $child_theme_slug; // Create ZIP file in the temporary directory. $filename = tempnam( get_temp_dir(), $theme['slug'] ); @@ -308,6 +320,8 @@ function export_theme( $theme ) { } function create_blank_theme( $theme, $screenshot ) { + $theme_slug = Theme_Utils::get_theme_slug( $theme['name'] ); + // Sanitize inputs. $theme['name'] = sanitize_text_field( $theme['name'] ); $theme['description'] = sanitize_text_field( $theme['description'] ); @@ -316,7 +330,8 @@ function create_blank_theme( $theme, $screenshot ) { $theme['author_uri'] = sanitize_text_field( $theme['author_uri'] ); $theme['tags_custom'] = sanitize_text_field( $theme['tags_custom'] ); $theme['template'] = ''; - $theme['slug'] = Theme_Utils::get_theme_slug( $theme['name'] ); + $theme['slug'] = $theme_slug; + $theme['text_domain'] = $theme_slug; // Create theme directory. $source = plugin_dir_path( __DIR__ ) . 'assets/boilerplate'; diff --git a/admin/create-theme/theme-styles.php b/admin/create-theme/theme-styles.php index 042a31e9..2ac214c2 100644 --- a/admin/create-theme/theme-styles.php +++ b/admin/create-theme/theme-styles.php @@ -14,6 +14,7 @@ public static function build_child_style_css( $theme ) { $author = $theme['author']; $author_uri = $theme['author_uri']; $template = $theme['template']; + $text_domain = $theme['text_domain']; $tags = Theme_Tags::theme_tags_list( $theme ); return "/* Theme Name: {$name} @@ -28,7 +29,7 @@ public static function build_child_style_css( $theme ) { License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Template: {$template} -Text Domain: {$slug} +Text Domain: {$text_domain} Tags: {$tags} */"; } From b2566c87ba6c089d60face985b6e653526a4ba50 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Mon, 3 Apr 2023 17:13:10 -0300 Subject: [PATCH 2/5] Display theme metadata form for sibling themes --- admin/js/form-script.js | 1 + 1 file changed, 1 insertion(+) diff --git a/admin/js/form-script.js b/admin/js/form-script.js index a93ad6c4..03e9795a 100644 --- a/admin/js/form-script.js +++ b/admin/js/form-script.js @@ -14,6 +14,7 @@ function toggleForm( element ) { case 'child': case 'clone': case 'blank': + case 'sibling': // Show New Theme form document .getElementById( 'new_theme_metadata_form' ) From 960213a62d2fcede232fc9583889fc937daeb777 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Mon, 3 Apr 2023 17:13:50 -0300 Subject: [PATCH 3/5] removing sibling warning message about textdomain --- admin/create-theme/theme-form.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/admin/create-theme/theme-form.php b/admin/create-theme/theme-form.php index 2995852b..45ce70da 100644 --- a/admin/create-theme/theme-form.php +++ b/admin/create-theme/theme-form.php @@ -53,8 +53,7 @@ public static function create_admin_form_page() {
-

-
+