This serves as a reference example for developers extending the WordPress AI plugin with a custom experiment.
The example is intentionally small and uses the same APIs and patterns as the plugin itself. It is demo code, not production-ready plugin scaffolding.
- Creating a feature class by extending
Abstract_Feature - Registering the experiment with the AI plugin
- Adding metadata such as the label, description, and category
- Hooking into WordPress actions and filters in
register(), and user-facing hooks inregister_ui() - Disabling the experiment with the standard feature filters
The plugin ships with a complete reference implementation at:
includes/Experiments/Example_Experiment/Example_Experiment.phpincludes/Experiments/Example_Experiment/README.md
That example is not enabled as a default built-in experiment. It exists to show the expected structure for third-party extensions.
The following example shows the smallest practical custom experiment plugin:
<?php
/**
* Plugin Name: My AI Experiment
*/
declare( strict_types=1 );
namespace MyPlugin\AI;
use WordPress\AI\Abstracts\Abstract_Feature;
use WordPress\AI\Experiments\Experiment_Category;
class My_Experiment extends Abstract_Feature {
public static function get_id(): string {
return 'my-experiment';
}
protected function load_metadata(): array {
return array(
'label' => __( 'My Experiment', 'my-plugin' ),
'description' => __( 'Example custom experiment built on the AI plugin.', 'my-plugin' ),
'category' => Experiment_Category::ADMIN,
);
}
public function register(): void {
// Abilities, meta, frontend output, cron, and REST routes go here.
}
public function register_ui(): void {
add_action( 'admin_notices', array( $this, 'render_notice' ) );
}
public function render_notice(): void {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
echo '<div class="notice notice-info"><p>';
echo esc_html__( 'My Experiment is active.', 'my-plugin' );
echo '</p></div>';
}
}
add_action(
'wpai_register_features',
static function( $registry ): void {
$registry->register_feature( new My_Experiment() );
}
);Abstract_Featureprovides the shared experiment lifecycle used throughout the plugin.load_metadata()keeps labels and descriptions in one place, matching built-in experiments.register()is the required method where the experiment attaches behavior through WordPress hooks.register_ui()runs only for users allowed to use the feature, or for everyone when the feature does not opt in to access control. Put asset enqueues, columns, row or bulk actions, and admin menu items there. Abilities, meta, frontend output, cron, and REST routes stay inregister().- Register your feature's abilities with
register_feature_ability()so its access control settings apply wherever the ability runs. Abilities registered directly withwp_register_ability()are not tied to any feature. - The optional
access_controlmetadata key opts the feature in to access control settings. It is opt-in and defaults tofalse, so this example does not opt in. Set'access_control' => trueonly once the feature registers its abilities withregister_feature_ability()and its UI hooks inregister_ui(). wpai_register_featuresis the safest entry point for third-party plugins because it registers your feature after the plugin sets up its registry.
If you want your class added to the default feature class list before instantiation, use the wpai_default_feature_classes filter:
add_filter(
'wpai_default_feature_classes',
static function( array $feature_classes ): array {
$feature_classes[ My_Experiment::get_id() ] = My_Experiment::class;
return $feature_classes;
}
);This is useful when your integration closely mirrors the plugin's built-in feature loading flow.
Disable only this experiment:
add_filter( 'wpai_feature_my-experiment_enabled', '__return_false' );Disable all AI plugin features:
add_filter( 'wpai_features_enabled', '__return_false' );After the experiment class is working, most production integrations will also want to:
- add tests under
tests/Integration/ - add any editor or admin assets through
Asset_Loader - document settings, abilities, and REST endpoints
- note any provider or environment requirements
For a deeper walkthrough, see the Developer Guide and the in-repo Example Experiment reference implementation.