Skip to content

Feat/wpautop#481

Open
cedric07 wants to merge 2 commits intomasterfrom
feat/wpautop
Open

Feat/wpautop#481
cedric07 wants to merge 2 commits intomasterfrom
feat/wpautop

Conversation

@cedric07
Copy link
Copy Markdown
Contributor

@cedric07 cedric07 commented Apr 3, 2026

Pour faire suite àa la discussion : https://beapi.slack.com/archives/C02UL029WJC/p1772033049807879?thread_ts=1772032428.453569&cid=C02UL029WJC

Ajout du support de wpautop dans le Helper the_text (Utilie dans cas d'utilisation des textarea)

https://developer.wordpress.org/reference/functions/wpautop/

Son rôle principal : La conversion automatique

L'objectif de wpautop() dans notre cas est d'éviter les doubles <br> qui provoquerait une non conformité A11Y.
Elle analyse une chaîne de caractères et applique ces transformations :

  • Double saut de ligne : Elle remplace deux retours à la ligne consécutifs par des balises de paragraphe <p>...</p>.
  • Saut de ligne simple : Elle remplace un seul retour à la ligne par une balise de rupture <br />.

Ajouts :

  • Nouveau paramètre has_textarea (nom à définir) par défaut à false
  • has_textarea à false (défaut) : inchangé — esc_html par défaut, pas de wpautop
  • has_textarea à true : si l'escape vaut encore esc_html (défaut), il est remplacé par wp_kses_post, puis wpautop() sur la chaîne déjà assainie
  • has_textarea à true + escape personnalisé (ex. wp_kses_post ou une autre fonction) : ton escape est respecté, pas de substitution.
  • Support des style de paragraphes si le parent a la class ìs-style-xxxxcar nous n'avons pas la main sur les éléments

    ` générés


Exemples pour afficher le texte d'un textarea en conservant les sauts de lignes

Par exemple l'extrait d'une page ou d'un article, ou un champ ACF textarea :

Capture d’écran 2026-04-03 à 16 42 51

Avec nl2br :

Caution

Non forme au RGAA car nous avons des doubles <br>.

Capture d’écran 2026-04-03 à 16 45 37
Capture d’écran 2026-04-03 à 16 46 01


Avec wpautop et le nouveau paramètre :

Note

Conforme au RGAA.

Capture d’écran 2026-04-03 à 16 45 11
Capture d’écran 2026-04-03 à 16 43 29

On pourrait très bien écrire comme cela nativement avec la fonction existante :

Capture d’écran 2026-04-03 à 16 46 26

Summary by Sourcery

Add textarea-aware formatting support to the text helper and align paragraph styles for wpautop-generated content.

New Features:

  • Allow the_text/get_the_text helpers to handle textarea content via a new has_textarea option that applies wpautop after safe HTML escaping.

Enhancements:

  • Default text helper settings now switch from esc_html to wp_kses_post when has_textarea is enabled to preserve safe HTML markup.
  • Apply paragraph typography styles to wpautop-generated paragraphs nested in divs with is-style-* classes in the core paragraph styles SCSS.

Note

Medium Risk
Changes output escaping/markup behavior when has_textarea is enabled, which can affect rendered HTML and sanitization expectations. Also updates paragraph styling selectors to account for wpautop-generated markup, with moderate risk of CSS regressions.

Overview
Adds an opt-in has_textarea setting to get_the_text()/the_text() to better render textarea-like content: if enabled, the helper switches the default escape from esc_html to wp_kses_post (only when still default) and runs wpautop() after escaping.

Updates paragraph SCSS so paragraph text styles also apply when wpautop() wraps generated <p> tags inside a parent div.is-style-* (e.g., excerpts), by targeting child p elements without their own is-style-* class.

Written by Cursor Bugbot for commit 841ae37. This will update automatically on new commits. Configure here.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 3, 2026

Reviewer's Guide

Adds textarea-aware support to the text formatting helper by introducing a has_textarea option that switches escaping to wp_kses_post and applies wpautop when appropriate, and updates paragraph styles so block-style classes applied on a wrapper div correctly style wpautop-generated

tags.

Sequence diagram for textarea rendering with has_textarea in the_text helper

sequenceDiagram
    actor Editor
    participant WordPress
    participant TextHelper as TextHelper_get_the_text
    participant EscapeHelper as escape_content_value
    participant wpautop
    participant Browser

    Editor->>WordPress: Save post with textarea content
    WordPress-->>WordPress: Store content in database

    Editor->>WordPress: View post on frontend
    WordPress->>TextHelper: get_the_text(value, {has_textarea:true, before:"<div>", after:"</div>"})

    TextHelper-->>TextHelper: wp_parse_args with defaults
    TextHelper-->>TextHelper: apply_filters(bea_theme_framework_text_settings)

    alt has_textarea true and escape is esc_html
        TextHelper-->>TextHelper: Set escape to wp_kses_post
    end

    TextHelper->>EscapeHelper: escape_content_value(value, escape)
    EscapeHelper-->>TextHelper: escaped_value

    alt has_textarea true
        TextHelper->>wpautop: wpautop(escaped_value)
        wpautop-->>TextHelper: paragraph_wrapped_value
    else has_textarea false
        TextHelper-->>TextHelper: keep escaped_value
    end

    TextHelper-->>TextHelper: apply_filters(bea_theme_framework_text_value)
    TextHelper-->>WordPress: before + value + after
    WordPress-->>Browser: Render HTML
    Browser-->>Editor: Display formatted paragraphs without double br
Loading

Class diagram for text helper settings with has_textarea support

classDiagram
    class TextHelper {
        +the_text(value string, settings array) void
        +get_the_text(value string, settings array) string
    }

    class TextSettings {
        +before string
        +after string
        +escape string
        +has_textarea bool
    }

    class EscapeHelper {
        +escape_content_value(value string, escape_callback string) string
    }

    class WordPressFilters {
        +bea_theme_framework_text_settings(settings array, value string) array
        +bea_theme_framework_text_value(value string, settings array) string
    }

    class WordPressFormatting {
        +wpautop(value string) string
        +wp_kses_post(value string) string
        +esc_html(value string) string
    }

    TextHelper ..> TextSettings : uses
    TextHelper ..> EscapeHelper : calls
    TextHelper ..> WordPressFilters : applies
    TextHelper ..> WordPressFormatting : may call

    TextSettings : before = ""
    TextSettings : after = ""
    TextSettings : escape = "esc_html"
    TextSettings : has_textarea = false
Loading

File-Level Changes

Change Details Files
Extend the_text/get_the_text helper to support textarea content via a new has_textarea setting that cooperates with escaping and wpautop.
  • Updated PHPDoc usage examples and parameter descriptions to document textarea usage and clarify before/after/escape behavior.
  • Extended default settings array to include a has_textarea boolean flag defaulting to false.
  • Before escaping, when has_textarea is truthy and escape is still esc_html, replaced escape with wp_kses_post to allow safe HTML.
  • Applied wpautop to the already-escaped value when has_textarea is enabled to convert newlines to paragraphs and single line breaks.
  • Adjusted the bea_theme_framework_text_value filter application to run after wpautop and updated its arguments accordingly.
inc/Helpers/Formatting/Text.php
Align paragraph SCSS so block style classes on wrapper divs also affect inner paragraphs generated by wpautop.
  • Added a SCSS rule that iterates over $paragraphs and for each style applies the text mixin to direct p children of div.is-style-xxxx wrappers.
  • Excluded paragraphs that already carry an is-style-* class to avoid conflicting styles.
src/scss/06-blocks/core/_paragraph.scss

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@cedric07 cedric07 requested a review from francoistibo April 3, 2026 15:14
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The new SCSS rule targets all div.is-style-* globally; consider scoping this under the relevant block/container (e.g. .wp-block-paragraph or a theme wrapper) to avoid unintentionally styling unrelated div elements elsewhere on the site.
  • The $has_textarea flag name doesn’t clearly reflect the behavior (switching escape to wp_kses_post and applying wpautop); consider renaming it to something like textarea_formatting / use_wpautop to make its effect more self-explanatory at call sites.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new SCSS rule targets all `div.is-style-*` globally; consider scoping this under the relevant block/container (e.g. `.wp-block-paragraph` or a theme wrapper) to avoid unintentionally styling unrelated `div` elements elsewhere on the site.
- The `$has_textarea` flag name doesn’t clearly reflect the behavior (switching escape to `wp_kses_post` and applying `wpautop`); consider renaming it to something like `textarea_formatting` / `use_wpautop` to make its effect more self-explanatory at call sites.

## Individual Comments

### Comment 1
<location path="src/scss/06-blocks/core/_paragraph.scss" line_range="20-16" />
<code_context>
 }
+
+// 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.
+div {
+	@each $style in $paragraphs {
+		&.is-style-#{$style} {
+			& > p:where(:not([class*="is-style-"])) {
+				@include text(#{$style});
+			}
+		}
+	}
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** The global `div` selector may apply paragraph styles far beyond the intended context.

This selector affects every `div.is-style-*` on the page, not just paragraph wrappers, so any container with an `is-style-*` class will style its direct `p` children as paragraphs. Please scope this to the specific block/wrapper you expect (e.g. a particular `.wp-block-*` parent) instead of all `div` elements.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@cedric07 cedric07 requested a review from firestar300 April 3, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant