Making WordPress.org

Changeset 12705


Ignore:
Timestamp:
07/03/2023 07:25:34 PM (3 years ago)
Author:
coffee2code
Message:

Photo Directory, Flagged: Automatically flag submissions that seem controversial based on Vision API's moderation assessment.

See #7119.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/flagged.php

    r12699 r12705  
    3030        // Register post statuses.
    3131        add_action( 'init',                                  [ __CLASS__, 'register_post_statuses' ] );
     32
     33        // Change submission status to flagged if Vision analysis suggests potential concern.
     34        add_action( 'wporg_photos_photo_analysis_complete',  [ __CLASS__, 'flag_controversial_photos' ], 20 );
    3235
    3336        // Restrict access to the listing of flagged photos.
     
    121124        $post_statuses[] = self::get_post_status();
    122125        return $post_statuses;
     126    }
     127
     128    /**
     129     * Flags submission if Vision analysis suggests potential concerns.
     130     *
     131     * @param int  $image_id The ID of the attachment that is the photo.
     132     */
     133    public static function flag_controversial_photos( $image_id ) {
     134        $post_id = wp_get_post_parent_id( $image_id );
     135
     136        if ( ! $post_id ) {
     137            return;
     138        }
     139
     140        if ( Photo::get_filtered_moderation_assessment( $post_id ) ) {
     141            wp_update_post( [
     142                'ID'          => $post_id,
     143                'post_status' => self::get_post_status(),
     144            ] );
     145        }
    123146    }
    124147
Note: See TracChangeset for help on using the changeset viewer.