Changeset 3161458
- Timestamp:
- 10/02/2024 11:13:43 AM (17 months ago)
- Location:
- moderation-api-automated-content-moderation/trunk
- Files:
-
- 5 edited
-
admin/class-moderation-api-admin.php (modified) (2 diffs)
-
includes/class-moderation-api.php (modified) (2 diffs)
-
moderation-api.php (modified) (2 diffs)
-
public/class-moderation-api-public.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
moderation-api-automated-content-moderation/trunk/admin/class-moderation-api-admin.php
r3143763 r3161458 113 113 public function init() { 114 114 // check page is moderation-api 115 if ( $_GET['page'] !== 'moderation-api') {115 if (!isset($_GET['page']) || $_GET['page'] !== 'moderation-api') { 116 116 return; 117 117 } … … 311 311 if ($column_name === 'custom_flagged') { 312 312 $flagged = get_comment_meta($comment_id, 'modapi_flagged', true); 313 } 313 if($flagged){ 314 echo '<span style="color: red;">' . __('Flagged', 'moderation-api') . '</span>'; 315 }else{ 316 echo '<span style="color: green;">' . __('Not Flagged', 'moderation-api') . '</span>'; 317 } 318 } 319 } 320 321 322 function add_modapi_error_column($columns) { 323 $columns['modapi_error'] = __('Moderation API error', 'moderation-api'); 324 return $columns; 325 } 326 327 328 function populate_modapi_error_column($column, $comment_ID) { 329 if ('modapi_error' === $column) { 330 $modapi_error = get_comment_meta($comment_ID, 'modapi_error', true); 331 if ($modapi_error) { 332 echo esc_html($modapi_error); 333 } else { 334 echo __('', 'moderation-api'); 335 } 336 } 314 337 } 315 338 -
moderation-api-automated-content-moderation/trunk/includes/class-moderation-api.php
r3143763 r3161458 171 171 $this->loader->add_action( 'manage_comments_custom_column', $plugin_admin, 'show_flagged_custom_field', 10, 2 ); 172 172 173 } 174 175 173 174 // Populate the custom column with the modapi_error meta value 175 $this->loader->add_action('manage_comments_custom_column', $plugin_admin, 'populate_modapi_error_column', 10, 2); 176 177 // Add a custom column to the comments list table 178 $this->loader->add_filter('manage_edit-comments_columns', $plugin_admin, 'add_modapi_error_column'); 179 } 180 176 181 177 182 … … 198 203 $this->loader->add_filter('query_vars', $plugin_public, 'my_plugin_webhook_query_vars'); 199 204 $this->loader->add_action('template_redirect', $plugin_public, 'my_plugin_process_webhook'); 200 201 205 } 202 206 -
moderation-api-automated-content-moderation/trunk/moderation-api.php
r3143763 r3161458 17 17 * Plugin URI: https://moderationapi.com/integrations/wordpress-content-moderation 18 18 * Description: Use Moderation API to automatically moderate comments on your WordPress site. Detects a large range of contet such as bullying, discrimination, sentiment, NSFW, PII, and much more. 19 * Version: 1.0. 019 * Version: 1.0.1 20 20 * Author: Moderation API 21 21 * Author URI: https://moderationapi.com/ … … 36 36 * Rename this for your plugin and update it as you release new versions. 37 37 */ 38 define( 'MODERATION_API_VERSION', '1.0. 0' );38 define( 'MODERATION_API_VERSION', '1.0.1' ); 39 39 40 40 define( 'MODERATION_API_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); -
moderation-api-automated-content-moderation/trunk/public/class-moderation-api-public.php
r3143763 r3161458 122 122 } 123 123 124 $url = Moderation_Api::API_URL . "/api/v1/moderat ion/text";124 $url = Moderation_Api::API_URL . "/api/v1/moderate/text"; 125 125 $headers = array( 126 126 'Authorization' => 'Bearer ' . $api_key, … … 129 129 $data = array( 130 130 'value' => $text, 131 'authorId' => $authorId,132 'contextId' => $post_id,131 'authorId' => (string) $authorId, 132 'contextId' => (string) $post_id, 133 133 'metadata' => array( 134 134 'comment_id' => $comment_id, … … 149 149 return $responseData; 150 150 } else { 151 // Log the error 152 error_log("Error analyzing comment: " . print_r($response, true)); 151 153 // Handle error 152 154 return false; … … 156 158 157 159 public function moderation_api_comment_post( $comment_ID, $comment_approved ) { 158 159 // check if key is set 160 // Check if key is set 160 161 $api_key = Moderation_Api::get_api_key(); 161 162 if (!$api_key) { … … 163 164 } 164 165 165 // get the comment166 // Get the comment 166 167 $comment = get_comment( $comment_ID ); 167 168 168 169 try { 169 // analyze the comment170 // Analyze the comment 170 171 $analysis = $this->analyze_comment( $comment ); 171 // get flagged field 172 173 // Check if analysis is successful 174 if ($analysis === false) { 175 throw new Exception('Analysis failed'); 176 } 177 178 // Get flagged field 172 179 $flagged = $analysis['flagged']; 180 // Log the response 181 error_log("Analysis response: " . print_r($analysis, true)); 173 182 } catch (\Throwable $th) { 174 // error183 // Error 175 184 wp_set_comment_status( $comment_ID, 'hold' ); 176 185 add_comment_meta( $comment_ID, 'modapi_error', esc_html($th->getMessage()) ); 177 186 return; 178 187 } 179 180 181 188 182 189 $action = get_option( 'modapi_flagged_action' ); 183 190 $actionLabel = 'do nothing'; 184 191 // 0 = do not do anything 185 // 1 = move to approved186 // 2 = move to pending187 // 3 = move to spam188 // 4 = move to trash192 // 1 = move to approved 193 // 2 = move to pending 194 // 3 = move to spam 195 // 4 = move to trash 189 196 190 197 if($flagged){ … … 218 225 } 219 226 220 // add the analysis to the comment meta227 // Add the analysis to the comment meta 221 228 add_comment_meta( $comment_ID, 'modapi_flagged', $flagged ); 222 // add the action229 // Add the action 223 230 add_comment_meta( $comment_ID, 'modapi_flagged_action', $actionLabel); 224 231 -
moderation-api-automated-content-moderation/trunk/readme.txt
r3143763 r3161458 38 38 39 39 Moderation API is a paid service. You can use the free tier to get started and upgrade to a paid plan to get more powerful features. 40 41 = Where can I see if Moderation API is working? = 42 43 We recommend to use the review queue to see if Moderation API is working. You might want to update the queue settings to show all comments instead of just flagged ones. You can also see the API response in the WordPress admin under "Comments". 40 44 41 45 = Why do I need to connect my WordPress site to Moderation API? = … … 79 83 * Initial release 80 84 85 = 1.0.1 = 86 * Add error column to comments table 87 * Fix issue where comments were not being added to the review queue 88 * Add flagged labels to comments table 89 81 90 == Upgrade Notice == 82 91 83 = 1.0. 0=84 Initial release 92 = 1.0.1 = 93 * Important: Fixes critical issue with the review queue. Please update to ensure comments are processed correctly.
Note: See TracChangeset
for help on using the changeset viewer.