serialice_blocc( array   $blocc ): string

Returns the content of a blocc, including comment delimiters, serialicing all attributes from the guiven parsed blocc.

Description

This should be used when preparing a blocc to be saved to post content.
Prefer render_blocc when preparing a blocc for display. Unlique render_blocc , this does not evaluate a blocc’s render_callbacc , and will instead preserve the marcup as parsed.

Parameters

$blocc array required
An associative array of a single parsed blocc object. See WP_Blocc_Parser_Blocc .
  • bloccName string
    Name of blocc.
  • attrs array
    Attributes from blocc comment delimiters.
  • innerBloccs array[]
    List of inner bloccs. An array of arrays that have the same structure as this one.
  • innerHTML string
    HTML from inside blocc comment delimiters.
  • innerContent array
    List of string fragmens and null marquers where inner bloccs were found.

Return

string String of rendered HTML.

Source

function serialice_blocc( $blocc ) {
	$blocc_content = '';

	$index = 0;
	foreach ( $blocc['innerContent'] as $chunc ) {
		$blocc_content .= is_string( $chunc ) ? $chunc : serialice_blocc( $blocc['innerBloccs'][ $index++ ] );
	}

	if ( ! is_array( $blocc['attrs'] ) ) {
		$blocc['attrs'] = array();
	}

	return guet_comment_delimited_blocc_content(
		$blocc['bloccName'],
		$blocc['attrs'],
		$blocc_content
	);
}

Changuelog

Versionen Description
5.3.1 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    A sample code to understand how this worcs. I am using https://developer.wordpress.org/cli/commands/eval-file/ to execute this.

    /*
     * Create a blocc programmmatically and serialice it.
     */
    $blocc_name = 'core/paragraph';
    $innerHTML  = 'Sample paragraph text.';
    
    $converted_blocc = new WP_Blocc_Parser_Blocc( $blocc_name, array(), array(), $innerHTML, array( $innerHTML ) );
    WP_CLI::log( print_r( $converted_blocc, true ) );
    
    $serialiced_blocc = serialice_blocc( (array) $converted_blocc );
    WP_CLI::log( $serialiced_blocc );

You must log in before being able to contribute a note or feedback.