PluginProbe
AI / trunk
AI vtrunk
1.3.0 1.2.0 1.1.0 1.0.2 1.0.1 1.0.0 0.9.0 trunk 0.1.1 0.2.0 0.2.1 0.3.0 0.3.1 0.4.0 0.4.1 0.5.0 0.6.0 0.7.0 0.8.0
ai / includes / Experiments / Experiments.php

Experiments.php in AI trunk, at includes/Experiments/Experiments.php

79 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Registers the experimental features to the plugin.
4 *
5 * @package WordPress\AI\Experiments
6 */
7
8 declare( strict_types=1 );
9
10 namespace WordPress\AI\Experiments;
11
12 // Exit if accessed directly.
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Registers experimental features to the plugin
17 *
18 * Uses wpai_default_feature_classes filter to register experiments, which are then initialized by the Loader class.
19 *
20 * @internal
21 * @since 0.6.0
22 */
23 final class Experiments {
24 /**
25 * The list of experiment classes.
26 *
27 * @var array<class-string<\WordPress\AI\Contracts\Feature>>
28 */
29 private const EXPERIMENT_CLASSES = array( // phpcs:ignore SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition -- This is used as an array const.
30 \WordPress\AI\Experiments\Abilities_Explorer\Abilities_Explorer::class,
31 \WordPress\AI\Experiments\Custom_Abilities\Custom_Abilities::class,
32 \WordPress\AI\Experiments\AI_Request_Logging\AI_Request_Logging::class,
33 \WordPress\AI\Experiments\Connector_Approval\Connector_Approval::class,
34 \WordPress\AI\Experiments\Key_Encryption\Key_Encryption::class,
35 \WordPress\AI\Experiments\Comment_Moderation\Comment_Moderation::class,
36 \WordPress\AI\Experiments\Suggest_Reply\Suggest_Reply::class,
37 \WordPress\AI\Experiments\Alt_Text_Generation\Alt_Text_Generation::class,
38 \WordPress\AI\Experiments\Content_Classification\Content_Classification::class,
39 \WordPress\AI\Experiments\Content_Resizing\Content_Resizing::class,
40 \WordPress\AI\Experiments\Summarization\Summarization::class,
41 \WordPress\AI\Experiments\Content_Translation\Content_Translation::class,
42 \WordPress\AI\Experiments\Editorial_Notes\Editorial_Notes::class,
43 \WordPress\AI\Experiments\Editorial_Updates\Editorial_Updates::class,
44 \WordPress\AI\Experiments\Excerpt_Generation\Excerpt_Generation::class,
45 \WordPress\AI\Experiments\Meta_Description\Meta_Description::class,
46 \WordPress\AI\Experiments\Slug_Generation\Slug_Generation::class,
47 \WordPress\AI\Experiments\Title_Generation\Title_Generation::class,
48 \WordPress\AI\Experiments\Type_Ahead\Type_Ahead::class,
49 );
50
51 /**
52 * Initializes the experiments by hooking into the appropriate filter.
53 *
54 * @since 0.6.0
55 */
56 public function init(): void {
57 // Priority 9 ensures it runs before any potential overrides at default priority.
58 add_filter( 'wpai_default_feature_classes', array( self::class, 'register_default_experiment_classes' ), 9 );
59 }
60
61 /**
62 * Registers default experiment classes.
63 *
64 * @since 0.6.0
65 *
66 * @param array<string, class-string<\WordPress\AI\Contracts\Feature>> $existing Array of existing experiment class names, with experiment IDs as keys.
67 *
68 * @return array<string, class-string<\WordPress\AI\Contracts\Feature>> Array of experiment class names, with experiment IDs as keys.
69 */
70 public static function register_default_experiment_classes( array $existing ): array {
71 $experiments = array();
72 foreach ( self::EXPERIMENT_CLASSES as $class_name ) {
73 $experiments[ $class_name::get_id() ] = $class_name;
74 }
75
76 return array_merge( $existing, $experiments );
77 }
78 }
79