The Feature
interface describes a project feature. Features can be large or small, although smaller features can take advantage of decorators more easily. Use the boot()
method to add actions and filters.
interface Feature {
public function boot(): void;
}
- Effect: Boot a feature as an effect of a condition being true.
- Lazy_Feature: Instantiate a feature only when called upon.
- Ordered: Boot features in a guaranteed order.
- Quick_Feature: Make a callable a feature.
- Template_Feature: Boot a feature only when templates load.
- WP_CLI_Feature: Boot a feature only WP-CLI loads.
All Features
implementations also implement Feature
.
The Library
subnamespace includes concrete implementations of common features. These can be used on their own or as part of a set of features that make up a larger integration.
- Allowed_Blocks: Limit blocks allowed in the editor to those that are explicitly supported.
- Block_Content_Filter: Filter block markup in
the_content
for the post being viewed. - GTM_Script: Add the standard Google Tag Manager script and data layer.
- Plugin_Loader: Makes the Alley plugin loader available in a feature.
See the documentation for the Features interface for a more comprehensive example.
use Alley\WP\Features\Effect;
use Alley\WP\Features\Group;
use Alley\WP\Features\Lazy_Feature;
use Alley\WP\Features\Library;
use Alley\WP\Features\Ordered;
use Alley\WP\Features\Template_Feature;
$feature = new Effect(
when: fn () => get_current_blog_id() !== 1,
then: new Ordered(
first: new Library\Plugin_Loader(
plugins: [
'block-visibility/block-visibility.php',
],
),
then: new Group(
new Features\Block_Visibility_Settings(),
new Features\Block_Visibility_Custom_Conditions(),
),
),
);
$feature->boot();