CurrencyFormatter.php
2 years ago
DefaultFormatter.php
2 years ago
FormatterInterface.php
2 years ago
HtmlFormatter.php
2 years ago
MoneyFormatter.php
2 years ago
HtmlFormatter.php
29 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\StoreApi\Formatters; |
| 3 | |
| 4 | /** |
| 5 | * Html Formatter. |
| 6 | * |
| 7 | * Formats HTML in API responses. |
| 8 | * |
| 9 | * @internal This API is used internally by Blocks--it is still in flux and may be subject to revisions. |
| 10 | */ |
| 11 | class HtmlFormatter implements FormatterInterface { |
| 12 | /** |
| 13 | * Format a given value and return the result. |
| 14 | * |
| 15 | * The wptexturize, convert_chars, and trim functions are also used in the `the_title` filter. |
| 16 | * The function wp_kses_post removes disallowed HTML tags. |
| 17 | * |
| 18 | * @param string|array $value Value to format. |
| 19 | * @param array $options Options that influence the formatting. |
| 20 | * @return string |
| 21 | */ |
| 22 | public function format( $value, array $options = [] ) { |
| 23 | if ( is_array( $value ) ) { |
| 24 | return array_map( [ $this, 'format' ], $value ); |
| 25 | } |
| 26 | return is_scalar( $value ) ? wp_kses_post( trim( convert_chars( wptexturize( $value ) ) ) ) : $value; |
| 27 | } |
| 28 | } |
| 29 |