diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index c418a011..24ce5729 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -869,9 +869,29 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) { $wp_versions_to_test[] = 'latest'; $wp_versions_to_test[] = 'trunk'; + $main_file = ''; + + if ( 'plugin' === $type ) { + $all_plugins = get_plugins(); + + if ( ! empty( $all_plugins ) ) { + $filtered = array_filter( + array_keys( $all_plugins ), + static function ( $item ) use ( $slug ) { + return ( false !== strpos( $item, "{$slug}/" ) ); + } + ); + + if ( ! empty( $filtered ) ) { + $main_file = basename( reset( $filtered ) ); + } + } + } + $template_data = [ - "{$type}_slug" => $slug, - "{$type}_package" => $package, + "{$type}_slug" => $slug, + "{$type}_package" => $package, + "{$type}_main_file" => $main_file, ]; $force = Utils\get_flag_value( $assoc_args, 'force' ); diff --git a/templates/plugin-bootstrap.mustache b/templates/plugin-bootstrap.mustache index efaaa314..e35163a9 100644 --- a/templates/plugin-bootstrap.mustache +++ b/templates/plugin-bootstrap.mustache @@ -29,7 +29,7 @@ require_once "{$_tests_dir}/includes/functions.php"; * Manually load the plugin being tested. */ function _manually_load_plugin() { - require dirname( dirname( __FILE__ ) ) . '/{{plugin_slug}}.php'; + require dirname( dirname( __FILE__ ) ) . '/{{plugin_main_file}}'; } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );