Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

How to define global functions in Winter CMS

7
by mjauvin, last modified on April 23rd, 2023 - Previously published on OctoberTricks

I've seen this question asked over and over again, here's how to do this cleanly and easily with Winter...

Just add a file called "init.php" within your plugin's root:

init.php:

<?php

if (!function_exists('myGlobalFunction')) {
    function myGlobalFunction()
    {
        return "Hello World!";
    }
}

Discussion

2 comments

0
AIC BV
Post on January 7th, 2022 11:08 AM

How do you call the global function from a settings model for example?

0
BennoThommo
Post on January 13th, 2022 5:04 AM

Since it's a global command, you just use myGlobalFunction() in the Settings model, using the example above.

We use cookies to measure the performance of this website. Do you want to accept these cookies?