Opened 18 months ago

Last modified 17 months ago

#19550 reopened enhancement

Please provide option to disable wptexturize entirely

Reported by: jwz Owned by:
Priority: normal Milestone: Awaiting Review
Component: Formatting Version: 3.3
Severity: minor Keywords: has-patch
Cc: info@…

Description

I assume this is controversial, but I want wptexturize to *always* be a no-op. I know I'm not alone on this. There exists a 3rd-party "wpuntexturize" plugin, but it is insufficient; even using that plugin, I keep running in to places where texturization is happening anyway.

Rather than making us play whack-a-mole with all the places it gets turned back on, can't we please just have a checkbox to disable it globally?

Alternately, if you would make wptexturize be a pluggable function, I could just re-define it.

As it is, with each new release, I am forced to modify the source to add "return $text" as the first line of the function.

Attachments (2)

patch-wptexturize.patch (959 bytes) - added by toscho 17 months ago.
Add 'do_texturize' filter
19550.diff (1.1 KB) - added by nacin 17 months ago.
A run-once filter.

Download all attachments as: .zip

Change History (24)

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Indeed, this has been brought up several times already: #17926 #17207

Please don't open new tickets for old issues. Instead, leave comments on the old tickets.

  • Cc info@… added
  • Resolution duplicate deleted
  • Status changed from closed to reopened

The request to make wptexturize() a pluggable function is not covered by these old tickets which address singular problems. I support this request, because wptexturize() is used in eight places directly, not per filter. So we should either move wptexturize() to pluggable.php or replace all direct calls with hooks.

  • Milestone set to Awaiting Review
  • Type changed from feature request to enhancement

Pluggable functions are a lousy way to fix this.

We should replace all direct calls with hooks.

List of direct calls to wptexturize()

wp-admin/includes/plugin.php:143
	$plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
	
wp-admin/import.php:115
	$action = "<a href='" . esc_url("admin.php?import=$id") . "' title='" . esc_attr( wptexturize(strip_tags($data[1])) ) ."'>{$data[0]}</a>";

wp-admin/menu-header.php:75
	$title = wptexturize( $item[0] );

wp-admin/menu-header.php:148
	$title = wptexturize($sub_item[0]);

wp-includes/comment-template.php:758
	echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";

wp-includes/general-template.php:833
	$text = wptexturize($text);
	
wp-includes/media.php:867
	" . wptexturize($attachment->post_excerpt) . "

wp-includes/theme.php:217
	$theme_data['Description'] = wptexturize( wp_kses( $theme_data['Description'], $themes_allowed_tags ) );

wp-includes/theme.php:290
	$description = wptexturize($theme_data['Description']);

The question is how we name such a filter. And if we need more than one name.

comment:5 follow-up: ↓ 6   scribu18 months ago

Actually, what would be the point in disabling wptexturize() for plugin and theme descriptions?

wp-admin/includes/plugin.php:143
	$plugin_data['Description'] = wptexturize( $plugin_data['Description'] );

wp-includes/theme.php:217
	$theme_data['Description'] = wptexturize( wp_kses( $theme_data['Description'], $themes_allowed_tags ) );

wp-includes/theme.php:290
	$description = wptexturize($theme_data['Description']);

comment:6 in reply to: ↑ 5   toscho18 months ago

Replying to scribu:

Actually, what would be the point in disabling wptexturize() for plugin and theme descriptions?

Okay, these cases aren’t important. :)

Relevant: #19602

The problem isn't just direct calls to wptexturize, it's things like this that occur in other plugins that are *also* trying to get around the effects of wptexturize, for example, Otto's Simple Facebook Connect does:

	remove_filter( 'the_content', 'wptexturize' );
	$text = apply_filters('the_content', $text);
	add_filter( 'the_content', 'wptexturize' );

If wptexturize was a pluggable function that I could turn into a no-op, it wouldn't matter to me that random plugins re-add it to the_content filter because they think I want it there.

Good point.

What if we extend just the function?

function wptexturize($text) {
	$do_texturize = apply_filters( 'do_texturize', TRUE, $text );
	if ( ! $do_texturize )
		return $text;

	global $wp_cockneyreplace;

Then you could disable wptexturize() case by case. More context for the filter would be better, of course …

Sure, that'd work for me...

Add 'do_texturize' filter

To disable wptexturize() globally now use:

add_filter( 'do_texturize', '__return_false' );

comment:12 follow-up: ↓ 18   scribu17 months ago

Looking again through this ticket, I still haven't heard an actual use-case for disabling wptexturize().

wptexturize() changes quotations, link titles, samp and var by default. Yes, you can filter each case, but if you don’t need the function at all? Plus, it is rather slow.

http://i.imgur.com/pEtYM.png

As @jwz explained: Sometimes you just cannot remove the function from a hook – a plugin may re-add it. So I see use cases here, and the additional hook doesn’t cost that much. :)

comment:14 follow-up: ↓ 15   dd3217 months ago

wptexturize() changes quotations, link titles, samp and var by default.

It sounds like your problems with the function might be things which you should focus on improving, rather than attempting to remove it entirely (which.. Isn't going to happen IMO)

comment:15 in reply to: ↑ 14 ; follow-up: ↓ 16   toscho17 months ago

Replying to dd32:

It sounds like your problems with the function might be things which you should focus on improving, rather than attempting to remove it entirely (which.. Isn't going to happen IMO)

Of course, the details should be improved, and the function should not be removed. :)

The performance issues are caused by the regexes, I don’t see how to fix that.

The patch just gives more control for those who think they may need it. And it doesn’t hurt anyone.

comment:16 in reply to: ↑ 15   scribu17 months ago

Replying to toscho:

And it doesn’t hurt anyone.

Yes it does; each extra filter adds a tiny bit of overhead, both in terms of page load and of maintenance cost.

apply_filters() is called in this function anyway – so there are no measurable page load costs (do I miss anything?). Checking side effects is up to those who use the filter. The output of wptexturize() is already different for each language.

comment:18 in reply to: ↑ 12   jwz17 months ago

Replying to scribu:

Looking again through this ticket, I still haven't heard an actual use-case for disabling wptexturize().

If what you're asking is "why do I want to disable wptexturize?", I thought that would be obvious. That function does certain things -- namely taking the characters that I typed, and turning them into other characters -- and I don't want that. I want to see the characters I actually typed instead.

I'm not nitpicking just about how it's translating my quotes, or whether one particular hyphen is being rewritten right. I want it keep its hands completely off of my text. If I had wanted curly quotes then that's what I would have typed.

If other people want that, great. But please don't force this "feature" on me with no reasonable way to disable it.

nacin17 months ago

A run-once filter.

comment:19 follow-ups: ↓ 20 ↓ 21   nacin17 months ago

I'm wondering whether this is sufficient. While it will not catch *every* instance, it will catch all relevant core instances to dealing with content:

foreach ( array( 'the_title', 'the_content', 'the_excerpt',
		'comment_text', 'list_cats', 'comment_author',
		'term_name', 'link_name', 'link_description',
		'link_notes', 'bloginfo', 'wp_title', 'widget_title',
		'term_description'
	) as $filter )
		remove_filter( $filter, 'wptexturize' );

comment:20 in reply to: ↑ 19   toscho17 months ago

Replying to nacin:

I'm wondering whether this is sufficient. While it will not catch *every* instance, it will catch all relevant core instances to dealing with content:

Yeah, I have written a plugin like this some time ago. It doesn’t catch the problem @jwz mentioned and of course not the hard coded calls. The new hook would help to enforce a consistent behavior.

comment:21 in reply to: ↑ 19   nacin17 months ago

The code in comment 8 could be rewritten as such:

$priority = remove_filter( 'the_content', 'wptexturize' );
$text = apply_filters( 'the_content', $text );
if ( false !== $priority )
	add_filter( 'the_content', 'wptexturize', $priority );
  • Keywords has-patch added
Note: See TracTickets for help on using tickets.