Plugin Directory

Changeset 3161458


Ignore:
Timestamp:
10/02/2024 11:13:43 AM (17 months ago)
Author:
moderationapi
Message:

Update to version 1.0.1

Location:
moderation-api-automated-content-moderation/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • moderation-api-automated-content-moderation/trunk/admin/class-moderation-api-admin.php

    r3143763 r3161458  
    113113    public function init() {
    114114        // check page is moderation-api
    115         if ($_GET['page'] !== 'moderation-api') {
     115        if (!isset($_GET['page']) || $_GET['page'] !== 'moderation-api') {
    116116            return;
    117117        }
     
    311311        if ($column_name === 'custom_flagged') {
    312312                $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            }
    314337    }
    315338
  • moderation-api-automated-content-moderation/trunk/includes/class-moderation-api.php

    r3143763 r3161458  
    171171        $this->loader->add_action( 'manage_comments_custom_column', $plugin_admin, 'show_flagged_custom_field', 10, 2 );
    172172
    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
    176181
    177182
     
    198203        $this->loader->add_filter('query_vars', $plugin_public, 'my_plugin_webhook_query_vars');
    199204        $this->loader->add_action('template_redirect', $plugin_public, 'my_plugin_process_webhook');
    200 
    201205    }
    202206
  • moderation-api-automated-content-moderation/trunk/moderation-api.php

    r3143763 r3161458  
    1717 * Plugin URI:        https://moderationapi.com/integrations/wordpress-content-moderation
    1818 * 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.0
     19 * Version:           1.0.1
    2020 * Author:            Moderation API
    2121 * Author URI:        https://moderationapi.com/
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define( 'MODERATION_API_VERSION', '1.0.0' );
     38define( 'MODERATION_API_VERSION', '1.0.1' );
    3939
    4040define( 'MODERATION_API_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
  • moderation-api-automated-content-moderation/trunk/public/class-moderation-api-public.php

    r3143763 r3161458  
    122122        }
    123123
    124         $url = Moderation_Api::API_URL . "/api/v1/moderation/text";
     124        $url = Moderation_Api::API_URL . "/api/v1/moderate/text";
    125125        $headers = array(
    126126            'Authorization' => 'Bearer ' . $api_key,
     
    129129        $data = array(
    130130            'value' => $text,
    131             'authorId' => $authorId,
    132             'contextId' => $post_id,
     131            'authorId' => (string) $authorId,
     132            'contextId' => (string) $post_id,
    133133            'metadata' => array(
    134134                'comment_id' => $comment_id,
     
    149149            return $responseData;
    150150        } else {
     151            // Log the error
     152            error_log("Error analyzing comment: " . print_r($response, true));
    151153            // Handle error
    152154            return false;
     
    156158   
    157159    public function moderation_api_comment_post( $comment_ID, $comment_approved ) {
    158        
    159         //  check if key is set
     160        // Check if key is set
    160161        $api_key = Moderation_Api::get_api_key();
    161162        if (!$api_key) {
     
    163164        }
    164165
    165         // get the comment
     166        // Get the comment
    166167        $comment = get_comment( $comment_ID );
    167168
    168169        try {
    169             // analyze the comment
     170            // Analyze the comment
    170171            $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
    172179            $flagged = $analysis['flagged'];
     180            // Log the response
     181            error_log("Analysis response: " . print_r($analysis, true));
    173182        } catch (\Throwable $th) {
    174             // error
     183            // Error
    175184            wp_set_comment_status( $comment_ID, 'hold' );
    176185            add_comment_meta( $comment_ID, 'modapi_error', esc_html($th->getMessage()) );
    177186            return;
    178187        }
    179    
    180 
    181188
    182189        $action = get_option( 'modapi_flagged_action' );
    183190        $actionLabel = 'do nothing';
    184191        // 0 = do not do anything
    185         // 1 = move to approved
    186         // 2 = move to pending
    187         // 3 = move to spam
    188         // 4 = move to trash
     192            // 1 = move to approved
     193            // 2 = move to pending
     194            // 3 = move to spam
     195            // 4 = move to trash
    189196
    190197        if($flagged){
     
    218225        }
    219226
    220         // add the analysis to the comment meta
     227        // Add the analysis to the comment meta
    221228        add_comment_meta( $comment_ID, 'modapi_flagged', $flagged );
    222         // add the action
     229        // Add the action
    223230        add_comment_meta( $comment_ID, 'modapi_flagged_action', $actionLabel);
    224231   
  • moderation-api-automated-content-moderation/trunk/readme.txt

    r3143763 r3161458  
    3838
    3939Moderation 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
     43We 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".
    4044
    4145= Why do I need to connect my WordPress site to Moderation API? =
     
    7983* Initial release
    8084
     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
    8190== Upgrade Notice ==
    8291
    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.