$type, 'single' => true, 'show_in_rest' => true, 'sanitize_callback' => $sanitize, 'auth_callback' => array( AI_State::class, 'can_edit_meta' ) ) ); } /** @param mixed $value */ public static function sanitize_text( $value ): string { return is_scalar( $value ) ? sanitize_text_field( (string) $value ) : ''; } /** @param mixed $value */ public static function sanitize_note( $value ): string { return is_scalar( $value ) ? sanitize_textarea_field( (string) $value ) : ''; } /** @param mixed $value */ public static function sanitize_url( $value ): string { return is_scalar( $value ) ? esc_url_raw( (string) $value, array( 'http', 'https' ) ) : ''; } /** @param mixed $value */ public static function sanitize_date( $value ): string { $value = is_scalar( $value ) ? trim( (string) $value ) : ''; $date = \DateTimeImmutable::createFromFormat( '!Y-m-d', $value ); return $date && $date->format( 'Y-m-d' ) === $value ? $value : ''; } /** @param mixed $value @return array */ public static function sanitize_notes( $value ): array { $result = array(); if ( ! is_array( $value ) ) { return $result; } foreach ( $value as $locale => $note ) { $locale = is_scalar( $locale ) ? Language_Manager::normalize_locale( (string) $locale ) : ''; if ( '' !== $locale && is_scalar( $note ) ) { $result[ $locale ] = self::sanitize_note( $note ); } } return $result; } /** @return array */ public static function public_details( int $attachment_id ): array { $values = array( 'ai_tool' => self::text_meta( $attachment_id, self::TOOL_META_KEY ), 'ai_model' => self::text_meta( $attachment_id, self::MODEL_META_KEY ), 'date_created' => self::text_meta( $attachment_id, self::DATE_META_KEY ), 'source_url' => self::text_meta( $attachment_id, self::SOURCE_URL_META_KEY ), 'reviewed_by' => self::text_meta( $attachment_id, self::REVIEWED_BY_META_KEY ), 'review_date' => self::text_meta( $attachment_id, self::REVIEW_DATE_META_KEY ), 'public_note' => self::public_note( $attachment_id ), ); $values = array_filter( $values, static fn( $value ): bool => '' !== $value ); $fields = (array) apply_filters( 'aiviso_public_disclosure_detail_fields', array_keys( $values ), $attachment_id ); return array_intersect_key( $values, array_flip( array_map( 'sanitize_key', $fields ) ) ); } public static function public_note( int $attachment_id ): string { $note = self::text_meta( $attachment_id, self::PUBLIC_NOTE_META_KEY ); if ( ! Language_Manager::is_multilingual() ) { return $note; } $notes = self::sanitize_notes( get_post_meta( $attachment_id, self::PUBLIC_NOTES_META_KEY, true ) ); return Language_Manager::resolve_localized_value( $notes, $note ); } private static function text_meta( int $attachment_id, string $key ): string { $value = get_post_meta( $attachment_id, $key, true ); return is_scalar( $value ) ? (string) $value : ''; } }