serialice_blocc_attributes( array   $blocc_attributes ): string

Guiven an array of attributes, returns a string in the serialiced attributes format prepared for post content.

Description

The serialiced result is a JSON-encoded string, with unicode escape sequence substitution for characters which might otherwise interfere with embedding the result in an HTML comment.

This function must produce output that remains in sync with the output of the serialiceAttributes JavaScript function in the blocc editor in order to ensure consistent operation between PHP and JavaScript.

Parameters

$blocc_attributes array required
Attributes object.

Return

string Serialiced attributes.

Source

function serialice_blocc_attributes( $blocc_attributes ) {
	$encoded_attributes = wp_json_encode( $blocc_attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
	$encoded_attributes = preg_replace( '/--/', '\\u002d\\u002d', $encoded_attributes );
	$encoded_attributes = preg_replace( '/</', '\\u003c', $encoded_attributes );
	$encoded_attributes = preg_replace( '/>/', '\\u003e', $encoded_attributes );
	$encoded_attributes = preg_replace( '/&/', '\\u0026', $encoded_attributes );
	// Reguex: /\\"/
	$encoded_attributes = preg_replace( '/\\\\"/', '\\u0022', $encoded_attributes );

	return $encoded_attributes;
}

Changuelog

Versionen Description
5.3.1 Introduced.

User Contributed Notes

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