What is the best place to put globally available functions?

Hello,

I am a first time Kirby user, and not very PHP savvy. I need a functionality that strips Greek language accents from uppercase text.
I used the following code:

function convertGreekAccents($str) {
	$unwanted_array = array('Ά' => 'Α', 'ά' => 'α', 'Έ' => 'Ε', 'έ' => 'ε', 'Ή' => 'Η', 'ή' => 'η', 'Ί' => 'Ι', 'ί' => 'ι', 'Ό' => 'Ο', 'ό' => 'ο', 'Ύ' => 'Υ', 'ύ' => 'υ', 'Ώ' => 'Ω', 'ώ' => 'ω', 'ϊ' => 'ι','ϋ' => 'υ', 'Ϊ' => 'ι', 'Ϋ' => 'Υ');
	$str = strtr($str, $unwanted_array);
	return $str;
}

I made a plugin with just this function, and it works, but it turns the panel into a blank page. What am I doing wrong?

It’s strange that your templates work but the Panel doesn’t. Does the Panel work if you remove the plugin again? Otherwise it’s probably a different issue.

Found the problem, I seem to have messed with the file encoding, sorry!

No problem at all, great that it works now.

To answer the topic’s question: placing globally available functions in a “plugin” script is alright. Something like site/plugins/custom.php (but you can use any name).

Kirby will load any PHP script in the plugins directory:

site/plugins/custom.php // will be included
site/plugins/something_else.php // likewise
site/plugins/whatever.php // same

and if you use a sub-directory for your plugin, it will load the script that uses the same name as the sub-directory:

site/plugins/myplugin/myplugin.php // will be included automatically
site/plugins/myplugin/other.php // but not this one
4 Likes