Make WordPress Core

Opened 4 years ago

Last modified 3 years ago

#43224 new enhancement

Extract `$utf8_pcre` from `wp_check_invalid_utf8()` into a separate function

Reported by: jaswrks Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Formatting Keywords:
Focuses: Cc:


The wp_check_invalid_utf8() function checks to confirm support for the /u flag in regular expressions. The result of that check is cached in a static variable within that function. However, other areas of the codebase might want to run the same check, or maybe plugins would like to check also.

I'm considering a change in Gutenberg's PEG parser and that might serve as an example use case for the new wp_can_utf8_pcre() function I'm proposing in this ticket. Instead of running the same check all over again, having this check run once by a utility function would be nice.

See: https://github.com/WordPress/gutenberg/blob/daad3f21319ec9ec73fa1b907119a7464442bfac/lib/parser.php#L1818

Attachments (1)

43224.patch (1.1 KB) - added by jaswrks 4 years ago.

Download all attachments as: .zip

Change History (5)

4 years ago

#2 @jaswrks
4 years ago

Update: The Gutenberg PEG parser (in PHP) is actually generated by a JavaScript library, so maybe it's not the best example of a use case for this. However, I still think the patch is worth considering.

Last edited 4 years ago by jaswrks (previous) (diff)

#3 @jnylen0
4 years ago

The information in this ticket is correct, but this function already exists in WP, almost exactly as written in the patch:


Introduced here: https://core.trac.wordpress.org/changeset/32364#file2

It would be good to refactor wp_check_invalid_utf8 to use the shared function rather than doing its own thing.

#4 @pento
3 years ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.