Make WordPress Core

Opened 7 weeks ago

Last modified 5 weeks ago

#63192 new feature request

wptexturize add filter for disable some replacement

Reported by: jubasik23's profile jubasik23 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Formatting Keywords: has-patch changes-requested
Focuses: Cc:

Description

I need to have ability to keep wptexturize but disable specific replacemnt. In my case I need to deactivate replace for double dash.

Change History (4)

This ticket was mentioned in PR #8610 on WordPress/wordpress-develop by @jubasik23.


7 weeks ago
#1

  • Keywords has-patch added

## Description

Introduces a new filter dash_wptexturize to provide more granular control over dash replacements in WordPress's texturize functionality.

### Proposed Change

  • Added a new filter dash_wptexturize that allows developers to programmatically disable dash replacements
  • The filter defaults to true, maintaining current default behavior
  • Allows for selective disabling of dash-to-typography conversions

### Motivation
Provide more flexibility for developers who need precise control over typography transformations, especially in contexts where automatic dash replacements are undesirable.

### Example Usage
`php
add_filter('dash_wptexturize', 'return_false');

#2 follow-up: @audrasjb
7 weeks ago

  • Component changed from General to Formatting
  • Keywords changes-requested added

Hello @jubasik23, welcome to WordPress Core Trac and thanks for the ticket and patch,

The proposed PR only fixes this specific need, which is not sufficient.
If we want to add a filter, we should pass the whole set of character replacements as an argument array, to allow developers to filter each replacement character.

#3 in reply to: ↑ 2 @jubasik23
7 weeks ago

Replying to audrasjb:

Hello @jubasik23, welcome to WordPress Core Trac and thanks for the ticket and patch,

The proposed PR only fixes this specific need, which is not sufficient.
If we want to add a filter, we should pass the whole set of character replacements as an argument array, to allow developers to filter each replacement character.

Noted.
Thanks,

#4 @sabernhardt
5 weeks ago

I do not like how the current patch defines original characters in a $default_replacements array, and they are not always correct. For example, -- can become an en dash, but with spaces around the two hyphens ( -- ) they change to an em dash.

If the characters list is made filterable, wptexturize probably could check whether each character is enabled before running any replacements with it.

If you only want to replace the en dash with two hyphens, you technically could do that now with the 'gettext_with_context' hook.

Note: See TracTickets for help on using tickets.