| 1 |
<?php |
| 2 |
/** |
| 3 |
* Editorial Updates experiment implementation. |
| 4 |
* |
| 5 |
* @package WordPress\AI |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace WordPress\AI\Experiments\Editorial_Updates; |
| 11 |
|
| 12 |
use WordPress\AI\Abilities\Editorial_Updates\Editorial_Updates as Editorial_Updates_Ability; |
| 13 |
use WordPress\AI\Abstracts\Abstract_Feature; |
| 14 |
use WordPress\AI\Asset_Loader; |
| 15 |
use WordPress\AI\Experiments\Experiment_Category; |
| 16 |
|
| 17 |
// Exit if accessed directly. |
| 18 |
if ( ! defined( 'ABSPATH' ) ) { |
| 19 |
exit; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Editorial Updates experiment. |
| 24 |
* |
| 25 |
* Adds functionality to apply refinements based on editorial |
| 26 |
* feedback (Notes) left on individual blocks. |
| 27 |
* |
| 28 |
* @since 0.8.0 |
| 29 |
*/ |
| 30 |
class Editorial_Updates extends Abstract_Feature { |
| 31 |
|
| 32 |
/** |
| 33 |
* {@inheritDoc} |
| 34 |
*/ |
| 35 |
public static function get_id(): string { |
| 36 |
return 'editorial-updates'; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* {@inheritDoc} |
| 41 |
* |
| 42 |
* @since 0.8.0 |
| 43 |
*/ |
| 44 |
protected function load_metadata(): array { |
| 45 |
return array( |
| 46 |
'label' => __( 'Editorial Updates', 'ai' ), |
| 47 |
'description' => __( 'Applies pending editorial Notes to your content automatically. Requires an AI connector that includes support for text generation models.', 'ai' ), |
| 48 |
'category' => Experiment_Category::EDITOR, |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* {@inheritDoc} |
| 54 |
* |
| 55 |
* @since 0.8.0 |
| 56 |
*/ |
| 57 |
public function register(): void { |
| 58 |
add_action( 'wp_abilities_api_init', array( $this, 'register_abilities' ) ); |
| 59 |
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_assets' ) ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Registers any needed abilities. |
| 64 |
* |
| 65 |
* @since 0.8.0 |
| 66 |
*/ |
| 67 |
public function register_abilities(): void { |
| 68 |
wp_register_ability( |
| 69 |
'ai/' . $this->get_id(), |
| 70 |
array( |
| 71 |
'label' => $this->get_label(), |
| 72 |
'description' => $this->get_description(), |
| 73 |
'ability_class' => Editorial_Updates_Ability::class, |
| 74 |
), |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Enqueues and localizes the block editor script. |
| 80 |
* |
| 81 |
* @since 0.8.0 |
| 82 |
*/ |
| 83 |
public function enqueue_assets(): void { |
| 84 |
Asset_Loader::enqueue_script( 'editorial_updates', 'experiments/editorial-updates', array( 'include_core_abilities' => true ) ); |
| 85 |
|
| 86 |
$post_type = get_post_type(); |
| 87 |
$post_type_object = $post_type ? get_post_type_object( $post_type ) : null; |
| 88 |
$rest_base = $post_type_object && $post_type_object->rest_base |
| 89 |
? $post_type_object->rest_base |
| 90 |
: null; |
| 91 |
|
| 92 |
Asset_Loader::localize_script( |
| 93 |
'editorial_updates', |
| 94 |
'EditorialUpdatesData', |
| 95 |
array( |
| 96 |
'enabled' => $this->is_enabled(), |
| 97 |
'rest_base' => $rest_base, |
| 98 |
'admin_url' => admin_url(), |
| 99 |
) |
| 100 |
); |
| 101 |
} |
| 102 |
} |
| 103 |
|