diff --git a/includes/classes/Command.php b/includes/classes/Command.php index 0d296a78f1..e8e2fe64bd 100644 --- a/includes/classes/Command.php +++ b/includes/classes/Command.php @@ -570,6 +570,10 @@ public function recreate_network_alias( $args, $assoc_args ) { $this->connect_check(); $this->index_occurring(); + if ( ! defined( 'EP_IS_NETWORK' ) || ! EP_IS_NETWORK ) { + WP_CLI::error( esc_html__( 'ElasticPress is not network activated.', 'elasticpress' ) ); + } + $indexables = Indexables::factory()->get_all( false ); foreach ( $indexables as $indexable ) { diff --git a/tests/cypress/integration/wp-cli.spec.js b/tests/cypress/integration/wp-cli.spec.js index 364b94d76c..e8e19175ad 100644 --- a/tests/cypress/integration/wp-cli.spec.js +++ b/tests/cypress/integration/wp-cli.spec.js @@ -144,6 +144,12 @@ describe('WP-CLI Commands', () => { it('Can recreate the alias index which points to every index in the network if user runs wp elasticpress recreate-network-alias command', () => {}); + it('Can throw an error while running wp elasticpress recreate-network-alias if the plugin is not network activated', () => { + cy.wpCli('wp elasticpress recreate-network-alias', true) + .its('stderr') + .should('contain', 'ElasticPress is not network activated'); + }); + it('Can activate and deactivate a feature', () => { cy.wpCli('wp elasticpress activate-feature search', true) .its('stderr')