> */ private array $images = array(); public function register(): void { add_action( 'wp_footer', array( $this, 'render' ), 99 ); } public function add( int $attachment_id, int $post_id, string $description = '' ): void { if ( $attachment_id <= 0 || isset( $this->images[ $attachment_id ] ) || ! AI_State::is_ai_generated( $attachment_id ) || ! Post_Type_Scope::allows( $post_id ) ) { return; } $url = wp_get_attachment_url( $attachment_id ); if ( ! $url ) { return; } $type = AI_State::get_type( $attachment_id ); $details = Disclosure_Details::public_details( $attachment_id ); $object = array( '@type' => 'ImageObject', '@id' => esc_url_raw( $url ) . '#aiviso-disclosure', 'contentUrl' => esc_url_raw( $url ) ); $source_type = Digital_Source_Type::get( $attachment_id ); if ( '' !== $source_type ) { $object['digitalSourceType'] = $source_type; } $description = '' !== $description ? $description : Language_Manager::resolve_badge_text( Settings_Page::get(), $type, $attachment_id ); if ( '' !== $description ) { $object['description'] = $description; } if ( isset( $details['date_created'] ) ) { $object['dateCreated'] = $details['date_created']; unset( $details['date_created'] ); } if ( isset( $details['source_url'] ) ) { $object['isBasedOn'] = $details['source_url']; unset( $details['source_url'] ); } $names = array( 'ai_tool' => __( 'AI tool', 'aiviso-ai-image-disclosure' ), 'ai_model' => __( 'AI model or version', 'aiviso-ai-image-disclosure' ), 'reviewed_by' => __( 'Reviewed by', 'aiviso-ai-image-disclosure' ), 'review_date' => __( 'Review date', 'aiviso-ai-image-disclosure' ), 'public_note' => __( 'Public disclosure note', 'aiviso-ai-image-disclosure' ) ); $additional = array(); foreach ( $details as $key => $value ) { if ( isset( $names[ $key ] ) ) { $additional[] = array( '@type' => 'PropertyValue', 'name' => $names[ $key ], 'value' => $value ); } } if ( $additional ) { $object['additionalProperty'] = $additional; } $this->images[ $attachment_id ] = (array) apply_filters( 'aiviso_image_object', $object, $attachment_id, $post_id ); } public function render(): void { $options = Settings_Page::get(); $enabled = ! empty( $options['machine_readable_metadata'] ); if ( ! apply_filters( 'aiviso_machine_readable_metadata_enabled', $enabled, $this->images ) || ! $this->images ) { return; } $graph = array( '@context' => 'https://schema.org', '@graph' => array_values( $this->images ) ); $graph = (array) apply_filters( 'aiviso_jsonld_graph', $graph, $this->images ); $json = wp_json_encode( $graph, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES ); if ( is_string( $json ) ) { echo '' . "\n"; } } }