feat: AutoLoad plugins init.php, by default disabled

This commit is contained in:
slawkens 2025-06-03 08:52:33 +02:00
parent 8fdea94376
commit 207d6bc691
2 changed files with 25 additions and 0 deletions

View File

@ -12,6 +12,7 @@ use DebugBar\StandardDebugBar;
use MyAAC\Cache\Cache; use MyAAC\Cache\Cache;
use MyAAC\CsrfToken; use MyAAC\CsrfToken;
use MyAAC\Hooks; use MyAAC\Hooks;
use MyAAC\Plugins;
use MyAAC\Models\Town; use MyAAC\Models\Town;
use MyAAC\Settings; use MyAAC\Settings;
@ -46,6 +47,11 @@ if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HT
global $cache; global $cache;
$cache = Cache::getInstance(); $cache = Cache::getInstance();
// load plugins init.php
foreach (Plugins::getInits() as $init) {
require $init;
}
// event system // event system
global $hooks; global $hooks;
$hooks = new Hooks(); $hooks = new Hooks();

View File

@ -11,6 +11,25 @@ class Plugins {
private static $error = null; private static $error = null;
private static $plugin_json = []; private static $plugin_json = [];
public static function getInits()
{
return Cache::remember('plugins_inits', 10 * 60, function () {
$inits = [];
foreach(self::getAllPluginsJson() as $plugin) {
if (!self::getAutoLoadOption($plugin, 'init', false)) {
continue;
}
$pluginInits = glob(PLUGINS . $plugin['filename'] . '/init.php');
foreach ($pluginInits as $path) {
$inits[] = $path;
}
}
return $inits;
});
}
public static function getAdminPages() public static function getAdminPages()
{ {
return Cache::remember('plugins_admin_pages', 10 * 60, function () { return Cache::remember('plugins_admin_pages', 10 * 60, function () {