getMessage() ); } catch ( \Throwable $ignored ) { // A broken logger must not fatal the page either: fail closed means render nothing, quietly. unset( $ignored ); } } return; } echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- every part is escaped in build(). } /** * @param array $flags Injection flags. * @throws \RuntimeException When JSON encoding fails. */ public static function build( \WC_Product $product, array $flags ): string { $url = (string) get_permalink( $product->get_id() ); $out = array(); if ( $flags['canonical'] ) { $out[] = sprintf( '', esc_url( $url ) ); } if ( $flags['og_title'] ) { $out[] = self::og( 'og:title', $product->get_name() ); } if ( $flags['og_description'] ) { $out[] = self::og( 'og:description', ProductSchema::plain( $product->get_description() ) ); } if ( $flags['og_image'] ) { $image = ProductSchema::image_url( $product ); if ( '' !== $image ) { $out[] = self::og( 'og:image', $image, true ); } } if ( $flags['og_title'] || $flags['og_description'] || $flags['og_image'] ) { $out[] = self::og( 'og:type', 'product' ); $out[] = self::og( 'og:url', $url, true ); } if ( $flags['json_ld'] ) { // JSON_HEX_TAG: product text can never close the '; } return array() === $out ? '' : implode( "\n", $out ) . "\n"; } private static function og( string $property, string $content, bool $is_url = false ): string { return sprintf( '', esc_attr( $property ), $is_url ? esc_url( $content ) : esc_attr( $content ) ); } }