%s
', wp_kses_post( $html ) ); } $parts = array(); foreach ( $nodes as $node ) { $tag = (string) $node['tag']; if ( 'p' === $tag ) { $parts[] = sprintf( '%s', wp_kses_post( (string) $node['html'] ) ); continue; } if ( 'ul' === $tag || 'ol' === $tag ) { $parts[] = sprintf( '%s', wp_kses_post( (string) $node['html'] ) ); continue; } if ( 'h' === substr( $tag, 0, 1 ) && strlen( $tag ) === 2 ) { $level = (int) substr( $tag, 1 ); $parts[] = sprintf( '%2$s', $level, wp_kses_post( (string) $node['html'] ) ); continue; } if ( 'table' === $tag || 'figure' === $tag ) { $converted = Gutenberg_Content::from_html( (string) $node['html'] ); if ( '' !== $converted ) { $parts[] = $converted; continue; } } $text = trim( (string) $node['text'] ); if ( '' === $text ) { continue; } $parts[] = sprintf( '%s
', esc_html( $text ) ); } return implode( "\n\n", $parts ); } /** * Build a core/image block for an uploaded attachment. * * @param string $align left|center|right or empty. */ public function build_image_block( int $attachment_id, string $url, string $alt = '', string $align = '' ): string { if ( $attachment_id <= 0 || '' === $url ) { return ''; } $align = sanitize_key( $align ); if ( ! in_array( $align, array( 'left', 'center', 'right' ), true ) ) { $align = ''; } $attrs = array( 'id' => $attachment_id, 'sizeSlug' => 'large', 'linkDestination' => 'none', ); if ( '' !== $align ) { $attrs['align'] = $align; } $encoded = wp_json_encode( $attrs, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); if ( ! is_string( $encoded ) ) { $encoded = '{}'; } $class = 'wp-block-image size-large'; if ( '' !== $align ) { $class .= ' align' . $align; } return sprintf( '