TangibleInc / template-system

A template system for WordPress with content type loops and conditions
https://docs.loopsandlogic.com/reference/template-system/
8 stars 3 forks source link

Convert accented characters to plain when saving template name #96

Closed BenTangible closed 7 months ago

BenTangible commented 7 months ago

As reported here, when saving a template that has accented characters in its title or name, these characters are currently encoded into URL-safe characters. In the case of accented characters, it would be preferable to save the letters without accents instead of encoding them (assuming accented characters can't safely be saved as-is).

For example, when creating a template with the title "Careful with your ácçènts!", L&L currently converts it to the name/slug careful-with-your-%c3%a1c%c3%a7%c3%a8nts-2. It would instead be preferable for it to save as careful-with-your-accents.

Edit: I just realized that Format slug exhibits this same behavior. While we're addressing this template-saving format, we should probably change Format slug to have it work the same way, keeping the letters without the accents rather than using URL-safe % characters. We already have Format url_query that encodes things as a URL query string, so we don't need Format slug to do that too, I would assume.

eliot-akira commented 7 months ago

The culprit was sanitize_title_with_dashes, which is used to generate a slug from a post title.

Limits the output to alphanumeric characters, underscore (_) and dash (-). ..This function does not replace special accented characters.

It actually removes all accented characters.

To convert them to regular characters, there's a function called remove_accents. In commit https://github.com/TangibleInc/template-system/commit/a7af4a1e258ba63ee620ab94847e67f6c39f5632, I updated the template save and format slugify functions to apply this.