__( 'Excerpt Generation', 'ai' ), 'description' => __( 'Generates excerpt suggestions from content. Requires an AI connector that includes support for text generation models.', 'ai' ), 'category' => Experiment_Category::EDITOR, ); } /** * {@inheritDoc} */ public function register(): void { add_action( 'wp_abilities_api_init', array( $this, 'register_abilities' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); } /** * Registers any needed abilities. * * @since 0.2.0 */ public function register_abilities(): void { wp_register_ability( 'ai/' . $this->get_id(), array( 'label' => $this->get_label(), 'description' => $this->get_description(), 'ability_class' => Excerpt_Generation_Ability::class, ), ); } /** * Enqueues and localizes the admin script. * * @since 0.2.0 * * @param string $hook_suffix The current admin page hook suffix. */ public function enqueue_assets( string $hook_suffix ): void { // Load asset in new post and edit post screens only. if ( 'post.php' !== $hook_suffix && 'post-new.php' !== $hook_suffix ) { return; } $screen = get_current_screen(); // Load the assets only if the post type supports excerpts and is not an attachment. if ( ! $screen || ! post_type_supports( $screen->post_type, 'excerpt' ) || in_array( $screen->post_type, array( 'attachment' ), true ) ) { return; } Asset_Loader::enqueue_script( 'excerpt_generation', 'experiments/excerpt-generation', array( 'include_core_abilities' => true ) ); Asset_Loader::localize_script( 'excerpt_generation', 'ExcerptGenerationData', array( 'enabled' => $this->is_enabled(), 'minContentLength' => get_min_content_length( 'excerpt-generation', 250 ), ) ); } }