Stripping unicode characters out of slug

Question

I am trying to strip the following characters out of slugs: ṁ, ṭ, ḍ, ṇ, ṅ, ñ, ḷ, ṃ.

I found this code here (note: I have removed public in order to get it to work)

add_action('wp_insert_post_data', __NAMESPACE__ . 'processPermalink');
/**
 * Processes the permalink so we can remove any characters that may cause a problem when communicating
 * with the API.
 *
 * @param  array $data The array of information about the post.
 * @return array $data The data without the malformed information in the post name for the URL.
 */
function processPermalink($data)
{
    if (!in_array($data['post_status'], array('draft', 'pending', 'auto-draft'))) {
        $data['post_name'] =
            preg_replace(
                '/(%ef%b8%8f|™|®|©|™|®|©|™|®|©)/',
                '',
                $data['post_name']
            );
    }
    return $data;
}

I have tried replacing the preg_replace in these three ways, but none of them work (the original code does what it shoudl):

'/(⃨⃨⃨ṁ|ṭ|ḍ|ṇ|ṅ|ñ|ḷ|ṃ)/'
'/(ṁ|ṭ|ḍ|ṇ|ṅ|ñ|ḷ|ṃ)/'
'/(ṁ|ṭ|ḍ|ṇ|ṅ|ñ|ḷ|ṃ)/'

None of them successfully strip out the characters.

Any ideas? Thanks!

0
HopefullCoder 3 months 2022-05-25T22:38:02-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse