Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ This issue is for tracking changes for the X.Y.Z release. Target release date:
## [Release steps](https://github.com/wordpress/ai/blob/develop/CONTRIBUTING.md#release-instructions)

- [ ] Branch: Starting from `develop`, cut a release branch named `release/X.Y.Z` for your changes.
- [ ] Version bump: Bump the version number in `ai.php`, `package-lock.json` (twice), `package.json`, and `readme.txt` if it does not already reflect the version being released. In `includes/bootstrap.php`, ensure you're updating the `AI_VERSION` version constant.
- [ ] Version bump: Bump the version number in `ai.php`, `package-lock.json` (twice), `package.json`, and `readme.txt` if it does not already reflect the version being released. In `includes/bootstrap.php`, ensure you're updating the `AI_EXPERIMENTS_VERSION` version constant.
- [ ] Update `@since`: Find all new `@since x.x.x` lines and update those with the new version number in place of `x.x.x`.
- [ ] Changelog: Add/update the changelog in `CHANGELOG.md` and in `readme.txt`.
- [ ] Props: update `CREDITS.md` file with any new contributors, confirm maintainers are accurate.
Expand Down
4 changes: 2 additions & 2 deletions ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
/**
* Shortcut constant to the path of this file.
*/
define( 'WP_AI_DIR', plugin_dir_path( __FILE__ ) );
define( 'AI_EXPERIMENTS_DIR', plugin_dir_path( __FILE__ ) );

require_once WP_AI_DIR . 'includes/bootstrap.php';
require_once AI_EXPERIMENTS_DIR . 'includes/bootstrap.php';
10 changes: 5 additions & 5 deletions docs/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ The plugin provides a set of hooks and filters to allow third-party developers t

### Registering a Custom Experiment

Developers can register their own experiments using the `ai_register_experiments` action. This is the primary way to add new functionality to the plugin.
Developers can register their own experiments using the `ai_experiments_register_experiments` action. This is the primary way to add new functionality to the plugin.

```php
add_action( 'ai_register_experiments', function( $registry ) {
add_action( 'ai_experiments_register_experiments', function( $registry ) {
$registry->register_experiment( new My_Custom_Experiment() );
} );
```
Expand All @@ -277,7 +277,7 @@ add_action( 'ai_register_experiments', function( $registry ) {
Modify the list of default experiment classes before they are instantiated:

```php
add_filter( 'ai_default_experiment_classes', function( $experiment_classes ) {
add_filter( 'ai_experiments_default_experiment_classes', function( $experiment_classes ) {
// Add a custom experiment
$experiment_classes[] = 'My_Namespace\My_Custom_Experiment';

Expand All @@ -296,7 +296,7 @@ add_filter( 'ai_default_experiment_classes', function( $experiment_classes ) {
Experiments can be disabled using the `ai_experiment_{$experiment_id}_enabled` filter:

```php
add_filter( 'ai_experiment_example-experiment_enabled', '__return_false' );
add_filter( 'ai_experiments_experiment_example-experiment_enabled', '__return_false' );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:alot: of experiment

```

### Disabling All Experiments
Expand All @@ -311,7 +311,7 @@ add_filter( 'ai_experiments_enabled', '__return_false' );

The plugin also includes the following action hooks:

- `ai_register_experiments`: Fires after default experiments are registered, receives `$registry` parameter
- `ai_experiments_register_experiments`: Fires after default experiments are registered, receives `$registry` parameter
- `ai_experiments_initialized`: Fires after all registered experiments have been initialized

### Asset Loading
Expand Down
4 changes: 2 additions & 2 deletions includes/Abilities/Utilities/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private function register_get_post_details_ability(): void {
array(
'label' => esc_html__( 'Get post details', 'ai' ),
'description' => esc_html__( 'Get the details of a post based on the post ID. Optionally, limit the details to specific fields.', 'ai' ),
'category' => AI_DEFAULT_ABILITY_CATEGORY,
'category' => AI_EXPERIMENTS_DEFAULT_ABILITY_CATEGORY,
'input_schema' => array(
'type' => 'object',
'properties' => array(
Expand Down Expand Up @@ -174,7 +174,7 @@ private function register_get_terms_ability(): void {
array(
'label' => esc_html__( 'Get the post terms', 'ai' ),
'description' => esc_html__( 'Get the terms of a post based on the post ID and optionally filter by taxonomy.', 'ai' ),
'category' => AI_DEFAULT_ABILITY_CATEGORY,
'category' => AI_EXPERIMENTS_DEFAULT_ABILITY_CATEGORY,
'input_schema' => array(
'type' => 'object',
'properties' => array(
Expand Down
2 changes: 1 addition & 1 deletion includes/Abstracts/Abstract_Ability.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct( string $name, array $properties = array() ) {
* @return string The category of the ability.
*/
protected function category(): string {
return AI_DEFAULT_ABILITY_CATEGORY;
return AI_EXPERIMENTS_DEFAULT_ABILITY_CATEGORY;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/Abstracts/Abstract_Experiment.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ final public function is_enabled(): bool {
*
* @param bool $experiment_enabled Whether the experiment is enabled.
*/
$is_enabled = (bool) apply_filters( "ai_experiment_{$this->id}_enabled", $experiment_enabled );
$is_enabled = (bool) apply_filters( "ai_experiments_experiment_{$this->id}_enabled", $experiment_enabled );

// Check if we have valid AI credentials.
if ( ! has_valid_ai_credentials() ) {
Expand Down
8 changes: 4 additions & 4 deletions includes/Asset_Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Asset_Loader {
* @param string $file_name The script file name.
*/
public static function enqueue_script( string $handle, string $file_name ): void {
$script_path = WP_AI_DIR . 'build/' . $file_name . '.js';
$script_url = AI_PLUGIN_URL . 'build/' . $file_name . '.js';
$script_path = AI_EXPERIMENTS_DIR . 'build/' . $file_name . '.js';
$script_url = AI_EXPERIMENTS_PLUGIN_URL . 'build/' . $file_name . '.js';
$script_asset_path = $script_path . '.asset.php';

if ( file_exists( $script_asset_path ) ) {
Expand Down Expand Up @@ -67,8 +67,8 @@ public static function enqueue_script( string $handle, string $file_name ): void
* @param string $file_name The script file name.
*/
public static function enqueue_style( string $handle, string $file_name ): void {
$style_path = WP_AI_DIR . 'build/' . $file_name . '.css';
$style_url = AI_PLUGIN_URL . 'build/' . $file_name . '.css';
$style_path = AI_EXPERIMENTS_DIR . 'build/' . $file_name . '.css';
$style_url = AI_EXPERIMENTS_PLUGIN_URL . 'build/' . $file_name . '.css';
$style_asset_path = $style_path . '.asset.php';

if ( file_exists( $style_asset_path ) ) {
Expand Down
8 changes: 4 additions & 4 deletions includes/Experiment_Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct( Experiment_Registry $registry ) {
* Registers default experiments.
*
* This is where built-in experiments are registered. Third-party experiments
* should use the 'ai_register_experiments' action hook.
* should use the 'ai_experiments_register_experiments' action hook.
*
* @since 0.1.0
*
Expand Down Expand Up @@ -82,7 +82,7 @@ public function register_default_experiments(): void {
*
* Example:
* ```php
* add_action( 'ai_register_experiments', function( $registry ) {
* add_action( 'ai_experiments_register_experiments', function( $registry ) {
* $registry->register_experiment( new My_Custom_Experiment() );
* } );
* ```
Expand All @@ -91,7 +91,7 @@ public function register_default_experiments(): void {
*
* @param \WordPress\AI\Experiment_Registry $registry The experiment registry instance.
*/
do_action( 'ai_register_experiments', $this->registry );
do_action( 'ai_experiments_register_experiments', $this->registry );
}

/**
Expand All @@ -118,7 +118,7 @@ private function get_default_experiments(): array {
*
* @param array $experiment_classes Array of experiment class names or instances.
*/
$items = apply_filters( 'ai_default_experiment_classes', $experiment_classes );
$items = apply_filters( 'ai_experiments_default_experiment_classes', $experiment_classes );

$experiments = array();
foreach ( $items as $item ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/Experiments/Example_Experiment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This experiment registers a REST endpoint to demonstrate how to expose experimen
Use the experiment-specific filter:

```php
add_filter( 'ai_experiment_example-experiment_enabled', '__return_false' );
add_filter( 'ai_experiments_experiment_example-experiment_enabled', '__return_false' );
```

Or use the generic filter to disable all experiments:
Expand Down
50 changes: 25 additions & 25 deletions includes/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Bootstrap file for the AI plugin.
* Bootstrap file for the AI Experiments plugin.
*
* Handles plugin initialization, version checks, and feature loading.
*
Expand All @@ -22,26 +22,26 @@
}

// Define plugin constants.
if ( ! defined( 'AI_VERSION' ) ) {
define( 'AI_VERSION', '0.1.0' );
if ( ! defined( 'AI_EXPERIMENTS_VERSION' ) ) {
define( 'AI_EXPERIMENTS_VERSION', '0.1.0' );
}
if ( ! defined( 'AI_PLUGIN_FILE' ) ) {
define( 'AI_PLUGIN_FILE', defined( 'WP_AI_DIR' ) ? WP_AI_DIR . 'ai.php' : '' );
if ( ! defined( 'AI_EXPERIMENTS_PLUGIN_FILE' ) ) {
define( 'AI_EXPERIMENTS_PLUGIN_FILE', defined( 'AI_EXPERIMENTS_DIR' ) ? AI_EXPERIMENTS_DIR . 'ai.php' : '' );
}
if ( ! defined( 'AI_PLUGIN_DIR' ) ) {
define( 'AI_PLUGIN_DIR', defined( 'WP_AI_DIR' ) ? WP_AI_DIR : '' );
if ( ! defined( 'AI_EXPERIMENTS_PLUGIN_DIR' ) ) {
define( 'AI_EXPERIMENTS_PLUGIN_DIR', defined( 'AI_EXPERIMENTS_DIR' ) ? AI_EXPERIMENTS_DIR : '' );
}
if ( ! defined( 'AI_PLUGIN_URL' ) ) {
define( 'AI_PLUGIN_URL', plugin_dir_url( AI_PLUGIN_FILE ) );
if ( ! defined( 'AI_EXPERIMENTS_PLUGIN_URL' ) ) {
define( 'AI_EXPERIMENTS_PLUGIN_URL', plugin_dir_url( AI_EXPERIMENTS_PLUGIN_FILE ) );
}
if ( ! defined( 'AI_MIN_PHP_VERSION' ) ) {
define( 'AI_MIN_PHP_VERSION', '7.4' );
if ( ! defined( 'AI_EXPERIMENTS_MIN_PHP_VERSION' ) ) {
define( 'AI_EXPERIMENTS_MIN_PHP_VERSION', '7.4' );
}
if ( ! defined( 'AI_MIN_WP_VERSION' ) ) {
define( 'AI_MIN_WP_VERSION', '6.8' );
if ( ! defined( 'AI_EXPERIMENTS_MIN_WP_VERSION' ) ) {
define( 'AI_EXPERIMENTS_MIN_WP_VERSION', '6.8' );
}
if ( ! defined( 'AI_DEFAULT_ABILITY_CATEGORY' ) ) {
define( 'AI_DEFAULT_ABILITY_CATEGORY', 'ai-experiments' );
if ( ! defined( 'AI_EXPERIMENTS_DEFAULT_ABILITY_CATEGORY' ) ) {
define( 'AI_EXPERIMENTS_DEFAULT_ABILITY_CATEGORY', 'ai-experiments' );
}

/**
Expand Down Expand Up @@ -70,15 +70,15 @@ function version_notice( string $message ): void {
* @return bool True if PHP version is sufficient, false otherwise.
*/
function check_php_version(): bool {
if ( version_compare( phpversion(), AI_MIN_PHP_VERSION, '<' ) ) {
if ( version_compare( phpversion(), AI_EXPERIMENTS_MIN_PHP_VERSION, '<' ) ) {
add_action(
'admin_notices',
static function () {
version_notice(
sprintf(
/* translators: 1: Required PHP version, 2: Current PHP version */
__( 'AI plugin requires PHP version %1$s or higher. You are running PHP version %2$s.', 'ai' ),
AI_MIN_PHP_VERSION,
__( 'AI Experiments plugin requires PHP version %1$s or higher. You are running PHP version %2$s.', 'ai' ),
AI_EXPERIMENTS_MIN_PHP_VERSION,
PHP_VERSION
)
);
Expand All @@ -99,16 +99,16 @@ static function () {
function check_wp_version(): bool {
global $wp_version;

if ( version_compare( $wp_version, AI_MIN_WP_VERSION, '<' ) ) {
if ( version_compare( $wp_version, AI_EXPERIMENTS_MIN_WP_VERSION, '<' ) ) {
add_action(
'admin_notices',
static function () {
global $wp_version;
version_notice(
sprintf(
/* translators: 1: Required WordPress version, 2: Current WordPress version */
__( 'AI plugin requires WordPress version %1$s or higher. You are running WordPress version %2$s.', 'ai' ),
AI_MIN_WP_VERSION,
__( 'AI Experiments plugin requires WordPress version %1$s or higher. You are running WordPress version %2$s.', 'ai' ),
AI_EXPERIMENTS_MIN_WP_VERSION,
$wp_version
)
);
Expand All @@ -131,7 +131,7 @@ function display_composer_notice(): void {
<?php
printf(
/* translators: %s: composer install command */
esc_html__( 'Your installation of the AI plugin is incomplete. Please run %s.', 'ai' ),
esc_html__( 'Your installation of the AI Experiments plugin is incomplete. Please run %s.', 'ai' ),
'<code>composer install</code>'
);
?>
Expand Down Expand Up @@ -159,11 +159,11 @@ function load(): void {
}

// Load the Jetpack autoloader.
if ( ! file_exists( AI_PLUGIN_DIR . 'vendor/autoload_packages.php' ) ) {
if ( ! file_exists( AI_EXPERIMENTS_PLUGIN_DIR . 'vendor/autoload_packages.php' ) ) {
add_action( 'admin_notices', __NAMESPACE__ . '\display_composer_notice' );
return;
}
require_once AI_PLUGIN_DIR . 'vendor/autoload_packages.php';
require_once AI_EXPERIMENTS_PLUGIN_DIR . 'vendor/autoload_packages.php';

$loaded = true;

Expand Down Expand Up @@ -209,7 +209,7 @@ static function () {
* in the future if we need/want more specific categories.
*/
wp_register_ability_category(
AI_DEFAULT_ABILITY_CATEGORY,
AI_EXPERIMENTS_DEFAULT_ABILITY_CATEGORY,
array(
'label' => __( 'AI Experiments', 'ai' ),
'description' => __( 'Various AI experiments.', 'ai' ),
Expand Down
12 changes: 4 additions & 8 deletions includes/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ function normalize_content( string $content ): string {
* Hook to filter content before cleaning it.
*
* @since 0.1.0
* @hook ai_pre_normalize_content
*
* @param string $post_content The post content.
*
* @return string The filtered Post content.
*/
$content = (string) apply_filters( 'ai_pre_normalize_content', $content );
$content = (string) apply_filters( 'ai_experiments_pre_normalize_content', $content );

// Strip HTML entities.
$content = preg_replace( '/&#?[a-z0-9]{2,8};/i', '', $content );
Expand All @@ -49,13 +48,12 @@ function normalize_content( string $content ): string {
* Filters the normalized content to allow for additional cleanup.
*
* @since 0.1.0
* @hook ai_normalize_content
*
* @param string $content The normalized content.
*
* @return string The filtered normalized content.
*/
$content = (string) apply_filters( 'ai_normalize_content', (string) $content );
$content = (string) apply_filters( 'ai_experiments_normalize_content', (string) $content );

return trim( $content );
}
Expand Down Expand Up @@ -151,12 +149,11 @@ function get_preferred_models(): array {
* Filters the preferred models.
*
* @since 0.1.0
* @hook ai_preferred_models
*
* @param array<int, array{string, string}> $preferred_models The preferred models.
* @return array<int, array{string, string}> The filtered preferred models.
*/
return (array) apply_filters( 'ai_preferred_models', $preferred_models );
return (array) apply_filters( 'ai_experiments_preferred_models', $preferred_models );
}

/**
Expand Down Expand Up @@ -204,12 +201,11 @@ function has_valid_ai_credentials(): bool {
* Allows overriding the credentials check, useful for testing.
*
* @since 0.1.0
* @hook ai_pre_has_valid_credentials_check
*
* @param bool|null $has_valid_credentials Whether valid credentials are available. Return null to use default check.
* @return bool|null True if valid credentials are available, false otherwise, or null to use default check.
*/
$valid = apply_filters( 'ai_pre_has_valid_credentials_check', null );
$valid = apply_filters( 'ai_experiments_pre_has_valid_credentials_check', null );
if ( null !== $valid ) {
return (bool) $valid;
}
Expand Down
4 changes: 3 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ AI Experiments is a plugin for testing and developing AI-powered experiments for

1. Upload the plugin files to the `/wp-content/plugins/ai` directory, or install the plugin through the WordPress plugins screen directly.
2. Activate the plugin through the 'Plugins' screen in WordPress.
3. Use the Settings->AI screen to configure the plugin.
3. Go to `Settings -> AI Credentials` and add at least one valid AI credential.
4. Go to `Settings -> AI Experiments` and globally enable experiments and then enable the individual experiments you want to test.
5. Start experimenting with AI features! For the Title Generation experiment, edit a post and click into the title field. You should see a `Generate/Re-generate` button above the field. Click that button and after the request is complete, title suggestions will be displayed in a modal. Choose the title you like and click the `Select` button to insert it into the title field.

== Frequently Asked Questions ==

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function setUp(): void {
update_option( 'wp_ai_client_provider_credentials', array( 'openai' => 'test-api-key' ) );

// Mock has_valid_ai_credentials to return true for tests.
add_filter( 'ai_pre_has_valid_credentials_check', '__return_true' );
add_filter( 'ai_experiments_pre_has_valid_credentials_check', '__return_true' );
}

/**
Expand Down
Loading
Loading