Merge pull request #13421 from woocommerce/fix/cli-version-target

Only target v2 of the WC REST API when generating CLI commands.
This commit is contained in:
Justin Shreve 2017-03-01 13:34:59 -08:00 committed by GitHub
commit 0a4c20183d
1 changed files with 9 additions and 2 deletions

View File

@ -30,6 +30,12 @@ class WC_CLI_Runner {
'reports/top_sellers',
);
/**
* The version of the REST API we should target to
* generate commands.
*/
private static $target_rest_version = 'v2';
/**
* Register's all endpoints as commands once WP and WC have all loaded.
*/
@ -48,10 +54,11 @@ class WC_CLI_Runner {
// Loop through all of our endpoints and register any valid WC endpoints.
foreach ( $response_data['routes'] as $route => $route_data ) {
// Only register WC endpoints
if ( substr( $route, 0, 4 ) !== '/wc/' ) {
// Only register endpoints for WC and our target version.
if ( '/wc/' . self::$target_rest_version !== substr( $route, 0, 4 + strlen( self::$target_rest_version ) ) ) {
continue;
}
// Only register endpoints with schemas
if ( empty( $route_data['schema']['title'] ) ) {
WP_CLI::debug( sprintf( __( 'No schema title found for %s, skipping REST command registration.', 'woocommerce' ), $route ), 'wc' );