@@ -306,7 +306,7 @@ public function _s( $args, $assoc_args ) {
306
306
307
307
if ( true === $ unzip_result ) {
308
308
$ this ->create_files ( array (
309
- "$ theme_path/ {$ theme_slug }/.editorconfig " => file_get_contents ( WP_CLI_ROOT . " / templates/.editorconfig " ),
309
+ "$ theme_path/ {$ theme_slug }/.editorconfig " => file_get_contents ( self :: get_template_path ( " templates/.editorconfig " ) ),
310
310
), false );
311
311
WP_CLI ::success ( "Created theme ' {$ data ['theme_name ' ]}'. " );
312
312
} else {
@@ -395,7 +395,7 @@ function child_theme( $args, $assoc_args ) {
395
395
$ files_written = $ this ->create_files ( array (
396
396
$ theme_style_path => self ::mustache_render ( 'child_theme.mustache ' , $ data ),
397
397
$ theme_functions_path => self ::mustache_render ( 'child_theme_functions.mustache ' , $ data ),
398
- "$ theme_dir/.editorconfig " => file_get_contents ( WP_CLI_ROOT . "/templates/.editorconfig " ),
398
+ "$ theme_dir/.editorconfig " => file_get_contents ( self :: get_template_path ( "/templates/.editorconfig " ) ),
399
399
), $ force );
400
400
$ this ->log_whether_files_written (
401
401
$ files_written ,
@@ -553,7 +553,7 @@ function plugin( $args, $assoc_args ) {
553
553
"$ plugin_dir/Gruntfile.js " => self ::mustache_render ( 'plugin-gruntfile.mustache ' , $ data ),
554
554
"$ plugin_dir/.gitignore " => self ::mustache_render ( 'plugin-gitignore.mustache ' , $ data ),
555
555
"$ plugin_dir/.distignore " => self ::mustache_render ( 'plugin-distignore.mustache ' , $ data ),
556
- "$ plugin_dir/.editorconfig " => file_get_contents ( WP_CLI_ROOT . "/templates/.editorconfig " ),
556
+ "$ plugin_dir/.editorconfig " => file_get_contents ( self :: get_template_path ( "/templates/.editorconfig " ) ),
557
557
), $ force );
558
558
559
559
$ this ->log_whether_files_written (
@@ -773,7 +773,7 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
773
773
}
774
774
$ files_written [] = $ file_name ;
775
775
776
- $ wp_filesystem ->copy ( WP_CLI_ROOT . "/templates/ $ file " , $ file_name , true );
776
+ $ wp_filesystem ->copy ( self :: get_template_path ( "/templates/ $ file " ) , $ file_name , true );
777
777
if ( 'install-wp-tests.sh ' === $ file ) {
778
778
if ( ! $ wp_filesystem ->chmod ( "$ dir/ $ file " , 0755 ) ) {
779
779
WP_CLI ::warning ( "Couldn't mark 'install-wp-tests.sh' as executable. " );
@@ -991,4 +991,19 @@ private static function mustache_render( $template, $data = array() ) {
991
991
return Utils \mustache_render ( dirname ( dirname ( __FILE__ ) ) . '/templates/ ' . $ template , $ data );
992
992
}
993
993
994
+ /**
995
+ * Get template path based on installation type
996
+ */
997
+ private static function get_template_path ( $ template ) {
998
+ $ template_path = WP_CLI_ROOT . '/vendor/wp-cli/scaffold-command/templates/ ' . $ template ;
999
+ if ( ! file_exists ( $ template_path ) ) {
1000
+ // scaffold command must've been built with vendor/wp-cli/wp-cli
1001
+ $ template_path = WP_CLI_ROOT . '/../../../templates/ ' . $ template ;
1002
+ if ( ! file_exists ( $ template_path ) ) {
1003
+ WP_CLI ::error ( "Couldn't find {$ template }" );
1004
+ }
1005
+ }
1006
+ return $ template_path ;
1007
+ }
1008
+
994
1009
}
0 commit comments