Skip to content

Commit

Permalink
Fixes wp-cli#263.
Browse files Browse the repository at this point in the history
parent_dir contains a normalized path whereas  WP_CONTENT_DIR contains a relative path. By running the WP_CONTENT_DIR through realpath we get a path we can actually compare between the target dir and where we want to place the new theme.

Also fixes wp-cli#251
  • Loading branch information
NielsdeBlaauw committed Jun 2, 2022
1 parent 5e35d11 commit 2413ee9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Scaffold_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,12 +958,17 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
*/
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 ) {
if ( 'theme' === $type && (
realpath( str_replace( '\\', '/', WP_CONTENT_DIR . '/themes' ) ) !== $parent_dir &&
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' );
}

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

Expand Down

0 comments on commit 2413ee9

Please sign in to comment.