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
10 changes: 10 additions & 0 deletions features/scaffold.feature
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ Feature: WordPress code scaffolding
"""
And the return code should be 1

@theme
Scenario: Scaffold a child theme with a relative --path argument containing '..'
Given a WP install in 'subdir'
And I run `wp --path=.. theme path` from 'subdir/wp-content'
And save STDOUT as {THEME_DIR}

When I run `wp scaffold child-theme zombieland --parent_theme=umbrella --path=..` from 'subdir/wp-content'
Then the {THEME_DIR}/zombieland/style.css file should exist
And the {THEME_DIR}/zombieland/functions.php file should exist

@theme
Scenario: Scaffold a child theme with dots in the slug
Given a WP install
Expand Down
10 changes: 6 additions & 4 deletions src/Scaffold_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -986,12 +986,14 @@ static function ( $item ) use ( $slug ) {
private function check_target_directory( $type, $target_dir ) {
$parent_dir = dirname( self::canonicalize_path( str_replace( '\\', '/', $target_dir ) ) );

if ( 'theme' === $type && str_replace( '\\', '/', WP_CONTENT_DIR . '/themes' ) !== $parent_dir ) {
return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, WP_CONTENT_DIR . '/themes' );
$themes_dir = self::canonicalize_path( str_replace( '\\', '/', WP_CONTENT_DIR . '/themes' ) );
if ( 'theme' === $type && $themes_dir !== $parent_dir ) {
return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, $themes_dir );
}

if ( 'plugin' === $type && str_replace( '\\', '/', WP_PLUGIN_DIR ) !== $parent_dir ) {
return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, WP_PLUGIN_DIR );
$plugins_dir = self::canonicalize_path( str_replace( '\\', '/', WP_PLUGIN_DIR ) );
if ( 'plugin' === $type && $plugins_dir !== $parent_dir ) {
return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, $plugins_dir );
}

// Success.
Expand Down