Skip to content

Commit a0d8996

Browse files
Copilotswissspidy
andauthored
Sanitize theme slugs for usage in PHP function names (#381)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent bd23b5f commit a0d8996

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

features/scaffold.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,23 @@ Feature: WordPress code scaffolding
116116
"""
117117
And the return code should be 1
118118

119+
@theme
120+
Scenario: Scaffold a child theme with dots in the slug
121+
Given a WP install
122+
And I run `wp theme path`
123+
And save STDOUT as {THEME_DIR}
124+
125+
When I run `wp scaffold child-theme my-theme-2.0.1 --parent_theme=umbrella`
126+
Then the {THEME_DIR}/my-theme-2.0.1/functions.php file should exist
127+
And the {THEME_DIR}/my-theme-2.0.1/functions.php file should contain:
128+
"""
129+
function my_theme_2_0_1_parent_theme_enqueue_styles()
130+
"""
131+
And the {THEME_DIR}/my-theme-2.0.1/functions.php file should contain:
132+
"""
133+
add_action( 'wp_enqueue_scripts', 'my_theme_2_0_1_parent_theme_enqueue_styles' );
134+
"""
135+
119136
@tax @cpt
120137
Scenario: Scaffold a Custom Taxonomy and Custom Post Type and write it to active theme
121138
Given a WP install

src/Scaffold_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ public function child_theme( $args, $assoc_args ) {
513513

514514
$data = wp_parse_args( $assoc_args, $defaults );
515515
$data['slug'] = $theme_slug;
516-
$data['prefix_safe'] = str_replace( [ ' ', '-' ], '_', $theme_slug );
516+
$data['prefix_safe'] = preg_replace( '/[^a-zA-Z0-9_]/', '_', $theme_slug );
517517
$data['description'] = ucfirst( $data['parent_theme'] ) . ' child theme.';
518518

519519
$theme_dir = WP_CONTENT_DIR . "/themes/{$theme_slug}";

0 commit comments

Comments
 (0)