*/ private array $attachment_url_cache = array(); public static function set_metadata_renderer( Machine_Readable_Metadata $renderer ): void { self::$metadata_renderer = $renderer; } public function register(): void { add_action( 'wp_enqueue_scripts', array( $this, 'prepare_singular_assets' ) ); add_filter( 'the_posts', array( $this, 'prepare_query_assets' ), 10, 2 ); add_filter( 'post_thumbnail_html', array( $this, 'wrap_thumbnail' ), 20, 5 ); add_filter( 'the_content', array( $this, 'wrap_content_images' ), 20 ); add_action( 'wp_head', array( $this, 'singular_metadata' ) ); } public function prepare_singular_assets(): void { if ( ! is_singular() ) { return; } $options = Settings_Page::get(); $content_images_need_styles = ! empty( $options['content_images_enabled'] ) && is_singular() && Post_Type_Scope::allows( get_queried_object_id(), $options ); if ( $content_images_need_styles || $this->post_has_ai_thumbnail( get_queried_object_id() ) ) { $this->enqueue_styles(); } } /** @param \WP_Post[] $posts @param \WP_Query $query @return \WP_Post[] */ public function prepare_query_assets( array $posts, \WP_Query $query ): array { if ( ! is_admin() && $query->is_main_query() ) { foreach ( $posts as $post ) { if ( $this->post_has_ai_thumbnail( $post->ID ) ) { $this->enqueue_styles(); break; } } } return $posts; } private function enqueue_styles(): void { if ( $this->style_enqueued ) { return; } $this->style_enqueued = true; $dev_mode = defined( 'AIVISO_DEV_MODE' ) && AIVISO_DEV_MODE; $file = 'assets/css/frontend' . ( $dev_mode ? '' : '.min' ) . '.css'; $path = AIVISO_PATH . $file; wp_enqueue_style( 'aiviso-frontend', AIVISO_URL . $file, array(), is_readable( $path ) ? (string) filemtime( $path ) : AIVISO_VERSION ); $js = AIVISO_PATH . 'assets/js/frontend.js'; wp_enqueue_script( 'aiviso-frontend', AIVISO_URL . 'assets/js/frontend.js', array(), is_readable( $js ) ? (string) filemtime( $js ) : AIVISO_VERSION, true ); wp_add_inline_style( 'aiviso-frontend', $this->badge_style( Settings_Page::get() ) ); } /** @param array $options */ private function badge_style( array $options ): string { $background = $this->hex_to_rgba( (string) $options['badge_background_color'], (int) $options['badge_background_opacity'] ); $border = $this->hex_to_rgba( (string) $options['badge_border_color'], 28 ); $spacing = Settings_Page::badge_spacing( $options ); return '.aiviso-badge{--aiviso-badge-bg:' . $background . ' !important;--aiviso-badge-fg:' . (string) $options['badge_text_color'] . ' !important;--aiviso-badge-border-color:' . $border . ' !important;--aiviso-badge-border-width:' . (int) $options['badge_border_width'] . 'px !important;--aiviso-badge-radius:' . (int) $options['badge_border_radius'] . 'px !important;--aiviso-badge-icon-size:' . Settings_Page::badge_icon_size( $options ) . 'px !important;--aiviso-badge-icon-text-gap:' . $spacing['gap'] . 'px !important;--aiviso-badge-padding-top:' . $spacing['top'] . 'px !important;--aiviso-badge-padding-right:' . $spacing['right'] . 'px !important;--aiviso-badge-padding-bottom:' . $spacing['bottom'] . 'px !important;--aiviso-badge-padding-left:' . $spacing['left'] . 'px !important;}'; } private function hex_to_rgba( string $color, int $opacity ): string { $color = ltrim( $color, '#' ); if ( ! preg_match( '/^[a-f0-9]{6}$/i', $color ) ) { $color = '000000'; } $opacity = min( 100, max( 0, $opacity ) ); $alpha = rtrim( rtrim( number_format( $opacity / 100, 2, '.', '' ), '0' ), '.' ); return sprintf( 'rgba(%d, %d, %d, %s)', hexdec( substr( $color, 0, 2 ) ), hexdec( substr( $color, 2, 2 ) ), hexdec( substr( $color, 4, 2 ) ), $alpha ); } private function post_has_ai_thumbnail( int $post_id ): bool { $post_type = get_post_type( $post_id ); $type_object = $post_type ? get_post_type_object( $post_type ) : null; if ( $post_id <= 0 || ! $type_object || ! $type_object->public || ! Post_Type_Scope::allows( $post_id ) || ! post_type_supports( $post_type, 'thumbnail' ) ) { return false; } return AI_State::is_ai_generated( (int) get_post_thumbnail_id( $post_id ) ); } /** * Safely augments only standard featured-image HTML. Returning original markup is always the fallback. * * @param string $html Thumbnail HTML. * @param int $post_id Post ID. * @param int $thumbnail_id Attachment ID. * @param string|array $size Requested size. * @param string|array $attr Attributes. * @return string */ public function wrap_thumbnail( string $html, int $post_id, int $thumbnail_id, $size, $attr ): string { if ( is_admin() || '' === $html || false !== strpos( $html, 'aiviso-featured-image' ) || ! $this->post_has_ai_thumbnail( $post_id ) ) { return $html; } // A secondary query after the document head cannot load the stylesheet safely. if ( did_action( 'wp_head' ) && ! wp_style_is( 'aiviso-frontend', 'enqueued' ) ) { return $html; } $options = Settings_Page::get(); $display_in_context = 'everywhere' === $options['badge_display_scope'] || is_singular(); if ( empty( $options['enabled'] ) || ! apply_filters( 'aiviso_should_display_badge', $display_in_context, $post_id, $thumbnail_id ) ) { return $html; } if ( ! preg_match( '/^\s*(?:enqueue_styles(); $badge = $this->render_badge( $post_id, $thumbnail_id, $options ); $wrapped = 'machine_attributes( $thumbnail_id ) . '>' . $html . $badge . ''; $this->collect_metadata( $thumbnail_id, $post_id, $options ); return $wrapped; } /** * Adds disclosure overlays to declared Media Library images in the singular main post content. * * @param string $content Rendered post content. * @return string */ public function wrap_content_images( string $content ): string { if ( is_admin() || '' === $content || ! is_singular() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { return $content; } // Themes and builders may render the queried post content outside the active main Loop. $post_id = get_the_ID(); if ( $post_id <= 0 || $post_id !== get_queried_object_id() ) { return $content; } $post_type = get_post_type( $post_id ); $type_object = $post_type ? get_post_type_object( $post_type ) : null; $options = Settings_Page::get(); if ( ! $type_object || ! $type_object->public || ! Post_Type_Scope::allows( $post_id, $options ) || empty( $options['content_images_enabled'] ) ) { return $content; } return $this->augment_content_images( $content, $post_id, $options ); } /** * @param string $content Rendered post content. * @param int $post_id Post ID. * @param array $options Plugin options. * @return string */ private function augment_content_images( string $content, int $post_id, array $options ): string { if ( class_exists( '\DOMDocument' ) ) { return $this->augment_content_images_dom( $content, $post_id, $options ); } $image_pattern = '~"\']+|"[^"]*"|\'[^\']*\')*>~i'; $match_count = preg_match_all( $image_pattern, $content, $matches, PREG_OFFSET_CAPTURE ); if ( false === $match_count || 0 === $match_count ) { return $content; } $protected_ranges = $this->protected_content_ranges( $content ); $result = ''; $cursor = 0; foreach ( $matches[0] as $match ) { $img_tag = (string) $match[0]; $offset = (int) $match[1]; $result .= substr( $content, $cursor, $offset - $cursor ); if ( $this->offset_is_protected( $offset, $protected_ranges ) ) { $result .= $img_tag; } else { $result .= $this->augment_image_tag( $img_tag, $post_id, $options ); } $cursor = $offset + strlen( $img_tag ); } return $result . substr( $content, $cursor ); } /** * Uses a structural parser so image parent/child layout contracts survive. * * @param array $options Plugin options. */ private function augment_content_images_dom( string $content, int $post_id, array $options ): string { $document = new \DOMDocument( '1.0', 'UTF-8' ); $previous = libxml_use_internal_errors( true ); $root_id = 'aiviso-content-root'; $loaded = $document->loadHTML( '
' . $content . '
', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD ); libxml_clear_errors(); libxml_use_internal_errors( $previous ); if ( ! $loaded || ! $document->getElementById( $root_id ) ) { return $content; } $root = $document->getElementById( $root_id ); $images = array(); foreach ( $root->getElementsByTagName( 'img' ) as $image ) { $images[] = $image; } foreach ( $images as $image ) { if ( ! $image instanceof \DOMElement || $this->dom_image_is_protected( $image ) || $image->hasAttribute( 'data-aiviso-ai-generated' ) ) { continue; } $attachment_id = $this->resolve_attachment_id_from_img_tag( $document->saveHTML( $image ) ); if ( $attachment_id <= 0 || ! AI_State::is_ai_generated( $attachment_id ) ) { continue; } $this->set_dom_machine_attributes( $image, $attachment_id ); $badge = $this->render_badge( $post_id, $attachment_id, $options ); $this->collect_metadata( $attachment_id, $post_id, $options ); if ( '' === $badge || $this->dom_has_ancestor( $image, 'picture' ) ) { continue; } $host = $this->dom_content_host( $image ); if ( $host ) { $this->add_dom_class( $host, 'aiviso-content-image-host' ); $this->append_badge_fragment( $document, $host, $badge ); continue; } $parent = $image->parentNode; if ( ! $parent ) { continue; } $wrapper = $document->createElement( 'span' ); $wrapper->setAttribute( 'class', 'aiviso-content-image' ); $parent->replaceChild( $wrapper, $image ); $wrapper->appendChild( $image ); $this->append_badge_fragment( $document, $wrapper, $badge ); } $html = ''; foreach ( $root->childNodes as $child ) { $html .= $document->saveHTML( $child ); } return $html; } private function dom_image_is_protected( \DOMElement $image ): bool { foreach ( array( 'script', 'style', 'textarea' ) as $tag ) { if ( $this->dom_has_ancestor( $image, $tag ) ) { return true; } } return false; } private function dom_has_ancestor( \DOMElement $element, string $tag ): bool { for ( $node = $element->parentNode; $node instanceof \DOMElement; $node = $node->parentNode ) { if ( strtolower( $node->tagName ) === $tag ) { return true; } } return false; } private function dom_content_host( \DOMElement $image ): ?\DOMElement { $parent = $image->parentNode; if ( ! $parent instanceof \DOMElement ) { return null; } $class = $parent->getAttribute( 'class' ); $style = $parent->getAttribute( 'style' ); $is_host = 'a' === strtolower( $parent->tagName ) || ( 'div' === strtolower( $parent->tagName ) && ( preg_match( '/(?:^|[\s_-])(image|thumbnail|media|cover|ratio)(?:[\s_-]|$)/i', $class ) || preg_match( '/\bposition\s*:\s*(?:relative|absolute|fixed|sticky)\b/i', $style ) ) ); return $is_host ? $parent : null; } private function set_dom_machine_attributes( \DOMElement $image, int $attachment_id ): void { $image->setAttribute( 'data-aiviso-ai-generated', 'true' ); $image->setAttribute( 'data-aiviso-type', AI_State::get_type( $attachment_id ) ); $source_type = Digital_Source_Type::get( $attachment_id ); if ( '' !== $source_type ) { $image->setAttribute( 'data-aiviso-digital-source-type', $source_type ); } } private function add_dom_class( \DOMElement $element, string $class ): void { $classes = preg_split( '/\s+/', trim( $element->getAttribute( 'class' ) ) ) ?: array(); if ( ! in_array( $class, $classes, true ) ) { $classes[] = $class; $element->setAttribute( 'class', implode( ' ', $classes ) ); } } private function append_badge_fragment( \DOMDocument $document, \DOMElement $host, string $badge ): void { if ( false !== strpos( $document->saveHTML( $host ), 'aiviso-badge' ) ) { return; } $fragment = $document->createDocumentFragment(); $previous = libxml_use_internal_errors( true ); $appended = $fragment->appendXML( $badge ); libxml_clear_errors(); libxml_use_internal_errors( $previous ); if ( $appended ) { $host->appendChild( $fragment ); return; } $fallback = new \DOMDocument( '1.0', 'UTF-8' ); $previous = libxml_use_internal_errors( true ); $loaded = $fallback->loadHTML( '
' . $badge . '
', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD ); libxml_clear_errors(); libxml_use_internal_errors( $previous ); $container = $fallback->getElementById( 'aiviso-badge-fragment' ); if ( ! $loaded || ! $container ) { return; } foreach ( iterator_to_array( $container->childNodes ) as $child ) { $host->appendChild( $document->importNode( $child, true ) ); } } /** @return array */ private function protected_content_ranges( string $content ): array { $pattern = '~|<(picture|script|style|textarea)\\b(?:[^>"\']+|"[^"]*"|\'[^\']*\')*>.*?~is'; $count = preg_match_all( $pattern, $content, $matches, PREG_OFFSET_CAPTURE ); if ( false === $count || 0 === $count ) { return array(); } $ranges = array(); foreach ( $matches[0] as $match ) { $start = (int) $match[1]; $ranges[] = array( 'start' => $start, 'end' => $start + strlen( (string) $match[0] ), ); } return $ranges; } /** @param array $ranges */ private function offset_is_protected( int $offset, array $ranges ): bool { foreach ( $ranges as $range ) { if ( $offset >= $range['start'] && $offset < $range['end'] ) { return true; } } return false; } /** * @param string $img_tag Original image tag. * @param int $post_id Post ID. * @param array $options Plugin options. */ private function augment_image_tag( string $img_tag, int $post_id, array $options ): string { if ( preg_match( '/\\bdata-aiviso-ai-generated\\s*=/i', $img_tag ) ) { return $img_tag; } $attachment_id = $this->resolve_attachment_id_from_img_tag( $img_tag ); if ( $attachment_id <= 0 || ! AI_State::is_ai_generated( $attachment_id ) ) { return $img_tag; } $badge = $this->render_badge( $post_id, $attachment_id, $options ); if ( '' === $badge ) { return $img_tag; } $marked_img = $this->add_processed_attribute( $img_tag ); $this->collect_metadata( $attachment_id, $post_id, $options ); return 'machine_attributes( $attachment_id ) . '>' . $marked_img . $badge . ''; } private function resolve_attachment_id_from_img_tag( string $img_tag ): int { $class = $this->attribute_from_img_tag( $img_tag, 'class' ); if ( null !== $class ) { $attachment_id = $this->attachment_id_from_class( $class ); if ( $attachment_id > 0 ) { return $attachment_id; } } $explicit_id = $this->attribute_from_img_tag( $img_tag, 'data-attachment-id' ); if ( null !== $explicit_id && preg_match( '/^[0-9]+$/', $explicit_id ) ) { $attachment_id = absint( $explicit_id ); if ( $attachment_id > 0 ) { return $attachment_id; } } $src = $this->attribute_from_img_tag( $img_tag, 'src' ); return null === $src ? 0 : $this->attachment_id_from_local_url( $src ); } private function attachment_id_from_class( string $class ): int { return preg_match( '/(?:^|\\s)wp-image-([0-9]+)(?:\\s|$)/', $class, $matches ) ? absint( $matches[1] ) : 0; } private function attribute_from_img_tag( string $img_tag, string $attribute ): ?string { $pattern = '/(?:^|\\s)' . preg_quote( $attribute, '/' ) . '\\s*=\\s*(["\'])(.*?)\\1/is'; return preg_match( $pattern, $img_tag, $matches ) ? html_entity_decode( trim( (string) $matches[2] ), ENT_QUOTES | ENT_HTML5, 'UTF-8' ) : null; } private function attachment_id_from_local_url( string $src ): int { if ( isset( $this->attachment_url_cache[ $src ] ) ) { return $this->attachment_url_cache[ $src ]; } $attachment_id = 0; $uploads = wp_get_upload_dir(); $base_url = isset( $uploads['baseurl'] ) && is_string( $uploads['baseurl'] ) ? $uploads['baseurl'] : ''; $source_parts = wp_parse_url( $src ); $base_parts = wp_parse_url( $base_url ); if ( '' === $base_url || ! is_array( $source_parts ) || ! is_array( $base_parts ) || empty( $source_parts['path'] ) || empty( $base_parts['host'] ) || empty( $base_parts['path'] ) ) { $this->attachment_url_cache[ $src ] = 0; return 0; } $source_host = isset( $source_parts['host'] ) ? strtolower( (string) $source_parts['host'] ) : strtolower( (string) $base_parts['host'] ); $base_host = strtolower( (string) $base_parts['host'] ); $source_path = '/' . ltrim( (string) $source_parts['path'], '/' ); $base_path = rtrim( '/' . ltrim( (string) $base_parts['path'], '/' ), '/' ); $source_port = isset( $source_parts['port'] ) ? (int) $source_parts['port'] : ( isset( $base_parts['port'] ) ? (int) $base_parts['port'] : 0 ); $base_port = isset( $base_parts['port'] ) ? (int) $base_parts['port'] : 0; $source_scheme = isset( $source_parts['scheme'] ) ? strtolower( (string) $source_parts['scheme'] ) : ''; if ( ( '' !== $source_scheme && ! in_array( $source_scheme, array( 'http', 'https' ), true ) ) || $source_host !== $base_host || $source_port !== $base_port || ( $source_path !== $base_path && 0 !== strpos( $source_path, $base_path . '/' ) ) ) { $this->attachment_url_cache[ $src ] = 0; return 0; } $scheme = isset( $base_parts['scheme'] ) ? (string) $base_parts['scheme'] : 'https'; $port = 0 !== $source_port ? ':' . $source_port : ''; $lookup_url = $scheme . '://' . $source_host . $port . $source_path; if ( isset( $this->attachment_url_cache[ $lookup_url ] ) ) { $attachment_id = $this->attachment_url_cache[ $lookup_url ]; } else { $attachment_id = absint( attachment_url_to_postid( $lookup_url ) ); $this->attachment_url_cache[ $lookup_url ] = $attachment_id; } if ( 0 === $attachment_id ) { $full_size_url = preg_replace( '/-[0-9]+x[0-9]+(?=\\.(?:avif|gif|jpe?g|png|webp)$)/i', '', $lookup_url ); if ( is_string( $full_size_url ) && $full_size_url !== $lookup_url ) { if ( isset( $this->attachment_url_cache[ $full_size_url ] ) ) { $attachment_id = $this->attachment_url_cache[ $full_size_url ]; } else { $attachment_id = absint( attachment_url_to_postid( $full_size_url ) ); $this->attachment_url_cache[ $full_size_url ] = $attachment_id; } } } $this->attachment_url_cache[ $src ] = $attachment_id; return $attachment_id; } private function add_processed_attribute( string $img_tag ): string { $end = strrpos( $img_tag, '>' ); if ( false === $end ) { return $img_tag; } $insert_at = $end; $before_end = substr( $img_tag, 0, $end ); if ( preg_match( '/\/\\s*$/', $before_end, $matches, PREG_OFFSET_CAPTURE ) ) { $insert_at = (int) $matches[0][1]; } return substr( $img_tag, 0, $insert_at ) . ' data-aiviso-ai-generated="true"' . substr( $img_tag, $insert_at ); } private function machine_attributes( int $attachment_id ): string { $type = AI_State::get_type( $attachment_id ); $attributes = ' data-aiviso-ai-generated="true" data-aiviso-type="' . esc_attr( $type ) . '"'; $source_type = Digital_Source_Type::get( $attachment_id ); if ( '' !== $source_type ) { $attributes .= ' data-aiviso-digital-source-type="' . esc_attr( $source_type ) . '"'; } return $attributes; } /** @param array $options */ private function collect_metadata( int $attachment_id, int $post_id, array $options ): void { if ( ! empty( $options['machine_readable_metadata'] ) && self::$metadata_renderer ) { self::$metadata_renderer->add( $attachment_id, $post_id ); } } /** @param array $options */ private function render_badge( int $post_id, int $attachment_id, array $options ): string { $position = (string) apply_filters( 'aiviso_badge_position', $options['position'], $post_id, $attachment_id ); $type = AI_State::get_type( $attachment_id ); $locale = Language_Manager::current_locale(); $text = (string) apply_filters( 'aiviso_badge_text', Language_Manager::resolve_badge_text( $options, $type, $attachment_id ), $post_id, $attachment_id, $locale ); /** * Filters the language-resolved tooltip disclaimer before it is rendered. * Returned content is treated as plain text and sanitized again for safety. * * @param string $disclaimer Resolved disclaimer text. * @param int $post_id Post ID. * @param int $attachment_id Attachment ID. * @param string $type AI declaration type. * @param string $locale Current normalized locale. */ $disclaimer = (string) apply_filters( 'aiviso_badge_disclaimer', Language_Manager::resolve_badge_disclaimer( $options, $type ), $post_id, $attachment_id, $type, $locale ); $classes = (string) apply_filters( 'aiviso_badge_classes', 'aiviso-badge--' . $position . ' aiviso-badge--' . $options['size'], $post_id, $attachment_id ); $badge = $this->badge_markup( $text, $disclaimer, $classes, $post_id, $attachment_id, $options ); /** * Filters the complete disclosure badge element before it is placed beside an image. * * @param string $badge Badge HTML. * @param int $post_id Post ID. * @param int $attachment_id Attachment ID. */ return (string) apply_filters( 'aiviso_badge_markup', $badge, $post_id, $attachment_id ); } /** @param array $options */ private function badge_markup( string $text, string $disclaimer, string $classes, int $post_id, int $attachment_id, array $options ): string { $type = AI_State::get_type( $attachment_id ); $logo = $this->logo_markup( $options ); $logo = (string) apply_filters( 'aiviso_badge_logo', $logo, $post_id, $attachment_id ); if ( '' !== $text ) { $label = $text; } elseif ( 'custom' === $type ) { $label = __( 'Custom AI disclosure', 'aiviso-ai-image-disclosure' ); } elseif ( 'modified' === $type ) { $label = __( 'AI-modified image', 'aiviso-ai-image-disclosure' ); } else { $label = __( 'AI-generated image', 'aiviso-ai-image-disclosure' ); } $translation_exclusion = Language_Manager::is_translatepress_active() ? ' data-no-translation="true"' : ''; $disclaimer = sanitize_textarea_field( $disclaimer ); if ( '' === trim( $disclaimer ) ) { $badge = '' . $logo . ( '' !== $text ? '' . esc_html( $text ) . '' : '' ) . ''; } else { $tooltip_id = 'aiviso-disclaimer-' . ++$this->badge_instance; $badge = '' . ( '' !== $text ? '' . esc_html( $text ) . '' : '' ) . ''; } $details = ! empty( $options['show_disclosure_details'] ) ? Disclosure_Details::public_details( $attachment_id ) : array(); if ( ! $details ) { return $badge; } $details = (array) apply_filters( 'aiviso_frontend_disclosure_details', $details, $attachment_id, $post_id ); $items = ''; $labels = array( 'ai_tool' => __( 'AI tool', 'aiviso-ai-image-disclosure' ), 'ai_model' => __( 'AI model or version', 'aiviso-ai-image-disclosure' ), 'date_created' => __( 'Creation or modification date', 'aiviso-ai-image-disclosure' ), 'source_url' => __( 'Source URL', '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' ) ); foreach ( $details as $key => $value ) { if ( isset( $labels[ $key ] ) ) { $output = 'source_url' === $key ? '' . esc_html( $value ) . '' : esc_html( $value ); $items .= '' . esc_html( $labels[ $key ] ) . ': ' . $output . ''; } } $markup = '' . $badge . ''; return (string) apply_filters( 'aiviso_disclosure_details_markup', $markup, $details, $attachment_id, $post_id ); } /** * Escapes user text before converting only the supported, non-nested markers. */ private function format_disclaimer( string $text ): string { $text = sanitize_textarea_field( $text ); $text = str_replace( array( "\r\n", "\r", '\\r\\n', '\\n' ), "\n", $text ); $text = esc_html( $text ); $text = preg_replace( '~\*\*([^*\r\n]+)\*\*~', '$1', $text ) ?? $text; $text = preg_replace( '~(?$1', $text ) ?? $text; $text = preg_replace( '~_([^_\r\n]+)_~', '$1', $text ) ?? $text; return str_replace( "\n", '
', $text ); } /** @param array $options */ private function logo_markup( array $options ): string { if ( 'eu' === $options['logo_type'] ) { return ''; } if ( 'custom' === $options['logo_type'] && ! empty( $options['custom_logo_id'] ) && Settings_Page::is_safe_logo( (int) $options['custom_logo_id'] ) ) { $image = wp_get_attachment_image( (int) $options['custom_logo_id'], 'thumbnail', false, array( 'class' => 'aiviso-badge__logo', 'alt' => '', 'aria-hidden' => 'true' ) ); if ( $image ) { return $image; } } return ''; } public function singular_metadata(): void { if ( ! is_singular() || ! $this->post_has_ai_thumbnail( get_queried_object_id() ) ) { return; } echo "\n"; } }