Make WordPress Core

Opened 4 years ago

#49965 new defect (bug)

wptexturize should also work when using before hook after_theme_setup

Reported by: mguenter's profile mguenter Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.4
Component: Formatting Keywords:
Focuses: Cc:

Description

Hi!

Context: When using get_plugin_data before the hook after_theme_setup got fired, wptexturize does no longer work (de_DE). We are using a boilerplate WP React Starter and in the following line it uses the above function at plugin construction:

I could fix the issue with the following workaround, but I think this is not ideal:

<?php
/**
 * `get_plugin_data` uses `wptexturize` a bit too early and due to the fact,
 * that it saves `static` state in the function itself, it never get's reset
 * correctly. Fix it, by resetting manually in the earliest possible hook (`setup_theme` does not work).
 */
add_action('after_setup_theme', function() {
    if (function_exists('wptexturize')) {
        wptexturize(' ', true);
    }
}, 0);

Now, I think about to fix the issue by using did_action:

https://github.com/WordPress/WordPress/blob/589666abc3b21242c28dcea9f5e94b57032692e7/wp-includes/formatting.php#L80

<?php
// [...]
- if ( $reset || ! isset( $static_characters ) ) {
+ if ( $reset || ! isset( $static_characters ) || ! did_action( 'after_setup_theme' ) ) {

What do you think?

Change History (0)

Note: See TracTickets for help on using tickets.