__( 'Suggest Reply', 'ai' ), 'description' => __( 'Adds a "Suggest Reply" action to the Comments screen and Activity widget, enabling moderators to quickly generate comment reply suggestions.', 'ai' ), 'category' => Experiment_Category::ADMIN, 'usage' => array( 'trigger' => 'on_demand', 'runs' => __( 'When you click Suggest reply', 'ai' ), 'sends' => __( 'Comment text, author name, post title, and excerpt', 'ai' ), 'requests' => __( 'One request per click', 'ai' ), ), ); } /** * {@inheritDoc} * * @since 1.2.0 */ public function register(): void { add_action( 'wp_abilities_api_init', array( $this, 'register_abilities' ) ); add_filter( 'comment_row_actions', array( $this, 'add_row_action' ), 10, 2 ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); } /** * Registers the reply suggestion ability. * * @since 1.2.0 */ public function register_abilities(): void { wp_register_ability( 'ai/suggest-reply', array( 'label' => __( 'Reply Suggestion', 'ai' ), 'description' => __( 'Generates reply suggestions to a comment.', 'ai' ), 'ability_class' => Suggest_Reply_Ability::class, ) ); } /** * Adds a "Suggest reply" action link to the comment row actions. * * @since 1.2.0 * * @param mixed $actions The existing comment row actions. * @param \WP_Comment $comment The comment object. * @return array The modified actions array. */ public function add_row_action( $actions, $comment ): array { if ( ! is_array( $actions ) || ! $comment || ! is_a( $comment, '\WP_Comment' ) ) { return $actions; } $actions['wpai_suggest_reply'] = sprintf( '%s', absint( $comment->comment_ID ), esc_attr__( 'Suggest a reply to this comment', 'ai' ), esc_html__( 'Suggest reply', 'ai' ) ); return $actions; } /** * Enqueues assets for the Suggest Reply experiment. * * @since 1.2.0 * * @param string $hook_suffix The current admin page hook suffix. */ public function enqueue_assets( string $hook_suffix ): void { if ( ! in_array( $hook_suffix, array( 'edit-comments.php', 'index.php' ), true ) ) { return; } Asset_Loader::enqueue_script( 'suggest_reply', 'experiments/suggest-reply', array( 'include_core_abilities' => true ) ); Asset_Loader::enqueue_style( 'suggest_reply', 'experiments/suggest-reply' ); Asset_Loader::localize_script( 'suggest_reply', 'SuggestReplyData', array( 'enabled' => $this->is_enabled() ) ); } }