Making WordPress.org

Changeset 11713


Ignore:
Timestamp:
03/28/2022 11:06:18 PM (3 years ago)
Author:
coffee2code
Message:

Photo Directory, Photo: Add is_controversial() to determine if a photo might be of a controversial nature.

Currently only checks if Vision API assessed the photo as having any content criteria rating of 'possible' or more likely.

File:
1 edited

Legend:

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

    r11687 r11713  
    10261026    }
    10271027
     1028    /**
     1029     * Determines if a photo is controversial.
     1030     *
     1031     * This only applies for unpublished photos that also meet one of these
     1032     * criteria:
     1033     * - Flagged by Vision as being "possible" or more likely in any criteria category
     1034     *
     1035     * @param int|WP_Post|null Optional. The post or attachment. Default null,
     1036     *                         indicating the current post.
     1037     * @return bool True if photo is controversial, else false.
     1038     */
     1039    public static function is_controversial( $post = null ) {
     1040        $post = get_post( $post );
     1041
     1042        // If post is an attachment, get its parent.
     1043        if ( 'attachment' === get_post_type( $post ) ) {
     1044            $post = get_post( wp_get_post_parent_id( $post->ID ) );
     1045        }
     1046
     1047        if ( ! $post ) {
     1048            return false;
     1049        }
     1050
     1051        // Controversial if photo got flagged as 'possible' or more likely by Vision.
     1052        $flags = Photo::get_filtered_moderation_assessment( $post->ID );
     1053        if ( ! empty( $flags ) ) {
     1054            return true;
     1055        }
     1056
     1057        return false;
     1058    }
     1059
    10281060}
    10291061
Note: See TracChangeset for help on using the changeset viewer.