Skip to content

Commit

Permalink
Support use in WP-CLI packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dlh01 committed Feb 26, 2024
1 parent a702c80 commit 17c2f0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a C

Nothing yet.

## 2.1.0

### Changed

- Support use of `WP_CLI_Feature` in WP-CLI packages.

## 2.0.0

### Changed
Expand Down
13 changes: 12 additions & 1 deletion src/alley/wp/features/class-wp-cli-feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Alley\WP\Features;

use Alley\WP\Types\Feature;
use WP_CLI;

/**
* Boot a feature only WP-CLI loads.
Expand All @@ -26,6 +27,16 @@ public function __construct(
* Boot the feature.
*/
public function boot(): void {
add_action( 'cli_init', [ $this->origin, 'boot' ] );
if ( function_exists( 'add_action' ) ) {
add_action( 'cli_init', [ $this->origin, 'boot' ] );
} elseif ( class_exists( 'WP_CLI' ) ) {
/*
* This is being invoked in a WP-CLI package or in a similar context where
* WordPress hasn't yet been loaded.
*
* @see https://github.com/buddypress/wp-cli-buddypress/issues/18
*/
WP_CLI::add_hook( 'before_wp_load', [ $this->origin, 'boot' ] );
}
}
}

0 comments on commit 17c2f0a

Please sign in to comment.