Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions features/scaffold.feature
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ Feature: WordPress code scaffolding
"""
And the return code should be 1

@theme
Scenario: Scaffold a child theme with dots in the slug
Given a WP install
And I run `wp theme path`
And save STDOUT as {THEME_DIR}

When I run `wp scaffold child-theme my-theme-2.0.1 --parent_theme=umbrella`
Then the {THEME_DIR}/my-theme-2.0.1/functions.php file should exist
And the {THEME_DIR}/my-theme-2.0.1/functions.php file should contain:
"""
function my_theme_2_0_1_parent_theme_enqueue_styles()
"""
And the {THEME_DIR}/my-theme-2.0.1/functions.php file should contain:
"""
add_action( 'wp_enqueue_scripts', 'my_theme_2_0_1_parent_theme_enqueue_styles' );
"""

@tax @cpt
Scenario: Scaffold a Custom Taxonomy and Custom Post Type and write it to active theme
Given a WP install
Expand Down
2 changes: 1 addition & 1 deletion src/Scaffold_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public function child_theme( $args, $assoc_args ) {

$data = wp_parse_args( $assoc_args, $defaults );
$data['slug'] = $theme_slug;
$data['prefix_safe'] = str_replace( [ ' ', '-' ], '_', $theme_slug );
$data['prefix_safe'] = preg_replace( '/[^a-zA-Z0-9_]/', '_', $theme_slug );
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preg_replace( '/[^a-zA-Z0-9_]/', '_', $theme_slug ) still allows prefix_safe to start with a digit (e.g. slug 2.0-theme -> 2_0_theme), which would generate an invalid PHP function name and a parse error in the scaffolded functions.php. Consider additionally normalizing prefix_safe to ensure the first character is [A-Za-z_] (e.g. prefixing with _ or theme_ when it isn’t) and handling the edge case where the sanitized result becomes empty.

Suggested change
$data['prefix_safe'] = preg_replace( '/[^a-zA-Z0-9_]/', '_', $theme_slug );
$prefix_safe = preg_replace( '/[^a-zA-Z0-9_]/', '_', $theme_slug );
if ( '' === $prefix_safe ) {
$prefix_safe = 'theme';
}
if ( ! preg_match( '/^[A-Za-z_]/', $prefix_safe ) ) {
$prefix_safe = '_' . $prefix_safe;
}
$data['prefix_safe'] = $prefix_safe;

Copilot uses AI. Check for mistakes.
$data['description'] = ucfirst( $data['parent_theme'] ) . ' child theme.';

$theme_dir = WP_CONTENT_DIR . "/themes/{$theme_slug}";
Expand Down
Loading