Make WordPress Core

Opened 12 years ago

Closed 10 years ago

Last modified 6 years ago

#19550 closed enhancement (fixed)

Please provide option to disable wptexturize entirely

Reported by: jwz's profile jwz Owned by: drewapicture's profile DrewAPicture
Milestone: 4.0 Priority: normal
Severity: minor Version: 3.3
Component: Formatting Keywords: has-patch wptexturize 4.0-early needs-docs
Focuses: docs Cc:

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 (4)

patch-wptexturize.patch (959 bytes) - added by toscho 12 years ago.
Add 'do_texturize' filter
19550.diff (1.1 KB) - added by nacin 12 years ago.
A run-once filter.
19550.2.diff (1003 bytes) - added by SergeyBiryukov 10 years ago.
19550-docs.diff (725 bytes) - added by miqrogroove 10 years ago.

Download all attachments as: .zip

Change History (44)

#1 @scribu
12 years ago

  • 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.

#2 @toscho
12 years ago

  • 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.

#3 @scribu
12 years ago

  • 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.

#4 @toscho
12 years ago

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.

#5 follow-up: @scribu
12 years 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']);

#6 in reply to: ↑ 5 @toscho
12 years ago

Replying to scribu:

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

Okay, these cases aren’t important. :)

#7 @scribu
12 years ago

Relevant: #19602

#8 @jwz
12 years ago

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.

#9 @toscho
12 years ago

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 …

#10 @jwz
12 years ago

Sure, that'd work for me...

@toscho
12 years ago

Add 'do_texturize' filter

#11 @toscho
12 years ago

To disable wptexturize() globally now use:

add_filter( 'do_texturize', '__return_false' );

#12 follow-up: @scribu
12 years ago

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

#13 @toscho
12 years ago

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. :)

#14 follow-up: @dd32
12 years 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)

#15 in reply to: ↑ 14 ; follow-up: @toscho
12 years 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.

#16 in reply to: ↑ 15 @scribu
12 years 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.

#17 @toscho
12 years ago

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.

#18 in reply to: ↑ 12 @jwz
12 years 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.

@nacin
12 years ago

A run-once filter.

#19 follow-ups: @nacin
12 years 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' );

#20 in reply to: ↑ 19 @toscho
12 years 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.

#21 in reply to: ↑ 19 @nacin
12 years 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 );

#22 @SergeyBiryukov
12 years ago

  • Keywords has-patch added

#23 @context
10 years ago

  • Cc context added

#24 @nacin
10 years ago

  • Milestone changed from Awaiting Review to Future Release

It seems like 19550.diff would work.

#25 @nacin
10 years ago

  • Keywords wptexturize added

#26 follow-up: @miqrogroove
10 years ago

Testing the filter's result before running the filter seems unwise in 19550.diff.

#27 in reply to: ↑ 26 ; follow-up: @SergeyBiryukov
10 years ago

Replying to miqrogroove:

Testing the filter's result before running the filter seems unwise in 19550.diff.

The result in stored in a static variable for subsequent calls, I don't see anything wrong with that.

#28 in reply to: ↑ 27 @miqrogroove
10 years ago

Replying to SergeyBiryukov:

The result in stored in a static variable for subsequent calls, I don't see anything wrong with that.

If the purpose of the filter is to prevent wptexturize from altering the output, this patch will not do that. The filter result has to be tested after the filter, not before.

#29 @miqrogroove
10 years ago

See for yourself:

<?php
echo wptexturize( 'This is a test' );

function wptexturize($text) { 
    static $opening_quote, $run_texturize = true; 
    if ( false === $run_texturize )
        return $text; 
    if ( empty( $opening_quote ) ) { 
        $run_texturize = FALSE;  // apply_filters( 'run_wptexturize', $run_texturize ); 
        $opening_quote = '&#8220;';
    }
    $text = 'fail!';
    return $text;
}
?>
Last edited 10 years ago by miqrogroove (previous) (diff)

#30 @SergeyBiryukov
10 years ago

I see what you mean, the filter only works for subsequent calls, not for the initial one.

19550.2.diff should work for every call, including the initial one.

#31 @miqrogroove
10 years ago

Now it looks like a good run-once filter.

I suggest 3.9 Milestone. Can't see any reason to keep this ticket open beyond that.

#32 @SergeyBiryukov
10 years ago

  • Keywords 4.0-early added

#33 @wonderboymusic
10 years ago

  • Milestone changed from Future Release to 4.0

#34 @wonderboymusic
10 years ago

In 28715:

Add a $run_texturize static var to wptexturize() that is filterable via a new run-once filter: 'run_wptexturize'. Allows user to disable texturization.

Needs filter docs.

Props nacin, SergeyBiryukov.
See #19550.

#35 @wonderboymusic
10 years ago

  • Focuses docs added
  • Keywords needs-docs added

#36 @miqrogroove
10 years ago

Filter docs attached.

#37 @DrewAPicture
10 years ago

  • Owner set to DrewAPicture
  • Resolution set to fixed
  • Status changed from reopened to closed

In 28723:

Add inline documentation for the run_wptexturize filter.

Props miqrogroove for the original patch.
Fixes #19550.

#38 follow-up: @TomasM
10 years ago

Hello, I would like to ask for the usage example. I would like to disable certain texturized elements, like quotes. What code should I add to functions.php? Currently I use in parent theme:

remove_filter('the_content', 'wptexturize');
remove_filter ('the_excerpt', 'wptexturize');
remove_filter ('comment_text', 'wptexturize');

Also what code could I use in a child theme to enable wptexturize?

Thank you!

#39 @SergeyBiryukov
9 years ago

#17926 was marked as a duplicate.

#40 in reply to: ↑ 38 @pixeline
6 years ago

Replying to TomasM:

Hello, I would like to ask for the usage example. I would like to disable certain texturized elements, like quotes. What code should I add to functions.php? Currently I use in parent theme:

remove_filter('the_content', 'wptexturize');
remove_filter ('the_excerpt', 'wptexturize');
remove_filter ('comment_text', 'wptexturize');

Also what code could I use in a child theme to enable wptexturize?

Thank you!

To disable entirely the curly replacement throughout your site, simply add to your functions.php :

add_filter('run_wptexturize', '__return_false');
Note: See TracTickets for help on using tickets.