wpcf7_autop()CF7 1.0

Replaces double line breaks with paragraph elements.

Хуков нет.

Возвращает

Строку. Text which has been converted into correct paragraph tags.

Использование

wpcf7_autop( $input, $br );
$input(строка) (обязательный)
The text which has to be formatted.
$br(true|false)
If set, this will convert all remaining line breaks after paragraphing.
По умолчанию: true

Код wpcf7_autop() CF7 5.9.5

function wpcf7_autop( $input, $br = true ) {
	$placeholders = array();

	// Replace non-HTML embedded elements with placeholders.
	$input = preg_replace_callback(
		'/<(math|svg).*?<\/\1>/is',
		static function ( $matches ) use ( &$placeholders ) {
			$placeholder = sprintf(
				'<%1$s id="%2$s" />',
				WPCF7_HTMLFormatter::placeholder_inline,
				sha1( $matches[0] )
			);

			list( $placeholder ) =
				WPCF7_HTMLFormatter::normalize_start_tag( $placeholder );

			$placeholders[$placeholder] = $matches[0];

			return $placeholder;
		},
		$input
	);

	$formatter = new WPCF7_HTMLFormatter( array(
		'auto_br' => $br,
	) );

	$chunks = $formatter->separate_into_chunks( $input );

	$output = $formatter->format( $chunks );

	// Restore from placeholders.
	$output = str_replace(
		array_keys( $placeholders ),
		array_values( $placeholders ),
		$output
	);

	return $output;
}