Skip to content

Commit 96d0b61

Browse files
Merge pull request #104 from wp-cli/loading-order-fix
Only add commands if `scaffold` is already loaded.
2 parents 4f1b1d3 + 9f7794e commit 96d0b61

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

scaffold-package-command.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@
44
return;
55
}
66

7-
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
8-
if ( file_exists( $autoload ) ) {
9-
require_once $autoload;
10-
}
7+
$registration = function () {
8+
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
9+
if ( file_exists( $autoload ) ) {
10+
require_once $autoload;
11+
}
12+
13+
WP_CLI::add_command( 'scaffold package', array( 'WP_CLI\ScaffoldPackageCommand', 'package' ) );
14+
WP_CLI::add_command( 'scaffold package-readme', array( 'WP_CLI\ScaffoldPackageCommand', 'package_readme' ) );
15+
WP_CLI::add_command( 'scaffold package-tests', array( 'WP_CLI\ScaffoldPackageCommand', 'package_tests' ) );
16+
};
1117

12-
WP_CLI::add_command( 'scaffold package', array( 'WP_CLI\ScaffoldPackageCommand', 'package' ) );
13-
WP_CLI::add_command( 'scaffold package-readme', array( 'WP_CLI\ScaffoldPackageCommand', 'package_readme' ) );
14-
WP_CLI::add_command( 'scaffold package-tests', array( 'WP_CLI\ScaffoldPackageCommand', 'package_tests' ) );
18+
// Only use command hooks in versions that support them.
19+
if ( version_compare( WP_CLI_VERSION, '1.2.0-alpha', '>=' ) ) {
20+
WP_CLI::add_hook( 'after_add_command:scaffold', $registration );
21+
} else {
22+
$registration();
23+
}

0 commit comments

Comments
 (0)