Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Created August 26, 2025 15:20
Show Gist options
  • Save barryhughes/c0306558eb6cd65f31c4a58495c016ab to your computer and use it in GitHub Desktop.
Save barryhughes/c0306558eb6cd65f31c4a58495c016ab to your computer and use it in GitHub Desktop.
Solves a conflict between WooCommerce (and its Blueprints package) and WP Console, when invoking `wp shell`.
<?php
/**
* Avoid conflicts between WP Console and WooCommerce.
*
* In the context of WP CLI and specifically the `wp shell` command, we may wish to unhook WooCommerce's CLI integration
* for the Blueprint package to prevent a conflict between its dependencies and those of WP Console.
*
* Relevant versions when this snippet was written:
*
* - WooCommerce 10.1.0
* - WP Console 2.5.1
* - WP CLI 2.13.0
*/
add_action( 'plugins_loaded', function () {
// Not running in a CLI context? Nothing more to do.
if ( ! defined( 'WP_CLI' ) || ! class_exists( 'WP_CLI', false ) ) {
return;
}
$args = (array) WP_CLI::get_runner()->arguments;
// Crude test to check if `wp shell` was invoked. If it wasn't, there's nothing more to do.
if ( count( $args ) < 1 || 'shell' !== reset( $args ) ) {
return;
}
// We interact directly with the global $wp_filter object, as we don't have a better way to reference WC_CLI.
if ( ! isset( $GLOBALS['wp_filter']['init']->callbacks[10] ) ) {
return;
}
// Unhook Blueprint CLI.
foreach ( $GLOBALS['wp_filter']['init']->callbacks[10] as $hook => $callbacks ) {
if ( str_contains( $hook, 'add_blueprint_cli_hook' ) ) {
unset( $GLOBALS['wp_filter']['init']->callbacks[10][$hook] );
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment