[wp-trac] [WordPress Trac] #49965: wptexturize should also work when using before hook after_theme_setup

WordPress Trac noreply at wordpress.org
Tue Apr 21 06:41:39 UTC 2020


#49965: wptexturize should also work when using before hook after_theme_setup
--------------------------+-----------------------------
 Reporter:  mguenter      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Formatting    |    Version:  5.4
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hi!

 **Context**: When using
 [https://developer.wordpress.org/reference/functions/get_plugin_data/
 get_plugin_data] before the hook `after_theme_setup` got fired,
 [https://developer.wordpress.org/reference/functions/wptexturize/
 wptexturize] does no longer work (`de_DE`). We are using a boilerplate
 [https://github.com/devowlio/wp-react-starter/ 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
 <?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
 [https://developer.wordpress.org/reference/functions/did_action/
 did_action]:

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

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


 What do you think?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49965>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list