SimplePortal

Customization => Custom Coding => Topic started by: SniffTheGlove on August 26, 2010, 02:54:23 PM

Title: Include php function on every page
Post by: SniffTheGlove on August 26, 2010, 02:54:23 PM
SMF 2.0RCS
SP 2.3.2

I have wrote a custom function that I pull in when needed via a php include_once() however this causing problems if I need to pull it in twice (Once in a Block and also in a custom page), so where would be the best place to put an include statement so that the functions would be available for Blocks and also custom pages.
Title: Re: Include php function on every page
Post by: excaliburj on August 26, 2010, 07:31:23 PM
If these are functions you ALWAYS want available, then I would just put it in the main index.php (though I'd 'require_once', instead).

Right around line 60 or so, you'll find a number of 'require_once' lines. If you put your file in the Sources directory, you can use the same $sourcedir variable those use.

But, you can always avoid even trying to load things like this twice if you just check that any of the functions inside that file already exists (well, NOT exists):
Code: [Select]
if (!function_exists('FUNCTION-NAME')) require_once('FUNCTION-FILE');
SimplePortal 2.3.8 © 2008-2024, SimplePortal