I'd like to replace straight "dumb" quotes with curly “smart” quotes in my content blocks. There is an
existing php tool that does this nicely, and it's essentially a powerful str_replace so for the sake of simplicity let's imagine the code is:
Code: Select all
str_replace("cat","dog",$raw_text);
I understand how I could use this in a UDT and pass content to it from my template - something like:
Code: Select all
$raw_text = $params['text'];
$new_text = str_replace("cat","dog",$raw_text);
return $new_text;
But this calls the UDT every time the page is loaded when I really only need the replacement to be done once. I think it would be better to send text to the UDT as it comes from Edit Content screen (before it is saved to the database), process the text in the UDT, and then save the modified text to the database. To do this I expect I need to attach my UDT to an event such as ContentEditPre, but I'm not sure how I get the $raw_text and how I save the $new_text to the database.
Also, can I process multiple content blocks through the UDT if there is more than one in a page?