Make WordPress Core

Opened 3 years ago

Last modified 2 weeks ago

#54721 reopened defect (bug)

wptexturize caches the result of run_wptexturize preventing themes from using this if a plugin has already called get_plugin_data

Reported by: tremlas's profile tremlas Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.8.2
Component: Formatting Keywords: 2nd-opinion
Focuses: Cc:

Description

One of the plugins I use is simple_sitemap. This plugin (quite reasonably) uses get_plugin_data during its initialization. get_plugin_data makes calls to wptexturize as part of its operation. The plugin's initialization runs before the theme's functions.php is executed. Since wptexturize caches the result of the run_wptexturize filter, the theme is no longer able to disable wptexturize's function and hence gets unwanted smart quotes.

There is a workaround for the theme whereby it makes a dummy call to wptexturize with reset set to true. This makes the wptexturize implementation reinitialize and hence re-execute the call to the run_wptexturize filter. However the documentation states that this flag is designed for unit testing and hence this seems to be less than ideal.

(In passing I'll note that this caching of the result also prevents plugins from using it to temporarily disable the function by adding and then removing the filter should it be required.)

I've left the ticket type as 'defect' but it would be reasonable to argue that this is actually a request for a minor enhancement - if so please change the type field.

Change History (2)

#1 @bobbingwide
5 weeks ago

  • Keywords 2nd-opinion added
  • Resolution set to invalid
  • Status changed from new to closed

I've found a scenario where the reset logic doesn't work.

If wptexturize() has already been run and the run_texturize filter had been set to __return_false
by an activated plugin then it's not possible to use the $reset parameter since the following code is executed before anything else.

// If there's nothing to do, just stop.
	if ( empty( $text ) || false === $run_texturize ) {
		return $text;
	}

This problem happens to occur in my own PHPUnit tests where I tried to re-enable wptexturize's processing using:

remove_filter( 'run_wptexturize', '__return_false', 10);
wptexturize( '', true );

... which is ironic.

Also, the comment

The filter runs only once, the first time wptexturize() is called.

isn't completely true.
It's run when $reset is true and $run_texturize is true.

#2 @bobbingwide
2 weeks ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

I don't understand why this ticket was set to invalid and closed. That wasn't my intention. Reopening.

Note: See TracTickets for help on using tickets.