Opened 4 years ago
#49965 new defect (bug)
wptexturize should also work when using before hook after_theme_setup
Reported by: | 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:
- https://github.com/devowlio/wp-react-starter/blob/e25ca4aa7b743bed3aa09fda180429142b87204f/plugins/wp-reactjs-starter/src/inc/base/Core.php#L25
- https://github.com/devowlio/wp-react-starter/blob/e25ca4aa7b743bed3aa09fda180429142b87204f/packages/utils/src/Core.php#L129
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:
<?php // [...] - if ( $reset || ! isset( $static_characters ) ) { + if ( $reset || ! isset( $static_characters ) || ! did_action( 'after_setup_theme' ) ) {
What do you think?
Note: See
TracTickets for help on using
tickets.