Skip to content

Commit 22828f9

Browse files
authored
Merge pull request #481 from BeAPI/feat/wpautop
Feat/wpautop
2 parents 4788a1b + 3d51693 commit 22828f9

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

inc/Helpers/Formatting/Text.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
use function BEA\Theme\Framework\Helpers\Formatting\Escape\escape_content_value;
55

66
/**
7-
* @usage BEA\Theme\Framework\Helpers\Formatting\Text\the_text( 'text' => 'Lorem ipsum', [ 'before' => '<p>', 'after' => '</p>' ] );
7+
* @usage BEA\Theme\Framework\Helpers\Formatting\Text\the_text( $text, [ 'before' => '<p>', 'after' => '</p>' ] );
8+
* @usage BEA\Theme\Framework\Helpers\Formatting\Text\the_text( $text, [ 'wpautop' => true, 'before' => '<div>', 'after' => '</div>' ] );
89
*
910
* @param string $value Text to display
1011
* @param array $settings {
1112
* Optional. Settings for the text markup.
1213
*
13-
* @type string $before Optional. Markup to prepend to the text. Default empty.
14-
* @type string $after Optional. Markup to prepend to the text. Default empty.
15-
* @type string $escape Optional. Markup to prepend to the item. Default esc_html.
14+
* @type string $before Optional. Markup to prepend to the text. Default empty.
15+
* @type string $after Optional. Markup to append after the text. Default empty.
16+
* @type string $escape Optional. Escape callback name (e.g. esc_html, wp_kses_post). Default esc_html.
17+
* @type bool $wpautop Optional. When true, uses wp_kses_post if escape is still the default esc_html, then wpautop(). Default false.
1618
*
1719
* }
1820
*
@@ -30,9 +32,10 @@ function the_text( string $value, array $settings = [] ): void {
3032
* @param array $settings {
3133
* Optional. Settings for the text markup.
3234
*
33-
* @type string $before Optional. Markup to prepend to the text. Default empty.
34-
* @type string $after Optional. Markup to prepend to the text. Default empty.
35-
* @type string $escape Optional. Markup to prepend to the item. Default esc_html.
35+
* @type string $before Optional. Markup to prepend to the text. Default empty.
36+
* @type string $after Optional. Markup to append after the text. Default empty.
37+
* @type string $escape Optional. Escape callback name (e.g. esc_html, wp_kses_post). Default esc_html.
38+
* @type bool $wpautop Optional. When true, uses wp_kses_post if escape is still the default esc_html, then wpautop(). Default false.
3639
*
3740
* }
3841
*
@@ -46,14 +49,26 @@ function get_the_text( string $value, array $settings = [] ): string {
4649
$settings = wp_parse_args(
4750
$settings,
4851
[
49-
'before' => '',
50-
'after' => '',
51-
'escape' => 'esc_html',
52+
'before' => '',
53+
'after' => '',
54+
'escape' => 'esc_html',
55+
'wpautop' => false,
5256
]
5357
);
5458

5559
$settings = apply_filters( 'bea_theme_framework_text_settings', $settings, $value );
56-
$value = apply_filters( 'bea_theme_framework_text_value', escape_content_value( $value, $settings['escape'] ), $settings );
60+
61+
if ( ! empty( $settings['wpautop'] ) && 'esc_html' === $settings['escape'] ) {
62+
$settings['escape'] = 'wp_kses_post';
63+
}
64+
65+
$value = escape_content_value( $value, $settings['escape'] );
66+
67+
if ( ! empty( $settings['wpautop'] ) ) {
68+
$value = wpautop( $value );
69+
}
70+
71+
$value = apply_filters( 'bea_theme_framework_text_value', $value, $settings );
5772

5873
return $settings['before'] . $value . $settings['after'];
5974
}

src/scss/06-blocks/core/_paragraph.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ p {
1515
}
1616
}
1717
}
18+
19+
// For paragraphs generated by wpautop function (eg. excerpts), paragraphs are wrapped in a div with the class "is-style-large" for example. We need to apply the text style to the p elements inside the div.
20+
div {
21+
@each $style in $paragraphs {
22+
&.is-style-#{$style} {
23+
& > p:where(:not([class*="is-style-"])) {
24+
@include text(#{$style});
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)