WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#32380 closed defect (bug) (invalid)

WPTexturize doesn't handle locale switching properly

Reported by: ivanblagdan Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Formatting Keywords: wptexturize
Focuses: Cc:

Description

Had some issues with wptexturize() not applying french style quotes on a locale which had them defined via a .po file. The locale was defined in the options for the site on a multisite install.
The issue was tracked down to a plugin firing get_plugin_data(), which in turn fires wptexturize() when parsing out the description from the plugin header comment block. Since wptexturize() stores replacements in the static space and expects them to be populated on the first run, these get baked in with when _x() fired with the default locale. This is the case with most static replacements there, we had a problem with the quotes.
I'm attaching a patch that gives wptexturize a chance to reset itself if the locale changed.
There's also a test in the patch, which simulates the locale change behaviour since otherwise it would require some actual .po localization files to test this.

Attachments (2)

fix_wptexturize_locale_switch.patch (6.4 MB) - added by ivanblagdan 5 years ago.
Test and Fix for wptexturize not handling locale switching properly.
fix_wptexturize_locale_switch.2.patch (3.6 KB) - added by ivanblagdan 5 years ago.
Test and Fix for wptexturize not handling locale switching properly. PROPER

Change History (9)

#1 @miqrogroove
5 years ago

  • Keywords wptexturize added

@ivanblagdan
5 years ago

Test and Fix for wptexturize not handling locale switching properly.

@ivanblagdan
5 years ago

Test and Fix for wptexturize not handling locale switching properly. PROPER

#2 @ivanblagdan
5 years ago

Redid the patch, just saw it was 6.4MB, diffed the wrong branch :D

#3 @miqrogroove
5 years ago

Calling get_locale() for every instance of wptexturize() is probably not optimal. If get_locale() is the only function that modifies the global variable, then we could just call wptexturize('reset', true) from there.

#4 @miqrogroove
5 years ago

It's also possible that the plugin is just hooking some functions to the wrong actions.

#5 @ivanblagdan
5 years ago

You are kind of right on the it being used in a wrong place. Like I said, the plugin was using get_plugin_data() which triggers wp_texturize(). The plugin causing the issue is Crayon, https://wordpress.org/plugins/crayon-syntax-highlighter/, the call in question is in wp_crayon.class.php, line 39. Its basically in global scope, and I'd agree its wrong. I'd argue that its viable though and there should be some safeguard for it.

#6 @miqrogroove
5 years ago

I'll take a look. We have to decide if this is a plugin bug or a core bug.

#7 @miqrogroove
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 4.2.2 deleted
Note: See TracTickets for help on using tickets.