WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#18606 closed defect (bug) (worksforme)

wp_insert_term and wp_create_category fail on diacritics names

Reported by: abdessamad idrissi Owned by:
Milestone: Priority: normal
Severity: major Version: 3.2.1
Component: Taxonomy Keywords: close
Focuses: Cc:

Description

To create a category with the name

using either wp_insert_term or wp_create_category, an HTML entity representing the character must be given;
so this won't work :

wp_create_category( 'Ḍ' );
wp_insert_term( 'Ḍ' );

but this will work

wp_insert_term( mb_strtolower('Ḍ'), 'category',  array( 'slug' => html_entity_decode('Ḍ', ENT_QUOTES, 'UTF-8') ) );

What is strange is when the category is created using the admin panel it works with the original diacritics name,

Change History (3)

comment:1 follow-ups: johnbillion3 years ago

  • Keywords close added

If I understand correctly, you're doing this programatically, in which case it won't work because Ḍ is not an ASCII character and is therefore illegal in a PHP file. This has nothing to do with WordPress.

Entering Ḍ in the category/term forms in WordPress works because the character is UTF8 encoded when submitted.

comment:2 in reply to: ↑ 1 SergeyBiryukov3 years ago

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

Replying to johnbillion:

If I understand correctly, you're doing this programatically, in which case it won't work because Ḍ is not an ASCII character and is therefore illegal in a PHP file.

UTF-8 strings are perfectly valid in PHP files, as long as the file is saved in UTF-8.

Replying to abdessamad idrissi:

using either wp_insert_term or wp_create_category, an HTML entity representing the character must be given;

I've just tried to run your examples on 3.3-trunk, and they work fine. Make sure your PHP file is saved in UTF-8 (without byte order mark).

Note that you need to specify taxonomy for wp_insert_term():

wp_insert_term( 'Ḍ', 'category' );

comment:3 in reply to: ↑ 1 abdessamad idrissi3 years ago

Replying to SergeyBiryukov:

Make sure your PHP file is saved in UTF-8 (without byte order mark).

All my PHP files are saved in UTF-8 without including BOM.

Maybe it is fixed on 3.3 and I'm running 3.2.1

Note: See TracTickets for help on using tickets.