The Experiment Framework is the plugin's opt-in architecture for shipping AI functionality as isolated, toggleable units. Experiments are implemented as Feature classes, registered through a shared loader/registry system, and initialized only when global AI functionality and experiment-specific settings are enabled.
The framework powers the Settings > AI experience where users can:
- Globally enable or disable AI functionality.
- Turn individual experiments on or off independently.
- Combine only the capabilities needed for a site.
This makes experimentation safer by reducing unintended runtime behavior and allowing incremental adoption.
The framework standardizes experiment development by requiring:
- A unique feature ID (
get_id()). - Metadata (
label,description, optionalcategory,stability,image). - A
register()method that wires hooks only when enabled.
It also supports extension points for third-party plugins to register custom features/experiments and override defaults.
Abstract_Feature(includes/Abstracts/Abstract_Feature.php)- Base implementation for metadata, enablement checks, and shared settings conventions.
Registry(includes/Features/Registry.php)- Stores feature instances and exposes feature lookups.
Loader(includes/Features/Loader.php)- Instantiates default features, runs registration hooks, and initializes enabled items.
Experimentsbootstrap (includes/Experiments/Experiments.php)- Adds built-in experiment classes to
wpai_default_feature_classes.
- Adds built-in experiment classes to
Experiments::init()hookswpai_default_feature_classes.Loaderresolves default features and applieswpai_default_feature_classes.- Feature classes are validated and instantiated.
- Instances are stored in
Registry. wpai_register_featuresfires, allowing third-party registration.
Loader::initialize_features()checks global filterwpai_features_enabled.- Each registered feature checks
is_enabled():- Global option (
wpai_features_enabled). - Feature option (
wpai_feature_{id}_enabled). - Feature-specific enablement filter.
- Global option (
- Enabled features run
register()and wire runtime hooks. wpai_features_initializedfires after initialization.
The framework supports explicit stability levels:
experimentalstabledeprecated
Stability influences how functionality is surfaced in admin UI and grouped in status views. Experiments normally default to experimental unless explicitly set otherwise in metadata.
You can register your own class through wpai_register_features:
add_action( 'wpai_register_features', function( $registry ) {
$registry->register_feature( new My_Custom_Experiment() );
} );You can alter default class registration:
add_filter( 'wpai_default_feature_classes', function( $classes ) {
$classes[ My_Custom_Experiment::get_id() ] = My_Custom_Experiment::class;
return $classes;
} );Disable one experiment:
add_filter( 'wpai_feature_title-generation_enabled', '__return_false' );Disable all features/experiments:
add_filter( 'wpai_features_enabled', '__return_false' );Use this framework for any plugin capability that should:
- Be independently toggleable.
- Register its hooks lazily only when needed.
- Follow shared metadata/settings conventions.
- Stay isolated for experimentation and potential future promotion.
For broader policy and graduation criteria, see docs/FEATURE_EXPERIMENT_LIFECYCLE.md.
includes/Abstracts/Abstract_Feature.phpincludes/Features/Registry.phpincludes/Features/Loader.phpincludes/Experiments/Experiments.phpdocs/FEATURE_EXPERIMENT_LIFECYCLE.md