1111use Symfony \Component \Console \Input \InputInterface ;
1212use Symfony \Component \Console \Input \InputOption ;
1313use Symfony \Component \Console \Output \OutputInterface ;
14+ use Webmozart \PathUtil \Path ;
1415use WP \Console \Command \Shared \ConfirmationTrait ;
1516use WP \Console \Core \Command \Command ;
1617use WP \Console \Generator \ThemeGenerator ;
@@ -162,8 +163,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
162163 }
163164
164165 $ theme = $ this ->validator ->validatePluginName ($ input ->getOption ('theme ' ));
165-
166- $ themePath = $ this ->appRoot . $ input ->getOption ('theme-path ' );
166+
167+ // Get the theme path and define it, if it is null
168+ // Check that it is an absolute path or otherwise create an absolute path using appRoot
169+ $ themePath = $ input ->getOption ('theme-path ' );
170+ $ themePath = $ themePath == null ? basename (WP_CONTENT_DIR ) . DIRECTORY_SEPARATOR . 'themes ' : $ themePath ;
171+ $ themePath = Path::isAbsolute ($ themePath ) ? $ themePath : Path::makeAbsolute ($ themePath , $ this ->appRoot );
167172 $ themePath = $ this ->validator ->validatePluginPath ($ themePath , true );
168173
169174 $ machineName = $ this ->validator ->validateMachineName ($ input ->getOption ('machine-name ' ));
@@ -248,13 +253,12 @@ function ($machine_name) use ($validator) {
248253 // --theme path
249254 $ themePath = $ input ->getOption ('theme-path ' );
250255 if (!$ themePath ) {
251- $ wordpressRoot = $ this ->appRoot ;
252256 $ themePath = $ io ->ask (
253257 $ this ->trans ('commands.generate.theme.questions.theme-path ' ),
254- basename (WP_CONTENT_DIR ) . DIRECTORY_SEPARATOR . 'themes ' . DIRECTORY_SEPARATOR . $ machineName ,
255- function ($ themePath ) use ($ wordpressRoot , $ machineName ) {
256- $ themePath = ($ themePath[ 0 ] != ' / ' ? ' / ' : '' ). $ themePath ;
257- $ fullPath = $ wordpressRoot . $ themePath .'/ ' .$ machineName ;
258+ basename (WP_CONTENT_DIR ) . DIRECTORY_SEPARATOR . 'themes ' ,
259+ function ($ themePath ) use ($ machineName ) {
260+ $ fullPath = Path:: isAbsolute ($ themePath) ? $ themePath : Path:: makeAbsolute ( $ themePath, $ this -> appRoot ) ;
261+ $ fullPath = $ fullPath .'/ ' .$ machineName ;
258262 if (file_exists ($ fullPath )) {
259263 throw new \InvalidArgumentException (
260264 sprintf (
@@ -263,7 +267,6 @@ function ($themePath) use ($wordpressRoot, $machineName) {
263267 )
264268 );
265269 }
266-
267270 return $ themePath ;
268271 }
269272 );
0 commit comments