2020-12-08 21:15

Fixed event slug sanitization for accents and unicode characters

Problem this Pull Request solves

https://github.com/eventespresso/event-espresso-core/issues/575 Fixed event slug sanitization for accents and unicode characters. Before they would get percent-encoded, which should have been ok, but WP wasn't handling them correctly (see https://core.trac.wordpress.org/ticket/44759). So, our solution is to leave them as unicode characters, which is what https://wordpress.org/plugins/custom-post-type-ui/ and WooCommerce do. We do attempt do a bit of sanitization on the admin's submitted slug though- we do the same sanitization as what's done on post slugs (run it through sanitize_title()), except we undo the percent encoding of unicode characters. sanitize_title() does remove accents, which seems unnecessary to me, but if site owners take issue with that, they would have already taken issue with that in post titles (and they could use this code snippet I created: https://github.com/eventespresso/ee-code-snippet-library/blob/master/templates/mn_allow_accents_in_slugs.php), in which case those improvements would apply to our slug too, because we're using the same filter. Note: I asked about why WordPress removes accented characters from slugs in the first place on stack overflow: https://wordpress.stackexchange.com/questions/310894/why-dont-wordpress-post-slugs-allow-accents

How has this been tested

  • [x] Go to events -> templates and change the events slug to something with accented characters, like Áventos and save it. The accents should be removed, and most importantly, you should still be able to view events on the front-end
  • [x] Now change the events slug to have other unicode characters in it, like 中文 and save it. They should be left intact, and the new event permalinks should stil lwork
  • [x] Try to make an invalid events slug by adding every crazy character and bit of hacky HTML you can, and save. All that bad stuff should get thrown out, and you should just be left with a valid slug
  • [x] Try to save a slug with HTML or javascript or CSS or PHP or whatever crazy hacky thing you can think of. That should all be removed as hoped-for. Also, try to put a space in a slug. That should be turned into a dash as usual.


  • [ ] I have added a changelog entry for this pull request
  • [ ] I have read the documentation relating to systems affected by this pull request, see https://github.com/eventespresso/event-espresso-core/tree/master/docs
  • [ ] User input is adequately validated and sanitized
  • [ ] all publicly displayed strings are internationalized (usually using esc_html__(), see https://codex.wordpress.org/I18n_for_WordPress_Developers)
  • [ ] My code is tested.
  • [ ] My code follows the Event Espresso code style.
  • [ ] My code has proper inline documentation.
  • [ ] My code accounts for when the site is Maintenance Mode (MM2 especially disallows usage of models)


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39822443 weixin_39822443 5月前

    Sorry Josh, passing your way again, just because you're so good at reporting issues! (I think it's fine to pass it on to someone else if you like). Testing notes on my first comment.

    点赞 评论 复制链接分享
  • weixin_39650784 weixin_39650784 5月前

    This works great and can be merged.

    点赞 评论 复制链接分享
  • weixin_39822443 weixin_39822443 5月前

    great; Travis is having issues so I'm running tests locally and am taking off. If it all looks good I'll merge when I get back

    点赞 评论 复制链接分享
  • weixin_39822443 weixin_39822443 5月前

    there were some build issues, but unit tests pass locally

    点赞 评论 复制链接分享