Proper Way To Add A Function

I need to add a php function and am a little confused on how to implement it properly.

The function is: fn_text_space_to_underscore

It is used when the admin uploads an image (a logo) for the feature 'Manufacturer' to make sure a space in the file name is replaced with an underscore.

I created app/addons/my_changes/func.php with the code:

if (!defined('BOOTSTRAP')) { die('Access denied'); }

function fn_text_space_to_underscore($text)
if (AREA == 'A') {
$text = preg_replace("/\s/" , "_" , $text);
return $text;

I think I need to create app/addons/my_changes/init.php to include the function in the site. But, not sure how. Appreciate any help.

Try to use the update_image hook in the fn_update_image function (app/functions/fn.images.php) to update the $image_data['name'] parameter.

All you need is to create init.php file

if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }


and add the following function to the func.php file
function fn_my_changes_update_image(&$image_data, $image_id, $image_type, $images_path, $_data, $mime_type, $is_clone)
    if (!empty($image_data['name'])) {
        $image_data['name'] = fn_text_space_to_underscore($image_data['name']);
Then clear cache
(!) Not tested