From 1b6892d03534eee10bfbe6d59c05e34dfecf7016 Mon Sep 17 00:00:00 2001 From: priyanshuhaldar007 Date: Mon, 8 Jun 2026 13:10:59 +0530 Subject: [PATCH 1/5] feat: update the system instructions to generate a comment value score --- .../Comment_Moderation/system-instruction.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/Abilities/Comment_Moderation/system-instruction.php b/includes/Abilities/Comment_Moderation/system-instruction.php index 9369e7676..16a7a9433 100644 --- a/includes/Abilities/Comment_Moderation/system-instruction.php +++ b/includes/Abilities/Comment_Moderation/system-instruction.php @@ -6,7 +6,7 @@ */ return <<<'INSTRUCTION' -You are a comment moderation assistant. Analyze the provided comment and return the following: +You are a comment moderation assistant. You will be given an article and a comment left on that article. Analyze the comment and return the following: 1. "toxicity_score": A number between 0 and 1 indicating how toxic/harmful the comment is: - 0.0-0.3: Low toxicity (constructive, polite, or neutral) @@ -18,5 +18,17 @@ - "negative": The comment expresses criticism, disagreement, frustration, or disappointment - "neutral": The comment is factual, asks a question, or doesn't express clear emotion -Respond only with those two fields. No explanation, no markdown, no additional text. +3. "value_score": A number between 0 and 1 indicating how relevant and valuable the comment is to the article's discussion: + - 0.0-0.3: Low value (spam, engagement bait, generic acknowledgment such as "+1" or "thanks", or completely off-topic) + - 0.4-0.6: Moderate value (loosely related, adds minor context, or is brief but not noise) + - 0.7-1.0: High value (on-topic, substantive, adds new information, asks a meaningful question, or meaningfully advances the discussion) + + When scoring, consider: + - Relevance to the article's subject matter + - Whether the comment adds new information or perspective + - Whether it could stand alone as a meaningful contribution vs. filler + + If the article content is unavailable or too short to assess relevance, return null. + +Respond only with those three fields as a JSON object. No explanation, no markdown, no additional text. INSTRUCTION; From 5631c283853977019a6527359e329591f82790fc Mon Sep 17 00:00:00 2001 From: priyanshuhaldar007 Date: Mon, 8 Jun 2026 13:13:25 +0530 Subject: [PATCH 2/5] feat: add value score to comment analysis and enhance context retrieval --- .../Comment_Moderation/Comment_Analysis.php | 75 ++++++++++++++++--- 1 file changed, 64 insertions(+), 11 deletions(-) diff --git a/includes/Abilities/Comment_Moderation/Comment_Analysis.php b/includes/Abilities/Comment_Moderation/Comment_Analysis.php index 65723a081..d1e152398 100644 --- a/includes/Abilities/Comment_Moderation/Comment_Analysis.php +++ b/includes/Abilities/Comment_Moderation/Comment_Analysis.php @@ -66,6 +66,12 @@ protected function output_schema(): array { 'enum' => array_keys( Comment_Moderation::get_sentiment_config() ), 'description' => esc_html__( 'The sentiment of the comment.', 'ai' ), ), + 'value_score' => array( + 'type' => [ 'number', 'null' ], + 'minimum' => 0, + 'maximum' => 1, + 'description' => esc_html__( 'Value score from 0 (low value) to 1 (high value), or null if relevance cannot be assessed.', 'ai' ), + ), ), ); } @@ -129,7 +135,7 @@ public function analyze_comment_by_id( int $comment_id ) { update_comment_meta( $comment_id, Comment_Moderation::META_ANALYSIS_STATUS, Comment_Moderation::STATUS_PROCESSING ); // Analyze the comment. - $result = $this->analyze_comment( $comment->comment_content, $comment->comment_author ); + $result = $this->analyze_comment( $comment->comment_content, $comment->comment_author, $comment->comment_post_ID ); if ( is_wp_error( $result ) ) { // Mark as failed. @@ -140,6 +146,7 @@ public function analyze_comment_by_id( int $comment_id ) { // Store the results. update_comment_meta( $comment_id, Comment_Moderation::META_TOXICITY_SCORE, $result['toxicity_score'] ); update_comment_meta( $comment_id, Comment_Moderation::META_SENTIMENT, $result['sentiment'] ); + update_comment_meta( $comment_id, Comment_Moderation::META_VALUE_SCORE, $result['value_score'] ); update_comment_meta( $comment_id, Comment_Moderation::META_ANALYSIS_STATUS, Comment_Moderation::STATUS_COMPLETE ); update_comment_meta( $comment_id, Comment_Moderation::META_ANALYZED_AT, time() ); @@ -147,6 +154,7 @@ public function analyze_comment_by_id( int $comment_id ) { 'comment_id' => $comment_id, 'toxicity_score' => $result['toxicity_score'], 'sentiment' => $result['sentiment'], + 'value_score' => $result['value_score'], ); } @@ -190,8 +198,9 @@ private function response_schema(): array { 'properties' => array( 'toxicity_score' => array( 'type' => 'number' ), 'sentiment' => array( 'type' => 'string' ), + 'value_score' => array( 'type' => 'number' ), ), - 'required' => array( 'toxicity_score', 'sentiment' ), + 'required' => array( 'toxicity_score', 'sentiment', 'value_score' ), 'additionalProperties' => false, ); @@ -205,6 +214,38 @@ private function response_schema(): array { return (array) apply_filters( 'wpai_comment_analysis_response_schema', $schema ); } + /** + * Function to return context from the post for comment analysis. + * @param int $post_id The ID of the post. + * @return string The content of the post. + */ + private function get_post_context( int $post_id ): ?string { + $post = get_post( $post_id ); + + // 1. Use excerpt if available (human-written, most reliable) + $excerpt = trim( $post->post_excerpt ); + if ( ! empty( $excerpt ) ) { + return $excerpt; + } + + // 2. Fall back to AI-generated summary if available + $ai_summary = trim( get_post_meta( $post_id, '_ai_post_summary', true ) ); + if ( ! empty( $ai_summary ) ) { + return $ai_summary; + } + + // 3. Fall back to trimmed post content (strip tags, normalize whitespace) + $content = wp_strip_all_tags( $post->post_content ); + $content = preg_replace( '/\s+/', ' ', $content ); + $content = trim( $content ); + + if ( empty( $content ) ) { + return null; + } + + return mb_substr( $content, 0, 650 ); + } + /** * Analyzes a comment for toxicity and sentiment. * @@ -212,9 +253,11 @@ private function response_schema(): array { * * @param string $content The comment content. * @param string $author The comment author name. - * @return array{toxicity_score: float, sentiment: string}|\WP_Error The analysis result. + * @param string $post_id The ID of the post. + * @return array{toxicity_score: float, sentiment: string, value_score: float|null}|\WP_Error The analysis result. */ - private function analyze_comment( string $content, string $author ) { + private function analyze_comment( string $content, string $author, string $post_id ) { + /** * Filters the comment analysis result before calling the AI provider. * @@ -223,20 +266,24 @@ private function analyze_comment( string $content, string $author ) { * * @since 0.9.0 * - * @param array{toxicity_score: float, sentiment: string}|null $result Precomputed analysis result. - * @param string $content Comment content. - * @param string $author Comment author name. + * @param array{toxicity_score: float, sentiment: string, value_score: float|null}|null $result Precomputed analysis result. + * @param string $content Comment content. + * @param string $author Comment author name. + * @param string $post_id The ID of the post. */ - $pre_result = apply_filters( 'wpai_comment_analysis_result', null, $content, $author ); + $pre_result = apply_filters( 'wpai_comment_analysis_result', null, $content, $author, $post_id ); if ( is_array( $pre_result ) ) { return $this->sanitize_analysis_result( $pre_result ); } + $post_context = $this->get_post_context( absint( $post_id ) ); + $prompt = sprintf( - "Comment by %s:\n\"\"\"%s\"\"\"", + "Comment by %s:\n\"\"\"%s\"\"\"\nContext:\n\"\"\"%s\"\"\"", $author, - $content + $content, + $post_context ); $prompt_builder = $this->get_prompt_builder( $prompt ); @@ -290,7 +337,7 @@ private function get_prompt_builder( string $prompt ) { * @since 0.9.0 * * @param array $result Raw analysis result. - * @return array{toxicity_score: float, sentiment: string} Sanitized analysis result. + * @return array{toxicity_score: float, sentiment: string, value_score: float|null} Sanitized analysis result. */ private function sanitize_analysis_result( array $result ): array { // Validate and sanitize the response. @@ -302,10 +349,16 @@ private function sanitize_analysis_result( array $result ): array { $sentiment = isset( $result['sentiment'] ) && in_array( $result['sentiment'], $valid_sentiments, true ) ? $result['sentiment'] : Comment_Moderation::SENTIMENT_NEUTRAL; + + $value_score = null; + if ( isset( $result['value_score'] ) ) { + $value_score = max( 0, min( 1, (float) $result['value_score'] ) ); + } return array( 'toxicity_score' => $toxicity_score, 'sentiment' => $sentiment, + 'value_score' => $value_score, ); } } From aeabc2cd8b62c8ebcef44d1b18f48dfd907611bd Mon Sep 17 00:00:00 2001 From: priyanshuhaldar007 Date: Mon, 8 Jun 2026 13:13:43 +0530 Subject: [PATCH 3/5] feat: add value score functionality to comment moderation to display in admin dashboard --- .../Comment_Moderation/Comment_Moderation.php | 173 +++++++++++++++++- 1 file changed, 165 insertions(+), 8 deletions(-) diff --git a/includes/Experiments/Comment_Moderation/Comment_Moderation.php b/includes/Experiments/Comment_Moderation/Comment_Moderation.php index 98d526ea7..90ea20db2 100644 --- a/includes/Experiments/Comment_Moderation/Comment_Moderation.php +++ b/includes/Experiments/Comment_Moderation/Comment_Moderation.php @@ -44,6 +44,13 @@ class Comment_Moderation extends Abstract_Feature { */ public const META_SENTIMENT = '_wpai_sentiment'; + /** + * Comment meta key for value score. + * + * @var string + */ + public const META_VALUE_SCORE = '_wpai_value_score'; + /** * Comment meta key for analysis status. * @@ -128,6 +135,63 @@ class Comment_Moderation extends Abstract_Feature { */ public const TOXICITY_HIGH = 'high'; + /** + * Value score level: low. + * + * @var string + */ + public const VALUE_SCORE_LOW = 'low'; + + /** + * Value score level: medium. + * + * @var string + */ + public const VALUE_SCORE_MEDIUM = 'medium'; + + /** + * Value score level: high. + * + * @var string + */ + public const VALUE_SCORE_HIGH = 'high'; + + /** + * Gets the configuration for Value_Score levels. + * + * @since 1.0.0 + * + * @return array The Value_Score configuration. + */ + public static function get_value_score_config(): array { + return array( + self::VALUE_SCORE_LOW => array( + 'label' => __( 'Low', 'ai' ), + 'filterLabel' => __( 'Low Value Score (<40%)', 'ai' ), + 'class' => 'ai-badge--low-value', + 'icon' => '✓', + 'min' => 0.0, + 'max' => 0.4, + ), + self::VALUE_SCORE_MEDIUM => array( + 'label' => __( 'Medium', 'ai' ), + 'filterLabel' => __( 'Medium Value Score (40%-69%)', 'ai' ), + 'class' => 'ai-badge--medium-value', + 'icon' => '👍', + 'min' => 0.4, + 'max' => 0.7, + ), + self::VALUE_SCORE_HIGH => array( + 'label' => __( 'High', 'ai' ), + 'filterLabel' => __( 'High Value Score (>=70%)', 'ai' ), + 'class' => 'ai-badge--high-value', + 'icon' => '🌟', + 'min' => 0.7, + 'max' => 1.0, + ), + ); + } + /** * Gets the configuration for sentiment levels. * @@ -372,8 +436,9 @@ public function add_columns( $columns ): array { continue; } - $new_columns['wpai_sentiment'] = __( 'Sentiment', 'ai' ); - $new_columns['wpai_toxicity'] = __( 'Toxicity', 'ai' ); + $new_columns['wpai_sentiment'] = __( 'Sentiment', 'ai' ); + $new_columns['wpai_toxicity'] = __( 'Toxicity', 'ai' ); + $new_columns['wpai_value_score'] = __( 'Value', 'ai' ); } return $new_columns; @@ -420,7 +485,8 @@ public function add_dashboard_pills( $comment_excerpt, $comment_id, $comment ): } $sentiment = get_comment_meta( $comment_id, self::META_SENTIMENT, true ); - $score = (float) get_comment_meta( $comment_id, self::META_TOXICITY_SCORE, true ); + $toxicity = (float) get_comment_meta( $comment_id, self::META_TOXICITY_SCORE, true ); + $value = (float) get_comment_meta( $comment_id, self::META_VALUE_SCORE, true ); // Capture the pills HTML in an output buffer. ob_start(); @@ -428,7 +494,8 @@ public function add_dashboard_pills( $comment_excerpt, $comment_id, $comment ):
render_sentiment_badge( (string) $sentiment ); - $this->render_toxicity_badge( $score ); + $this->render_toxicity_badge( $toxicity ); + $this->render_value_score_badge( $value ); ?>
+ + + query_vars['orderby'] = 'wpai_toxicity_sort'; + } elseif ( 'wpai_value_score' === $orderby ) { + $meta_query[] = array( + 'relation' => 'OR', + 'wpai_value_score_sort' => array( + 'key' => self::META_VALUE_SCORE, + 'compare' => 'EXISTS', + 'type' => 'DECIMAL(10, 5)', + ), + 'wpai_value_score_empty' => array( + 'key' => self::META_VALUE_SCORE, + 'compare' => 'NOT EXISTS', + ), + ); + + $query->query_vars['orderby'] = 'wpai_value_score_sort'; } if ( empty( $meta_query ) ) { @@ -612,6 +711,8 @@ public function render_column( $column_name, $comment_id ): void { $this->render_sentiment_column( (int) $comment_id, $status ); } elseif ( 'wpai_toxicity' === (string) $column_name ) { $this->render_toxicity_column( (int) $comment_id, $status ); + } elseif ( 'wpai_value_score' === (string) $column_name ) { + $this->render_value_score_column( (int) $comment_id, $status ); } } @@ -663,6 +764,30 @@ private function render_toxicity_column( int $comment_id, string $status ): void } } + /** + * Renders the value score column content. + * + * @since 1.0.0 + * + * @param int $comment_id The comment ID. + * @param string $status The analysis status. + */ + private function render_value_score_column( int $comment_id, string $status ): void { + if ( self::STATUS_COMPLETE === $status ) { + $score = (float) get_comment_meta( $comment_id, self::META_VALUE_SCORE, true ); + $this->render_value_score_badge( $score ); + } elseif ( self::STATUS_PENDING === $status ) { + $this->render_pending_badge( $comment_id ); + } elseif ( self::STATUS_PROCESSING === $status ) { + $this->render_processing_badge( $comment_id ); + } elseif ( self::STATUS_FAILED === $status ) { + $this->render_failed_badge(); + } else { + // Empty or not analyzed - show dash. + echo ''; + } + } + /** * Renders a sentiment badge. * @@ -716,6 +841,37 @@ private function render_toxicity_badge( float $score ): void { ); } + /** + * Renders a value score badge. + * + * @since 1.0.0 + * + * @param float $score The value score (0-1). + */ + private function render_value_score_badge( float $score ): void { + $config = self::get_value_score_config(); + $badge = $config[ self::VALUE_SCORE_LOW ]; + + foreach ( $config as $tier ) { + if ( $score >= $tier['min'] && ( $score < $tier['max'] || 1.0 === $tier['max'] ) ) { + $badge = $tier; + break; + } + } + $label = $badge['label']; + $class = $badge['class']; + $icon = $badge['icon']; + + printf( + '%s %s', + esc_attr( $class ), + esc_attr( $label ), + absint( $score * 100 ), + esc_html( $icon ), + esc_html( $label ) + ); + } + /** * Renders a pending badge for comments queued for analysis. * @@ -965,6 +1121,7 @@ public function enqueue_assets( $hook_suffix ): void { 'labels' => array( 'sentiment' => self::get_sentiment_config(), 'toxicity' => self::get_toxicity_config(), + 'value_score' => self::get_value_score_config(), ), ) ); @@ -1010,17 +1167,17 @@ public function add_inline_styles(): void { color: #383d41; } - .ai-badge--low-toxicity { + .ai-badge--low-toxicity, .ai-badge--high-value { background-color: #d4edda; color: #155724; } - .ai-badge--medium-toxicity { + .ai-badge--medium-toxicity, .ai-badge--medium-value { background-color: #fff3cd; color: #856404; } - .ai-badge--high-toxicity { + .ai-badge--high-toxicity, .ai-badge--low-value { background-color: #f8d7da; color: #721c24; } From 63e112c184995b5010c111cd49c7423bc2d5c0ff Mon Sep 17 00:00:00 2001 From: priyanshuhaldar007 Date: Mon, 8 Jun 2026 13:14:15 +0530 Subject: [PATCH 4/5] feat: enhance comment analysis by adding value score badge and display logic on JS to update te status --- .../components/LazyAnalysisController.tsx | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/experiments/comment-moderation/components/LazyAnalysisController.tsx b/src/experiments/comment-moderation/components/LazyAnalysisController.tsx index 1be87f447..c41d3406e 100644 --- a/src/experiments/comment-moderation/components/LazyAnalysisController.tsx +++ b/src/experiments/comment-moderation/components/LazyAnalysisController.tsx @@ -23,6 +23,7 @@ import { runAbility } from '../../../utils/run-ability'; type AnalysisResult = { comment_id: number; toxicity_score: number; + value_score: number; sentiment: 'positive' | 'negative' | 'neutral'; }; @@ -47,6 +48,16 @@ declare global { max: number; } >; + value_score: Record< + string, + { + label: string; + class: string; + icon: string; + min: number; + max: number; + } + >; }; }; } @@ -56,6 +67,7 @@ type PendingComment = { id: number; sentimentBadge: HTMLElement; toxicityBadge: HTMLElement; + valueScoreBadge: HTMLElement; }; /** @@ -102,12 +114,39 @@ function getSentimentDisplay( sentiment: string ): { }; } +/** + * Gets the value score label and class from score. + */ +function getValueScoreDisplay( score: number ): { + label: string; + className: string; + icon: string; +} { + const valueScores = window.aiCommentModerationData?.labels?.value_score || {}; + + for ( const config of Object.values( valueScores ) ) { + if ( + score >= config.min && + ( score < config.max || config.max === 1 ) + ) { + return { + label: config.label, + className: config.class, + icon: config.icon, + }; + } + } + + return { label: 'Low', className: 'ai-badge--low-value-score', icon: '✓' }; +} + /** * Updates the badge elements with analysis results. */ function updateBadges( comment: PendingComment, result: AnalysisResult ): void { const sentimentDisplay = getSentimentDisplay( result.sentiment ); const toxicityDisplay = getToxicityDisplay( result.toxicity_score ); + const valueScoreDisplay = getValueScoreDisplay( result.value_score ); // Update sentiment badge. comment.sentimentBadge.className = `ai-badge ${ sentimentDisplay.className }`; @@ -121,6 +160,13 @@ function updateBadges( comment: PendingComment, result: AnalysisResult ): void { comment.toxicityBadge.title = `${ toxicityDisplay.label } (${ Math.round( result.toxicity_score * 100 ) }%)`; + + // Update value score badge. + comment.valueScoreBadge.className = `ai-badge ${ valueScoreDisplay.className }`; + comment.valueScoreBadge.textContent = `${ valueScoreDisplay.icon } ${ valueScoreDisplay.label }`; + comment.valueScoreBadge.title = `${ valueScoreDisplay.label } (${ Math.round( + result.value_score * 100 + ) }%)`; } /** @@ -198,13 +244,17 @@ export function LazyAnalysisController(): React.ReactElement | null { entry.sentimentBadge = badge; } else if ( cell?.classList.contains( 'column-wpai_toxicity' ) ) { entry.toxicityBadge = badge; + } else if ( cell?.classList.contains( 'column-wpai_value_score' ) ) { + entry.valueScoreBadge = badge; } } ); // Only return comments that have both badges. return Array.from( commentMap.values() ).filter( ( c ): c is PendingComment => - c.sentimentBadge !== undefined && c.toxicityBadge !== undefined + c.sentimentBadge !== undefined && + c.toxicityBadge !== undefined && + c.valueScoreBadge !== undefined ); }, [] ); @@ -216,6 +266,7 @@ export function LazyAnalysisController(): React.ReactElement | null { // Mark as processing. markBadgeProcessing( comment.sentimentBadge ); markBadgeProcessing( comment.toxicityBadge ); + markBadgeProcessing( comment.valueScoreBadge ); try { const result = await runAbility< AnalysisResult >( @@ -235,6 +286,7 @@ export function LazyAnalysisController(): React.ReactElement | null { // Keep failed state visible but do not auto-retry in this lazy pass. markBadgeFailed( comment.sentimentBadge ); markBadgeFailed( comment.toxicityBadge ); + markBadgeFailed( comment.valueScoreBadge ); } }, [] From e724be154da37ce5360d5ffb6297b0bfbf3c74bc Mon Sep 17 00:00:00 2001 From: priyanshuhaldar007 Date: Mon, 8 Jun 2026 13:40:01 +0530 Subject: [PATCH 5/5] fix: resolve lint and phpcs issues --- .../Comment_Moderation/Comment_Analysis.php | 4 +-- .../Comment_Moderation/Comment_Moderation.php | 28 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/includes/Abilities/Comment_Moderation/Comment_Analysis.php b/includes/Abilities/Comment_Moderation/Comment_Analysis.php index d1e152398..feb864ec2 100644 --- a/includes/Abilities/Comment_Moderation/Comment_Analysis.php +++ b/includes/Abilities/Comment_Moderation/Comment_Analysis.php @@ -67,7 +67,7 @@ protected function output_schema(): array { 'description' => esc_html__( 'The sentiment of the comment.', 'ai' ), ), 'value_score' => array( - 'type' => [ 'number', 'null' ], + 'type' => array( 'number', 'null' ), 'minimum' => 0, 'maximum' => 1, 'description' => esc_html__( 'Value score from 0 (low value) to 1 (high value), or null if relevance cannot be assessed.', 'ai' ), @@ -349,7 +349,7 @@ private function sanitize_analysis_result( array $result ): array { $sentiment = isset( $result['sentiment'] ) && in_array( $result['sentiment'], $valid_sentiments, true ) ? $result['sentiment'] : Comment_Moderation::SENTIMENT_NEUTRAL; - + $value_score = null; if ( isset( $result['value_score'] ) ) { $value_score = max( 0, min( 1, (float) $result['value_score'] ) ); diff --git a/includes/Experiments/Comment_Moderation/Comment_Moderation.php b/includes/Experiments/Comment_Moderation/Comment_Moderation.php index 90ea20db2..3a7bfd6c3 100644 --- a/includes/Experiments/Comment_Moderation/Comment_Moderation.php +++ b/includes/Experiments/Comment_Moderation/Comment_Moderation.php @@ -165,7 +165,7 @@ class Comment_Moderation extends Abstract_Feature { */ public static function get_value_score_config(): array { return array( - self::VALUE_SCORE_LOW => array( + self::VALUE_SCORE_LOW => array( 'label' => __( 'Low', 'ai' ), 'filterLabel' => __( 'Low Value Score (<40%)', 'ai' ), 'class' => 'ai-badge--low-value', @@ -173,7 +173,7 @@ public static function get_value_score_config(): array { 'min' => 0.0, 'max' => 0.4, ), - self::VALUE_SCORE_MEDIUM => array( + self::VALUE_SCORE_MEDIUM => array( 'label' => __( 'Medium', 'ai' ), 'filterLabel' => __( 'Medium Value Score (40%-69%)', 'ai' ), 'class' => 'ai-badge--medium-value', @@ -181,7 +181,7 @@ public static function get_value_score_config(): array { 'min' => 0.4, 'max' => 0.7, ), - self::VALUE_SCORE_HIGH => array( + self::VALUE_SCORE_HIGH => array( 'label' => __( 'High', 'ai' ), 'filterLabel' => __( 'High Value Score (>=70%)', 'ai' ), 'class' => 'ai-badge--high-value', @@ -436,9 +436,9 @@ public function add_columns( $columns ): array { continue; } - $new_columns['wpai_sentiment'] = __( 'Sentiment', 'ai' ); - $new_columns['wpai_toxicity'] = __( 'Toxicity', 'ai' ); - $new_columns['wpai_value_score'] = __( 'Value', 'ai' ); + $new_columns['wpai_sentiment'] = __( 'Sentiment', 'ai' ); + $new_columns['wpai_toxicity'] = __( 'Toxicity', 'ai' ); + $new_columns['wpai_value_score'] = __( 'Value', 'ai' ); } return $new_columns; @@ -575,8 +575,8 @@ public function add_filter_dropdowns(): void { * @return array The modified sortable columns. */ public function add_sortable_columns( $columns ): array { - $columns['wpai_sentiment'] = 'wpai_sentiment'; - $columns['wpai_toxicity'] = 'wpai_toxicity'; + $columns['wpai_sentiment'] = 'wpai_sentiment'; + $columns['wpai_toxicity'] = 'wpai_toxicity'; $columns['wpai_value_score'] = 'wpai_value_score'; return $columns; @@ -605,9 +605,9 @@ public function handle_sorting_and_filtering( $query ): void { } // Handle filtering. - $sentiment = isset( $_GET['wpai_sentiment'] ) ? sanitize_text_field( wp_unslash( $_GET['wpai_sentiment'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $toxicity = isset( $_GET['wpai_toxicity'] ) ? sanitize_text_field( wp_unslash( $_GET['wpai_toxicity'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $value = isset( $_GET['wpai_value_score'] ) ? sanitize_text_field( wp_unslash( $_GET['wpai_value_score'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $sentiment = isset( $_GET['wpai_sentiment'] ) ? sanitize_text_field( wp_unslash( $_GET['wpai_sentiment'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $toxicity = isset( $_GET['wpai_toxicity'] ) ? sanitize_text_field( wp_unslash( $_GET['wpai_toxicity'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $value = isset( $_GET['wpai_value_score'] ) ? sanitize_text_field( wp_unslash( $_GET['wpai_value_score'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $sentiments = self::get_sentiment_config(); if ( ! empty( $sentiment ) && array_key_exists( $sentiment, $sentiments ) ) { $meta_query[] = array( @@ -674,7 +674,7 @@ public function handle_sorting_and_filtering( $query ): void { $query->query_vars['orderby'] = 'wpai_toxicity_sort'; } elseif ( 'wpai_value_score' === $orderby ) { $meta_query[] = array( - 'relation' => 'OR', + 'relation' => 'OR', 'wpai_value_score_sort' => array( 'key' => self::META_VALUE_SCORE, 'compare' => 'EXISTS', @@ -1119,8 +1119,8 @@ public function enqueue_assets( $hook_suffix ): void { array( 'enabled' => $this->is_enabled(), 'labels' => array( - 'sentiment' => self::get_sentiment_config(), - 'toxicity' => self::get_toxicity_config(), + 'sentiment' => self::get_sentiment_config(), + 'toxicity' => self::get_toxicity_config(), 'value_score' => self::get_value_score_config(), ), )