'/(ṁ|ṭ|ḍ|ṇ|ṅ|ñ|ḷ|ṃ)/'
is a valid regex to process what you want.
$string = '/(ṁ|ṭ|ḍ|ṇ|ṅ|ñ|ḷ|ṃ)/ is my regex and my chosen string is: ṁ, ṭ, ḍ, ṇ, ṅ, ñ, ḷ, ṃ';
echo preg_replace(
'/(ṁ|ṭ|ḍ|ṇ|ṅ|ñ|ḷ|ṃ)/',
'',
$string,
);
// Returns '/(|||||||)/ is my regex and my chosen string is: , , , , , , , '
EDIT: So the issue is that the slug had already been urlencode
d at this point.
Try this
add_filter( 'wp_insert_post_data', 'wpse_406105_process_permalink', 10, 1 );
/**
* 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 wpse_406105_process_permalink( $data ) {
if ( ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
$data['post_name'] =
preg_replace(
'/(%E1%B9%81|%E1%B9%AD|%E1%B8%8D|%E1%B9%87|%E1%B9%85|%C3%B1|%E1%B8%B7|%E1%B9%83)/i',
'',
$data['post_name']
);
}
return $data;
}
You don’t want a namespace there, you have converted it to make it a procedural function. It’s a good idea to make procedural functions fairly uniquely named to avoid conflicts so I have also changed the function from processPermalink()
.
It’s also worth noting that these do not function until you have published the post – drafts, auto drafts and pending posts are skipped.