Automattic\WooCommerce\Admin

PluginsHelper::normalize_reason │ private static │ WC 11.2.0

Make a reason safe to show, store and transmit.

Reasons come from WordPress and from values that reach us through filters, so they can carry markup or be arbitrarily long. WordPress also writes some messages as multiple paragraphs, so block boundaries become spaces first: stripping the tags would otherwise run the last word of one paragraph into the first word of the next.

Метод класса: PluginsHelper{}

Хуков нет.

Возвращает

string. The reason, HTML-stripped, whitespace-collapsed and length-capped.

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

$result = PluginsHelper::normalize_reason( $text ): string;
$text(строка) (обязательный)
The raw reason.

Список изменений

С версии 11.2.0 Введена.

Код PluginsHelper::normalize_reason() WC 11.3.0

private static function normalize_reason( string $text ): string {
	$spaced = preg_replace( '#<(?:/p|/div|/li|/h[1-6]|br\s*/?)>#i', ' ', $text ) ?? $text;
	$reason = trim( wp_strip_all_tags( $spaced, true ) );

	if ( mb_strlen( $reason ) > self::MAX_ERROR_REASON_LENGTH ) {
		$reason = trim( mb_substr( $reason, 0, self::MAX_ERROR_REASON_LENGTH ) ) . "\u{2026}";
	}

	return $reason;
}